aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr <ognelisar@gmail.com>2017-10-04 16:23:04 +0700
committerAleksandr <ognelisar@gmail.com>2017-10-04 16:23:04 +0700
commit7446fbcb6f51ae67ae8bf0f54729e774da8e7f73 (patch)
tree667c0f62d13561732096c2c9b251e3a227abfbe0
parent996af2657cdd779e08e46fc1ba5f47d9e7c5aac5 (diff)
downloadrest-query-7446fbcb6f51ae67ae8bf0f54729e774da8e7f73.tar.gz
rest-query-7446fbcb6f51ae67ae8bf0f54729e774da8e7f73.tar.bz2
rest-query-7446fbcb6f51ae67ae8bf0f54729e774da8e7f73.zip
Implemented new spray json formats for PatientHypothesis and PatientLabel
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala15
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala16
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala19
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala24
4 files changed, 68 insertions, 6 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
index 82759ab..bd448b3 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala
@@ -19,7 +19,7 @@ object patienthypothesis {
case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json")
}
- implicit val patientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] =
+ implicit val richPatientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] =
new RootJsonWriter[RichPatientHypothesis] {
override def write(obj: RichPatientHypothesis): JsValue = {
JsObject(
@@ -33,4 +33,17 @@ object patienthypothesis {
}
}
+ implicit val patientHypothesisWriter: RootJsonWriter[PatientHypothesis] =
+ new RootJsonWriter[PatientHypothesis] {
+ override def write(obj: PatientHypothesis): JsValue = {
+ JsObject(
+ "id" -> obj.id.toJson,
+ "patientId" -> obj.patientId.toJson,
+ "hypothesisId" -> obj.hypothesisId.toJson,
+ "matchedTrials" -> obj.matchedTrials.toJson,
+ "rationale" -> obj.rationale.toJson
+ )
+ }
+ }
+
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala
index f4af376..10a0a94 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala
@@ -29,7 +29,7 @@ object patientlabel {
case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json")
}
- implicit val patientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] {
+ implicit val richPatientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] {
override def write(obj: RichPatientLabel): JsValue = {
JsObject(
"id" -> obj.patientLabel.id.toJson,
@@ -44,6 +44,20 @@ object patientlabel {
}
}
+ implicit val patientLabelWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] {
+ override def write(obj: PatientLabel): JsValue = {
+ JsObject(
+ "id" -> obj.id.toJson,
+ "labelId" -> obj.labelId.toJson,
+ "primaryValue" -> obj.primaryValue.toJson,
+ "verifiedPrimaryValue" -> obj.verifiedPrimaryValue.toJson,
+ "score" -> obj.score.toJson,
+ "isImplicitMatch" -> obj.isImplicitMatch.toJson,
+ "isVisible" -> obj.isVisible.toJson
+ )
+ }
+ }
+
implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] =
new RootJsonWriter[PatientLabelEvidenceView] {
override def write(evidence: PatientLabelEvidenceView): JsValue =
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala
index 1a5b7eb..fbb5213 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala
@@ -9,7 +9,7 @@ import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypot
class PatientHypothesisFormatSuite extends FlatSpec with Matchers {
import patienthypothesis._
- "Json format for PatientHypothesis" should "read and write correct JSON" in {
+ "Json format for RichPatientHypothesis" should "read and write correct JSON" in {
val orig = PatientHypothesis(
id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"),
patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
@@ -17,7 +17,7 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers {
rationale = None,
matchedTrials = 1
)
- val writtenJson = patientHypothesisWriter.write(RichPatientHypothesis(orig, true))
+ val writtenJson = richPatientHypothesisWriter.write(RichPatientHypothesis(orig, isRequired = true))
writtenJson should be (
"""{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343",
@@ -29,4 +29,19 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers {
parsedUpdatePatientHypothesis should be(expectedUpdatedPatientHypothesis)
}
+ "Json format for patientHypothesis" should "read and write correct JSON" in {
+ val orig = PatientHypothesis(
+ id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"),
+ patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
+ hypothesisId = UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4"),
+ rationale = None,
+ matchedTrials = 1
+ )
+ val writtenJson = patientHypothesisWriter.write(orig)
+
+ writtenJson should be (
+ """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343",
+ "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","rationale":null,"matchedTrials":1}""".parseJson)
+ }
+
}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala
index 8b7c138..ffb1bd4 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala
@@ -10,7 +10,7 @@ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel
class PatientLabelFormatSuite extends FlatSpec with Matchers {
- "Json format for PatientLabel" should "read and write correct JSON" in {
+ "Json format for RichPatientLabel" should "read and write correct JSON" in {
import patientlabel._
val orig = PatientLabel(
id = LongId(1),
@@ -22,7 +22,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers {
score = 1,
isImplicitMatch = false
)
- val writtenJson = patientLabelWriter.write(RichPatientLabel(orig, true))
+ val writtenJson = richPatientLabelWriter.write(RichPatientLabel(orig, isVerified = true))
writtenJson should be (
"""{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true,
@@ -34,6 +34,26 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers {
parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel)
}
+ "Json format for PatientLabel" should "read and write correct JSON" in {
+ import patientlabel._
+ val orig = PatientLabel(
+ id = LongId(1),
+ patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
+ labelId = LongId(20),
+ primaryValue = Some(FuzzyValue.Yes),
+ verifiedPrimaryValue = None,
+ isVisible = true,
+ score = 1,
+ isImplicitMatch = false
+ )
+ val writtenJson = patientLabelWriter.write(orig)
+
+ writtenJson should be (
+ """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,
+ "score":1,"isImplicitMatch":false}""".parseJson)
+ }
+
+
"Json format for PatientLabelEvidence" should "read and write correct JSON" in {
import patientlabel._
val orig = PatientLabelEvidenceView(