I'm currently trying to combine my mind around Scala with the intention of using it for my next project, which is supposed to deal with DICOM. DICOM has a fairly broad specification, which covers more than a thousand pages of the standard. My understanding of DICOM is quite limited, but in short, DICOM objects β IODs (definition of an informational object) βconsist of modules, and modules are a set of name-value attribute pairs. This is further complicated by the optionality of certain modules and attributes. For example:
SimpleImageIOD: { PatientModule: { name: String dateOfBirth: DateTime } StudyModule: { name: String date: DateTime (optional) } SeriesModule: { name: String } ImageModule: { height: Integer width: Integer pixelSize: Double (optional) } EquipmentModule: { (optional) type: String } }
There are tons of modules, they can be composed in various combinations forming different IODs. Scala, in turn, has many modeling capabilities with all the features, class classes, dynamic classes, etc. How could you model such a domain in Scala? I am new to the language, but I thought of using immutable case classes to define modules, then combining them into different IODs and using lenses to update:
case class Patient(name: String, dateOfBirth: DateTime) case class Study(name: String, date: Option[DateTime]) case class Series(name: String) case class Image(height: Integer, width: Integer, pixelSize: Option[Double]) case class Equipment(type: String) case class SimpleImageIOD(patient: Patient, study: Study, series: Series, image: Image, equipment: Option[Equipment]) object Patient { val nameL: Lens[Patient, String] = ... val dateOfBirthL: Lens[Patient, DateTime] = ... } object SimpleImageIOD { val patientL: Lens[SimpleImageIOD, Patient] = ... val patientNamel = patientL andThen Patient.nameL }
Etc etc. As for lenses, the problem of coding the entire template may arise - there will be an order of M x N x L lenses to cover the entire domain for the M IOD, N and L modules M Also, the optionality of some fields complicates the task, at least with scalaz-seven .
What other viable approaches are available out there that are in line with the spirit of Scala?