aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-04 17:57:12 +0600
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-11 14:41:17 +0600
commitef9517e1b8f599fbdd15c474cf7dfea61e803c2f (patch)
treec31a139d35dab0c10c70bb7afef2bca8e48f0fee /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
parent5519c219e2404cb19b6116dee90b40b5e5e2a720 (diff)
downloadrest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.gz
rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.bz2
rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.zip
PDSUI-2188 Created and fixed spray json formats for tric and rep
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
new file mode 100644
index 0000000..4f2783c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
@@ -0,0 +1,37 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import xyz.driver.pdsuidomain.entities._
+
+object patienthypothesis {
+ import DefaultJsonProtocol._
+ import common._
+
+ def applyUpdateToPatientHypothesis(json: JsValue, orig: PatientHypothesis): PatientHypothesis = json match {
+ case JsObject(fields) =>
+ val rationale = if (fields.contains("rationale")) {
+ fields.get("rationale").map(_.convertTo[String])
+ } else orig.rationale
+
+ orig.copy(rationale = rationale)
+
+ case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json")
+ }
+
+ implicit val patientHypothesisWriter: JsonWriter[(PatientHypothesis, Boolean)] =
+ new JsonWriter[(PatientHypothesis, Boolean)] {
+ override def write(obj: (PatientHypothesis, Boolean)): JsValue = {
+ val patientHypothesis = obj._1
+ val isRationaleRequired = obj._2
+ JsObject(
+ "id" -> patientHypothesis.id.toJson,
+ "patientId" -> patientHypothesis.patientId.toJson,
+ "hypothesisId" -> patientHypothesis.hypothesisId.toJson,
+ "matchedTrials" -> patientHypothesis.matchedTrials.toJson,
+ "rationale" -> patientHypothesis.rationale.toJson,
+ "isRationaleRequired" -> isRationaleRequired.toJson
+ )
+ }
+ }
+
+}