aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2017-07-27 13:14:04 -0700
committerJakob Odersky <jakob@driver.xyz>2017-07-27 13:14:04 -0700
commit838c6a345c749a58472ee4324f60a3759a83aedd (patch)
treeb62bf2ba5082750a6a95c3e53a06f050e9e94199 /src/main/scala/xyz/driver/pdsuidomain/formats
parente120d1b2ffbf42b5b809b69a2201b3b8dd1a1ef9 (diff)
downloadrest-query-838c6a345c749a58472ee4324f60a3759a83aedd.tar.gz
rest-query-838c6a345c749a58472ee4324f60a3759a83aedd.tar.bz2
rest-query-838c6a345c749a58472ee4324f60a3759a83aedd.zip
Implement RestPatientServicev0.2.8
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala34
1 files changed, 30 insertions, 4 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
index 05a57e4..db430ae 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala
@@ -1,8 +1,10 @@
package xyz.driver.pdsuidomain.formats.json.patient
import java.time.{LocalDate, ZoneId, ZonedDateTime}
+import java.util.UUID
-import xyz.driver.pdsuidomain.entities.Patient
+import xyz.driver.pdsuicommon.domain.{StringId, UuidId}
+import xyz.driver.pdsuidomain.entities.{Patient, PatientOrderId}
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
@@ -15,7 +17,29 @@ final case class ApiPatient(id: String,
previousAssignee: Option[String],
lastActiveUser: Option[String],
lastUpdate: ZonedDateTime,
- condition: String)
+ condition: String,
+ orderId: UUID) {
+
+ private def extractStatus(status: String): Patient.Status =
+ PatientStatus.statusFromString
+ .applyOrElse(status, (s: String) => throw new NoSuchElementException(s"Unknown status $s"))
+
+ def toDomain = Patient(
+ id = UuidId(this.id),
+ status = extractStatus(this.status),
+ name = this.name,
+ dob = this.dob,
+ assignee = this.assignee.map(StringId(_)),
+ previousStatus = this.previousStatus.map(extractStatus),
+ previousAssignee = this.previousAssignee.map(StringId(_)),
+ lastActiveUserId = this.lastActiveUser.map(StringId(_)),
+ isUpdateRequired = false,
+ condition = this.condition,
+ orderId = PatientOrderId(this.orderId),
+ lastUpdate = this.lastUpdate.toLocalDateTime
+ )
+
+}
object ApiPatient {
@@ -29,7 +53,8 @@ object ApiPatient {
(JsPath \ "previousAssignee").formatNullable[String] and
(JsPath \ "lastActiveUser").formatNullable[String] and
(JsPath \ "lastUpdate").format[ZonedDateTime] and
- (JsPath \ "condition").format[String]
+ (JsPath \ "condition").format[String] and
+ (JsPath \ "orderId").format[UUID]
)(ApiPatient.apply, unlift(ApiPatient.unapply))
def fromDomain(patient: Patient) = ApiPatient(
@@ -42,6 +67,7 @@ object ApiPatient {
previousAssignee = patient.previousAssignee.map(_.id),
lastActiveUser = patient.lastActiveUserId.map(_.id),
lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")),
- condition = patient.condition
+ condition = patient.condition,
+ orderId = patient.orderId.id
)
}