diff options
author | Jakob Odersky <jakob@driver.xyz> | 2017-10-30 14:17:28 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@driver.xyz> | 2017-10-30 14:30:28 -0700 |
commit | 344996ef6d19551d7cbff717ada35718afcf346a (patch) | |
tree | 42d6a85b8898ac228971c1c0bdb083145f906701 /src/main/scala/xyz/driver/pdsuidomain/formats/json | |
parent | 604fbf0a7a082bc440c0778abd6f90005b210c16 (diff) | |
download | rest-query-344996ef6d19551d7cbff717ada35718afcf346a.tar.gz rest-query-344996ef6d19551d7cbff717ada35718afcf346a.tar.bz2 rest-query-344996ef6d19551d7cbff717ada35718afcf346a.zip |
Implement REST layer for PatientLabelService
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala index 15fec45..d944e42 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala @@ -33,18 +33,17 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val richPatientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { + implicit val patientLabelFormat: RootJsonFormat[PatientLabel] = jsonFormat8(PatientLabel.apply) + + implicit val richPatientLabelFormat: RootJsonFormat[RichPatientLabel] = new RootJsonFormat[RichPatientLabel] { + override def read(json: JsValue): RichPatientLabel = { + val isVerified = + json.asJsObject.fields.getOrElse("isVerified", deserializationError("isVerified field is missing")) + RichPatientLabel(json.convertTo[PatientLabel], isVerified.convertTo[Boolean]) + } override def write(obj: RichPatientLabel): JsValue = { - JsObject( - "id" -> obj.patientLabel.id.toJson, - "labelId" -> obj.patientLabel.labelId.toJson, - "primaryValue" -> obj.patientLabel.primaryValue.toJson, - "verifiedPrimaryValue" -> obj.patientLabel.verifiedPrimaryValue.toJson, - "score" -> obj.patientLabel.score.toJson, - "isImplicitMatch" -> obj.patientLabel.isImplicitMatch.toJson, - "isVisible" -> obj.patientLabel.isVisible.toJson, - "isVerified" -> obj.isVerified.toJson - ) + val labelFields = obj.patientLabel.toJson.asJsObject.fields + JsObject(labelFields ++ Map("isVerified" -> obj.isVerified.toJson)) } } |