aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-10-30 16:29:46 +0700
committerGitHub <noreply@github.com>2017-10-30 16:29:46 +0700
commit604fbf0a7a082bc440c0778abd6f90005b210c16 (patch)
treefd846d42448b2d3f432056898f0c3433475ea0da /src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
parent8811d60442d060097027b33784ece9a704458e1d (diff)
parentd92a2795a02b9711aa9aed92a770f85377b31460 (diff)
downloadrest-query-604fbf0a7a082bc440c0778abd6f90005b210c16.tar.gz
rest-query-604fbf0a7a082bc440c0778abd6f90005b210c16.tar.bz2
rest-query-604fbf0a7a082bc440c0778abd6f90005b210c16.zip
Merge pull request #54 from drivergroup/PDSUI-2336v0.11.0
PDSUI-2336 Cleanup
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
new file mode 100644
index 0000000..5a2955f
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
@@ -0,0 +1,54 @@
+package xyz.driver.pdsuidomain.formats.json
+
+import java.time.LocalDateTime
+
+import spray.json._
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, User, UuidId}
+import xyz.driver.pdsuidomain.entities._
+
+object patientissue {
+ import DefaultJsonProtocol._
+ import common._
+
+ def applyUpdateToPatientIssue(json: JsValue, orig: PatientIssue): PatientIssue = {
+ json.asJsObject.getFields("text", "archiveRequired") match {
+ case Seq(text, archiveRequired) =>
+ orig.copy(
+ text = text.convertTo[String],
+ archiveRequired = archiveRequired.convertTo[Boolean]
+ )
+
+ case _ => deserializationError(s"Expected Json Object as partial PatientIssue, but got $json")
+ }
+ }
+
+ def jsValueToPatientIssue(json: JsValue, patientId: UuidId[Patient], userId: StringId[User]): PatientIssue = {
+ json.asJsObject.getFields("text") match {
+ case Seq(text) =>
+ PatientIssue(
+ id = LongId(0),
+ userId = userId,
+ patientId = patientId,
+ lastUpdate = LocalDateTime.MIN,
+ isDraft = true,
+ text = text.convertTo[String],
+ archiveRequired = false
+ )
+
+ case _ => deserializationError(s"Expected Json Object as PatientIssue, but got $json")
+ }
+
+ }
+
+ implicit val patientIssueWriter = new RootJsonWriter[PatientIssue] {
+ override def write(obj: PatientIssue) = JsObject(
+ "id" -> obj.id.toJson,
+ "text" -> obj.text.toJson,
+ "lastUpdate" -> obj.lastUpdate.toJson,
+ "userId" -> obj.userId.toJson,
+ "isDraft" -> obj.isDraft.toJson,
+ "archiveRequired" -> obj.archiveRequired.toJson
+ )
+ }
+
+}