aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala
blob: 7767db04cccd8c837f8dbbce875fcbc231bdafd8 (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
package xyz.driver.pdsuidomain.entities

import java.time.{LocalDate, LocalDateTime}

import xyz.driver.pdsuicommon.domain.{LongId, User, UuidId}
import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils

object Patient {

  // Product with Serizalizable fixes issue:
  // Set(New, Verified) has type Set[Status with Product with Serializable]
  sealed trait Status extends Product with Serializable {
    def oneOf(xs: Status*): Boolean = xs.contains(this)

    def oneOf(xs: Set[Status]): Boolean = xs.contains(this)
  }

  object Status {
    case object New extends Status
    case object Verified extends Status
    case object Reviewed extends Status
    case object Curated extends Status
    case object Flagged extends Status
    case object Done extends Status

    val AllPrevious = Set[Status](
      New, Verified, Reviewed, Curated
    )

    val All = Set[Status](
      New, Verified, Reviewed, Curated, Flagged, Done
    )

    implicit def toPhiString(x: Status): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass))
  }

  implicit def toPhiString(x: Patient): PhiString = {
    import x._
    phi"Patient(id=$id, status=$status, previousStatus=$previousStatus, " +
      phi"assignee=$assignee, previousAssignee=$previousAssignee)"
  }
}

case class Patient(id: UuidId[Patient],
                   status: Patient.Status,
                   name: String,
                   dob: LocalDate,
                   assignee: Option[LongId[User]],
                   previousStatus: Option[Patient.Status],
                   previousAssignee: Option[LongId[User]],
                   isUpdateRequired: Boolean,
                   condition: String,
                   orderId: PatientOrderId,
                   lastUpdate: LocalDateTime) {

  import Patient.Status._

  if (previousStatus.nonEmpty) {
    assert(AllPrevious.contains(previousStatus.get),
      s"Previous status has invalid value: ${previousStatus.get}")
  }
}