aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2017-08-14 22:29:45 -0700
committerGitHub <noreply@github.com>2017-08-14 22:29:45 -0700
commit322ea28ecf5ad5f65d3376f3e97e004d229d4736 (patch)
treec405d10d70f4ec1f18ffa81bc01cd8da64bddcba /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
parentbe74ae7c5531af998d38b9de8052791f17b25341 (diff)
parent442579b27ccbac82cb001a5b02402a593d005977 (diff)
downloadrest-query-322ea28ecf5ad5f65d3376f3e97e004d229d4736.tar.gz
rest-query-322ea28ecf5ad5f65d3376f3e97e004d229d4736.tar.bz2
rest-query-322ea28ecf5ad5f65d3376f3e97e004d229d4736.zip
Merge pull request #18 from drivergroup/PDSUI-2188
PDSUI-2188 Create spray json formats for domain entities
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
+ )
+ }
+ }
+
+}