aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr <ognelisar@gmail.com>2017-11-14 17:43:21 +0700
committerGitHub <noreply@github.com>2017-11-14 17:43:21 +0700
commit01392b84a06a086bc49803204a109a04837dba5b (patch)
tree3d15b3e5063b7e602f4a0aba5aab6df941e04494
parent29ee5de759374ceed9c856a51443a3f7c2cec029 (diff)
parent579951fa5fe2f518cb0281e6dcee346ae6dace74 (diff)
downloadrest-query-01392b84a06a086bc49803204a109a04837dba5b.tar.gz
rest-query-01392b84a06a086bc49803204a109a04837dba5b.tar.bz2
rest-query-01392b84a06a086bc49803204a109a04837dba5b.zip
Merge pull request #62 from drivergroup/PDSUI-2345
PDSUI-2345 Store some more granular information in records/documents history
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala87
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala108
3 files changed, 116 insertions, 83 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
index 95710be..0669baf 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
@@ -428,8 +428,8 @@ object Document {
}).right
areDatesInThePast <- {
- val dates = List(input.startDate, input.endDate).flatten
- val now = LocalDate.now()
+ val dates = List(input.startDate, input.endDate).flatten
+ val now = LocalDate.now()
val hasInvalid = dates.exists(_.isAfter(now))
if (hasInvalid) Validators.fail("Dates should be in the past")
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala
index 0a8480b..81fa240 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala
@@ -6,7 +6,9 @@ import xyz.driver.core.auth.User
import xyz.driver.pdsuicommon.domain._
import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils
-import xyz.driver.pdsuidomain.entities.DocumentHistory._
+import xyz.driver.pdsuidomain.entities.DocumentHistory.{Action, _}
+
+import scala.collection.immutable
object DocumentHistory {
@@ -21,20 +23,25 @@ object DocumentHistory {
case object Extract extends State
case object Review extends State
case object Flag extends State
+ case object New extends State
- val All: Set[State] = Set[State](Extract, Review, Flag)
-
- val fromString: PartialFunction[String, State] = {
- case "Extract" => State.Extract
- case "Review" => State.Review
- case "Flag" => State.Flag
+ private implicit def stateToName(state: State): (State, String) = {
+ state -> state.getClass.getSimpleName
}
- def stateToString(x: State): String = x match {
- case State.Extract => "Extract"
- case State.Review => "Review"
- case State.Flag => "Flag"
- }
+ private val stateToName = immutable.Map[State, String](
+ State.Extract,
+ State.Review,
+ State.Flag,
+ State.New
+ )
+
+ val All: Set[State] = stateToName.keySet
+
+ val fromString: PartialFunction[String, State] =
+ for ((k, v) <- stateToName) yield (v, k)
+
+ def stateToString: State => String = stateToName
implicit def toPhiString(x: State): PhiString =
Unsafe(Utils.getClassSimpleName(x.getClass))
@@ -49,38 +56,42 @@ object DocumentHistory {
}
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
+ 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
+ case object PostedEvidence extends Action
+ case object CreatedDocument extends Action
+ case object ReadDocument extends Action
+
+ private implicit def stateToName(action: Action): (Action, String) = {
+ action -> action.getClass.getSimpleName
}
- 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"
- }
+ private val actionToName = immutable.Map[Action, String](
+ Action.Start,
+ Action.Submit,
+ Action.Unassign,
+ Action.Resolve,
+ Action.Flag,
+ Action.Archive,
+ Action.PostedEvidence,
+ Action.CreatedDocument,
+ Action.ReadDocument
+ )
+
+ val All: Set[Action] = actionToName.keySet
+
+ val fromString: PartialFunction[String, Action] =
+ for ((k, v) <- actionToName) yield (v, k)
+
+ def actionToString: Action => String = actionToName
implicit def toPhiString(x: Action): PhiString =
Unsafe(Utils.getClassSimpleName(x.getClass))
}
-
}
final case class DocumentHistory(id: LongId[DocumentHistory],
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala
index 4259737..66fd5b0 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala
@@ -8,6 +8,8 @@ import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils
import xyz.driver.pdsuidomain.entities.MedicalRecordHistory._
+import scala.collection.immutable
+
object MedicalRecordHistory {
implicit def toPhiString(x: MedicalRecordHistory): PhiString = {
@@ -17,73 +19,93 @@ object MedicalRecordHistory {
}
sealed trait State
+
object State {
+ case object New extends State
case object Clean extends State
case object Organize extends State
case object Review extends State
case object Flag extends State
- val All: Set[State] = Set[State](Clean, Organize, Review, Flag)
-
- val fromString: PartialFunction[String, State] = {
- case "Clean" => State.Clean
- case "Organize" => State.Organize
- case "Review" => State.Review
- case "Flag" => State.Flag
+ private implicit def stateToName(state: State): (State, String) = {
+ state -> state.getClass.getSimpleName
}
- def stateToString(x: State): String = x match {
- case State.Clean => "Clean"
- case State.Organize => "Organize"
- case State.Review => "Review"
- case State.Flag => "Flag"
- }
+ private val stateToName = immutable.Map[State, String](
+ State.New,
+ State.Clean,
+ State.Organize,
+ State.Review,
+ State.Flag
+ )
+
+ val All: Set[State] = stateToName.keySet
+
+ val fromString: PartialFunction[String, State] =
+ for ((k, v) <- stateToName) yield (v, k)
+
+ def stateToString: State => String = stateToName
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: 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
+ 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
+ case object SavedDuplicate extends Action
+ case object SavedReorder extends Action
+ case object SavedRotation extends Action
+ case object DeletedDuplicate extends Action
+ case object DeletedReorder extends Action
+ case object DeletedRotation extends Action
+ case object CreatedDocument extends Action
+ case object DeletedDocument extends Action
+ case object CreatedRecord extends Action
+ case object ReadRecord extends Action
+
+ private implicit def stateToName(action: Action): (Action, String) = {
+ action -> action.getClass.getSimpleName
}
- 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"
- }
+ private val actionToName = immutable.Map[Action, String](
+ Action.Start,
+ Action.Submit,
+ Action.Unassign,
+ Action.Resolve,
+ Action.Flag,
+ Action.Archive,
+ Action.SavedDuplicate,
+ Action.SavedReorder,
+ Action.SavedRotation,
+ Action.DeletedDuplicate,
+ Action.DeletedReorder,
+ Action.DeletedRotation,
+ Action.CreatedDocument,
+ Action.DeletedDocument,
+ Action.CreatedRecord,
+ Action.ReadRecord
+ )
+
+ val fromString: PartialFunction[String, Action] =
+ for ((k, v) <- actionToName) yield (v, k)
+
+ val All: Set[Action] = actionToName.keySet
+
+ def actionToString: Action => String = actionToName
implicit def toPhiString(x: Action): PhiString =
Unsafe(Utils.getClassSimpleName(x.getClass))
}
-
}
final case class MedicalRecordHistory(id: LongId[MedicalRecordHistory],