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

import java.time.{LocalDateTime, ZoneId}

import xyz.driver.core.auth.User
import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils
import xyz.driver.pdsuidomain.entities.PatientHistory.{Action, State}

object PatientHistory {

  implicit def toPhiString(x: PatientHistory): PhiString = {
    import x._
    phi"PatientHistory(id=$id, executor=${Unsafe(executor)}, patientId=$patientId, " +
      phi"state=$state, action=$action, created=$created)"
  }

  sealed trait State
  object State {
    case object Verify extends State
    case object Curate extends State
    case object Review extends State
    case object Flag   extends State

    val All: Set[State] = Set[State](Verify, Curate, Review, Flag)

    val fromString: PartialFunction[String, State] = {
      case "Verify" => State.Verify
      case "Curate" => State.Curate
      case "Review" => State.Review
      case "Flag"   => State.Flag
    }

    def stateToString(x: State): String = x match {
      case State.Verify => "Verify"
      case State.Curate => "Curate"
      case State.Review => "Review"
      case State.Flag   => "Flag"
    }

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

  sealed trait Action extends Product with Serializable {

    def oneOf(xs: Action*): Boolean = xs.contains(this)

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

  }

  object Action {
    case object Start    extends Action
    case object Submit   extends Action
    case object Unassign extends Action
    case object Resolve  extends Action
    case object Flag     extends Action
    case object Archive  extends Action

    val All: Set[Action] =
      Set[Action](Start, Submit, Unassign, Resolve, Flag, Archive)

    val fromString: PartialFunction[String, Action] = {
      case "Start"    => Action.Start
      case "Submit"   => Action.Submit
      case "Unassign" => Action.Unassign
      case "Resolve"  => Action.Resolve
      case "Flag"     => Action.Flag
      case "Archive"  => Action.Archive
    }

    def actionToString(x: Action): String = x match {
      case Action.Start    => "Start"
      case Action.Submit   => "Submit"
      case Action.Unassign => "Unassign"
      case Action.Resolve  => "Resolve"
      case Action.Flag     => "Flag"
      case Action.Archive  => "Archive"
    }

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

}

final case class PatientHistory(id: LongId[PatientHistory],
                                executor: xyz.driver.core.Id[User],
                                patientId: UuidId[Patient],
                                state: State,
                                action: Action,
                                created: LocalDateTime = LocalDateTime.now(ZoneId.of("Z")))