From a0599ae4d12acafb934b40f52d4a771709b3e583 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 16 Oct 2017 20:06:52 +0700 Subject: PDSUI-2318 Created custom swagger format for TM --- .../fakes/entities/recordprocessing.scala | 284 +++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala new file mode 100644 index 0000000..279ea38 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala @@ -0,0 +1,284 @@ +package xyz.driver.pdsuidomain.fakes.entities + +import java.time.LocalDate + +import xyz.driver.core.generators +import xyz.driver.core.generators._ +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} +import xyz.driver.pdsuidomain.entities.ExtractedData.Meta +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.fakes.entities.common._ +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData + +object recordprocessing { + + private val maxItemsInCollectionNumber: Int = 50 + private val maxPageNumber = 100 + private val maxIndexNumber = 100 + private val maxOffsetNumber = 10 + + implicit private class LocalDateOrdering(localData: LocalDate) extends Ordered[LocalDate] { + override def compare(that: LocalDate): Int = { + this.localData.compareTo(that) + } + } + + 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 + } + } + + private def nextDates(): (Option[LocalDate], Option[LocalDate]) = + genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + + private val medicalRecordMeta: Set[() => MedicalRecord.Meta] = { + Set( + () => nextMedicalRecordMetaReorder(), + () => nextMedicalRecordMetaDuplicate(), + () => nextMedicalRecordMetaRotation() + ) + } + + def nextMedicalRecordMeta(count: Int): List[MedicalRecord.Meta] = + List.fill(count)(nextMedicalRecordMeta()) + + def nextMedicalRecordMetaJson(): TextJson[List[MedicalRecord.Meta]] = + TextJson(nextMedicalRecordMeta(nextInt(maxItemsInCollectionNumber))) + + private def nextDocumentList(count: Int): List[Document] = + List.fill(count)(nextDocument()) + + def nextDocumentList(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { + val documents = nextDocumentList( + nextInt(maxItemsInCollectionNumber) + ) + 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(items) + } + + def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { + val startPageGen = nextInt(maxPageNumber) + val endPageGen = nextInt(maxPageNumber, startPageGen) + + MedicalRecord.Meta.Duplicate( + 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(items = items) + } + + def nextMedicalRecordMeta(): MedicalRecord.Meta = generators.oneOf(medicalRecordMeta)() + + def nextRecordRequestId(): RecordRequestId = RecordRequestId(generators.nextUuid()) + + def nextMedicalRecord(): MedicalRecord = MedicalRecord( + id = nextLongId[MedicalRecord], + status = nextMedicalRecordStatus(), + previousStatus = None, + assignee = nextOption(nextStringId), + previousAssignee = nextOption(nextStringId), + lastActiveUserId = nextOption(nextStringId), + patientId = nextUuidId, + requestId = nextRecordRequestId(), + disease = generators.nextString(), + caseId = nextOption(CaseId(generators.nextString())), + physician = nextOption(generators.nextString()), + meta = nextOption(nextMedicalRecordMetaJson()), + lastUpdate = nextLocalDateTime, + totalPages = nextInt(10) + ) + + def nextMedicalRecordHistory(): MedicalRecordHistory = MedicalRecordHistory( + id = nextLongId[MedicalRecordHistory], + executor = nextStringId[User], + recordId = nextLongId[MedicalRecord], + state = nextMedicalRecordHistoryState(), + action = nextMedicalRecordHistoryAction(), + created = nextLocalDateTime + ) + + def nextMedicalRecordIssue(): MedicalRecordIssue = { + val (startPage, endPage) = nextStartAndEndPagesOption + + MedicalRecordIssue( + id = nextLongId[MedicalRecordIssue], + userId = nextStringId[User], + recordId = nextLongId[MedicalRecord], + startPage = startPage, + endPage = endPage, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + + 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) = nextStartAndEndPages + Document.Meta(startPage, endPage) + } + + def nextDocumentMetaJson(): TextJson[Document.Meta] = nextTextJson(nextDocumentMeta()) + + def nextDocument(): Document = { + val (startDate, endDate) = nextDates() + + Document( + id = nextLongId[Document], + status = nextDocumentStatus(), + previousStatus = None, + 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()), + institutionName = nextOption(nextString()), + meta = nextOption(nextDocumentMetaJson()), + startDate = startDate, + endDate = endDate, + lastUpdate = nextLocalDateTime + ) + } + + def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = { + val (startPage, endPage) = nextStartAndEndPagesOption + DocumentIssue( + id = nextLongId[DocumentIssue], + userId = nextStringId[User], + documentId = documentId, + startPage = startPage, + endPage = endPage, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + + def nextDocumentHistory(): DocumentHistory = DocumentHistory( + id = nextLongId[DocumentHistory], + executor = nextStringId[User], + documentId = nextLongId[Document], + state = nextDocumentHistoryState(), + action = nextDocumentHistoryAction(), + created = nextLocalDateTime + ) + + def nextExtractedDataMetaKeyword(): Meta.Keyword = { + ExtractedData.Meta.Keyword( + page = nextInt(maxPageNumber), + pageRatio = nextOption(nextDouble()), + index = nextInt(maxIndexNumber), + sortIndex = nextString() + ) + } + + def nextExtractedDataMetaTextLayerPosition(): Meta.TextLayerPosition = { + ExtractedData.Meta.TextLayerPosition( + page = nextInt(maxPageNumber), + index = nextInt(maxIndexNumber), + offset = nextInt(maxOffsetNumber) + ) + } + + def nextExtractedDataMetaEvidence(): Meta.Evidence = { + val (start, end) = + genBoundedRange[ExtractedData.Meta.TextLayerPosition]( + nextExtractedDataMetaTextLayerPosition(), + nextExtractedDataMetaTextLayerPosition() + ) + + ExtractedData.Meta.Evidence( + pageRatio = nextDouble(), + start = start, + end = end + ) + } + + def nextExtractedDataMeta(): Meta = { + ExtractedData.Meta( + nextExtractedDataMetaKeyword(), + nextExtractedDataMetaEvidence() + ) + } + + def nextExtractedDataMetaJson(): TextJson[Meta] = + nextTextJson(ExtractedData.Meta(nextExtractedDataMetaKeyword(), nextExtractedDataMetaEvidence())) + + def nextExtractedData(): ExtractedData = { + ExtractedData( + id = nextLongId[ExtractedData], + documentId = nextLongId[Document], + keywordId = nextOption(nextLongId[Keyword]), + evidenceText = nextOption(nextString()), + meta = nextOption(nextExtractedDataMetaJson()) + ) + } + + def nextExtractedDataLabel(dataId: LongId[ExtractedData]): ExtractedDataLabel = { + ExtractedDataLabel( + id = nextLongId[ExtractedDataLabel], + dataId = nextLongId[ExtractedData], + labelId = nextOption(nextLongId[Label]), + categoryId = nextOption(nextLongId[LabelCategory]), + value = nextOption(generators.oneOf[LabelValue](LabelValue.Yes, LabelValue.No, LabelValue.Maybe)) + ) + } + + def nextRichExtractedData(): RichExtractedData = { + val extractedData = nextExtractedData() + RichExtractedData( + extractedData = extractedData, + labels = List.fill( + nextInt(maxItemsInCollectionNumber) + )(nextExtractedDataLabel(extractedData.id)) + ) + } + +} -- cgit v1.2.3 From eb9a75c226b005e5989d2a6494160ebe0dd9d9e7 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Tue, 17 Oct 2017 16:17:47 +0700 Subject: Fixed custom formats for rep and tric --- .../utils/CustomSwaggerJsonFormats.scala | 158 +++++++++++---------- .../fakes/entities/recordprocessing.scala | 4 +- .../fakes/entities/treatmentmatching.scala | 129 ++++++++++++++++- 3 files changed, 210 insertions(+), 81 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index b122fab..004a914 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -4,20 +4,16 @@ import java.time.{LocalDate, LocalDateTime} import io.swagger.models.properties.Property import spray.json.JsValue -import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.intervention._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.hypothesis._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.studydesign._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.trial._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.trialhistory._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.trialissue._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.ListResponse._ import xyz.driver.core.swagger.CustomSwaggerJsonConverter._ import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue +import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels +import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels import xyz.driver.pdsuidomain.fakes.entities.common +import xyz.driver.pdsuidomain.formats.json.sprayformats.ListResponse import xyz.driver.pdsuidomain.formats.json.sprayformats.bridgeuploadqueue._ import xyz.driver.pdsuidomain.formats.json.sprayformats.record._ import xyz.driver.pdsuidomain.formats.json.sprayformats.document._ @@ -47,35 +43,48 @@ object CustomSwaggerJsonFormats { classOf[DocumentType] -> documentTypeFormat.write(common.nextDocumentType()) ) - val customTrialCurationProperties = immutable.Map[Class[_], Property]( - classOf[Trial.Status] -> stringProperty(), - classOf[TrialHistory.Action] -> stringProperty(), - classOf[TrialHistory.State] -> stringProperty() - ) ++ customCommonProperties - - val customTrialCurationObjectsExamples = immutable.Map[Class[_], JsValue]( - classOf[Trial] -> trialWriter.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrial()), - classOf[Arm] -> armFormat.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextArm()), - classOf[TrialHistory] -> trialHistoryFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialHistory()), - classOf[TrialIssue] -> trialIssueWriter.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialIssue()), - classOf[RichCriterion] -> richCriterionFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextRichCriterion()), - classOf[InterventionWithArms] -> interventionFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionWithArms()), - classOf[InterventionType] -> interventionTypeFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionType()), - classOf[Hypothesis] -> hypothesisFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextHypothesis()), - classOf[StudyDesign] -> studyDesignFormat.write( - xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) - ) + object trialcuration { + import xyz.driver.pdsuidomain.fakes.entities.trialcuration._ + import xyz.driver.pdsuidomain.fakes.entities.export + import xyz.driver.pdsuidomain.formats.json.sprayformats.export._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.intervention._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.hypothesis._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.studydesign._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.trial._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.trialhistory._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.trialissue._ + + val customTrialCurationProperties = immutable.Map[Class[_], Property]( + classOf[Trial.Status] -> stringProperty(), + classOf[TrialHistory.Action] -> stringProperty(), + classOf[TrialHistory.State] -> stringProperty() + ) ++ customCommonProperties + + val customTrialCurationObjectsExamples = immutable.Map[Class[_], JsValue]( + classOf[Trial] -> trialWriter.write(nextTrial()), + classOf[Arm] -> armFormat.write(nextArm()), + classOf[TrialHistory] -> trialHistoryFormat.write(nextTrialHistory()), + classOf[TrialIssue] -> trialIssueWriter.write(nextTrialIssue()), + classOf[RichCriterion] -> richCriterionFormat.write(nextRichCriterion()), + classOf[InterventionWithArms] -> interventionFormat.write(nextInterventionWithArms()), + classOf[InterventionType] -> interventionTypeFormat.write(nextInterventionType()), + classOf[Hypothesis] -> hypothesisFormat.write(nextHypothesis()), + classOf[StudyDesign] -> studyDesignFormat.write(nextStudyDesign()), + classOf[ExportTrialWithLabels] -> trialWithLabelsFormat.write(export.nextExportTrialWithLabels()) + ) + } - // records-processing-service - object Rep { + object recordprocessing { import xyz.driver.pdsuidomain.fakes.entities.recordprocessing._ - import xyz.driver.pdsuidomain.formats.json.sprayformats._ + import xyz.driver.pdsuidomain.fakes.entities.export + import xyz.driver.pdsuidomain.formats.json.sprayformats.export._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.documentissue._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.documenthistory._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordissue._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordhistory._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.extracteddata._ val customRecordProcessingProperties = immutable.Map[Class[_], Property]( classOf[MedicalRecord.Status] -> stringProperty(), @@ -87,37 +96,15 @@ object CustomSwaggerJsonFormats { classOf[DocumentHistory.State] -> stringProperty() ) ++ customCommonProperties - val customRepObjectsExamples = immutable.Map[Class[_], JsValue]( - classOf[Document] -> - document.documentFormat.write(nextDocument()), - classOf[DocumentIssue] -> - documentissue.documentIssueFormat.write(nextDocumentIssue()), - classOf[DocumentHistory] -> - documenthistory.documentHistoryFormat.write(nextDocumentHistory()), - classOf[TextJson[List[MedicalRecord.Meta]]] -> - record.recordMetaFormat.write(nextMedicalRecordMetaJson()), - classOf[MedicalRecord] -> - record.recordFormat.write(nextMedicalRecord()), - classOf[MedicalRecordIssue] -> - recordissue.recordIssueFormat.write(nextMedicalRecordIssue()), - classOf[MedicalRecordHistory] -> - recordhistory.recordHistoryFormat.write(nextMedicalRecordHistory()), - classOf[RichExtractedData] -> - extracteddata.extractedDataFormat.write(nextRichExtractedData()), - classOf[MedicalRecord.Meta] -> - record.recordMetaTypeFormat.write(nextMedicalRecordMeta()), - classOf[TextJson[Document.Meta]] -> - document.fullDocumentMetaFormat.write(nextDocumentMetaJson()), - classOf[ExtractedData.Meta] -> - extracteddata.extractedDataMetaFormat.write(nextExtractedDataMeta()), - classOf[ExtractedData.Meta.Evidence] -> - extracteddata.metaEvidenceFormat.write(nextExtractedDataMetaEvidence()), - classOf[ExtractedData.Meta.Keyword] -> - extracteddata.metaKeywordFormat.write(nextExtractedDataMetaKeyword()), - classOf[ExtractedData.Meta.TextLayerPosition] -> - extracteddata.metaTextLayerPositionFormat.write(nextExtractedDataMetaTextLayerPosition()), - classOf[TextJson[ExtractedData.Meta]] -> - extracteddata.fullExtractedDataMetaFormat.write(nextExtractedDataMetaJson()) + val customRecordProcessingObjectsExamples = immutable.Map[Class[_], JsValue]( + classOf[Document] -> documentFormat.write(nextDocument()), + classOf[DocumentIssue] -> documentIssueFormat.write(nextDocumentIssue()), + classOf[DocumentHistory] -> documentHistoryFormat.write(nextDocumentHistory()), + classOf[MedicalRecord] -> recordFormat.write(nextMedicalRecord()), + classOf[MedicalRecordIssue] -> recordIssueFormat.write(nextMedicalRecordIssue()), + classOf[MedicalRecordHistory] -> recordHistoryFormat.write(nextMedicalRecordHistory()), + classOf[RichExtractedData] -> extractedDataFormat.write(nextRichExtractedData()), + classOf[ExportPatientWithLabels] -> patientWithLabelsFormat.write(export.nextExportPatientWithLabels()) ) ++ customCommonObjectsExamples } @@ -139,17 +126,32 @@ object CustomSwaggerJsonFormats { ) ++ customCommonProperties val customTreatmentMatchingObjectsExamples = immutable.Map[Class[_], JsValue]( - classOf[Patient] -> patientWriter.write(nextPatient()), - classOf[RichPatientLabel] -> richPatientLabelWriter.write(nextRichPatientLabel()), - classOf[PatientLabel] -> patientLabelDefiningCriteriaWriter.write(nextPatientLabel()), - classOf[RichPatientCriterion] -> patientCriterionWriter.write(nextRichPatientCriterion()), - classOf[DraftPatientCriterion] -> draftPatientCriterionFormat.write(nextDraftPatientCriterion()), - classOf[PatientLabelEvidenceView] -> patientLabelEvidenceWriter.write(nextPatientLabelEvidenceView()), - classOf[RichPatientEligibleTrial] -> patientEligibleTrialWriter.write(nextRichPatientEligibleTrial()), - classOf[PatientHypothesis] -> patientHypothesisWriter.write(nextPatientHypothesis()), - classOf[RichPatientHypothesis] -> richPatientHypothesisWriter.write(nextRichPatientHypothesis()), - classOf[PatientHistory] -> patientHistoryFormat.write(nextPatientHistory()), - classOf[PatientIssue] -> patientIssueWriter.write(nextPatientIssue()) + classOf[Patient] -> patientWriter.write(nextPatient()), + classOf[RichPatientLabel] -> richPatientLabelWriter.write(nextRichPatientLabel()), + classOf[PatientLabel] -> patientLabelDefiningCriteriaWriter.write(nextPatientLabel()), + classOf[RichPatientCriterion] -> patientCriterionWriter.write(nextRichPatientCriterion()), + classOf[DraftPatientCriterion] -> draftPatientCriterionFormat.write(nextDraftPatientCriterion()), + classOf[PatientLabelEvidenceView] -> patientLabelEvidenceWriter.write(nextPatientLabelEvidenceView()), + classOf[RichPatientEligibleTrial] -> patientEligibleTrialWriter.write(nextRichPatientEligibleTrial()), + classOf[PatientHypothesis] -> patientHypothesisWriter.write(nextPatientHypothesis()), + classOf[RichPatientHypothesis] -> richPatientHypothesisWriter.write(nextRichPatientHypothesis()), + classOf[PatientHistory] -> patientHistoryFormat.write(nextPatientHistory()), + classOf[PatientIssue] -> patientIssueWriter.write(nextPatientIssue()), + classOf[ListResponse[Patient]] -> listResponseWriter[Patient].write(nextPatientListResponse()), + classOf[ListResponse[PatientLabel]] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), + classOf[ListResponse[RichPatientLabel]] -> listResponseWriter[RichPatientLabel].write( + nextRichPatientLabelListResponse()), + classOf[ListResponse[RichPatientCriterion]] -> listResponseWriter[RichPatientCriterion].write( + nextRichPatientCriterionListResponse()), + classOf[ListResponse[PatientLabelEvidenceView]] -> listResponseWriter[PatientLabelEvidenceView].write( + nextPatientLabelEvidenceViewListResponse()), + classOf[ListResponse[RichPatientEligibleTrial]] -> listResponseWriter[RichPatientEligibleTrial].write( + nextRichPatientEligibleTrialListResponse()), + classOf[ListResponse[RichPatientHypothesis]] -> listResponseWriter[RichPatientHypothesis].write( + nextRichPatientHypothesisListResponse()), + classOf[ListResponse[PatientIssue]] -> listResponseWriter[PatientIssue].write(nextPatientIssuesListResponse()), + classOf[ListResponse[PatientHistory]] -> listResponseWriter[PatientHistory].write( + nextPatientHistoryListResponse()) ) ++ customCommonObjectsExamples } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala index 279ea38..d2a648c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala @@ -105,7 +105,7 @@ object recordprocessing { def nextMedicalRecord(): MedicalRecord = MedicalRecord( id = nextLongId[MedicalRecord], status = nextMedicalRecordStatus(), - previousStatus = None, + previousStatus = nextOption(generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.AllPrevious)), assignee = nextOption(nextStringId), previousAssignee = nextOption(nextStringId), lastActiveUserId = nextOption(nextStringId), @@ -168,7 +168,7 @@ object recordprocessing { Document( id = nextLongId[Document], status = nextDocumentStatus(), - previousStatus = None, + previousStatus = nextOption(generators.oneOf[Document.Status](Document.Status.AllPrevious)), assignee = nextOption(nextStringId[User]), previousAssignee = nextOption(nextStringId[User]), lastActiveUserId = nextOption(nextStringId[User]), diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala index 35aa5ef..b0ca136 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala @@ -4,6 +4,7 @@ import xyz.driver.entities.labels.Label import xyz.driver.fakes import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.ListResponse import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis @@ -27,7 +28,7 @@ object treatmentmatching { name = nextFullName[Patient], dob = nextLocalDate, assignee = generators.nextOption(nextStringId[User]), - previousStatus = generators.nextOption(nextPatientStatus), + previousStatus = generators.nextOption(generators.oneOf[Patient.Status](Patient.Status.AllPrevious)), previousAssignee = generators.nextOption(nextStringId[User]), lastActiveUserId = generators.nextOption(nextStringId[User]), isUpdateRequired = generators.nextBoolean(), @@ -164,4 +165,130 @@ object treatmentmatching { created = nextLocalDateTime ) + def nextPatientListResponse(): ListResponse[Patient] = { + val xs: Seq[Patient] = Seq.fill(3)(nextPatient()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextRichPatientLabelListResponse(): ListResponse[RichPatientLabel] = { + val xs: Seq[RichPatientLabel] = Seq.fill(3)(nextRichPatientLabel()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextPatientLabelListResponse(): ListResponse[PatientLabel] = { + val xs: Seq[PatientLabel] = Seq.fill(3)(nextPatientLabel()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextRichPatientCriterionListResponse(): ListResponse[RichPatientCriterion] = { + val xs: Seq[RichPatientCriterion] = Seq.fill(3)(nextRichPatientCriterion()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextRichPatientEligibleTrialListResponse(): ListResponse[RichPatientEligibleTrial] = { + val xs: Seq[RichPatientEligibleTrial] = Seq.fill(3)(nextRichPatientEligibleTrial()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextRichPatientHypothesisListResponse(): ListResponse[RichPatientHypothesis] = { + val xs: Seq[RichPatientHypothesis] = Seq.fill(3)(nextRichPatientHypothesis()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextPatientLabelEvidenceViewListResponse(): ListResponse[PatientLabelEvidenceView] = { + val xs: Seq[PatientLabelEvidenceView] = Seq.fill(3)(nextPatientLabelEvidenceView()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextPatientIssuesListResponse(): ListResponse[PatientIssue] = { + val xs: Seq[PatientIssue] = Seq.fill(3)(nextPatientIssue()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + + def nextPatientHistoryListResponse(): ListResponse[PatientHistory] = { + val xs: Seq[PatientHistory] = Seq.fill(3)(nextPatientHistory()) + val pageSize = generators.nextInt(xs.size, 1) + ListResponse( + items = xs, + meta = ListResponse.Meta( + itemsCount = xs.size, + pageNumber = generators.nextInt(xs.size / pageSize), + pageSize = pageSize, + lastUpdate = generators.nextOption(nextLocalDateTime) + ) + ) + } + } -- cgit v1.2.3