aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr <ognelisar@gmail.com>2017-09-28 13:31:21 +0700
committerAleksandr <ognelisar@gmail.com>2017-09-28 13:31:21 +0700
commitd8e71e0a9ee7db58032384d059403bc227a35138 (patch)
tree4803503379c4e71f2e6ed1c8c50a8914186a5798
parentc24679f1ae7d7ccc4e6693535b0aa3ac0e1ca225 (diff)
downloadrest-query-d8e71e0a9ee7db58032384d059403bc227a35138.tar.gz
rest-query-d8e71e0a9ee7db58032384d059403bc227a35138.tar.bz2
rest-query-d8e71e0a9ee7db58032384d059403bc227a35138.zip
Implemented some REP entities objects generators
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala112
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala35
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala68
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala74
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala63
5 files changed, 352 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala
new file mode 100644
index 0000000..93bfce6
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala
@@ -0,0 +1,112 @@
+package xyz.driver.pdsuidomain.fakes.entities
+
+
+import xyz.driver.pdsuidomain.entities._
+import xyz.driver.core.generators
+import xyz.driver.core.generators._
+import common._
+import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue
+import xyz.driver.pdsuicommon.domain.{TextJson, User}
+import xyz.driver.pdsuidomain.fakes.entities.rep.{DocumentGen, MedicalRecordMetaGen, Common}
+
+
+object RecordsProcessingApi {
+ private val maxCollectionNumber = 5
+
+ private val maxAttemtsNumber = 100
+
+ private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] =
+ TextJson(nextMedicalRecordMetas(nextInt(maxCollectionNumber, minValue = 0)))
+
+ private def nextDocuments: TextJson[List[Document]] =
+ TextJson(nextDocuments(nextInt(maxCollectionNumber, minValue = 0)))
+
+ def nextMedicalRecordStatus: MedicalRecord.Status =
+ generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All)
+
+ def nextMedicalRecordMeta: MedicalRecord.Meta =
+ MedicalRecordMetaGen.nextMedicalRecordMeta
+
+ def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] =
+ List.fill(count)(nextMedicalRecordMeta)
+
+ def nextMedicalRecordHistoryState: MedicalRecordHistory.State =
+ generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All)
+
+ def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action =
+ generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All)
+
+ def nextDocument: Document =
+ DocumentGen.nextDocument
+
+ def nextDocuments(count: Int): List[Document] =
+ List.fill(count)(nextDocument)
+
+ def nextMedicalRecord() = {
+ 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),
+ lastUpdate = nextLocalDateTime
+ )
+ }
+
+ def nextMedicalRecordHistory() = {
+ MedicalRecordHistory(
+ id = nextLongId[MedicalRecordHistory],
+ executor = nextStringId[User],
+ recordId = nextLongId[MedicalRecord],
+ state = nextMedicalRecordHistoryState,
+ action = nextMedicalRecordHistoryAction,
+ created = nextLocalDateTime
+ )
+ }
+
+ def nextMedicalRecordIssue(): MedicalRecordIssue = {
+ val pages = Common.genStartAndEndPages
+
+ MedicalRecordIssue(
+ id = nextLongId[MedicalRecordIssue],
+ userId = nextStringId[User],
+ recordId = nextLongId[MedicalRecord],
+ startPage = pages._1,
+ endPage = pages._2,
+ lastUpdate = nextLocalDateTime,
+ isDraft = nextBoolean(),
+ text = nextString(),
+ archiveRequired = nextBoolean()
+ )
+ }
+
+ def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = {
+ BridgeUploadQueue.Item(
+ kind = nextString(),
+ tag = nextString(),
+ created = nextLocalDateTime,
+ attempts = nextInt(maxAttemtsNumber, minValue = 0),
+ nextAttempt = nextLocalDateTime,
+ completed = nextBoolean(),
+ dependencyKind = nextOption(nextString()),
+ dependencyTag = nextOption(nextString())
+ )
+ }
+
+ def nextProviderType(): ProviderType = {
+ ProviderType(
+ id = nextLongId[ProviderType],
+ name = nextString()
+ )
+ }
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala
new file mode 100644
index 0000000..d09e09b
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala
@@ -0,0 +1,35 @@
+package xyz.driver.pdsuidomain.fakes.entities.rep
+
+import xyz.driver.core.generators._
+
+object Common {
+ def genBoundedRange[T](from: T,
+ to: T)
+ (implicit ord: Ordering[T]): (T, T) = {
+ if (ord.compare(from, to) > 0) {
+ to -> from
+ }
+ else {
+ from -> to
+ }
+ }
+
+ def genBoundedRangeOption[T](from: T,
+ to: T)
+ (implicit ord: Ordering[T]): (Option[T], Option[T]) = {
+ val ranges = nextOption(from)
+ .map(left =>
+ genBoundedRange(left, to)
+ )
+ .map { case (left, right) =>
+ left -> nextOption(right)
+ }
+
+ ranges.map(_._1) -> ranges.flatMap(_._2)
+ }
+
+ def genStartAndEndPages: (Option[Double], Option[Double]) = {
+ genBoundedRangeOption[Double](nextDouble(), nextDouble())
+ }
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala
new file mode 100644
index 0000000..1c77a78
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala
@@ -0,0 +1,68 @@
+package xyz.driver.pdsuidomain.fakes.entities.rep
+
+
+import java.time.LocalDate
+
+import xyz.driver.core.generators
+import xyz.driver.core.generators.{nextBoolean, nextDouble, nextOption, nextString}
+import xyz.driver.pdsuicommon.domain.{TextJson, User}
+import xyz.driver.pdsuidomain.entities.{Document, DocumentType, MedicalRecord, ProviderType}
+import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId}
+
+object DocumentGen {
+ implicit private class LocalDateOrdering(localData: LocalDate)
+ extends Ordered[LocalDate] {
+
+ override def compare(that: LocalDate): Int = {
+ this.localData.compareTo(that)
+ }
+ }
+
+ def nextDocumentStatus: Document.Status =
+ generators.oneOf[Document.Status](Document.Status.All)
+
+ def nextDocumentRequiredType: Document.RequiredType =
+ generators.oneOf[Document.RequiredType](Document.RequiredType.All)
+
+ def nextDocumentMeta: Document.Meta = {
+ val (startPage, endPage) = {
+ val startPage = nextDouble()
+ val endPage = nextDouble()
+ if (startPage > endPage) {
+ endPage -> startPage
+ }
+ else {
+ startPage -> endPage
+ }
+ }
+
+ Document.Meta(
+ nextOption(nextBoolean()), startPage, endPage
+ )
+ }
+
+ def nextDocument: Document = {
+ val dates = Common
+ .genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate)
+
+ Document(
+ id = nextLongId[Document],
+ status = nextDocumentStatus,
+ previousStatus = nextOption(nextDocumentStatus),
+ assignee = nextOption(nextStringId[User]),
+ previousAssignee = nextOption(nextStringId[User]),
+ lastActiveUserId = nextOption(nextStringId[User]),
+ recordId = nextLongId[MedicalRecord],
+ physician = nextOption(nextString()),
+ typeId = nextOption(nextLongId[DocumentType]),
+ providerName = nextOption(nextString()),
+ providerTypeId = nextOption(nextLongId[ProviderType]),
+ requiredType = nextOption(nextDocumentRequiredType),
+ meta = nextOption(TextJson(nextDocumentMeta)),
+ startDate = dates._1,
+ endDate = dates._2,
+ lastUpdate = nextLocalDateTime
+ )
+ }
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala
new file mode 100644
index 0000000..48eaf79
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala
@@ -0,0 +1,74 @@
+package xyz.driver.pdsuidomain.fakes.entities.rep
+
+import xyz.driver.core.generators._
+import xyz.driver.pdsuidomain.entities.{Document, ExtractedData}
+import xyz.driver.pdsuidomain.entities.ExtractedData.Meta
+import xyz.driver.pdsuidomain.fakes.entities.common._
+
+
+object ExtractedDataGen {
+ private val maxPageNumber = 100
+ private val maxIndexNumber = 100
+ private val maxOffsetNumber = 10
+
+ implicit private class TextLayerPositionOrdering(textLayerPosition: ExtractedData.Meta.TextLayerPosition)
+ extends Ordered[ExtractedData.Meta.TextLayerPosition] {
+ override def compare(that: Meta.TextLayerPosition): Int = {
+ if (this.textLayerPosition.page < that.page) -1
+ else if (this.textLayerPosition.page > that.page) 1
+ else if (this.textLayerPosition.index < that.index) -1
+ else if (this.textLayerPosition.index > that.index) 1
+ else if (this.textLayerPosition.offset < that.offset) -1
+ else if (this.textLayerPosition.offset > that.offset) 1
+ else 0
+ }
+ }
+
+ def nextExtractedDataMetaKeyword(): Meta.Keyword = {
+ ExtractedData.Meta.Keyword(
+ page = nextInt(maxPageNumber, minValue = 0),
+ pageRatio = nextOption(nextDouble()),
+ index = nextInt(maxIndexNumber, minValue = 0),
+ sortIndex = nextString()
+ )
+ }
+
+ def nextExtractedDataMetaTextLayerPosition(): Meta.TextLayerPosition = {
+ ExtractedData.Meta.TextLayerPosition(
+ page = nextInt(maxPageNumber, minValue = 0),
+ index = nextInt(maxIndexNumber, minValue = 0),
+ offset = nextInt(maxOffsetNumber, minValue = 0)
+ )
+ }
+
+ def nextExtractedDataMetaEvidence(): Meta.Evidence = {
+ val layersPosition =
+ Common.genBoundedRange[ExtractedData.Meta.TextLayerPosition](
+ nextExtractedDataMetaTextLayerPosition(),
+ nextExtractedDataMetaTextLayerPosition()
+ )
+
+ ExtractedData.Meta.Evidence(
+ pageRatio = nextDouble(),
+ start = layersPosition._1,
+ end = layersPosition._2
+ )
+ }
+
+ def nextExtractedDataMeta(): Meta = {
+ ExtractedData.Meta(
+ nextExtractedDataMetaKeyword(),
+ nextExtractedDataMetaEvidence()
+ )
+ }
+
+ def nextExtractedData() = {
+ ExtractedData.apply(
+ id = nextLongId[ExtractedData],
+ documentId = nextLongId[Document],
+ keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]),
+ evidenceText = nextOption(nextString()),
+ ???
+ )
+ }
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala
new file mode 100644
index 0000000..1536c65
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala
@@ -0,0 +1,63 @@
+package xyz.driver.pdsuidomain.fakes.entities.rep
+
+import xyz.driver.pdsuidomain.entities.MedicalRecord
+import xyz.driver.core.generators
+import xyz.driver.core.generators._
+
+object MedicalRecordMetaGen {
+ private val maxItemsInCollectionNumber = 50
+ private val pageMaxNumber = 1000
+
+ private val medicalRecordMetas = {
+ Set(
+ () => nextMedicalRecordMetaReorder,
+ () => nextMedicalRecordMetaDuplicate,
+ () => nextMedicalRecordMetaRotation
+ )
+ }
+
+
+ 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)()
+ }
+}