aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-27 17:13:02 -0700
committervlad <vlad@driver.xyz>2017-06-27 17:13:02 -0700
commit5832f63b84d7388441d1200f2442dc1e9de0225c (patch)
tree32f63acdc920c14effc3d0d2822c05c125ad49e4 /src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
parent9dd50590d4c8f8b9442d7c21ddd1def9dd453d5e (diff)
downloadrest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.gz
rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.bz2
rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.zip
All PDS UI domain models, API case classes, service traits and necessary utils moved to pdsui-commonv0.1.11
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
new file mode 100644
index 0000000..0a3938c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
@@ -0,0 +1,44 @@
+package xyz.driver.pdsuidomain.formats.json.patient
+
+import java.time.{LocalDate, ZoneId, ZonedDateTime}
+
+import xyz.driver.pdsuidomain.entities.Patient
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+
+final case class ApiPatient(id: String,
+ status: String,
+ name: String,
+ dob: LocalDate,
+ assignee: Option[Long],
+ previousStatus: Option[String],
+ previousAssignee: Option[Long],
+ lastUpdate: ZonedDateTime,
+ condition: String)
+
+object ApiPatient {
+
+ implicit val format: Format[ApiPatient] = (
+ (JsPath \ "id").format[String] and
+ (JsPath \ "status").format[String] and
+ (JsPath \ "name").format[String] and
+ (JsPath \ "dob").format[LocalDate] and
+ (JsPath \ "assignee").formatNullable[Long] and
+ (JsPath \ "previousStatus").formatNullable[String] and
+ (JsPath \ "previousAssignee").formatNullable[Long] and
+ (JsPath \ "lastUpdate").format[ZonedDateTime] and
+ (JsPath \ "condition").format[String]
+ ) (ApiPatient.apply, unlift(ApiPatient.unapply))
+
+ def fromDomain(patient: Patient) = ApiPatient(
+ id = patient.id.toString,
+ status = PatientStatus.statusToString(patient.status),
+ name = patient.name,
+ dob = patient.dob,
+ assignee = patient.assignee.map(_.id),
+ previousStatus = patient.previousStatus.map(PatientStatus.statusToString),
+ previousAssignee = patient.previousAssignee.map(_.id),
+ lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")),
+ condition = patient.condition
+ )
+}