aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/patient')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala25
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala8
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala15
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala8
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala14
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala18
8 files changed, 75 insertions, 54 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..585d4ed 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,
@@ -17,24 +19,35 @@ final case class ApiPatient(id: String,
previousAssignee: Option[String],
lastActiveUser: Option[String],
lastUpdate: ZonedDateTime,
- condition: String,
+ disease: String,
orderId: UUID) {
private def extractStatus(status: String): Patient.Status =
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,
+ disease = patient.CancerType
+ .fromString(this.disease)
+ .getOrElse(throw new IllegalArgumentException(s"Unknown cancer type ${this.disease}")),
orderId = PatientOrderId(this.orderId),
lastUpdate = this.lastUpdate.toLocalDateTime
)
@@ -53,21 +66,21 @@ object ApiPatient {
(JsPath \ "previousAssignee").formatNullable[String] and
(JsPath \ "lastActiveUser").formatNullable[String] and
(JsPath \ "lastUpdate").format[ZonedDateTime] and
- (JsPath \ "condition").format[String] and
+ (JsPath \ "disease").format[String] and
(JsPath \ "orderId").format[UUID]
)(ApiPatient.apply, unlift(ApiPatient.unapply))
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,
+ disease = patient.disease.toString,
orderId = patient.orderId.id
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala
index 4136715..55c8149 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala
@@ -5,7 +5,7 @@ import java.util.UUID
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial
final case class ApiPatientEligibleTrial(id: Long,
@@ -30,8 +30,8 @@ object ApiPatientEligibleTrial {
Reads
.of[String]
.filter(ValidationError("unknown eligibility status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]
)) and
@@ -45,7 +45,7 @@ object ApiPatientEligibleTrial {
trialTitle = eligibleTrialWithTrial.trial.title,
arms = eligibleTrialWithTrial.arms.map(_.armName),
hypothesisId = eligibleTrialWithTrial.group.hypothesisId.id,
- eligibleTrialWithTrial.group.verifiedEligibilityStatus.map(FuzzyValue.valueToString),
+ eligibleTrialWithTrial.group.verifiedEligibilityStatus.map(_.toString),
eligibleTrialWithTrial.group.isVerified
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala
index 91d0a0e..d92872c 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala
@@ -6,15 +6,14 @@ import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.entities.labels.LabelValue
final case class ApiPartialPatientLabel(primaryValue: Option[String], verifiedPrimaryValue: Tristate[String]) {
def applyTo(orig: PatientLabel): PatientLabel = {
orig.copy(
- primaryValue = primaryValue.map(FuzzyValue.fromString).orElse(orig.primaryValue),
- verifiedPrimaryValue =
- verifiedPrimaryValue.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedPrimaryValue)
+ primaryValue = primaryValue.flatMap(LabelValue.fromString).orElse(orig.primaryValue),
+ verifiedPrimaryValue = verifiedPrimaryValue.cata(x => LabelValue.fromString(x), None, orig.verifiedPrimaryValue)
)
}
}
@@ -26,8 +25,8 @@ object ApiPartialPatientLabel {
Format(Reads
.of[String]
.filter(ValidationError("unknown primary value"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String])) and
(JsPath \ "verifiedPrimaryValue").formatTristate[String](
@@ -35,8 +34,8 @@ object ApiPartialPatientLabel {
Reads
.of[String]
.filter(ValidationError("unknown verified primary value"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]
))
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala
index fc8687b..cc8532d 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala
@@ -4,7 +4,7 @@ import xyz.driver.pdsuidomain.entities.PatientLabel
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.entities.labels.LabelValue
final case class ApiPatientLabel(id: Long,
labelId: Long,
@@ -20,25 +20,33 @@ object ApiPatientLabel {
implicit val apiPatientLabelJsonFormat: Format[ApiPatientLabel] = (
(JsPath \ "id").format[Long] and
(JsPath \ "labelId").format[Long] and
- (JsPath \ "primaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
- }), Writes.of[String])) and
- (JsPath \ "verifiedPrimaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
- }), Writes.of[String])) and
+ (JsPath \ "primaryValue").formatNullable[String](
+ Format(Reads
+ .of[String]
+ .filter(ValidationError("unknown value"))({
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
+ }),
+ Writes.of[String])) and
+ (JsPath \ "verifiedPrimaryValue").formatNullable[String](
+ Format(Reads
+ .of[String]
+ .filter(ValidationError("unknown value"))({
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
+ }),
+ Writes.of[String])) and
(JsPath \ "score").format[Int] and
(JsPath \ "isImplicitMatch").format[Boolean] and
(JsPath \ "isVisible").format[Boolean] and
(JsPath \ "isVerified").format[Boolean]
- ) (ApiPatientLabel.apply, unlift(ApiPatientLabel.unapply))
+ )(ApiPatientLabel.apply, unlift(ApiPatientLabel.unapply))
def fromDomain(patientLabel: PatientLabel, isVerified: Boolean): ApiPatientLabel = ApiPatientLabel(
id = patientLabel.id.id,
labelId = patientLabel.labelId.id,
- primaryValue = patientLabel.primaryValue.map(FuzzyValue.valueToString),
- verifiedPrimaryValue = patientLabel.verifiedPrimaryValue.map(FuzzyValue.valueToString),
+ primaryValue = patientLabel.primaryValue.map(_.toString),
+ verifiedPrimaryValue = patientLabel.verifiedPrimaryValue.map(_.toString),
score = patientLabel.score,
isImplicitMatch = patientLabel.isImplicitMatch,
isVisible = patientLabel.isVisible,
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala
index ae64c33..16b9cc9 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala
@@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.patient.label
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuidomain.entities.PatientLabel
final case class ApiPatientLabelDefiningCriteria(labelId: Long, value: Option[String])
@@ -16,14 +16,14 @@ object ApiPatientLabelDefiningCriteria {
Format(Reads
.of[String]
.filter(ValidationError("unknown value"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]))
)(ApiPatientLabelDefiningCriteria.apply, unlift(ApiPatientLabelDefiningCriteria.unapply))
def fromDomain(x: PatientLabel) = ApiPatientLabelDefiningCriteria(
labelId = x.labelId.id,
- value = x.verifiedPrimaryValue.map(FuzzyValue.valueToString)
+ value = x.verifiedPrimaryValue.map(_.toString)
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala
index 399bc7d..09538b8 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala
@@ -6,16 +6,16 @@ import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath, Reads, Writes}
-import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.entities.labels.LabelValue
final case class ApiPartialPatientCriterion(eligibilityStatus: Option[String],
verifiedEligibilityStatus: Tristate[String]) {
def applyTo(orig: PatientCriterion): PatientCriterion = {
orig.copy(
- eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString).orElse(orig.eligibilityStatus),
+ eligibilityStatus = eligibilityStatus.flatMap(LabelValue.fromString).orElse(orig.eligibilityStatus),
verifiedEligibilityStatus =
- verifiedEligibilityStatus.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedEligibilityStatus)
+ verifiedEligibilityStatus.cata(x => LabelValue.fromString(x), None, orig.verifiedEligibilityStatus)
)
}
}
@@ -28,8 +28,8 @@ object ApiPartialPatientCriterion {
Reads
.of[String]
.filter(ValidationError("unknown eligibility status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]
)) and
@@ -38,8 +38,8 @@ object ApiPartialPatientCriterion {
Reads
.of[String]
.filter(ValidationError("unknown verified eligibility status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]
))
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala
index 4b08970..b7616a1 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala
@@ -1,10 +1,11 @@
package xyz.driver.pdsuidomain.formats.json.patient.trial
-import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
+import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.PatientCriterion
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath, Reads, Writes}
+import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion
final case class ApiPartialPatientCriterionList(id: Long,
@@ -13,7 +14,7 @@ final case class ApiPartialPatientCriterionList(id: Long,
def toDomain: DraftPatientCriterion = DraftPatientCriterion(
id = LongId[PatientCriterion](id),
- eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString),
+ eligibilityStatus = eligibilityStatus.flatMap(LabelValue.fromString),
isVerified = isVerified
)
}
@@ -26,8 +27,8 @@ object ApiPartialPatientCriterionList {
Reads
.of[String]
.filter(ValidationError("unknown eligibility status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}),
Writes.of[String]
)) and
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
index 6eeb40b..b9bf772 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
@@ -2,12 +2,12 @@ package xyz.driver.pdsuidomain.formats.json.patient.trial
import java.time.{ZoneId, ZonedDateTime}
-import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
+import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm}
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath, Reads, Writes}
-import xyz.driver.entities.labels.Label
+import xyz.driver.entities.labels.{Label, LabelValue}
final case class ApiPatientCriterion(id: Long,
labelId: Long,
@@ -39,13 +39,13 @@ object ApiPatientCriterion {
(JsPath \ "criterionIsCompound").format[Boolean] and
(JsPath \ "arms").format[List[String]] and
(JsPath \ "eligibilityStatus").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}), Writes.of[String])) and
(JsPath \ "verifiedEligibilityStatus").formatNullable[String](Format(
Reads.of[String].filter(ValidationError("unknown status"))({
- case x if FuzzyValue.fromString.isDefinedAt(x) => true
- case _ => false
+ case x if LabelValue.fromString(x).isDefined => true
+ case _ => false
}), Writes.of[String])) and
(JsPath \ "isVerified").format[Boolean] and
(JsPath \ "isVisible").format[Boolean] and
@@ -61,13 +61,13 @@ object ApiPatientCriterion {
criterionId = patientCriterion.criterionId.id,
criterionText = patientCriterion.criterionText,
criterionValue = patientCriterion.criterionValue.map { x =>
- FuzzyValue.valueToString(FuzzyValue.fromBoolean(x))
+ LabelValue.fromBoolean(x).toString
},
criterionIsDefining = patientCriterion.criterionIsDefining,
criterionIsCompound = patientCriterion.criterionValue.isEmpty,
arms = arms.map(_.armName),
- eligibilityStatus = patientCriterion.eligibilityStatus.map(FuzzyValue.valueToString),
- verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(FuzzyValue.valueToString),
+ eligibilityStatus = patientCriterion.eligibilityStatus.map(_.toString),
+ verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(_.toString),
isVerified = patientCriterion.isVerified,
isVisible = patientCriterion.isVisible,
lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z"))