aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
new file mode 100644
index 0000000..0ea3cdd
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala
@@ -0,0 +1,146 @@
+package xyz.driver.pdsuidomain.fakes.entities.rep
+
+import xyz.driver.pdsuidomain.entities._
+import xyz.driver.core.generators
+import xyz.driver.core.generators._
+import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User}
+import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId, nextStringId, nextUuidId}
+
+object MedicalRecordGen {
+ private val maxItemsInCollectionNumber = 50
+
+ private val pageMaxNumber = 1000
+
+ private val medicalRecordMetas = {
+ Set(
+ () => nextMedicalRecordMetaReorder,
+ () => nextMedicalRecordMetaDuplicate,
+ () => nextMedicalRecordMetaRotation
+ )
+ }
+
+ def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] =
+ List.fill(count)(nextMedicalRecordMeta)
+
+ private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] =
+ TextJson(nextMedicalRecordMetas(nextInt(maxItemsInCollectionNumber, minValue = 0)))
+
+ private def nextDocument: Document =
+ DocumentGen.nextDocument
+
+ private def nextDocuments(count: Int): List[Document] =
+ List.fill(count)(nextDocument)
+
+ private def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = {
+ val documents = nextDocuments(
+ nextInt(maxItemsInCollectionNumber, minValue = 0)
+ )
+
+ TextJson(documents.map(_.copy(recordId = recordId)))
+ }
+
+
+ def nextMedicalRecordStatus: MedicalRecord.Status =
+ generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All)
+
+ def nextMedicalRecordHistoryState: MedicalRecordHistory.State =
+ generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All)
+
+ def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action =
+ generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All)
+
+
+ def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = {
+ val itemsNumber =
+ maxItemsInCollectionNumber
+ val items = scala.util.Random
+ .shuffle(Seq.tabulate(itemsNumber)(identity))
+
+ MedicalRecord.Meta.Reorder(
+ predicted = nextOption(nextBoolean),
+ items = items
+ )
+ }
+
+
+ def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = {
+ val startPageGen =
+ nextInt(pageMaxNumber, minValue = 0)
+ val endPageGen =
+ nextInt(pageMaxNumber, startPageGen)
+
+ MedicalRecord.Meta.Duplicate(
+ predicted = nextOption(nextBoolean),
+ startPage = startPageGen.toDouble,
+ endPage = endPageGen.toDouble,
+ startOriginalPage = startPageGen.toDouble,
+ endOriginalPage = nextOption(endPageGen.toDouble)
+ )
+ }
+
+ def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = {
+ val items =
+ Array.tabulate(maxItemsInCollectionNumber)(
+ index => nextString() -> index
+ ).toMap
+
+ MedicalRecord.Meta.Rotation(
+ predicted = nextOption(nextBoolean()),
+ items = items
+ )
+ }
+
+ def nextMedicalRecordMeta: MedicalRecord.Meta = {
+ generators.oneOf(medicalRecordMetas)()
+ }
+
+
+ def nextMedicalRecord(): MedicalRecord = {
+ val id = nextLongId[MedicalRecord]
+ MedicalRecord(
+ id = nextLongId[MedicalRecord],
+ status = nextMedicalRecordStatus,
+ previousStatus = nextOption(nextMedicalRecordStatus),
+ assignee = nextOption(nextStringId),
+ previousAssignee = nextOption(nextStringId),
+ lastActiveUserId = nextOption(nextStringId),
+ patientId = nextUuidId,
+ requestId = RecordRequestId(generators.nextUuid()),
+ disease = generators.nextString(),
+ caseId = nextOption(CaseId(generators.nextString())),
+ physician = nextOption(generators.nextString()),
+ meta = nextOption(nextMedicalRecordMetasJson),
+ predictedMeta = nextOption(nextMedicalRecordMetasJson),
+ predictedDocuments = nextOption(nextDocuments(id)),
+ lastUpdate = nextLocalDateTime
+ )
+ }
+
+ def nextMedicalRecordHistory(): MedicalRecordHistory = {
+ MedicalRecordHistory(
+ id = nextLongId[MedicalRecordHistory],
+ executor = nextStringId[User],
+ recordId = nextLongId[MedicalRecord],
+ state = nextMedicalRecordHistoryState,
+ action = nextMedicalRecordHistoryAction,
+ created = nextLocalDateTime
+ )
+ }
+
+ def nextMedicalRecordIssue(): MedicalRecordIssue = {
+ val pages = Common.nextStartAndEndPages
+
+ MedicalRecordIssue(
+ id = nextLongId[MedicalRecordIssue],
+ userId = nextStringId[User],
+ recordId = nextLongId[MedicalRecord],
+ startPage = pages._1,
+ endPage = pages._2,
+ lastUpdate = nextLocalDateTime,
+ isDraft = nextBoolean(),
+ text = nextString(),
+ archiveRequired = nextBoolean()
+ )
+ }
+
+}