From f4a3b7aad2075eee91433a000be19cddcb32c7ad Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 9 Nov 2017 15:18:41 +0700 Subject: Added Actions to MedicalRecordHistory object --- .../entities/MedicalRecordHistory.scala | 48 ++++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala index 4259737..65c2731 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -52,32 +52,44 @@ object MedicalRecordHistory { } 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 + 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 Duplicate extends Action + case object Reorder extends Action + case object Rotation extends Action + case object Clean 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 "Start" => Action.Start + case "Submit" => Action.Submit + case "Unassign" => Action.Unassign + case "Resolve" => Action.Resolve + case "Flag" => Action.Flag + case "Archive" => Action.Archive + case "Duplicate" => Action.Duplicate + case "Reorder" => Action.Reorder + case "Rotate" => Action.Rotation + case "Clean" => Action.Clean } 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" + case Action.Start => "Start" + case Action.Submit => "Submit" + case Action.Unassign => "Unassign" + case Action.Resolve => "Resolve" + case Action.Flag => "Flag" + case Action.Archive => "Archive" + case Action.Duplicate => "Duplicate" + case Action.Reorder => "Reorder" + case Action.Rotation => "Rotate" + case Action.Clean => "Clean" } implicit def toPhiString(x: Action): PhiString = -- cgit v1.2.3 From 2afec69b277c031eb52e1a05e57ff7bb0079f8d1 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 14 Nov 2017 15:44:43 +0700 Subject: Implemented Actions for DocumentHistoryService and MedicalRecordHistoryService --- .../pdsuidomain/entities/DocumentHistory.scala | 85 +++++++-------- .../entities/MedicalRecordHistory.scala | 114 ++++++++++----------- 2 files changed, 102 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 0a8480b..a1404a7 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,21 @@ object DocumentHistory { case object Extract extends State case object Review extends State case object Flag extends State + case object New extends State + + private val stateToName = immutable.Map[State, String]( + State.Extract -> "Extract", + State.Review -> "Review", + State.Flag -> "Flag", + State.New -> "New" + ) - val All: Set[State] = Set[State](Extract, Review, Flag) + val All: Set[State] = stateToName.keySet - val fromString: PartialFunction[String, State] = { - case "Extract" => State.Extract - case "Review" => State.Review - case "Flag" => State.Flag - } + val fromString: PartialFunction[String, State] = + for ((k, v) <- stateToName) yield (v, k) - def stateToString(x: State): String = x match { - case State.Extract => "Extract" - case State.Review => "Review" - case State.Flag => "Flag" - } + def stateToString: State => String = stateToName implicit def toPhiString(x: State): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass)) @@ -49,38 +52,40 @@ 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 - } - - 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" - } + 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 + case object DeletedDocument extends Action + + private val actionToName = immutable.Map[Action, String]( + Action.Start -> "Start", + Action.Submit -> "Submit", + Action.Unassign -> "Unassign", + Action.Resolve -> "Resolve", + Action.Flag -> "Flag", + Action.Archive -> "Archive", + Action.PostedEvidence -> "PostedEvidence", + Action.CreatedDocument -> "CreatedDocument", + Action.DeletedDocument -> "DeletedDocument", + Action.ReadDocument -> "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 65c2731..b97120b 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,85 +19,83 @@ object MedicalRecordHistory { } sealed trait State + object 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) + private val stateToName = immutable.Map[State, String]( + State.Clean -> "Clean", + State.Organize -> "Organize", + State.Review -> "Review", + State.Flag -> "Flag" + ) - val fromString: PartialFunction[String, State] = { - case "Clean" => State.Clean - case "Organize" => State.Organize - case "Review" => State.Review - case "Flag" => State.Flag - } + val All: Set[State] = stateToName.keySet - def stateToString(x: State): String = x match { - case State.Clean => "Clean" - case State.Organize => "Organize" - case State.Review => "Review" - case State.Flag => "Flag" - } + 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 - case object Duplicate extends Action - case object Reorder extends Action - case object Rotation extends Action - case object Clean 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 "Duplicate" => Action.Duplicate - case "Reorder" => Action.Reorder - case "Rotate" => Action.Rotation - case "Clean" => Action.Clean - } - - 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" - case Action.Duplicate => "Duplicate" - case Action.Reorder => "Reorder" - case Action.Rotation => "Rotate" - case Action.Clean => "Clean" - } + 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 val actionToName = immutable.Map[Action, String]( + Action.Start -> "Start", + Action.Submit -> "Submit", + Action.Unassign -> "Unassign", + Action.Resolve -> "Resolve", + Action.Flag -> "Flag", + Action.Archive -> "Archive", + Action.SavedDuplicate -> "SavedDuplicate", + Action.SavedReorder -> "SavedReorder", + Action.SavedRotation -> "SavedRotate", + Action.DeletedDuplicate -> "DeletedDuplicate", + Action.DeletedReorder -> "DeletedReorder", + Action.DeletedRotation -> "DeletedRotation", + Action.CreatedDocument -> "CreatedDocument", + Action.DeletedDocument -> "DeletedDocument", + Action.CreatedRecord -> "CreatedRecord", + Action.ReadRecord -> "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], -- cgit v1.2.3 From 579951fa5fe2f518cb0281e6dcee346ae6dace74 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 14 Nov 2017 17:14:10 +0700 Subject: Improved DocumentHistory and MedicalRecordHistory --- .../xyz/driver/pdsuidomain/entities/Document.scala | 4 +- .../pdsuidomain/entities/DocumentHistory.scala | 36 +++++++++------- .../entities/MedicalRecordHistory.scala | 50 +++++++++++++--------- 3 files changed, 53 insertions(+), 37 deletions(-) (limited to 'src') 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 a1404a7..81fa240 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -25,11 +25,15 @@ object DocumentHistory { case object Flag extends State case object New extends State + private implicit def stateToName(state: State): (State, String) = { + state -> state.getClass.getSimpleName + } + private val stateToName = immutable.Map[State, String]( - State.Extract -> "Extract", - State.Review -> "Review", - State.Flag -> "Flag", - State.New -> "New" + State.Extract, + State.Review, + State.Flag, + State.New ) val All: Set[State] = stateToName.keySet @@ -61,19 +65,21 @@ object DocumentHistory { case object PostedEvidence extends Action case object CreatedDocument extends Action case object ReadDocument extends Action - case object DeletedDocument extends Action + + private implicit def stateToName(action: Action): (Action, String) = { + action -> action.getClass.getSimpleName + } private val actionToName = immutable.Map[Action, String]( - Action.Start -> "Start", - Action.Submit -> "Submit", - Action.Unassign -> "Unassign", - Action.Resolve -> "Resolve", - Action.Flag -> "Flag", - Action.Archive -> "Archive", - Action.PostedEvidence -> "PostedEvidence", - Action.CreatedDocument -> "CreatedDocument", - Action.DeletedDocument -> "DeletedDocument", - Action.ReadDocument -> "ReadDocument" + Action.Start, + Action.Submit, + Action.Unassign, + Action.Resolve, + Action.Flag, + Action.Archive, + Action.PostedEvidence, + Action.CreatedDocument, + Action.ReadDocument ) val All: Set[Action] = actionToName.keySet diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala index b97120b..66fd5b0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -21,16 +21,22 @@ 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 + private implicit def stateToName(state: State): (State, String) = { + state -> state.getClass.getSimpleName + } + private val stateToName = immutable.Map[State, String]( - State.Clean -> "Clean", - State.Organize -> "Organize", - State.Review -> "Review", - State.Flag -> "Flag" + State.New, + State.Clean, + State.Organize, + State.Review, + State.Flag ) val All: Set[State] = stateToName.keySet @@ -67,23 +73,27 @@ object MedicalRecordHistory { case object CreatedRecord extends Action case object ReadRecord extends Action + private implicit def stateToName(action: Action): (Action, String) = { + action -> action.getClass.getSimpleName + } + private val actionToName = immutable.Map[Action, String]( - Action.Start -> "Start", - Action.Submit -> "Submit", - Action.Unassign -> "Unassign", - Action.Resolve -> "Resolve", - Action.Flag -> "Flag", - Action.Archive -> "Archive", - Action.SavedDuplicate -> "SavedDuplicate", - Action.SavedReorder -> "SavedReorder", - Action.SavedRotation -> "SavedRotate", - Action.DeletedDuplicate -> "DeletedDuplicate", - Action.DeletedReorder -> "DeletedReorder", - Action.DeletedRotation -> "DeletedRotation", - Action.CreatedDocument -> "CreatedDocument", - Action.DeletedDocument -> "DeletedDocument", - Action.CreatedRecord -> "CreatedRecord", - Action.ReadRecord -> "ReadRecord" + 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] = -- cgit v1.2.3 From 1bb4b39dc9f407238307a121b2846ca79e3636e7 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 14 Nov 2017 18:16:50 +0700 Subject: Fixed MedicalRecordHistory and DocumentHistory --- src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala | 4 ++-- .../scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 81fa240..5c96f94 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -26,7 +26,7 @@ object DocumentHistory { case object New extends State private implicit def stateToName(state: State): (State, String) = { - state -> state.getClass.getSimpleName + state -> state.toString } private val stateToName = immutable.Map[State, String]( @@ -67,7 +67,7 @@ object DocumentHistory { case object ReadDocument extends Action private implicit def stateToName(action: Action): (Action, String) = { - action -> action.getClass.getSimpleName + action -> action.toString } private val actionToName = immutable.Map[Action, String]( diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala index 66fd5b0..f08f3de 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -28,7 +28,7 @@ object MedicalRecordHistory { case object Flag extends State private implicit def stateToName(state: State): (State, String) = { - state -> state.getClass.getSimpleName + state -> state.toString } private val stateToName = immutable.Map[State, String]( @@ -74,7 +74,7 @@ object MedicalRecordHistory { case object ReadRecord extends Action private implicit def stateToName(action: Action): (Action, String) = { - action -> action.getClass.getSimpleName + action -> action.toString } private val actionToName = immutable.Map[Action, String]( -- cgit v1.2.3 From aa7f7297daf13c6a31578959299484dc4be4ccc7 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 14 Nov 2017 18:38:26 +0700 Subject: Simplified DocumentHistory and MedicalRecordHistory --- .../pdsuidomain/entities/DocumentHistory.scala | 20 ++++++-------------- .../entities/MedicalRecordHistory.scala | 22 +++++++--------------- 2 files changed, 13 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 5c96f94..089658e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -8,8 +8,6 @@ import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuicommon.utils.Utils import xyz.driver.pdsuidomain.entities.DocumentHistory.{Action, _} -import scala.collection.immutable - object DocumentHistory { implicit def toPhiString(x: DocumentHistory): PhiString = { @@ -25,18 +23,15 @@ object DocumentHistory { case object Flag extends State case object New extends State - private implicit def stateToName(state: State): (State, String) = { - state -> state.toString - } - - private val stateToName = immutable.Map[State, String]( + val All: Set[State] = Set( State.Extract, State.Review, State.Flag, State.New ) - val All: Set[State] = stateToName.keySet + private val stateToName: Map[State, String] = + All.map(s => s -> s.toString).toMap val fromString: PartialFunction[String, State] = for ((k, v) <- stateToName) yield (v, k) @@ -66,11 +61,7 @@ object DocumentHistory { case object CreatedDocument extends Action case object ReadDocument extends Action - private implicit def stateToName(action: Action): (Action, String) = { - action -> action.toString - } - - private val actionToName = immutable.Map[Action, String]( + val All: Set[Action] = Set( Action.Start, Action.Submit, Action.Unassign, @@ -82,7 +73,8 @@ object DocumentHistory { Action.ReadDocument ) - val All: Set[Action] = actionToName.keySet + private val actionToName: Map[Action, String] = + All.map(a => a -> a.toString).toMap val fromString: PartialFunction[String, Action] = for ((k, v) <- actionToName) yield (v, k) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala index f08f3de..bdbdc93 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -8,8 +8,6 @@ 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 = { @@ -27,11 +25,7 @@ object MedicalRecordHistory { case object Review extends State case object Flag extends State - private implicit def stateToName(state: State): (State, String) = { - state -> state.toString - } - - private val stateToName = immutable.Map[State, String]( + val All: Set[State] = Set( State.New, State.Clean, State.Organize, @@ -39,7 +33,8 @@ object MedicalRecordHistory { State.Flag ) - val All: Set[State] = stateToName.keySet + private val stateToName: Map[State, String] = + All.map(s => s -> s.toString).toMap val fromString: PartialFunction[String, State] = for ((k, v) <- stateToName) yield (v, k) @@ -73,11 +68,7 @@ object MedicalRecordHistory { case object CreatedRecord extends Action case object ReadRecord extends Action - private implicit def stateToName(action: Action): (Action, String) = { - action -> action.toString - } - - private val actionToName = immutable.Map[Action, String]( + val All: Set[Action] = Set( Action.Start, Action.Submit, Action.Unassign, @@ -96,11 +87,12 @@ object MedicalRecordHistory { Action.ReadRecord ) + private val actionToName: Map[Action, String] = + All.map(a => a -> a.toString).toMap + 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 = -- cgit v1.2.3 From ec2cf8d63735d842cd34206d95a597819991f8c5 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 15 Nov 2017 11:46:54 +0700 Subject: Added new states to DocumentHistory and MedicalRecordHistory --- .../pdsuidomain/entities/DocumentHistory.scala | 30 +++++++----- .../entities/MedicalRecordHistory.scala | 56 ++++++++++++---------- 2 files changed, 47 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 089658e..452caa7 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -18,16 +18,20 @@ object DocumentHistory { sealed trait State object State { + case object New extends State case object Extract extends State case object Review extends State + case object Done extends State case object Flag extends State - case object New extends State + case object Archive extends State val All: Set[State] = Set( + State.New, State.Extract, State.Review, + State.Done, State.Flag, - State.New + State.Archive ) private val stateToName: Map[State, String] = @@ -51,15 +55,15 @@ 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 - case object PostedEvidence extends Action - case object CreatedDocument extends Action - case object ReadDocument extends 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 + case object PosteEvidence extends Action + case object CreateDocument extends Action + case object ReadDocument extends Action val All: Set[Action] = Set( Action.Start, @@ -68,8 +72,8 @@ object DocumentHistory { Action.Resolve, Action.Flag, Action.Archive, - Action.PostedEvidence, - Action.CreatedDocument, + Action.PosteEvidence, + Action.CreateDocument, Action.ReadDocument ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala index bdbdc93..5ed5805 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -23,14 +23,18 @@ object MedicalRecordHistory { case object Clean extends State case object Organize extends State case object Review extends State + case object Done extends State case object Flag extends State + case object Archive extends State val All: Set[State] = Set( State.New, State.Clean, State.Organize, State.Review, - State.Flag + State.Done, + State.Flag, + State.Archive ) private val stateToName: Map[State, String] = @@ -51,22 +55,22 @@ object MedicalRecordHistory { } 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 - 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 + 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 SaveDuplicate extends Action + case object SaveReorder extends Action + case object SaveRotation extends Action + case object DeleteDuplicate extends Action + case object DeleteReorder extends Action + case object DeleteRotation extends Action + case object CreateDocument extends Action + case object DeleteDocument extends Action + case object CreateRecord extends Action + case object ReadRecord extends Action val All: Set[Action] = Set( Action.Start, @@ -75,15 +79,15 @@ object MedicalRecordHistory { 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.SaveDuplicate, + Action.SaveReorder, + Action.SaveRotation, + Action.DeleteDuplicate, + Action.DeleteReorder, + Action.DeleteRotation, + Action.CreateDocument, + Action.DeleteDocument, + Action.CreateRecord, Action.ReadRecord ) -- cgit v1.2.3 From 9d907320174e59b29a3293d937b5e6eb7fd55af9 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 15 Nov 2017 12:19:39 +0700 Subject: Fixed typo --- src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 452caa7..43a1832 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -61,7 +61,7 @@ object DocumentHistory { case object Resolve extends Action case object Flag extends Action case object Archive extends Action - case object PosteEvidence extends Action + case object PostEvidence extends Action case object CreateDocument extends Action case object ReadDocument extends Action @@ -72,7 +72,7 @@ object DocumentHistory { Action.Resolve, Action.Flag, Action.Archive, - Action.PosteEvidence, + Action.PostEvidence, Action.CreateDocument, Action.ReadDocument ) -- cgit v1.2.3 From 977e5e1a17a385fdc215251924da0a64228413b5 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 15 Nov 2017 14:49:50 +0700 Subject: Fixed json formats for DocumentHistory and MedicalRecordHistory; Added tests for them --- .../pdsuidomain/entities/DocumentHistory.scala | 2 +- .../pdsuidomain/formats/json/documenthistory.scala | 20 ++++++++++------ .../pdsuidomain/formats/json/recordhistory.scala | 27 ++++++++++++++++------ .../formats/json/DocumentHistoryFormatSuite.scala | 24 ++++++++++++++++--- .../json/MedicalRecordHistoryFormatSuite.scala | 26 ++++++++++++++++++--- 5 files changed, 78 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 43a1832..f076074 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -61,7 +61,7 @@ object DocumentHistory { case object Resolve extends Action case object Flag extends Action case object Archive extends Action - case object PostEvidence extends Action + case object PostEvidence extends Action case object CreateDocument extends Action case object ReadDocument extends Action diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala index ea79b92..1652f7b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala @@ -10,18 +10,24 @@ object documenthistory { import common._ implicit val documentStateFormat = new EnumJsonFormat[State]( + "New" -> State.New, "Extract" -> State.Extract, + "Done" -> State.Done, "Review" -> State.Review, - "Flag" -> State.Flag + "Flag" -> State.Flag, + "Archive" -> State.Archive ) implicit val documentActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive + "Start" -> Action.Start, + "Submit" -> Action.Submit, + "Unassign" -> Action.Unassign, + "Resolve" -> Action.Resolve, + "Flag" -> Action.Flag, + "Archive" -> Action.Archive, + "PostEvidence" -> Action.PostEvidence, + "CreateDocument" -> Action.CreateDocument, + "ReadDocument" -> Action.ReadDocument ) implicit val documentHistoryFormat: RootJsonFormat[DocumentHistory] = jsonFormat6(DocumentHistory.apply) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala index 8341f97..be9dae9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala @@ -10,19 +10,32 @@ object recordhistory { import common._ implicit val recordStateFormat = new EnumJsonFormat[State]( + "New" -> State.New, "Clean" -> State.Clean, "Organize" -> State.Organize, "Review" -> State.Review, - "Flag" -> State.Flag + "Done" -> State.Done, + "Flag" -> State.Flag, + "Archive" -> State.Archive ) implicit val recordActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive + "Start" -> Action.Start, + "Submit" -> Action.Submit, + "Unassign" -> Action.Unassign, + "Resolve" -> Action.Resolve, + "Flag" -> Action.Flag, + "Archive" -> Action.Archive, + "SaveDuplicate" -> Action.SaveDuplicate, + "SaveReorder" -> Action.SaveReorder, + "SaveRotation" -> Action.SaveRotation, + "DeleteDuplicate" -> Action.DeleteDuplicate, + "DeleteReorder" -> Action.DeleteReorder, + "DeleteRotation" -> Action.DeleteRotation, + "CreateDocument" -> Action.CreateDocument, + "DeleteDocument" -> Action.DeleteDocument, + "CreateRecord" -> Action.CreateRecord, + "ReadRecord" -> Action.ReadRecord ) implicit val recordHistoryFormat: RootJsonFormat[MedicalRecordHistory] = jsonFormat6(MedicalRecordHistory.apply) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala index 4dc4d00..d85a53b 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala @@ -2,15 +2,33 @@ package xyz.driver.pdsuidomain.formats.json import java.time.LocalDateTime -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.{FreeSpecLike, Matchers} import spray.json._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.DocumentHistory -class DocumentHistoryFormatSuite extends FlatSpec with Matchers { +class DocumentHistoryFormatSuite extends FreeSpecLike with Matchers { import xyz.driver.pdsuidomain.formats.json.documenthistory._ - "Json format for DocumentHistory" should "read and write correct JSON" in { + "Can read and write DocumentHistory states" - { + val states = DocumentHistory.State.All + states.foreach { state =>s"$state" in test(state)} + } + + "Can read and write DocumentHistory actions" - { + val actions = DocumentHistory.Action.All + actions.foreach { action =>s"$action" in test(action)} + } + + private def test(state: DocumentHistory.State) = { + documentStateFormat.read(documentStateFormat.write(state)) shouldBe state + } + + private def test(action: DocumentHistory.Action) = { + documentActionFormat.read(documentActionFormat.write(action)) shouldBe action + } + + "Json format for DocumentHistory should read and write correct JSON" - { val documentHistory = DocumentHistory( id = LongId(10), documentId = LongId(1), diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala index 88240cd..c34f8c0 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala @@ -2,15 +2,35 @@ package xyz.driver.pdsuidomain.formats.json import java.time.LocalDateTime -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.{FreeSpecLike, Matchers} import spray.json._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.MedicalRecordHistory -class MedicalRecordHistoryFormatSuite extends FlatSpec with Matchers { +class MedicalRecordHistoryFormatSuite extends FreeSpecLike with Matchers { import xyz.driver.pdsuidomain.formats.json.recordhistory._ - "Json format for MedicalRecordHistory" should "read and write correct JSON" in { + + "Can read and write MedicalRecordHistory states" - { + val states = MedicalRecordHistory.State.All + states.foreach { state =>s"$state" in test(state)} + } + + "Can read and write MedicalRecordHistory actions" - { + val actions = MedicalRecordHistory.Action.All + actions.foreach { action =>s"$action" in test(action)} + } + + private def test(state: MedicalRecordHistory.State) = { + recordStateFormat.read(recordStateFormat.write(state)) shouldBe state + } + + private def test(action: MedicalRecordHistory.Action) = { + recordActionFormat.read(recordActionFormat.write(action)) shouldBe action + } + + + "Json format for MedicalRecordHistory should read and write correct JSON" - { val recordHistory = MedicalRecordHistory( id = LongId(10), recordId = LongId(1), -- cgit v1.2.3