From 1f569ac1a31f88334c25976d94e7c495a7bbde80 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 14:32:21 +0700 Subject: Implemented all generator for REP's entities --- .../fakes/entities/rep/BridgeUploadQueueGen.scala | 31 +++++ .../pdsuidomain/fakes/entities/rep/Common.scala | 10 +- .../fakes/entities/rep/DocumentGen.scala | 68 ++++++++-- .../fakes/entities/rep/ExportPatientGen.scala | 55 ++++++++ .../fakes/entities/rep/ExtractedDataGen.scala | 35 ++++- .../fakes/entities/rep/MedicalRecordGen.scala | 146 +++++++++++++++++++++ .../fakes/entities/rep/MedicalRecordMetaGen.scala | 63 --------- 7 files changed, 324 insertions(+), 84 deletions(-) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala new file mode 100644 index 0000000..fb1d3e3 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala @@ -0,0 +1,31 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators.{nextBoolean, nextInt, nextOption, nextString} +import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue +import xyz.driver.pdsuidomain.entities.ProviderType +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId} + +object BridgeUploadQueueGen { + private val maxAttemtsNumber = 100 + + 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 index d09e09b..337dc2b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala @@ -1,8 +1,10 @@ package xyz.driver.pdsuidomain.fakes.entities.rep +import xyz.driver.core.generators import xyz.driver.core.generators._ +import xyz.driver.pdsuicommon.domain.FuzzyValue -object Common { +private[rep] object Common { def genBoundedRange[T](from: T, to: T) (implicit ord: Ordering[T]): (T, T) = { @@ -28,7 +30,11 @@ object Common { ranges.map(_._1) -> ranges.flatMap(_._2) } - def genStartAndEndPages: (Option[Double], Option[Double]) = { + def nextFuzzyValue(): FuzzyValue = { + generators.oneOf[FuzzyValue](FuzzyValue.All) + } + + def nextStartAndEndPages: (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 index 1c77a78..2f07f1d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -5,8 +5,8 @@ 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.pdsuicommon.domain.{LongId, TextJson, User} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} object DocumentGen { @@ -18,23 +18,30 @@ object DocumentGen { } } + private def nextDates = + Common.genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + + private def nextStartAndEndPagesOption = + Common.nextStartAndEndPages + + private def nextStartAndEndPage = + Common.genBoundedRange(nextDouble(),nextDouble()) + + def nextDocumentStatus: Document.Status = generators.oneOf[Document.Status](Document.Status.All) def nextDocumentRequiredType: Document.RequiredType = generators.oneOf[Document.RequiredType](Document.RequiredType.All) + def nextDocumentHistoryState: DocumentHistory.State = + generators.oneOf[DocumentHistory.State](DocumentHistory.State.All) + + def nextDocumentHistoryAction: DocumentHistory.Action = + generators.oneOf[DocumentHistory.Action](DocumentHistory.Action.All) + def nextDocumentMeta: Document.Meta = { - val (startPage, endPage) = { - val startPage = nextDouble() - val endPage = nextDouble() - if (startPage > endPage) { - endPage -> startPage - } - else { - startPage -> endPage - } - } + val (startPage, endPage) = nextStartAndEndPage Document.Meta( nextOption(nextBoolean()), startPage, endPage @@ -42,8 +49,7 @@ object DocumentGen { } def nextDocument: Document = { - val dates = Common - .genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + val dates = nextDates Document( id = nextLongId[Document], @@ -65,4 +71,38 @@ object DocumentGen { ) } + def nextDocumentType: DocumentType = { + DocumentType( + id = nextLongId[DocumentType], + name = nextString() + ) + } + + def nextDocumentIssue(documentId: LongId[Document]): DocumentIssue = { + val pages = nextStartAndEndPagesOption + + DocumentIssue( + id = nextLongId[DocumentIssue], + userId = nextStringId[User], + documentId = documentId, + startPage = pages._1, + endPage = pages._2, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + + + def nextDocumentHistory(documentId: LongId[Document]): DocumentHistory = { + DocumentHistory( + id = nextLongId[DocumentHistory], + executor = nextStringId[User], + documentId = documentId, + state = nextDocumentHistoryState, + action = nextDocumentHistoryAction, + created = nextLocalDateTime + ) + } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala new file mode 100644 index 0000000..4a4164a --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -0,0 +1,55 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators._ +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.entities.{Document, ExtractedData, Label, RecordRequestId} +import xyz.driver.pdsuidomain.entities.export.patient.{ +ExportPatientLabel, +ExportPatientLabelEvidence, +ExportPatientLabelEvidenceDocument, +ExportPatientWithLabels +} +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} + +object ExportPatientGen { + private val maxItemsInCollectionNumber = 3 + + def nextExportPatientLabelEvidenceDocument(documentId: LongId[Document]): ExportPatientLabelEvidenceDocument = { + ExportPatientLabelEvidenceDocument( + documentId = documentId, + requestId = RecordRequestId(nextUuid()), + documentType = nextString(), + providerType = nextString(), + date = nextLocalDate + ) + } + + def nextExportPatientLabelEvidence(documentId: LongId[Document]): ExportPatientLabelEvidence = { + ExportPatientLabelEvidence( + id = nextLongId[ExtractedData], + value = Common.nextFuzzyValue(), + evidenceText = nextString(), + document = nextExportPatientLabelEvidenceDocument(documentId) + ) + } + + def nextExportPatientLabel(documentId: LongId[Document]): ExportPatientLabel = { + ExportPatientLabel( + id = nextLongId[Label], + evidences = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExportPatientLabelEvidence(documentId)) + ) + } + + def nextExportPatientWithLabels(documentId: LongId[Document]): ExportPatientWithLabels = { + ExportPatientWithLabels( + patientId = UuidId[xyz.driver.pdsuidomain.entities.Patient](nextUuid()), + labelVersion = scala.util.Random.nextLong(), + labels = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExportPatientLabel(documentId)) + ) + } + +} 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 index 48eaf79..512e324 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -1,12 +1,17 @@ package xyz.driver.pdsuidomain.fakes.entities.rep + import xyz.driver.core.generators._ -import xyz.driver.pdsuidomain.entities.{Document, ExtractedData} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta import xyz.driver.pdsuidomain.fakes.entities.common._ +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData object ExtractedDataGen { + private val maxItemsInCollectionNumber = 50 + private val maxPageNumber = 100 private val maxIndexNumber = 100 private val maxOffsetNumber = 10 @@ -62,13 +67,33 @@ object ExtractedDataGen { ) } - def nextExtractedData() = { - ExtractedData.apply( + def nextExtractedData(documentId: LongId[Document]): ExtractedData = { + ExtractedData( id = nextLongId[ExtractedData], - documentId = nextLongId[Document], + documentId = documentId, keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]), evidenceText = nextOption(nextString()), - ??? + meta = nextOption(TextJson(nextExtractedDataMeta())) + ) + } + + + def nextExtractedDataLabel(): ExtractedDataLabel = { + ExtractedDataLabel( + id = nextLongId[ExtractedDataLabel], + dataId = nextLongId[ExtractedData], + labelId = nextOption(nextLongId[Label]), + categoryId = nextOption(nextLongId[Category]), + value = nextOption(Common.nextFuzzyValue()) + ) + } + + def nextRichExtractedData(documentId: LongId[Document]): RichExtractedData = { + RichExtractedData( + extractedData = nextExtractedData(documentId), + labels = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExtractedDataLabel()) ) } } 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() + ) + } + +} 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 deleted file mode 100644 index 1536c65..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala +++ /dev/null @@ -1,63 +0,0 @@ -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)() - } -} -- cgit v1.2.3