From 344996ef6d19551d7cbff717ada35718afcf346a Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 30 Oct 2017 14:17:28 -0700 Subject: Implement REST layer for PatientLabelService --- .../pdsuidomain/formats/json/patientlabel.scala | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json') 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)) } } -- cgit v1.2.3