diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-08-04 17:57:12 +0600 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-08-11 14:41:17 +0600 |
commit | ef9517e1b8f599fbdd15c474cf7dfea61e803c2f (patch) | |
tree | c31a139d35dab0c10c70bb7afef2bca8e48f0fee /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala | |
parent | 5519c219e2404cb19b6116dee90b40b5e5e2a720 (diff) | |
download | rest-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/patientissue.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala new file mode 100644 index 0000000..ffe31cf --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala @@ -0,0 +1,54 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +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", "archiveRequired") match { + case Seq(text, archiveRequired) => + PatientIssue( + id = LongId(0), + userId = userId, + patientId = patientId, + lastUpdate = LocalDateTime.MIN, + isDraft = true, + text = text.convertTo[String], + archiveRequired = archiveRequired.convertTo[Boolean] + ) + + case _ => deserializationError(s"Expected Json Object as PatientIssue, but got $json") + } + + } + + implicit val patientIssueWriter = new JsonWriter[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 + ) + } + +} |