aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-10-02 01:05:42 -0700
committervlad <vlad@driver.xyz>2017-10-02 01:05:42 -0700
commitd0482b45b6f9149f050c5e5a6dbab6f059229282 (patch)
treec82ce57536dc2ec51b34f1b6f8159835d95c2cc6
parentc5b7f009479930b82f0fb839971eeb2c457dcef0 (diff)
downloadrest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.tar.gz
rest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.tar.bz2
rest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.zip
DocumentType and ProviderType as enumsv0.5.3
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala364
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala8
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala16
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala19
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala19
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala16
12 files changed, 326 insertions, 163 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
index a3f48d1..83c4e6f 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
@@ -62,7 +62,6 @@ object CustomSwaggerJsonFormats {
import xyz.driver.pdsuidomain.formats.json.sprayformats.document
import xyz.driver.pdsuidomain.formats.json.sprayformats.documentissue
import xyz.driver.pdsuidomain.formats.json.sprayformats.documenthistory
- import xyz.driver.pdsuidomain.formats.json.sprayformats.providertype
import xyz.driver.pdsuidomain.formats.json.sprayformats.record
import xyz.driver.pdsuidomain.formats.json.sprayformats.recordissue
import xyz.driver.pdsuidomain.formats.json.sprayformats.recordhistory
@@ -89,7 +88,7 @@ object CustomSwaggerJsonFormats {
classOf[DocumentHistory.State] ->
documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()),
classOf[ProviderType] ->
- providertype.providerTypeFormat.write(rep.MedicalRecordGen.nextProviderType()),
+ record.providerTypeFormat.write(rep.MedicalRecordGen.nextProviderType()),
classOf[TextJson[List[MedicalRecord.Meta]]] ->
record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()),
classOf[MedicalRecord] ->
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
index 839fead..eccb254 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
@@ -15,74 +15,195 @@ import xyz.driver.pdsuicommon.validation.Validators.Validator
import xyz.driver.pdsuidomain.entities.Document.Meta
import scalaz.Equal
+import scalaz.syntax.equal._
+import scalaz.Scalaz.stringInstance
-final case class ProviderType(id: LongId[ProviderType], name: String)
+sealed trait ProviderType {
+ val id: LongId[ProviderType]
+ val name: String
+}
object ProviderType {
- sealed trait ProviderTypeName
- case object MedicalOncology extends ProviderTypeName
- case object Surgery extends ProviderTypeName
- case object Pathology extends ProviderTypeName
- case object MolecularPathology extends ProviderTypeName
- case object LaboratoryMedicine extends ProviderTypeName
- case object Radiology extends ProviderTypeName
- case object InterventionalRadiology extends ProviderTypeName
- case object RadiationOncology extends ProviderTypeName
- case object PrimaryCare extends ProviderTypeName
- case object Cardiology extends ProviderTypeName
- case object Dermatology extends ProviderTypeName
- case object Ophthalmology extends ProviderTypeName
- case object Gastroenterology extends ProviderTypeName
- case object Neurology extends ProviderTypeName
- case object Psychiatry extends ProviderTypeName
- case object Gynecology extends ProviderTypeName
- case object InfectiousDisease extends ProviderTypeName
- case object Immunology extends ProviderTypeName
- case object Nephrology extends ProviderTypeName
- case object Rheumatology extends ProviderTypeName
- case object Cytology extends ProviderTypeName
- case object Otolaryngology extends ProviderTypeName
- case object Anesthesiology extends ProviderTypeName
- case object Urology extends ProviderTypeName
- case object PalliativeCare extends ProviderTypeName
- case object EmergencyMedicine extends ProviderTypeName
- case object SocialWork extends ProviderTypeName
- case object NA extends ProviderTypeName
- case object Other extends ProviderTypeName
-
- def fromString(txt: String): Option[ProviderTypeName] = {
- txt match {
- case "Medical Oncology" => Some(MedicalOncology)
- case "Surgery" => Some(Surgery)
- case "Pathology" => Some(Pathology)
- case "Molecular Pathology" => Some(MolecularPathology)
- case "LaboratoryMedicine" => Some(LaboratoryMedicine)
- case "Radiology" => Some(Radiology)
- case "Interventional Radiology" => Some(InterventionalRadiology)
- case "Radiation Oncology" => Some(RadiationOncology)
- case "Primary Care" => Some(PrimaryCare)
- case "Cardiology" => Some(Cardiology)
- case "Dermatology" => Some(Dermatology)
- case "Ophthalmology" => Some(Ophthalmology)
- case "Gastroenterology" => Some(Gastroenterology)
- case "Neurology" => Some(Neurology)
- case "Psychiatry" => Some(Psychiatry)
- case "Gynecology" => Some(Gynecology)
- case "Infectious Disease" => Some(InfectiousDisease)
- case "Immunology" => Some(Immunology)
- case "Nephrology" => Some(Nephrology)
- case "Rheumatology" => Some(Rheumatology)
- case "Cytology" => Some(Cytology)
- case "Otolaryngology" => Some(Otolaryngology)
- case "Anesthesiology" => Some(Anesthesiology)
- case "Urology" => Some(Urology)
- case "Palliative Care" => Some(PalliativeCare)
- case "Emergency Medicine" => Some(EmergencyMedicine)
- case "Social Work" => Some(SocialWork)
- case "N/A" => Some(NA)
- case "Other" => Some(Other)
- case _ => None
- }
+
+ case object MedicalOncology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](1)
+ val name: String = "Medical Oncology"
+ }
+
+ case object Surgery extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](2)
+ val name: String = "Surgery"
+ }
+
+ case object Pathology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](3)
+ val name: String = "Pathology"
+ }
+
+ case object MolecularPathology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](4)
+ val name: String = "Molecular Pathology"
+ }
+
+ case object LaboratoryMedicine extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](5)
+ val name: String = "Laboratory Medicine"
+ }
+
+ case object Radiology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](6)
+ val name: String = "Radiology"
+ }
+
+ case object InterventionalRadiology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](7)
+ val name: String = "Interventional Radiology"
+ }
+
+ case object RadiationOncology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](8)
+ val name: String = "Radiation Oncology"
+ }
+
+ case object PrimaryCare extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](9)
+ val name: String = "Primary Care"
+ }
+
+ case object Cardiology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](10)
+ val name: String = "Cardiology"
+ }
+
+ case object Dermatology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](11)
+ val name: String = "Dermatology"
+ }
+
+ case object Ophthalmology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](12)
+ val name: String = "Ophthalmology"
+ }
+
+ case object Gastroenterology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](13)
+ val name: String = "Gastroenterology"
+ }
+
+ case object Neurology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](14)
+ val name: String = "Neurology"
+ }
+
+ case object Psychiatry extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](15)
+ val name: String = "Psychiatry"
+ }
+
+ case object Gynecology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](16)
+ val name: String = "Gynecology"
+ }
+
+ case object InfectiousDisease extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](17)
+ val name: String = "Infectious Disease"
+ }
+
+ case object Immunology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](18)
+ val name: String = "Immunology"
+ }
+
+ case object Nephrology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](19)
+ val name: String = "Nephrology"
+ }
+
+ case object Rheumatology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](20)
+ val name: String = "Rheumatology"
+ }
+
+ case object Cytology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](21)
+ val name: String = "Cytology"
+ }
+
+ case object Otolaryngology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](22)
+ val name: String = "Otolaryngology"
+ }
+
+ case object Anesthesiology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](23)
+ val name: String = "Anesthesiology"
+ }
+
+ case object Urology extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](24)
+ val name: String = "Urology"
+ }
+
+ case object PalliativeCare extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](25)
+ val name: String = "Palliative Care"
+ }
+
+ case object EmergencyMedicine extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](26)
+ val name: String = "Emergency Medicine"
+ }
+
+ case object SocialWork extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](27)
+ val name: String = "Social Work"
+ }
+
+ case object NA extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](28)
+ val name: String = "N/A"
+ }
+
+ case object Other extends ProviderType {
+ val id: LongId[ProviderType] = LongId[ProviderType](29)
+ val name: String = "Other"
+ }
+
+ val All = Seq[ProviderType](
+ MedicalOncology,
+ Surgery,
+ Pathology,
+ MolecularPathology,
+ LaboratoryMedicine,
+ Radiology,
+ InterventionalRadiology,
+ RadiationOncology,
+ PrimaryCare,
+ Cardiology,
+ Dermatology,
+ Ophthalmology,
+ Gastroenterology,
+ Neurology,
+ Psychiatry,
+ Gynecology,
+ InfectiousDisease,
+ Immunology,
+ Nephrology,
+ Rheumatology,
+ Cytology,
+ Otolaryngology,
+ Anesthesiology,
+ Urology,
+ PalliativeCare,
+ EmergencyMedicine,
+ SocialWork,
+ NA,
+ Other
+ )
+
+ def fromString(txt: String): Option[ProviderType] = {
+ All.find(_.name === txt)
}
implicit def toPhiString(x: ProviderType): PhiString = {
@@ -91,39 +212,90 @@ object ProviderType {
}
}
-final case class DocumentType(id: LongId[DocumentType], name: String)
+sealed trait DocumentType {
+ val id: LongId[DocumentType]
+ val name: String
+}
object DocumentType {
- sealed trait DocumentTypeName
- case object OutpatientPhysicianNote extends DocumentTypeName
- case object DischargeNote extends DocumentTypeName
- case object LaboratoryReport extends DocumentTypeName
- case object MedicationList extends DocumentTypeName
- case object HospitalizationNote extends DocumentTypeName
- case object PathologyReport extends DocumentTypeName
- case object RadiologyReport extends DocumentTypeName
- case object OperativeProcedureReport extends DocumentTypeName
- case object MedicationAdministration extends DocumentTypeName
- case object SocialWorkCaseManagementNote extends DocumentTypeName
- case object NonPhysicianProviderNote extends DocumentTypeName
- case object Administrative extends DocumentTypeName
-
- def fromString(txt: String): Option[DocumentTypeName] = {
- txt match {
- case "Outpatient Physician Note" => Some(OutpatientPhysicianNote)
- case "Discharge Note" => Some(DischargeNote)
- case "Laboratory Report" => Some(LaboratoryReport)
- case "Medication List" => Some(MedicationList)
- case "Hospitalization Note" => Some(HospitalizationNote)
- case "Pathology Report" => Some(PathologyReport)
- case "Radiology Report" => Some(RadiologyReport)
- case "Operative/Procedure Report" => Some(OperativeProcedureReport)
- case "Medication Administration" => Some(MedicationAdministration)
- case "Social Work/Case Management Note" => Some(SocialWorkCaseManagementNote)
- case "Non-physician Provider Note" => Some(NonPhysicianProviderNote)
- case "Administrative" => Some(Administrative)
- case _ => None
- }
+
+ case object OutpatientPhysicianNote extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](1)
+ val name: String = "Outpatient Physician Note"
+ }
+
+ case object DischargeNote extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](2)
+ val name: String = "Discharge Note"
+ }
+
+ case object LaboratoryReport extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](3)
+ val name: String = "Laboratory Report"
+ }
+
+ case object MedicationList extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](4)
+ val name: String = "Medication List"
+ }
+
+ case object HospitalizationNote extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](5)
+ val name: String = "Hospitalization Note"
+ }
+
+ case object PathologyReport extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](6)
+ val name: String = "Pathology Report"
+ }
+
+ case object RadiologyReport extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](7)
+ val name: String = "Radiology Report"
+ }
+
+ case object OperativeProcedureReport extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](8)
+ val name: String = "Operative/Procedure Report"
+ }
+
+ case object MedicationAdministration extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](9)
+ val name: String = "Medication Administration"
+ }
+
+ case object SocialWorkCaseManagementNote extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](10)
+ val name: String = "Social Work/Case Management Note"
+ }
+
+ case object NonPhysicianProviderNote extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](11)
+ val name: String = "Non-physician Provider Note"
+ }
+
+ case object Administrative extends DocumentType {
+ val id: LongId[DocumentType] = LongId[DocumentType](12)
+ val name: String = "Administrative"
+ }
+
+ val All = Seq[DocumentType](
+ OutpatientPhysicianNote,
+ DischargeNote,
+ LaboratoryReport,
+ MedicationList,
+ HospitalizationNote,
+ PathologyReport,
+ RadiologyReport,
+ OperativeProcedureReport,
+ MedicationAdministration,
+ SocialWorkCaseManagementNote,
+ NonPhysicianProviderNote,
+ Administrative
+ )
+
+ def fromString(txt: String): Option[DocumentType] = {
+ All.find(_.name === txt)
}
implicit def equal: Equal[DocumentType] = Equal.equal[DocumentType](_ == _)
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala
index 6d5330e..1ac75ab 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala
@@ -75,12 +75,8 @@ object DocumentGen {
)
}
- def nextDocumentType(): DocumentType = {
- DocumentType(
- id = nextLongId[DocumentType],
- name = nextString()
- )
- }
+ def nextDocumentType(): DocumentType =
+ generators.oneOf(DocumentType.All: _*)
def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = {
val pages = nextStartAndEndPagesOption()
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala
index e3ef6bc..3fcc4cb 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala
@@ -7,24 +7,12 @@ import xyz.driver.pdsuidomain.fakes.entities.common._
import xyz.driver.pdsuidomain.entities._
import xyz.driver.pdsuidomain.entities.export.patient._
import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId}
+import xyz.driver.pdsuidomain.fakes.entities.rep.DocumentGen._
+import xyz.driver.pdsuidomain.fakes.entities.rep.MedicalRecordGen._
object ExportPatientGen {
private val maxItemsInCollectionNumber = 3
- def nextDocumentType(documentTypeId: LongId[DocumentType] = nextLongId): DocumentType = {
- DocumentType(
- documentTypeId,
- nextString()
- )
- }
-
- def nextProviderType(providerTypeId: LongId[ProviderType] = nextLongId): ProviderType = {
- ProviderType(
- providerTypeId,
- nextString()
- )
- }
-
def nextExportPatientLabelEvidenceDocument(documentId: LongId[Document]): ExportPatientLabelEvidenceDocument = {
ExportPatientLabelEvidenceDocument(
documentId = documentId,
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
index 023dc00..2777116 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
@@ -142,6 +142,6 @@ object MedicalRecordGen {
}
def nextProviderType(): ProviderType =
- ProviderType(id = nextLongId[ProviderType], name = nextString())
+ generators.oneOf(ProviderType.All: _*)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
index 8b4974f..22bea6b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
@@ -2,15 +2,14 @@ package xyz.driver.pdsuidomain.formats.json.document
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.DocumentType
final case class ApiDocumentType(id: Long, name: String) {
- def toDomain = DocumentType(
- id = LongId(this.id),
- name = this.name
- )
+ def toDomain: DocumentType =
+ DocumentType
+ .fromString(name)
+ .getOrElse(throw new IllegalArgumentException(s"Unknown document type name $name"))
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
index c0eddad..9c0c216 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
@@ -2,15 +2,14 @@ package xyz.driver.pdsuidomain.formats.json.document
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.ProviderType
final case class ApiProviderType(id: Long, name: String) {
- def toDomain = ProviderType(
- id = LongId(this.id),
- name = this.name
- )
+ def toDomain: ProviderType =
+ ProviderType
+ .fromString(name)
+ .getOrElse(throw new IllegalArgumentException(s"Unknown provider type name $name"))
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala
index ff0603a..e3f6a9c 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala
@@ -28,7 +28,24 @@ object document {
implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply)
- implicit val documentTypeFormat: RootJsonFormat[DocumentType] = jsonFormat2(DocumentType.apply)
+ implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] {
+ override def read(json: JsValue): DocumentType = json match {
+ case JsObject(fields) =>
+ val name = fields
+ .get("name")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json"))
+
+ DocumentType
+ .fromString(name)
+ .getOrElse(deserializationError(s"Unknown document type: $name"))
+
+ case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json")
+ }
+
+ override def write(obj: DocumentType) =
+ JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
+ }
implicit val fullDocumentMetaFormat = new RootJsonFormat[TextJson[Meta]] {
override def write(obj: TextJson[Meta]): JsValue = obj.content.toJson
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala
deleted file mode 100644
index 7ec6ef5..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.sprayformats
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities.DocumentType
-
-object documenttype {
- import DefaultJsonProtocol._
- import common._
-
- implicit val format: RootJsonFormat[DocumentType] = jsonFormat2(DocumentType.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala
deleted file mode 100644
index 385feb2..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.sprayformats
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities.ProviderType
-
-object providertype {
- import DefaultJsonProtocol._
- import common._
-
- implicit val providerTypeFormat: RootJsonFormat[ProviderType] = jsonFormat2(ProviderType.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala
index 6b69873..8eef44a 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala
@@ -36,7 +36,24 @@ object record {
}
}
- implicit val providerTypeFormat = jsonFormat2(ProviderType.apply)
+ implicit val providerTypeFormat: RootJsonFormat[ProviderType] = new RootJsonFormat[ProviderType] {
+ override def read(json: JsValue): ProviderType = json match {
+ case JsObject(fields) =>
+ val name = fields
+ .get("name")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json"))
+
+ ProviderType
+ .fromString(name)
+ .getOrElse(deserializationError(s"Unknown provider type: $name"))
+
+ case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json")
+ }
+
+ override def write(obj: ProviderType) =
+ JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
+ }
implicit val caseIdFormat = new RootJsonFormat[CaseId] {
override def write(caseId: CaseId): JsString = JsString(caseId.toString)
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
index 52c8c81..a451905 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
@@ -16,8 +16,8 @@ class ExportFormatSuite extends FlatSpec with Matchers {
val document = ExportPatientLabelEvidenceDocument(
documentId = LongId(101),
requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")),
- documentType = DocumentType(LongId[DocumentType](1), "document type"),
- providerType = ProviderType(LongId[ProviderType](2), "provider type"),
+ documentType = DocumentType.OutpatientPhysicianNote,
+ providerType = ProviderType.Surgery,
date = LocalDate.parse("2017-08-10")
)
@@ -67,14 +67,14 @@ class ExportFormatSuite extends FlatSpec with Matchers {
writtenJson should be(
"""{"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","labelVersion":1,"labels":[{"labelId":1,"evidence":[{"evidenceId":11,
"labelValue":"Yes","evidenceText":"evidence text 11","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
- "documentType":{"id":1,"name":"document type"},"providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}},
+ "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}},
{"evidenceId":12,"labelValue":"No","evidenceText":"evidence text 12","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
- "documentType":{"id":1,"name":"document type"},"providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}}]},
+ "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}}]},
{"labelId":2,"evidence":[{"evidenceId":12,"labelValue":"Yes","evidenceText":"evidence text 12","document":
- {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"document type"},
- "providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}},{"evidenceId":13,"labelValue":"Yes","evidenceText":"evidence text 13",
- "document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"document type"},
- "providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}}]}]}""".parseJson)
+ {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"Outpatient Physician Note"},
+ "providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}},{"evidenceId":13,"labelValue":"Yes","evidenceText":"evidence text 13",
+ "document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"Outpatient Physician Note"},
+ "providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}}]}]}""".parseJson)
}
"Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in {