diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain')
9 files changed, 86 insertions, 37 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala index 79a19ed..7027eef 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala @@ -9,11 +9,11 @@ import xyz.driver.pdsuicommon.logging._ object PatientCriterion { implicit def toPhiString(x: PatientCriterion): PhiString = { import x._ - phi"PatientCriterion(id=$id, patientLabelId=$patientLabelId, trialId=${Unsafe(trialId)}, nctId=${Unsafe(nctId)}, " + + phi"PatientCriterion(id=$id, patientLabelId=$patientLabelId, trialId=${Unsafe(trialId)}, nctId=$nctId, " + phi"criterionId=$criterionId, criterionValue=${Unsafe(criterionValue)}, " + phi"isImplicitMatch=$criterionIsDefining), criterionIsDefining=${Unsafe(criterionIsDefining)}, " + phi"eligibilityStatus=${Unsafe(eligibilityStatus)}, verifiedEligibilityStatus=${Unsafe(verifiedEligibilityStatus)}, " + - phi"isVerified=${Unsafe(isVerified)}, lastUpdate=${Unsafe(lastUpdate)}" + phi"isVerified=${Unsafe(isVerified)}, lastUpdate=${Unsafe(lastUpdate)}, inclusion=${Unsafe(inclusion)}" } /** @@ -52,7 +52,8 @@ final case class PatientCriterion(id: LongId[PatientCriterion], verifiedEligibilityStatus: Option[LabelValue], isVerified: Boolean, isVisible: Boolean, - lastUpdate: LocalDateTime) { + lastUpdate: LocalDateTime, + inclusion: Option[Boolean]) { def isIneligibleForEv: Boolean = eligibilityStatus.contains(LabelValue.No) && isVerified } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala index 8376e34..98bd084 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala @@ -11,13 +11,14 @@ final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion], armIds: Set[LongId[EligibilityArm]], criteria: String, isCompound: Boolean, - isDefining: Boolean) + isDefining: Boolean, + inclusion: Option[Boolean]) object ExportTrialLabelCriterion { implicit def toPhiString(x: ExportTrialLabelCriterion): PhiString = { import x._ phi"TrialLabelCriterion(criterionId=$criterionId, value=$value, labelId=$labelId, " + - phi"criteria=${Unsafe(criteria)}, isCompound=$isCompound, isDefining=$isDefining)" + phi"criteria=${Unsafe(criteria)}, isCompound=$isCompound, isDefining=$isDefining), inclusion=${Unsafe(inclusion)}" } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala index 2c7d0e0..33da392 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -28,7 +28,8 @@ object export { armIds = setOf(nextLongId[EligibilityArm]), criteria = nextString(100), isCompound = nextBoolean(), - isDefining = nextBoolean() + isDefining = nextBoolean(), + inclusion = nextOption(nextBoolean()) ) def nextExportTrialWithLabels(): ExportTrialWithLabels = diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala index d5adc32..36ef3d9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala @@ -86,7 +86,8 @@ object treatmentmatching { verifiedEligibilityStatus = generators.nextOption(fakes.entities.labels.nextLabelValue()), isVerified = generators.nextBoolean(), isVisible = generators.nextBoolean(), - lastUpdate = nextLocalDateTime + lastUpdate = nextLocalDateTime, + inclusion = generators.nextOption(generators.nextBoolean()) ) def nextDraftPatientCriterion(): DraftPatientCriterion = DraftPatientCriterion( 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 b9bf772..5e44413 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 @@ -22,7 +22,8 @@ final case class ApiPatientCriterion(id: Long, verifiedEligibilityStatus: Option[String], isVerified: Boolean, isVisible: Boolean, - lastUpdate: ZonedDateTime) + lastUpdate: ZonedDateTime, + inclusion: Option[Boolean]) object ApiPatientCriterion { @@ -49,7 +50,8 @@ object ApiPatientCriterion { }), Writes.of[String])) and (JsPath \ "isVerified").format[Boolean] and (JsPath \ "isVisible").format[Boolean] and - (JsPath \ "lastUpdate").format[ZonedDateTime] + (JsPath \ "lastUpdate").format[ZonedDateTime] and + (JsPath \ "inclusion").formatNullable[Boolean] ) (ApiPatientCriterion.apply, unlift(ApiPatientCriterion.unapply)) def fromDomain(patientCriterion: PatientCriterion, @@ -70,6 +72,7 @@ object ApiPatientCriterion { verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(_.toString), isVerified = patientCriterion.isVerified, isVisible = patientCriterion.isVisible, - lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z")) + lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z")), + inclusion = patientCriterion.inclusion ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala index 4391453..9579288 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.entities.labels.Label import xyz.driver.formats.json.labels._ +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm} @@ -13,6 +14,14 @@ object export { import document._ import record._ + private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = { + deserializationError(s"$className json object do not contain '$field' field: $json") + } + + private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = { + deserializationError(s"Expected Json Object as $className, but got $json") + } + implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5(ExportPatientLabelEvidenceDocument.apply) @@ -29,6 +38,8 @@ object export { implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] = new RootJsonFormat[ExportTrialLabelCriterion] { + implicit val className: String = "ExportTrialLabelCriterion" + override def write(obj: ExportTrialLabelCriterion): JsValue = JsObject( "value" -> obj.value @@ -43,40 +54,69 @@ object export { "criterionText" -> obj.criteria.toJson, "armIds" -> obj.armIds.toJson, "isCompound" -> obj.isCompound.toJson, - "isDefining" -> obj.isDefining.toJson + "isDefining" -> obj.isDefining.toJson, + "inclusion" -> obj.inclusion.toJson ) override def read(json: JsValue): ExportTrialLabelCriterion = { + json match { + case JsObject(fields) => + val value = fields + .get("value") + .map(_.convertTo[String]) + .map { + case "Yes" => Option(true) + case "No" => Option(false) + case "Unknown" => Option.empty[Boolean] + } + .getOrElse(deserializationErrorFieldMessage("value", json)) - val fields = Seq("value", "labelId", "criterionId", "criterionText", "armIds", "isCompound", "isDefining") - - json.asJsObject.getFields(fields: _*) match { - case Seq(JsString(valueString), - labelId, - criterionId, - JsString(criterionText), - JsArray(armIdsVector), - JsBoolean(isCompound), - JsBoolean(isDefining)) => - val value = valueString match { - case "Yes" => Option(true) - case "No" => Option(false) - case "Unknown" => Option.empty[Boolean] - } + val labelId = fields + .get("labelId") + .map(_.convertTo[LongId[Label]]) + .getOrElse(deserializationErrorFieldMessage("labelId", json)) + + val criterionId = fields + .get("criterionId") + .map(_.convertTo[LongId[Criterion]]) + .getOrElse(deserializationErrorFieldMessage("criterionId", json)) + + val criterionText = fields + .get("criterionText") + .map(_.convertTo[String]) + .getOrElse(deserializationErrorFieldMessage("criterionText", json)) + + val armIds = fields + .get("armIds") + .map(_.convertTo[Set[LongId[EligibilityArm]]]) + .getOrElse(deserializationErrorFieldMessage("armIds", json)) + + val isCompound = fields + .get("isCompound") + .map(_.convertTo[Boolean]) + .getOrElse(deserializationErrorFieldMessage("isCompound", json)) + + val isDefining = fields + .get("isDefining") + .map(_.convertTo[Boolean]) + .getOrElse(deserializationErrorFieldMessage("isDefining", json)) + + val inclusion = fields + .get("inclusion") + .flatMap(_.convertTo[Option[Boolean]]) ExportTrialLabelCriterion( - longIdFormat[Criterion].read(criterionId), + criterionId, value, - longIdFormat[Label].read(labelId), - armIdsVector.map(longIdFormat[EligibilityArm].read).toSet, + labelId, + armIds, criterionText, isCompound, - isDefining + isDefining, + inclusion ) - case _ => - deserializationError( - s"Cannot find required fields ${fields.mkString(", ")} in ExportTrialLabelCriterion object!") + case _ => deserializationErrorEntityMessage(json) } } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala index f41c846..2cad78c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala @@ -56,7 +56,8 @@ object patientcriterion { "verifiedEligibilityStatus" -> obj.patientCriterion.verifiedEligibilityStatus.toJson, "isVerified" -> obj.patientCriterion.isVerified.toJson, "isVisible" -> obj.patientCriterion.isVisible.toJson, - "lastUpdate" -> obj.patientCriterion.lastUpdate.toJson + "lastUpdate" -> obj.patientCriterion.lastUpdate.toJson, + "inclusion" -> obj.patientCriterion.inclusion.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index e0efcd1..e23449c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -85,7 +85,8 @@ class FakeTrialService extends TrialService { generators.setOf(LongId[EligibilityArm](generators.nextInt(999999).toLong)), generators.nextName().value, generators.nextBoolean(), - generators.nextBoolean() + generators.nextBoolean(), + generators.nextOption(generators.nextBoolean()) )) ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala index 0ff29ef..7275e3c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala @@ -57,9 +57,9 @@ trait RestHelper { def exprToQuery(expr: SearchFilterExpr): Seq[(String, String)] = expr match { case SearchFilterExpr.Empty => Seq.empty case SearchFilterExpr.Atom.Binary(dimension, op, value) => - Seq("filters" -> s"${dimension.name} ${opToString(op)} $value") + Seq("filters" -> s"${dimension.tableName.fold("")(t => s"$t.") + dimension.name} ${opToString(op)} $value") case SearchFilterExpr.Atom.NAry(dimension, SearchFilterNAryOperation.In, values) => - Seq("filters" -> s"${dimension.name} in ${values.mkString(",")}") + Seq("filters" -> s"${dimension.tableName.fold("")(t => s"$t.") + dimension.name} in ${values.mkString(",")}") case SearchFilterExpr.Intersection(ops) => ops.flatMap(op => exprToQuery(op)) case expr => sys.error(s"No parser available for filter expression $expr.") |