diff options
Diffstat (limited to 'src')
7 files changed, 189 insertions, 107 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..f076074 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -6,7 +6,7 @@ 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, _} object DocumentHistory { @@ -18,23 +18,29 @@ 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 Archive extends State - val All: Set[State] = Set[State](Extract, Review, Flag) + val All: Set[State] = Set( + State.New, + State.Extract, + State.Review, + State.Done, + State.Flag, + State.Archive + ) - val fromString: PartialFunction[String, State] = { - case "Extract" => State.Extract - case "Review" => State.Review - case "Flag" => State.Flag - } + private val stateToName: Map[State, String] = + All.map(s => s -> s.toString).toMap - def stateToString(x: State): String = x match { - case State.Extract => "Extract" - 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)) @@ -49,38 +55,39 @@ 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 PostEvidence extends Action + case object CreateDocument extends Action + case object ReadDocument extends Action + + val All: Set[Action] = Set( + Action.Start, + Action.Submit, + Action.Unassign, + Action.Resolve, + Action.Flag, + Action.Archive, + Action.PostEvidence, + Action.CreateDocument, + Action.ReadDocument + ) + + 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) + + 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..5ed5805 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecordHistory.scala @@ -17,73 +17,91 @@ 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 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.Done, + State.Flag, + State.Archive + ) - val All: Set[State] = Set[State](Clean, Organize, Review, Flag) + private val stateToName: Map[State, String] = + All.map(s => s -> s.toString).toMap - val fromString: PartialFunction[String, State] = { - case "Clean" => State.Clean - case "Organize" => State.Organize - 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.Clean => "Clean" - case State.Organize => "Organize" - case State.Review => "Review" - case State.Flag => "Flag" - } + 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 - } - - 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 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, + Action.Submit, + Action.Unassign, + Action.Resolve, + Action.Flag, + Action.Archive, + Action.SaveDuplicate, + Action.SaveReorder, + Action.SaveRotation, + Action.DeleteDuplicate, + Action.DeleteReorder, + Action.DeleteRotation, + Action.CreateDocument, + Action.DeleteDocument, + Action.CreateRecord, + 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) + + def actionToString: Action => String = actionToName implicit def toPhiString(x: Action): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass)) } - } final case class MedicalRecordHistory(id: LongId[MedicalRecordHistory], 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), |