From f8902d43cb189b408210ae7c80e2112346bdc037 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 18:26:36 +0700 Subject: Fixed generators of entities for ReP; Implemented json examples for swagger for ReP --- .../utils/CustomSwaggerJsonFormats.scala | 94 +++++++++++++++++++++- 1 file changed, 90 insertions(+), 4 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuicommon') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 6c87858..f2c6d94 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -4,7 +4,7 @@ import java.time.{LocalDate, LocalDateTime} import io.swagger.models.properties.Property import spray.json.JsValue -import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson, UuidId} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._ import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._ @@ -15,25 +15,29 @@ 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.core.swagger.CustomSwaggerJsonConverter._ +import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData + +import scala.collection.immutable object CustomSwaggerJsonFormats { - val customCommonProperties = Map[Class[_], Property]( + val customCommonProperties = immutable.Map[Class[_], Property]( classOf[LocalDateTime] -> stringProperty(example = Some("2010-12-31'T'18:59:59Z")), classOf[LocalDate] -> stringProperty(example = Some("2010-12-31")), classOf[UuidId[_]] -> stringProperty(example = Some("370b0450-35cb-4aab-ba74-0145be75add5")), classOf[StringId[_]] -> stringProperty(), classOf[LongId[_]] -> stringProperty() ) - val customTrialCurationProperties = Map[Class[_], Property]( + val customTrialCurationProperties = immutable.Map[Class[_], Property]( classOf[Trial.Status] -> stringProperty(), classOf[Trial.Condition] -> stringProperty(), classOf[TrialHistory.Action] -> stringProperty(), classOf[TrialHistory.State] -> stringProperty() ) ++ customCommonProperties - val customTrialCurationObjectsExamples = Map[Class[_], JsValue]( + 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( @@ -52,4 +56,86 @@ object CustomSwaggerJsonFormats { xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) ) + //records-processing-service + object Rep { + import xyz.driver.pdsuidomain.fakes.entities.rep + import xyz.driver.pdsuidomain.formats.json.sprayformats.document + import xyz.driver.pdsuidomain.formats.json.sprayformats.documentissue + import xyz.driver.pdsuidomain.formats.json.sprayformats.documenthistory + import xyz.driver.pdsuidomain.formats.json.sprayformats.providertype + import xyz.driver.pdsuidomain.formats.json.sprayformats.record + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordissue + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordhistory + import xyz.driver.pdsuidomain.formats.json.sprayformats.bridgeuploadqueue + import xyz.driver.pdsuidomain.formats.json.sprayformats.extracteddata + + + val customRepObjectsExamples = immutable.Map[Class[_], JsValue]( + classOf[Document] -> + document.documentFormat.write(rep.DocumentGen.nextDocument()), + classOf[Document.Meta] -> + document.documentMetaFormat.write(rep.DocumentGen.nextDocumentMeta()), + classOf[TextJson[Document.Meta]] -> + document.fullDocumentMetaFormat.write(rep.DocumentGen.nextDocumentMetaJson()), + classOf[Document.RequiredType] -> + document.requiredTypeFormat.write(rep.DocumentGen.nextDocumentRequiredType()), + classOf[Document.Status] -> + document.documentStatusFormat.write(rep.DocumentGen.nextDocumentStatus()), + + classOf[DocumentIssue] -> + documentissue.documentIssueFormat.write(rep.DocumentGen.nextDocumentIssue()), + + classOf[DocumentHistory] -> + documenthistory.documentHistoryFormat.write(rep.DocumentGen.nextDocumentHistory()), + classOf[DocumentHistory.Action] -> + documenthistory.documentActionFormat.write(rep.DocumentGen.nextDocumentHistoryAction()), + classOf[DocumentHistory.State] -> + documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), + + classOf[ProviderType] -> + providertype.providerTypeFormat.write(rep.ProviderTypeGen.nextProviderType()), + + classOf[TextJson[List[MedicalRecord.Meta]]] -> + record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), + classOf[MedicalRecord] -> + record.recordFormat.write(rep.MedicalRecordGen.nextMedicalRecord()), + classOf[MedicalRecord.Meta] -> + record.recordMetaTypeFormat.write(rep.MedicalRecordGen.nextMedicalRecordMeta()), + classOf[MedicalRecord.Status] -> + record.recordStatusFormat.write(rep.MedicalRecordGen.nextMedicalRecordStatus()), + + classOf[MedicalRecordIssue] -> + recordissue.recordIssueFormat.write(rep.MedicalRecordGen.nextMedicalRecordIssue()), + + classOf[MedicalRecordHistory] -> + recordhistory.recordHistoryFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistory()), + classOf[MedicalRecordHistory.Action] -> + recordhistory.recordActionFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryAction()), + classOf[MedicalRecordHistory.State] -> + recordhistory.recordStateFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryState()), + + classOf[BridgeUploadQueue.Item] -> + bridgeuploadqueue.queueUploadItemFormat.write(rep.BridgeUploadQueueGen.nextBridgeUploadQueueItem()), + + classOf[ExtractedData.Meta] -> + extracteddata.extractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMeta()), + classOf[ExtractedData.Meta.Evidence] -> + extracteddata.metaEvidenceFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaEvidence()), + classOf[ExtractedData.Meta.Keyword] -> + extracteddata.metaKeywordFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaKeyword()), + classOf[ExtractedData.Meta.TextLayerPosition] -> + extracteddata.metaTextLayerPositionFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaTextLayerPosition()), + + classOf[TextJson[ExtractedData.Meta]] -> + extracteddata.fullExtractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaJson()), + + classOf[RichExtractedData] -> + extracteddata.extractedDataFormat.write(rep.ExtractedDataGen.nextRichExtractedData()), + + classOf[ExtractedDataLabel] -> + extracteddata.extractedDataLabelWriter.write(rep.ExtractedDataGen.nextExtractedDataLabel()) + ) + } + + } -- cgit v1.2.3 From fa841b8902ff29dc3d3e8c7dccd93d7b5b2b827f Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 18:27:34 +0700 Subject: Formatted code by scalafmt --- .../pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 13 ------------- .../pdsuidomain/fakes/entities/rep/Common.scala | 20 +++++++------------- .../pdsuidomain/fakes/entities/rep/DocumentGen.scala | 12 +++++------- .../fakes/entities/rep/ExportPatientGen.scala | 8 ++++---- .../fakes/entities/rep/ExtractedDataGen.scala | 12 ++++-------- .../fakes/entities/rep/MedicalRecordGen.scala | 12 +++++------- 6 files changed, 25 insertions(+), 52 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuicommon') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index f2c6d94..538618b 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -69,7 +69,6 @@ object CustomSwaggerJsonFormats { import xyz.driver.pdsuidomain.formats.json.sprayformats.bridgeuploadqueue import xyz.driver.pdsuidomain.formats.json.sprayformats.extracteddata - val customRepObjectsExamples = immutable.Map[Class[_], JsValue]( classOf[Document] -> document.documentFormat.write(rep.DocumentGen.nextDocument()), @@ -81,20 +80,16 @@ object CustomSwaggerJsonFormats { document.requiredTypeFormat.write(rep.DocumentGen.nextDocumentRequiredType()), classOf[Document.Status] -> document.documentStatusFormat.write(rep.DocumentGen.nextDocumentStatus()), - classOf[DocumentIssue] -> documentissue.documentIssueFormat.write(rep.DocumentGen.nextDocumentIssue()), - classOf[DocumentHistory] -> documenthistory.documentHistoryFormat.write(rep.DocumentGen.nextDocumentHistory()), classOf[DocumentHistory.Action] -> documenthistory.documentActionFormat.write(rep.DocumentGen.nextDocumentHistoryAction()), classOf[DocumentHistory.State] -> documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), - classOf[ProviderType] -> providertype.providerTypeFormat.write(rep.ProviderTypeGen.nextProviderType()), - classOf[TextJson[List[MedicalRecord.Meta]]] -> record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), classOf[MedicalRecord] -> @@ -103,20 +98,16 @@ object CustomSwaggerJsonFormats { record.recordMetaTypeFormat.write(rep.MedicalRecordGen.nextMedicalRecordMeta()), classOf[MedicalRecord.Status] -> record.recordStatusFormat.write(rep.MedicalRecordGen.nextMedicalRecordStatus()), - classOf[MedicalRecordIssue] -> recordissue.recordIssueFormat.write(rep.MedicalRecordGen.nextMedicalRecordIssue()), - classOf[MedicalRecordHistory] -> recordhistory.recordHistoryFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistory()), classOf[MedicalRecordHistory.Action] -> recordhistory.recordActionFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryAction()), classOf[MedicalRecordHistory.State] -> recordhistory.recordStateFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryState()), - classOf[BridgeUploadQueue.Item] -> bridgeuploadqueue.queueUploadItemFormat.write(rep.BridgeUploadQueueGen.nextBridgeUploadQueueItem()), - classOf[ExtractedData.Meta] -> extracteddata.extractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMeta()), classOf[ExtractedData.Meta.Evidence] -> @@ -125,17 +116,13 @@ object CustomSwaggerJsonFormats { extracteddata.metaKeywordFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaKeyword()), classOf[ExtractedData.Meta.TextLayerPosition] -> extracteddata.metaTextLayerPositionFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaTextLayerPosition()), - classOf[TextJson[ExtractedData.Meta]] -> extracteddata.fullExtractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaJson()), - classOf[RichExtractedData] -> extracteddata.extractedDataFormat.write(rep.ExtractedDataGen.nextRichExtractedData()), - classOf[ExtractedDataLabel] -> extracteddata.extractedDataLabelWriter.write(rep.ExtractedDataGen.nextExtractedDataLabel()) ) } - } 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 337dc2b..9618eed 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 @@ -5,26 +5,20 @@ import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.FuzzyValue private[rep] object Common { - def genBoundedRange[T](from: T, - to: T) - (implicit ord: Ordering[T]): (T, T) = { + def genBoundedRange[T](from: T, to: T)(implicit ord: Ordering[T]): (T, T) = { if (ord.compare(from, to) > 0) { to -> from - } - else { + } else { from -> to } } - def genBoundedRangeOption[T](from: T, - to: T) - (implicit ord: Ordering[T]): (Option[T], Option[T]) = { + 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) + .map(left => genBoundedRange(left, to)) + .map { + case (left, right) => + left -> nextOption(right) } ranges.map(_._1) -> ranges.flatMap(_._2) 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 0d32495..10349bb 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 @@ -1,6 +1,5 @@ package xyz.driver.pdsuidomain.fakes.entities.rep - import java.time.LocalDate import xyz.driver.core.generators @@ -10,8 +9,7 @@ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} object DocumentGen { - implicit private class LocalDateOrdering(localData: LocalDate) - extends Ordered[LocalDate] { + implicit private class LocalDateOrdering(localData: LocalDate) extends Ordered[LocalDate] { override def compare(that: LocalDate): Int = { this.localData.compareTo(that) @@ -25,8 +23,7 @@ object DocumentGen { Common.nextStartAndEndPages private def nextStartAndEndPage() = - Common.genBoundedRange(nextDouble(),nextDouble()) - + Common.genBoundedRange(nextDouble(), nextDouble()) def nextDocumentStatus(): Document.Status = Document.Status.New @@ -44,7 +41,9 @@ object DocumentGen { val (startPage, endPage) = nextStartAndEndPage() Document.Meta( - nextOption(nextBoolean()), startPage, endPage + nextOption(nextBoolean()), + startPage, + endPage ) } @@ -98,7 +97,6 @@ object DocumentGen { ) } - def nextDocumentHistory(documentId: LongId[Document] = nextLongId): DocumentHistory = { DocumentHistory( id = nextLongId[DocumentHistory], 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 index 4a4164a..7259d0c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -4,10 +4,10 @@ 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 + ExportPatientLabel, + ExportPatientLabelEvidence, + ExportPatientLabelEvidenceDocument, + ExportPatientWithLabels } import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} 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 0d99d19..8ac07d0 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,6 +1,5 @@ package xyz.driver.pdsuidomain.fakes.entities.rep - import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ @@ -8,16 +7,15 @@ 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 maxPageNumber = 100 + private val maxIndexNumber = 100 private val maxOffsetNumber = 10 implicit private class TextLayerPositionOrdering(textLayerPosition: ExtractedData.Meta.TextLayerPosition) - extends Ordered[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 @@ -56,7 +54,7 @@ object ExtractedDataGen { ExtractedData.Meta.Evidence( pageRatio = nextDouble(), start = layersPosition._1, - end = layersPosition._2 + end = layersPosition._2 ) } @@ -76,7 +74,6 @@ object ExtractedDataGen { ) } - def nextExtractedData(documentId: LongId[Document]): ExtractedData = { ExtractedData( id = nextLongId[ExtractedData], @@ -87,7 +84,6 @@ object ExtractedDataGen { ) } - def nextExtractedDataLabel(): ExtractedDataLabel = { ExtractedDataLabel( id = nextLongId[ExtractedDataLabel], 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 index 90c98c3..7221e66 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -39,7 +39,6 @@ object MedicalRecordGen { TextJson(documents.map(_.copy(recordId = recordId))) } - def nextMedicalRecordStatus(): MedicalRecord.Status = MedicalRecord.Status.New @@ -49,7 +48,6 @@ object MedicalRecordGen { def nextMedicalRecordHistoryAction(): MedicalRecordHistory.Action = generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) - def nextMedicalRecordMetaReorder(): MedicalRecord.Meta.Reorder = { val itemsNumber = maxItemsInCollectionNumber @@ -62,7 +60,6 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { val startPageGen = nextInt(pageMaxNumber, minValue = 0) @@ -80,9 +77,11 @@ object MedicalRecordGen { def nextMedicalRecordMetaRotation(): MedicalRecord.Meta.Rotation = { val items = - Array.tabulate(maxItemsInCollectionNumber)( - index => nextString() -> index - ).toMap + Array + .tabulate(maxItemsInCollectionNumber)( + index => nextString() -> index + ) + .toMap MedicalRecord.Meta.Rotation( predicted = nextOption(nextBoolean()), @@ -94,7 +93,6 @@ object MedicalRecordGen { generators.oneOf(medicalRecordMetas)() } - def nextMedicalRecord(): MedicalRecord = { val id = nextLongId[MedicalRecord] MedicalRecord( -- cgit v1.2.3 From b7dfa70fdc49d0a47f8628139baebf27ad2ea746 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 29 Sep 2017 09:33:59 +0700 Subject: Corrected scala style errors --- .../scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala/xyz/driver/pdsuicommon') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 538618b..4ecf915 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -56,7 +56,7 @@ object CustomSwaggerJsonFormats { xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) ) - //records-processing-service + // records-processing-service object Rep { import xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.pdsuidomain.formats.json.sprayformats.document -- cgit v1.2.3