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.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala24
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala18
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala46
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala27
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala38
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala47
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala25
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala40
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala72
12 files changed, 445 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
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala
new file mode 100644
index 0000000..d906fc6
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala
@@ -0,0 +1,24 @@
+package xyz.driver.pdsuidomain.formats.json.patient
+
+import xyz.driver.pdsuidomain.entities.Patient.Status
+
+object PatientStatus {
+
+ val statusFromString: PartialFunction[String, Status] = {
+ case "New" => Status.New
+ case "Verified" => Status.Verified
+ case "Reviewed" => Status.Reviewed
+ case "Curated" => Status.Curated
+ case "Flagged" => Status.Flagged
+ case "Done" => Status.Done
+ }
+
+ def statusToString(x: Status): String = x match {
+ case Status.New => "New"
+ case Status.Verified => "Verified"
+ case Status.Reviewed => "Reviewed"
+ case Status.Curated => "Curated"
+ case Status.Flagged => "Flagged"
+ case Status.Done => "Done"
+ }
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala
new file mode 100644
index 0000000..03ff275
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala
@@ -0,0 +1,18 @@
+package xyz.driver.pdsuidomain.formats.json.patient.eligible
+
+import xyz.driver.pdsuidomain.entities.PatientTrialArmGroupView
+import play.api.libs.json.{Format, Json}
+
+final case class ApiPartialPatientEligibleTrial(isVerified: Option[Boolean]) {
+
+ def applyTo(orig: PatientTrialArmGroupView): PatientTrialArmGroupView = {
+ orig.copy(
+ isVerified = isVerified.getOrElse(orig.isVerified)
+ )
+ }
+}
+
+object ApiPartialPatientEligibleTrial {
+
+ implicit val format: Format[ApiPartialPatientEligibleTrial] = Json.format
+}
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
new file mode 100644
index 0000000..c1a6e76
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala
@@ -0,0 +1,46 @@
+package xyz.driver.pdsuidomain.formats.json.patient.eligible
+
+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.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial
+
+final case class ApiPatientEligibleTrial(id: Long,
+ patientId: String,
+ trialId: String,
+ trialTitle: String,
+ arms: List[String],
+ hypothesisId: UUID,
+ eligibilityStatus: Option[String],
+ isVerified: Boolean)
+
+object ApiPatientEligibleTrial {
+
+ implicit val apiEligibleTrialJsonFormat: Format[ApiPatientEligibleTrial] = (
+ (JsPath \ "id").format[Long] and
+ (JsPath \ "patientId").format[String] and
+ (JsPath \ "trialId").format[String] and
+ (JsPath \ "trialTitle").format[String] and
+ (JsPath \ "arms").format[List[String]] and
+ (JsPath \ "hypothesisId").format[UUID] and
+ (JsPath \ "eligibilityStatus").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown eligibility status"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String])) and
+ (JsPath \ "isVerified").format[Boolean]
+ ) (ApiPatientEligibleTrial.apply, unlift(ApiPatientEligibleTrial.unapply))
+
+ def fromDomain(eligibleTrialWithTrial: RichPatientEligibleTrial) = ApiPatientEligibleTrial(
+ id = eligibleTrialWithTrial.group.id.id,
+ patientId = eligibleTrialWithTrial.group.patientId.toString,
+ trialId = eligibleTrialWithTrial.group.trialId.id,
+ trialTitle = eligibleTrialWithTrial.trial.title,
+ arms = eligibleTrialWithTrial.arms.map(_.name),
+ hypothesisId = eligibleTrialWithTrial.group.hypothesisId.id,
+ eligibleTrialWithTrial.group.eligibilityStatus.map(FuzzyValue.valueToString),
+ eligibleTrialWithTrial.group.isVerified
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala
new file mode 100644
index 0000000..0858ce1
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala
@@ -0,0 +1,27 @@
+package xyz.driver.pdsuidomain.formats.json.patient.hypothesis
+
+import xyz.driver.pdsuidomain.entities.PatientHypothesis
+import org.davidbild.tristate.Tristate
+import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+
+final case class ApiPartialPatientHypothesis(rationale: Tristate[String]) {
+
+ def applyTo(orig: PatientHypothesis): PatientHypothesis = {
+ orig.copy(
+ rationale = rationale.cata(Some(_), None, orig.rationale)
+ )
+ }
+}
+
+object ApiPartialPatientHypothesis {
+
+ implicit val reads: Reads[ApiPartialPatientHypothesis] =
+ (__ \ "rationale").readTristate[String].map(x => ApiPartialPatientHypothesis(x))
+
+ implicit val writes: Writes[ApiPartialPatientHypothesis] =
+ (__ \ "rationale").writeTristate[String].contramap(_.rationale)
+
+ implicit val format: Format[ApiPartialPatientHypothesis] = Format(reads, writes)
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala
new file mode 100644
index 0000000..1b0767d
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala
@@ -0,0 +1,32 @@
+package xyz.driver.pdsuidomain.formats.json.patient.hypothesis
+
+import java.util.UUID
+
+import xyz.driver.pdsuidomain.entities.PatientHypothesis
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+
+final case class ApiPatientHypothesis(id: UUID,
+ patientId: String,
+ hypothesisId: UUID,
+ matchedTrials: Long,
+ rationale: Option[String])
+
+object ApiPatientHypothesis {
+
+ implicit val apiPatientHypothesisJsonFormat: Format[ApiPatientHypothesis] = (
+ (JsPath \ "id").format[UUID] and
+ (JsPath \ "patientId").format[String] and
+ (JsPath \ "hypothesisId").format[UUID] and
+ (JsPath \ "matchedTrials").format[Long] and
+ (JsPath \ "rationale").formatNullable[String]
+ ) (ApiPatientHypothesis.apply, unlift(ApiPatientHypothesis.unapply))
+
+ def fromDomain(patientHypothesis: PatientHypothesis) = ApiPatientHypothesis(
+ id = patientHypothesis.id.id,
+ patientId = patientHypothesis.patientId.toString,
+ hypothesisId = patientHypothesis.hypothesisId.id,
+ matchedTrials = patientHypothesis.matchedTrials,
+ rationale = patientHypothesis.rationale
+ )
+}
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
new file mode 100644
index 0000000..82e3a3f
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala
@@ -0,0 +1,38 @@
+package xyz.driver.pdsuidomain.formats.json.patient.label
+
+import xyz.driver.pdsuidomain.entities.PatientLabel
+import org.davidbild.tristate.Tristate
+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
+
+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)
+ )
+ }
+
+}
+
+object ApiPartialPatientLabel {
+
+ implicit val format: Format[ApiPartialPatientLabel] = (
+ (JsPath \ "primaryValue").formatNullable[String](Format(
+ Reads.of[String].filter(ValidationError("unknown primary value"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String])) and
+ (JsPath \ "verifiedPrimaryValue").formatTristate[String](Format(
+ Reads.of[String].filter(ValidationError("unknown verified primary value"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String]))
+ ) (ApiPartialPatientLabel.apply, unlift(ApiPartialPatientLabel.unapply))
+
+}
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
new file mode 100644
index 0000000..fc8687b
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala
@@ -0,0 +1,47 @@
+package xyz.driver.pdsuidomain.formats.json.patient.label
+
+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
+
+final case class ApiPatientLabel(id: Long,
+ labelId: Long,
+ primaryValue: Option[String],
+ verifiedPrimaryValue: Option[String],
+ score: Int,
+ isImplicitMatch: Boolean,
+ isVisible: Boolean,
+ isVerified: Boolean)
+
+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 \ "score").format[Int] and
+ (JsPath \ "isImplicitMatch").format[Boolean] and
+ (JsPath \ "isVisible").format[Boolean] and
+ (JsPath \ "isVerified").format[Boolean]
+ ) (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),
+ score = patientLabel.score,
+ isImplicitMatch = patientLabel.isImplicitMatch,
+ isVisible = patientLabel.isVisible,
+ isVerified = isVerified
+ )
+}
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
new file mode 100644
index 0000000..3fe135e
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala
@@ -0,0 +1,25 @@
+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.pdsuidomain.entities.PatientLabel
+
+final case class ApiPatientLabelDefiningCriteria(labelId: Long, value: Option[String])
+
+object ApiPatientLabelDefiningCriteria {
+
+ implicit val format: Format[ApiPatientLabelDefiningCriteria] = (
+ (JsPath \ "labelId").format[Long] and
+ (JsPath \ "value").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => 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)
+ )
+}
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
new file mode 100644
index 0000000..b68dad5
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala
@@ -0,0 +1,40 @@
+package xyz.driver.pdsuidomain.formats.json.patient.trial
+
+import xyz.driver.pdsuidomain.entities.PatientCriterion
+import org.davidbild.tristate.Tristate
+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
+
+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),
+ verifiedEligibilityStatus = verifiedEligibilityStatus.cata(x =>
+ Some(FuzzyValue.fromString(x)),
+ None,
+ orig.verifiedEligibilityStatus
+ )
+ )
+ }
+}
+
+object ApiPartialPatientCriterion {
+
+ implicit val format: Format[ApiPartialPatientCriterion] = (
+ (JsPath \ "eligibilityStatus").formatNullable[String](Format(
+ Reads.of[String].filter(ValidationError("unknown eligibility status"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String])) and
+ (JsPath \ "verifiedEligibilityStatus").formatTristate[String](Format(
+ Reads.of[String].filter(ValidationError("unknown verified eligibility status"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String]))
+ ) (ApiPartialPatientCriterion.apply, unlift(ApiPartialPatientCriterion.unapply))
+}
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
new file mode 100644
index 0000000..71cb58f
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala
@@ -0,0 +1,32 @@
+package xyz.driver.pdsuidomain.formats.json.patient.trial
+
+import xyz.driver.pdsuicommon.domain.{FuzzyValue, 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.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion
+
+final case class ApiPartialPatientCriterionList(id: Long,
+ eligibilityStatus: Option[String],
+ isVerified: Option[Boolean]) {
+
+ def toDomain: DraftPatientCriterion = DraftPatientCriterion(
+ id = LongId[PatientCriterion](id),
+ eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString),
+ isVerified = isVerified
+ )
+}
+
+object ApiPartialPatientCriterionList {
+
+ implicit val format: Format[ApiPartialPatientCriterionList] = (
+ (JsPath \ "id").format[Long] and
+ (JsPath \ "eligibilityStatus").formatNullable[String](Format(
+ Reads.of[String].filter(ValidationError("unknown eligibility status"))({
+ case x if FuzzyValue.fromString.isDefinedAt(x) => true
+ case _ => false
+ }), Writes.of[String])) and
+ (JsPath \ "isVerified").formatNullable[Boolean]
+ ) (ApiPartialPatientCriterionList.apply, unlift(ApiPartialPatientCriterionList.unapply))
+}
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
new file mode 100644
index 0000000..3e2de99
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
@@ -0,0 +1,72 @@
+package xyz.driver.pdsuidomain.formats.json.patient.trial
+
+import java.time.{ZoneId, ZonedDateTime}
+
+import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
+import xyz.driver.pdsuidomain.entities.{Arm, Label, PatientCriterion}
+import play.api.data.validation.ValidationError
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath, Reads, Writes}
+
+final case class ApiPatientCriterion(id: Long,
+ labelId: Long,
+ nctId: String,
+ criterionText: String,
+ criterionValue: Option[String],
+ criterionIsDefining: Boolean,
+ criterionIsCompound: Boolean,
+ arms: List[String],
+ eligibilityStatus: Option[String],
+ verifiedEligibilityStatus: Option[String],
+ isVerified: Boolean,
+ isVisible: Boolean,
+ lastUpdate: ZonedDateTime)
+
+object ApiPatientCriterion {
+
+ implicit val format: Format[ApiPatientCriterion] = (
+ (JsPath \ "id").format[Long] and
+ (JsPath \ "labelId").format[Long] and
+ (JsPath \ "nctId").format[String] and
+ (JsPath \ "criterionText").format[String] and
+ (JsPath \ "criterionValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ x =>
+ x == "Yes" || x == "No"
+ }), Writes.of[String])) and
+ (JsPath \ "criterionIsDefining").format[Boolean] and
+ (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
+ }), 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
+ }), Writes.of[String])) and
+ (JsPath \ "isVerified").format[Boolean] and
+ (JsPath \ "isVisible").format[Boolean] and
+ (JsPath \ "lastUpdate").format[ZonedDateTime]
+ ) (ApiPatientCriterion.apply, unlift(ApiPatientCriterion.unapply))
+
+ def fromDomain(patientCriterion: PatientCriterion,
+ labelId: LongId[Label],
+ arms: List[Arm],
+ criterionIsCompound: Boolean) = ApiPatientCriterion(
+ id = patientCriterion.id.id,
+ labelId = labelId.id,
+ nctId = patientCriterion.nctId.id,
+ criterionText = patientCriterion.criterionText,
+ criterionValue = patientCriterion.criterionValue.map { x =>
+ FuzzyValue.valueToString(FuzzyValue.fromBoolean(x))
+ },
+ criterionIsDefining = patientCriterion.criterionIsDefining,
+ criterionIsCompound = criterionIsCompound,
+ arms = arms.map(_.name),
+ eligibilityStatus = patientCriterion.eligibilityStatus.map(FuzzyValue.valueToString),
+ verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(FuzzyValue.valueToString),
+ isVerified = patientCriterion.isVerified,
+ isVisible = patientCriterion.isVisible,
+ lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z"))
+ )
+}