diff options
author | vlad <vlad@driver.xyz> | 2017-10-09 12:24:59 -0700 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-10-09 12:24:59 -0700 |
commit | 7d8712a62d30b412717e1b730c0ad267cd207aa4 (patch) | |
tree | 76662e1b233943c1c840a658682aac9766aa64d7 /src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala | |
parent | 52b5e1a5febc91aa316565fdea309df2b646481e (diff) | |
download | rest-query-7d8712a62d30b412717e1b730c0ad267cd207aa4.tar.gz rest-query-7d8712a62d30b412717e1b730c0ad267cd207aa4.tar.bz2 rest-query-7d8712a62d30b412717e1b730c0ad267cd207aa4.zip |
Getting rid of the FuzzyValues, Name as a string, and condition
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.scala | 21 |
1 files changed, 17 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 db430ae..ad6bc80 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 @@ -7,6 +7,8 @@ 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} +import xyz.driver.entities.common.FullName +import xyz.driver.entities.patient final case class ApiPatient(id: String, status: String, @@ -24,17 +26,28 @@ final case class ApiPatient(id: String, PatientStatus.statusFromString .applyOrElse(status, (s: String) => throw new NoSuchElementException(s"Unknown status $s")) + private def parseName(name: String): FullName[Patient] = + name.split(" ") match { + case Array() => throw new NoSuchElementException(s"Patient's name cannot be empty") + case Array(first) => FullName.fromStrings[Patient](first, "", "") + case Array(first, last) => FullName.fromStrings[Patient](first, "", last) + case Array(first, middle, last) => FullName.fromStrings[Patient](first, middle, last) + case _ => throw new NoSuchElementException(s"Patient's name is ambiguous") + } + def toDomain = Patient( id = UuidId(this.id), status = extractStatus(this.status), - name = this.name, + name = parseName(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, + cancerType = patient.CancerType + .fromString(this.condition) + .getOrElse(throw new IllegalArgumentException(s"Unknown cancer type ${this.condition}")), orderId = PatientOrderId(this.orderId), lastUpdate = this.lastUpdate.toLocalDateTime ) @@ -60,14 +73,14 @@ object ApiPatient { def fromDomain(patient: Patient) = ApiPatient( id = patient.id.toString, status = PatientStatus.statusToString(patient.status), - name = patient.name, + name = patient.name.toString(), dob = patient.dob, assignee = patient.assignee.map(_.id), previousStatus = patient.previousStatus.map(PatientStatus.statusToString), previousAssignee = patient.previousAssignee.map(_.id), lastActiveUser = patient.lastActiveUserId.map(_.id), lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")), - condition = patient.condition, + condition = patient.cancerType.toString, orderId = patient.orderId.id ) } |