diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible')
2 files changed, 64 insertions, 0 deletions
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 + ) +} |