aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala
blob: e6d466a86294237d07b7dd700acd6478f184489c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package xyz.driver.pdsuidomain.entities

import java.time.LocalDateTime

import xyz.driver.entities.labels.{Label, LabelValue}
import xyz.driver.pdsuicommon.domain.{LongId, StringId}
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=$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)}, inclusion=${Unsafe(inclusion)}"
  }

  /**
    * @see https://driverinc.atlassian.net/wiki/display/MTCH/EV+Business+Process
    */
  def getEligibilityStatus(criterionValue: Option[Boolean], primaryValue: LabelValue): LabelValue = {
    primaryValue match {
      case LabelValue.Unknown          => LabelValue.Unknown
      case LabelValue.Maybe            => LabelValue.Maybe
      case _ if criterionValue.isEmpty => LabelValue.Maybe
      case status =>
        LabelValue.fromBoolean(
          LabelValue.fromBoolean(
            criterionValue.getOrElse(throw new IllegalArgumentException("Criterion should not be empty"))) == status
        )
    }
  }

}

/**
  * @param eligibilityStatus - a value, that selects an eligibility verifier (EV)
  * @param verifiedEligibilityStatus - a copy of eligibilityStatus, when a patient goes to routes curator (RC)
  * @param isVerified - is EV selected the eligibilityStatus?
  */
final case class PatientCriterion(id: LongId[PatientCriterion],
                                  patientLabelId: LongId[PatientLabel],
                                  trialId: Long,
                                  nctId: StringId[Trial],
                                  criterionId: LongId[Criterion],
                                  criterionText: String,
                                  criterionValue: Option[Boolean],
                                  criterionIsDefining: Boolean,
                                  eligibilityStatus: LabelValue,
                                  verifiedEligibilityStatus: LabelValue,
                                  isVerified: Boolean,
                                  isVisible: Boolean,
                                  lastUpdate: LocalDateTime,
                                  inclusion: Option[Boolean]) {
  import scalaz.syntax.equal._
  def isIneligibleForEv: Boolean = eligibilityStatus === LabelValue.No && isVerified
}

final case class DraftPatientCriterion(id: LongId[PatientCriterion],
                                       eligibilityStatus: Option[LabelValue],
                                       isVerified: Option[Boolean]) {
  def applyTo(orig: PatientCriterion) = {
    orig.copy(
      eligibilityStatus = eligibilityStatus.getOrElse(orig.eligibilityStatus),
      isVerified = isVerified.getOrElse(orig.isVerified)
    )
  }
}

object DraftPatientCriterion {
  implicit def toPhiString(x: DraftPatientCriterion): PhiString = {
    phi"DraftPatientCriterion(id=${x.id}, eligibilityStatus=${Unsafe(x.eligibilityStatus)}, isVerified=${x.isVerified})"
  }
}

final case class RichPatientCriterion(patientCriterion: PatientCriterion,
                                      labelId: LongId[Label],
                                      armList: List[PatientCriterionArm])

object RichPatientCriterion {
  implicit def toPhiString(x: RichPatientCriterion): PhiString = {
    phi"RichPatientCriterion(patientCriterion=${x.patientCriterion}, labelId=${x.labelId}, arms=${x.armList})"
  }
}

object PatientCriterionArm {

  implicit def toPhiString(x: PatientCriterionArm): PhiString = {
    import x._
    phi"PatientCriterionArm(patientCriterionId=$patientCriterionId, armId=$armId, armName=${Unsafe(armName)})"
  }

}

final case class PatientCriterionArm(patientCriterionId: LongId[PatientCriterion], armId: LongId[Arm], armName: String)