aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala
blob: fa5ed616c04e6469ff69ef0c3b28d46102b13f4f (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package xyz.driver.pdsuidomain.entities

import java.time.LocalDateTime

import xyz.driver.core.auth.User
import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils
import xyz.driver.pdsuidomain.entities.Trial.Status

import scalaz.syntax.equal._
import scalaz.Scalaz.stringInstance

sealed trait StudyDesign {
  val id: LongId[StudyDesign]
  val name: String
}

object StudyDesign {

  final case object Randomized extends StudyDesign {
    val id: LongId[StudyDesign] = LongId[StudyDesign](1)
    val name: String            = "Randomized"
  }

  final case object NonRandomized extends StudyDesign {
    val id: LongId[StudyDesign] = LongId[StudyDesign](2)
    val name: String            = "Non-randomized"
  }

  final case object SingleGroupAssignment extends StudyDesign {
    val id: LongId[StudyDesign] = LongId[StudyDesign](3)
    val name: String            = "Single-group assignment"
  }

  val All = Seq[StudyDesign](
    Randomized,
    NonRandomized,
    SingleGroupAssignment
  )

  def fromString(txt: String): Option[StudyDesign] = {
    All.find(_.name === txt)
  }

  implicit def toPhiString(x: StudyDesign): PhiString = {
    import x._
    phi"StudyDesign(id=$id, category=${Unsafe(name)})"
  }
}

object TrialCreationRequest {

  implicit def toPhiString(x: TrialCreationRequest): PhiString = phi"${Unsafe(x.toString)}"
}

final case class TrialCreationRequest(id: UuidId[Trial], nctId: String, phase: String)

object Trial {

  sealed trait Status {
    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 ReviewSummary  extends Status
    case object Summarized     extends Status
    case object PendingUpdate  extends Status
    case object Update         extends Status
    case object ReviewCriteria extends Status
    case object Done           extends Status
    case object Flagged        extends Status
    case object Archived       extends Status

    val All: Set[Status] = Set[Status](
      New,
      ReviewSummary,
      Summarized,
      PendingUpdate,
      Update,
      ReviewCriteria,
      Done,
      Flagged,
      Archived
    )

    val AllPrevious: Set[Status] = Set[Status](New, ReviewSummary, Summarized, ReviewCriteria)

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

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

  final case class Locations(locations: List[String])
}

final case class Trial(id: StringId[Trial],
                       externalId: UuidId[Trial],
                       status: Status,
                       assignee: Option[xyz.driver.core.Id[User]],
                       previousStatus: Option[Status],
                       previousAssignee: Option[xyz.driver.core.Id[User]],
                       lastActiveUserId: Option[xyz.driver.core.Id[User]],
                       lastUpdate: LocalDateTime,
                       phase: String,
                       hypothesisId: Option[UuidId[Hypothesis]],
                       studyDesignId: Option[LongId[StudyDesign]],
                       originalStudyDesign: Option[String],
                       isPartner: Boolean,
                       overview: Option[String],
                       overviewTemplate: String,
                       isUpdated: Boolean,
                       title: String,
                       originalTitle: String) {
  import Trial.Status._

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