aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/entities/export/trial')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala27
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala15
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala52
4 files changed, 126 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala
new file mode 100644
index 0000000..1aed121
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala
@@ -0,0 +1,27 @@
+package xyz.driver.pdsuidomain.entities.export.trial
+
+import java.time.LocalDateTime
+
+import xyz.driver.pdsuicommon.domain._
+import xyz.driver.pdsuicommon.logging._
+import xyz.driver.pdsuidomain.entities.Trial
+
+final case class ExportTrial(nctId: StringId[Trial],
+ trialId: UuidId[Trial],
+ condition: Trial.Condition,
+ lastReviewed: LocalDateTime)
+
+object ExportTrial {
+
+ implicit def toPhiString(x: ExportTrial): PhiString = {
+ import x._
+ phi"ExportTrial(nctId=$nctId, trialId=$trialId, condition=${Unsafe(condition)}, lastReviewed=$lastReviewed)"
+ }
+
+ def fromDomain(x: Trial) = ExportTrial(
+ nctId = x.id,
+ trialId = x.externalId,
+ condition = x.condition,
+ lastReviewed = x.lastUpdate
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala
new file mode 100644
index 0000000..5a9a406
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala
@@ -0,0 +1,15 @@
+package xyz.driver.pdsuidomain.entities.export.trial
+
+import xyz.driver.pdsuicommon.domain._
+import xyz.driver.pdsuicommon.logging._
+import xyz.driver.pdsuidomain.entities.Arm
+
+final case class ExportTrialArm(armId: LongId[Arm], armName: String)
+
+object ExportTrialArm {
+
+ implicit def toPhiString(x: ExportTrialArm): PhiString = {
+ import x._
+ phi"ExportTrialArm(armId=$armId, armName=${Unsafe(armName)})"
+ }
+}
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
new file mode 100644
index 0000000..7bff22c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala
@@ -0,0 +1,32 @@
+package xyz.driver.pdsuidomain.entities.export.trial
+
+import xyz.driver.pdsuicommon.domain._
+import xyz.driver.pdsuicommon.logging._
+import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label, RawTrialLabel}
+
+final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion],
+ value: Option[Boolean],
+ labelId: LongId[Label],
+ armIds: Set[LongId[Arm]],
+ criteria: String,
+ isCompound: Boolean,
+ isDefining: 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)"
+ }
+
+ def fromRaw(x: RawTrialLabel, armIds: Set[LongId[Arm]]) = ExportTrialLabelCriterion(
+ criterionId = x.criterionId,
+ value = x.value,
+ labelId = x.labelId,
+ armIds = armIds,
+ criteria = x.criteria,
+ isCompound = x.isCompound,
+ isDefining = x.isDefining
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala
new file mode 100644
index 0000000..1655a88
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala
@@ -0,0 +1,52 @@
+package xyz.driver.pdsuidomain.entities.export.trial
+
+import java.time.LocalDateTime
+
+import xyz.driver.pdsuicommon.domain._
+import xyz.driver.pdsuicommon.logging._
+import xyz.driver.pdsuidomain.entities.{RawTrialLabel, Trial}
+
+import scala.collection.breakOut
+
+final case class ExportTrialWithLabels(nctId: StringId[Trial],
+ trialId: UuidId[Trial],
+ condition: String,
+ lastReviewed: LocalDateTime,
+ labelVersion: Long,
+ arms: List[ExportTrialArm],
+ criteria: List[ExportTrialLabelCriterion])
+
+object ExportTrialWithLabels {
+
+ implicit def toPhiString(x: ExportTrialWithLabels): PhiString = {
+ import x._
+ phi"TrialWithLabels(nctId=$nctId, trialId=$trialId, condition=${Unsafe(condition)}, " +
+ phi"lastReviewed=$lastReviewed, labelVersion=${Unsafe(labelVersion)}, arms=$arms, criteria=$criteria)"
+ }
+
+ def fromRaw(rawData: List[RawTrialLabel]): ExportTrialWithLabels = {
+ val trials: Set[StringId[Trial]] = rawData.map(_.nctId)(breakOut)
+
+ assert(trials.size == 1, "There are more than one trials in the rawData")
+ val trial = rawData.head
+
+ ExportTrialWithLabels(
+ nctId = trial.nctId,
+ trialId = trial.trialId,
+ condition = trial.condition,
+ lastReviewed = trial.lastReviewed,
+ labelVersion = 1, // TODO It is needed to replace this mock label version.
+ arms = rawData.groupBy(_.armId).map { case (armId, rawTrials) =>
+ ExportTrialArm(armId, rawTrials.head.armName)
+ }(breakOut),
+ criteria = rawData.groupBy { x =>
+ (x.criterionId, x.labelId)
+ }.map {
+ case (_, rawTrialLabels) =>
+ val armIds = rawTrialLabels.map(_.criterionArmId).toSet
+ ExportTrialLabelCriterion.fromRaw(rawTrialLabels.head, armIds)
+ }(breakOut)
+ )
+ }
+
+}