diff options
4 files changed, 170 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala index 07d5014..f2a0ef0 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala @@ -187,6 +187,12 @@ object ACL extends PhiLogging { update = TreatmentMatchingRoles ) + object PatientHistory + extends BaseACL( + label = "patient history", + read = Set(TreatmentMatchingAdmin) + ) + object PatientIssue extends BaseACL( label = "patient issue", diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientHistory.scala new file mode 100644 index 0000000..39817c4 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientHistory.scala @@ -0,0 +1,92 @@ +package xyz.driver.pdsuidomain.entities + +import java.time.{LocalDateTime, ZoneId} + +import xyz.driver.pdsuicommon.domain.{LongId, StringId, User, 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=$executor, patientId=$patientId, 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: StringId[User], + patientId: UuidId[Patient], + state: State, + action: Action, + created: LocalDateTime = LocalDateTime.now(ZoneId.of("Z"))) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala new file mode 100644 index 0000000..cdcd510 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala @@ -0,0 +1,28 @@ +package xyz.driver.pdsuidomain.formats.json.patienthistory + +import java.time.{ZoneId, ZonedDateTime} +import java.util.UUID + +import play.api.libs.json.{Format, Json} +import xyz.driver.pdsuidomain.entities.PatientHistory + +final case class ApiPatientHistory(id: Long, + executor: String, + patientId: UUID, + state: String, + action: String, + created: ZonedDateTime) + +object ApiPatientHistory { + implicit val format: Format[ApiPatientHistory] = + Json.format[ApiPatientHistory] + + def fromDomain(x: PatientHistory) = ApiPatientHistory( + id = x.id.id, + executor = x.executor.id, + patientId = x.patientId.id, + state = PatientHistory.State.stateToString(x.state), + action = PatientHistory.Action.actionToString(x.action), + created = ZonedDateTime.of(x.created, ZoneId.of("Z")) + ) +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala new file mode 100644 index 0000000..855eddc --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala @@ -0,0 +1,44 @@ +package xyz.driver.pdsuidomain.services + +import java.time.LocalDateTime + +import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext +import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} +import xyz.driver.pdsuicommon.domain.UuidId +import xyz.driver.pdsuicommon.error.DomainError +import xyz.driver.pdsuidomain.entities.{Patient, PatientHistory} + +import scala.concurrent.Future + +object PatientHistoryService { + + trait DefaultNotFoundError { + def userMessage: String = "Patient history not found" + } + + trait DefaultAccessDeniedError { + def userMessage: String = "Access denied" + } + + sealed trait GetListReply + object GetListReply { + final case class EntityList(xs: Seq[PatientHistory], totalFound: Int, lastUpdate: Option[LocalDateTime]) + extends GetListReply + + final case object AuthorizationError + extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError + } + +} + +trait PatientHistoryService { + + import PatientHistoryService._ + + def getListByPatientId(id: UuidId[Patient], + filter: SearchFilterExpr = SearchFilterExpr.Empty, + sorting: Option[Sorting] = None, + pagination: Option[Pagination] = None)( + implicit requestContext: AuthenticatedRequestContext): Future[GetListReply] + +} |