From 61d03bffcb6000268bb600d5336fb490056837f9 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 18 Oct 2017 15:00:26 +0700 Subject: Created list response for each entity --- .../utils/CustomSwaggerJsonFormats.scala | 45 +++++---- .../xyz/driver/pdsuidomain/ListResponse.scala | 67 +++++++++++++ .../fakes/entities/treatmentmatching.scala | 20 ++-- .../formats/json/sprayformats/ListResponse.scala | 62 ------------ .../formats/json/sprayformats/listresponse.scala | 45 +++++++++ .../sprayformats/ListResponseFormatSuite.scala | 101 ++++++++++++++++++++ .../json/sprayformats/ListResponseSuite.scala | 106 --------------------- 7 files changed, 245 insertions(+), 201 deletions(-) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala delete mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index d2e70f2..8cff038 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -6,14 +6,14 @@ import io.swagger.models.properties.Property import spray.json.JsValue import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.ListResponse._ +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.ListResponse._ 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._ @@ -130,32 +130,31 @@ 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[ListResponse[Patient]] -> listResponseWriter[Patient].write(nextPatientListResponse()), - classOf[ListResponse[PatientLabel]] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), - classOf[ListResponse[RichPatientLabel]] -> listResponseWriter[RichPatientLabel].write( + 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[PatientListResponse] -> listResponseWriter[Patient].write(nextPatientListResponse()), + classOf[PatientLabelListResponse] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), + classOf[RichPatientLabelListResponse] -> listResponseWriter[RichPatientLabel].write( nextRichPatientLabelListResponse()), - classOf[ListResponse[RichPatientCriterion]] -> listResponseWriter[RichPatientCriterion].write( + classOf[RichPatientCriterionListResponse] -> listResponseWriter[RichPatientCriterion].write( nextRichPatientCriterionListResponse()), - classOf[ListResponse[PatientLabelEvidenceView]] -> listResponseWriter[PatientLabelEvidenceView].write( + classOf[PatientLabelEvidenceViewListResponse] -> listResponseWriter[PatientLabelEvidenceView].write( nextPatientLabelEvidenceViewListResponse()), - classOf[ListResponse[RichPatientEligibleTrial]] -> listResponseWriter[RichPatientEligibleTrial].write( + classOf[RichPatientEligibleTrialListResponse] -> listResponseWriter[RichPatientEligibleTrial].write( nextRichPatientEligibleTrialListResponse()), - classOf[ListResponse[RichPatientHypothesis]] -> listResponseWriter[RichPatientHypothesis].write( + classOf[RichPatientHypothesisListResponse] -> listResponseWriter[RichPatientHypothesis].write( nextRichPatientHypothesisListResponse()), - classOf[ListResponse[PatientIssue]] -> listResponseWriter[PatientIssue].write(nextPatientIssuesListResponse()), - classOf[ListResponse[PatientHistory]] -> listResponseWriter[PatientHistory].write( - nextPatientHistoryListResponse()) + classOf[PatientIssueListResponse] -> listResponseWriter[PatientIssue].write(nextPatientIssuesListResponse()), + classOf[PatientHistoryListResponse] -> listResponseWriter[PatientHistory].write(nextPatientHistoryListResponse()) ) ++ customCommonObjectsExamples } diff --git a/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala new file mode 100644 index 0000000..b0effdd --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala @@ -0,0 +1,67 @@ +package xyz.driver.pdsuidomain + +import java.time.LocalDateTime + +import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue +import xyz.driver.pdsuicommon.db.Pagination +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData +import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion +import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial +import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis +import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel + +@SuppressWarnings(Array("org.wartremover.warts.FinalCaseClass")) +case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) + +object ListResponse { + + final case class Meta(itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) + + object Meta { + def apply(itemsCount: Int, pagination: Pagination, lastUpdate: Option[LocalDateTime]): Meta = { + Meta( + itemsCount, + pagination.pageNumber, + pagination.pageSize, + lastUpdate + ) + } + } + + trait MedicalRecordListResponse extends ListResponse[MedicalRecord] + trait MedicalRecordIssueListResponse extends ListResponse[MedicalRecordIssue] + trait MedicalRecordHistoryListResponse extends ListResponse[MedicalRecordHistory] + trait DocumentListResponse extends ListResponse[Document] + trait DocumentIssueListResponse extends ListResponse[DocumentIssue] + trait DocumentHistoryListResponse extends ListResponse[DocumentHistory] + trait RichExtractedDataListResponse extends ListResponse[RichExtractedData] + trait DocumentTypeListResponse extends ListResponse[DocumentType] + trait ProviderTypeListResponse extends ListResponse[ProviderType] + + trait TrialListResponse extends ListResponse[Trial] + trait TrialIssueListResponse extends ListResponse[TrialIssue] + trait TrialHistoryListResponse extends ListResponse[TrialHistory] + trait ArmListResponse extends ListResponse[Arm] + trait InterventionWithArmsListResponse extends ListResponse[InterventionWithArms] + trait EligibilityArmWithDiseasesListResponse extends ListResponse[EligibilityArmWithDiseases] + trait SlotArmListResponse extends ListResponse[SlotArm] + trait RichCriterionListResponse extends ListResponse[RichCriterion] + trait InterventionTypeListResponse extends ListResponse[InterventionType] + trait StudyDesignListResponse extends ListResponse[StudyDesign] + trait HypothesisListResponse extends ListResponse[Hypothesis] + + trait PatientListResponse extends ListResponse[Patient] + trait PatientIssueListResponse extends ListResponse[PatientIssue] + trait PatientHistoryListResponse extends ListResponse[PatientHistory] + trait PatientLabelListResponse extends ListResponse[PatientLabel] + trait RichPatientLabelListResponse extends ListResponse[RichPatientLabel] + trait RichPatientCriterionListResponse extends ListResponse[RichPatientCriterion] + trait RichPatientEligibleTrialListResponse extends ListResponse[RichPatientEligibleTrial] + trait RichPatientHypothesisListResponse extends ListResponse[RichPatientHypothesis] + trait PatientLabelEvidenceViewListResponse extends ListResponse[PatientLabelEvidenceView] + + trait QueueUploadItemListResponse extends ListResponse[BridgeUploadQueue.Item] + +} 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 b0ca136..f8244f8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala @@ -3,8 +3,8 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.entities.labels.Label import xyz.driver.fakes import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} +import xyz.driver.pdsuidomain.ListResponse 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 @@ -168,7 +168,7 @@ object treatmentmatching { def nextPatientListResponse(): ListResponse[Patient] = { val xs: Seq[Patient] = Seq.fill(3)(nextPatient()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[Patient]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -182,7 +182,7 @@ object treatmentmatching { def nextRichPatientLabelListResponse(): ListResponse[RichPatientLabel] = { val xs: Seq[RichPatientLabel] = Seq.fill(3)(nextRichPatientLabel()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[RichPatientLabel]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -196,7 +196,7 @@ object treatmentmatching { def nextPatientLabelListResponse(): ListResponse[PatientLabel] = { val xs: Seq[PatientLabel] = Seq.fill(3)(nextPatientLabel()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[PatientLabel]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -210,7 +210,7 @@ object treatmentmatching { def nextRichPatientCriterionListResponse(): ListResponse[RichPatientCriterion] = { val xs: Seq[RichPatientCriterion] = Seq.fill(3)(nextRichPatientCriterion()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[RichPatientCriterion]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -224,7 +224,7 @@ object treatmentmatching { def nextRichPatientEligibleTrialListResponse(): ListResponse[RichPatientEligibleTrial] = { val xs: Seq[RichPatientEligibleTrial] = Seq.fill(3)(nextRichPatientEligibleTrial()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[RichPatientEligibleTrial]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -238,7 +238,7 @@ object treatmentmatching { def nextRichPatientHypothesisListResponse(): ListResponse[RichPatientHypothesis] = { val xs: Seq[RichPatientHypothesis] = Seq.fill(3)(nextRichPatientHypothesis()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[RichPatientHypothesis]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -252,7 +252,7 @@ object treatmentmatching { def nextPatientLabelEvidenceViewListResponse(): ListResponse[PatientLabelEvidenceView] = { val xs: Seq[PatientLabelEvidenceView] = Seq.fill(3)(nextPatientLabelEvidenceView()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[PatientLabelEvidenceView]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -266,7 +266,7 @@ object treatmentmatching { def nextPatientIssuesListResponse(): ListResponse[PatientIssue] = { val xs: Seq[PatientIssue] = Seq.fill(3)(nextPatientIssue()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[PatientIssue]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, @@ -280,7 +280,7 @@ object treatmentmatching { def nextPatientHistoryListResponse(): ListResponse[PatientHistory] = { val xs: Seq[PatientHistory] = Seq.fill(3)(nextPatientHistory()) val pageSize = generators.nextInt(xs.size, 1) - ListResponse( + new ListResponse[PatientHistory]( items = xs, meta = ListResponse.Meta( itemsCount = xs.size, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala deleted file mode 100644 index 4afe0ee..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala +++ /dev/null @@ -1,62 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime - -import spray.json._ -import spray.json.DefaultJsonProtocol._ -import xyz.driver.pdsuicommon.db.Pagination -import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ - -final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) - -object ListResponse { - private val itemsField = "items" - private val metaField = "meta" - - final case class Meta(itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) - - object Meta { - def apply(itemsCount: Int, pagination: Pagination, lastUpdate: Option[LocalDateTime]): Meta = { - Meta( - itemsCount, - pagination.pageNumber, - pagination.pageSize, - lastUpdate - ) - } - } - - implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) - - implicit def listResponseWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] = - new RootJsonWriter[ListResponse[T]] { - override def write(listResponse: ListResponse[T]): JsValue = { - JsObject( - itemsField -> listResponse.items.map(_.toJson).toJson, - metaField -> listResponse.meta.toJson - ) - } - } - - implicit def listResponseReader[T: JsonReader]: RootJsonReader[ListResponse[T]] = - new RootJsonReader[ListResponse[T]] { - override def read(json: JsValue): ListResponse[T] = json match { - case JsObject(fields) => - val items = fields - .get(itemsField) - .map { - case JsArray(elements) => elements.map(_.convertTo[T])(collection.breakOut) - case x => deserializationError(s"Expected Array as JsArray, but got $x") - } - .getOrElse(deserializationError(s"ListResponse json object does not contain `$itemsField` field: $json")) - - val meta = fields - .get(metaField) - .map(_.convertTo[Meta]) - .getOrElse(deserializationError(s"ListResponse json object does not contain `$metaField` field: $json")) - - ListResponse(items, meta) - case _ => deserializationError(s"Expected ListResponse json object, but got $json") - } - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala new file mode 100644 index 0000000..20644dc --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala @@ -0,0 +1,45 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import spray.json.DefaultJsonProtocol._ +import xyz.driver.pdsuidomain.ListResponse +import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ + +object listresponse { + private val itemsField = "items" + private val metaField = "meta" + + implicit val listResponseMetaFormat: RootJsonFormat[ListResponse.Meta] = jsonFormat4(ListResponse.Meta.apply) + + implicit def listResponseWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] = + new RootJsonWriter[ListResponse[T]] { + override def write(listResponse: ListResponse[T]): JsValue = { + JsObject( + itemsField -> listResponse.items.map(_.toJson).toJson, + metaField -> listResponse.meta.toJson + ) + } + } + + implicit def listResponseReader[T: JsonReader]: RootJsonReader[ListResponse[T]] = + new RootJsonReader[ListResponse[T]] { + override def read(json: JsValue): ListResponse[T] = json match { + case JsObject(fields) => + val items = fields + .get(itemsField) + .map { + case JsArray(elements) => elements.map(_.convertTo[T])(collection.breakOut) + case x => deserializationError(s"Expected Array as JsArray, but got $x") + } + .getOrElse(deserializationError(s"ListResponse json object does not contain `$itemsField` field: $json")) + + val meta = fields + .get(metaField) + .map(_.convertTo[ListResponse.Meta]) + .getOrElse(deserializationError(s"ListResponse json object does not contain `$metaField` field: $json")) + + ListResponse(items, meta) + case _ => deserializationError(s"Expected ListResponse json object, but got $json") + } + } +} diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala new file mode 100644 index 0000000..d6752d6 --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala @@ -0,0 +1,101 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import java.time.LocalDateTime +import java.util.UUID + +import spray.json._ +import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.ListResponse +import xyz.driver.pdsuidomain.entities.MedicalRecord.Status +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.record.recordFormat +import xyz.driver.pdsuidomain.formats.json.sprayformats.listresponse._ + + +class ListResponseFormatSuite extends FlatSpec with Matchers { + + private val lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") + private val lastUpdateToLocal = "2017-08-10T18:00Z" + + def metaJsonObjectAsString(meta: ListResponse.Meta) = { + import meta._ + val lastUpdate = meta.lastUpdate + .map(_ => s""","lastUpdate":"$lastUpdateToLocal"""") + .getOrElse("") + + s"""{"itemsCount":$itemsCount,"pageNumber":$pageNumber,"pageSize":$pageSize$lastUpdate}""" + } + + "Json format for ListResponse.Meta" should "read and write correct JSON" in { + val meta1 = + ListResponse.Meta( + itemsCount = 5, + pageNumber = 6, + pageSize = 7, + lastUpdate = None + ) + + val writtenJson1 = listResponseMetaFormat.write(meta1) + + writtenJson1 should be(metaJsonObjectAsString(meta1).parseJson) + + val parsedItem1: ListResponse.Meta = listResponseMetaFormat.read(writtenJson1) + + meta1 shouldBe parsedItem1 + + val meta2 = + ListResponse.Meta( + itemsCount = 1, + pageNumber = 4, + pageSize = 3, + lastUpdate = Some(lastUpdate) + ) + + val writtenJson2 = listResponseMetaFormat.write(meta2) + + writtenJson2 should be(metaJsonObjectAsString(meta2).parseJson) + + val parsedItem2: ListResponse.Meta = listResponseMetaFormat.read(writtenJson2) + + meta2 shouldBe parsedItem2 + } + + "Json format for ListResponse" should "write correct JSON" in { + + val orig = MedicalRecord( + id = LongId(1), + status = Status.New, + assignee = None, + previousStatus = None, + previousAssignee = None, + lastActiveUserId = None, + lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"), + physician = Some("physician"), + meta = None, + disease = "Breast", + requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")), + caseId = None, + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), + totalPages = 10 + ) + + val recordJsonAsString = recordFormat.write(orig) + + val meta = + ListResponse.Meta( + itemsCount = 5, + pageNumber = 6, + pageSize = 7, + lastUpdate = None + ) + + val listResponse = ListResponse(Seq(orig), meta) + + val writtenJson = listResponseWriter[MedicalRecord].write(listResponse) + val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${listResponseMetaFormat.write(meta)}}""" + + writtenJson should be(expectedJson.parseJson) + } + +} diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala deleted file mode 100644 index 40739f6..0000000 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala +++ /dev/null @@ -1,106 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime -import java.util.UUID - -import spray.json._ -import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuidomain.entities.MedicalRecord.Status -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.formats.json.sprayformats.record.recordFormat - -class ListResponseSuite extends FlatSpec with Matchers { - - private val lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") - private val lastUpdateToLocal = "2017-08-10T18:00Z" - - private def metaJsonObjectAsString(meta: ListResponse.Meta) = { - import meta._ - val lastUpdate = meta.lastUpdate - .map(_ => s""","lastUpdate":"$lastUpdateToLocal"""") - .getOrElse("") - - s"""{"itemsCount":$itemsCount,"pageNumber":$pageNumber,"pageSize":$pageSize$lastUpdate}""" - } - - "Json format for ListResponse.Meta" should "read and write correct JSON" in { - val meta1 = - ListResponse.Meta( - itemsCount = 5, - pageNumber = 6, - pageSize = 7, - lastUpdate = None - ) - - val writtenJson1 = - ListResponse.listResponseMetaFormat.write(meta1) - - writtenJson1 should be(metaJsonObjectAsString(meta1).parseJson) - - val parsedItem1: ListResponse.Meta = - ListResponse.listResponseMetaFormat.read(writtenJson1) - - meta1 shouldBe parsedItem1 - - val meta2 = - ListResponse.Meta( - itemsCount = 1, - pageNumber = 4, - pageSize = 3, - lastUpdate = Some(lastUpdate) - ) - - val writtenJson2 = - ListResponse.listResponseMetaFormat.write(meta2) - - writtenJson2 should be(metaJsonObjectAsString(meta2).parseJson) - - val parsedItem2: ListResponse.Meta = - ListResponse.listResponseMetaFormat.read(writtenJson2) - - meta2 shouldBe parsedItem2 - } - - "Json format for ListResponse" should "write correct JSON" in { - - val orig = MedicalRecord( - id = LongId(1), - status = Status.New, - assignee = None, - previousStatus = None, - previousAssignee = None, - lastActiveUserId = None, - lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"), - physician = Some("physician"), - meta = None, - disease = "Breast", - requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")), - caseId = None, - patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), - totalPages = 10 - ) - - val recordJsonAsString = - """{"id":1,"status":"New","assignee":null,"previousStatus":null,"previousAssignee":null,"lastActiveUser":null, - "lastUpdate":"2017-08-10T18:00Z","meta":[],"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","caseId":null, - "requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","disease":"Breast","physician":"physician","totalPages":10}""" - - val meta = - ListResponse.Meta( - itemsCount = 5, - pageNumber = 6, - pageSize = 7, - lastUpdate = None - ) - - val listResponse = ListResponse(Seq(orig), meta) - - - val writtenJson = ListResponse.listResponseWriter.write(listResponse) - val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${metaJsonObjectAsString(meta)}}""" - - writtenJson should be(expectedJson.parseJson) - } - -} -- cgit v1.2.3 From f3afdc358e52e2399bb4b089d26e3e3521570872 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Thu, 19 Oct 2017 14:53:56 +0700 Subject: Review fixes --- .../utils/CustomSwaggerJsonFormats.scala | 110 ++++++++++++++---- .../xyz/driver/pdsuidomain/ListResponse.scala | 45 +------- .../driver/pdsuidomain/fakes/entities/common.scala | 29 +++++ .../fakes/entities/recordprocessing.scala | 40 ++++++- .../fakes/entities/treatmentmatching.scala | 123 ++++++--------------- .../pdsuidomain/fakes/entities/trialcuration.scala | 57 ++++++++++ .../formats/json/sprayformats/arm.scala | 2 +- 7 files changed, 245 insertions(+), 161 deletions(-) diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 8cff038..8018034 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -10,7 +10,6 @@ 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.ListResponse._ import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels import xyz.driver.pdsuidomain.fakes.entities.common @@ -28,6 +27,40 @@ import scala.collection.immutable object CustomSwaggerJsonFormats { + trait MedicalRecordListResponse + trait MedicalRecordIssueListResponse + trait MedicalRecordHistoryListResponse + trait DocumentListResponse + trait DocumentIssueListResponse + trait DocumentHistoryListResponse + trait RichExtractedDataListResponse + trait DocumentTypeListResponse + trait ProviderTypeListResponse + + trait TrialListResponse + trait TrialIssueListResponse + trait TrialHistoryListResponse + trait ArmListResponse + trait InterventionWithArmsListResponse + trait EligibilityArmWithDiseasesListResponse + trait SlotArmListResponse + trait RichCriterionListResponse + trait InterventionTypeListResponse + trait StudyDesignListResponse + trait HypothesisListResponse + + trait PatientListResponse + trait PatientIssueListResponse + trait PatientHistoryListResponse + trait PatientLabelListResponse + trait RichPatientLabelListResponse + trait RichPatientCriterionListResponse + trait RichPatientEligibleTrialListResponse + trait RichPatientHypothesisListResponse + trait PatientLabelEvidenceViewListResponse + + trait QueueUploadItemListResponse + 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")), @@ -40,7 +73,11 @@ object CustomSwaggerJsonFormats { val customCommonObjectsExamples = immutable.Map[Class[_], JsValue]( classOf[BridgeUploadQueue.Item] -> queueUploadItemFormat.write(common.nextBridgeUploadQueueItem()), classOf[ProviderType] -> providerTypeFormat.write(common.nextProviderType()), - classOf[DocumentType] -> documentTypeFormat.write(common.nextDocumentType()) + classOf[DocumentType] -> documentTypeFormat.write(common.nextDocumentType()), + classOf[QueueUploadItemListResponse] -> listResponseWriter[BridgeUploadQueue.Item] + .write(common.nextBridgeUploadQueueItemListResponse()), + classOf[DocumentTypeListResponse] -> listResponseWriter[DocumentType].write(common.nextDocumentTypeListResponse()), + classOf[ProviderTypeListResponse] -> listResponseWriter[ProviderType].write(common.nextProviderTypeListResponse()) ) object trialcuration { @@ -76,7 +113,21 @@ object CustomSwaggerJsonFormats { classOf[StudyDesign] -> studyDesignFormat.write(nextStudyDesign()), classOf[ExportTrialWithLabels] -> trialWithLabelsFormat.write(export.nextExportTrialWithLabels()), classOf[EligibilityArmWithDiseases] -> eligibilityArmWithDiseasesWriter.write(nextEligibilityArmWithDiseases()), - classOf[SlotArm] -> slotArmFormat.write(nextSlotArm()) + classOf[SlotArm] -> slotArmFormat.write(nextSlotArm()), + classOf[TrialListResponse] -> listResponseWriter[Trial].write(nextTrialListResponse()), + classOf[TrialIssueListResponse] -> listResponseWriter[TrialIssue].write(nextTrialIssueListResponse()), + classOf[TrialHistoryListResponse] -> listResponseWriter[TrialHistory].write(nextTrialHistoryListResponse()), + classOf[ArmListResponse] -> listResponseWriter[Arm].write(nextArmListResponse()), + classOf[InterventionWithArmsListResponse] -> listResponseWriter[InterventionWithArms].write( + nextInterventionWithArmsListResponse()), + classOf[EligibilityArmWithDiseasesListResponse] -> listResponseWriter[EligibilityArmWithDiseases].write( + nextEligibilityArmWithDiseasesListResponse()), + classOf[SlotArmListResponse] -> listResponseWriter[SlotArm].write(nextSlotArmListResponse()), + classOf[RichCriterionListResponse] -> listResponseWriter[RichCriterion].write(nextRichCriterionListResponse()), + classOf[InterventionTypeListResponse] -> listResponseWriter[InterventionType].write( + nextInterventionTypeListResponse()), + classOf[StudyDesignListResponse] -> listResponseWriter[StudyDesign].write(nextStudyDesignListResponse()), + classOf[HypothesisListResponse] -> listResponseWriter[Hypothesis].write(nextHypothesesListResponse()) ) } @@ -101,14 +152,25 @@ object CustomSwaggerJsonFormats { ) ++ customCommonProperties 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()) + 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()), + classOf[MedicalRecordListResponse] -> listResponseWriter[MedicalRecord].write(nextMedicalRecordListResponse()), + classOf[MedicalRecordIssueListResponse] -> listResponseWriter[MedicalRecordIssue].write( + nextMedicalRecordIssueListResponse()), + classOf[MedicalRecordHistoryListResponse] -> listResponseWriter[MedicalRecordHistory].write( + nextMedicalRecordHistoryListResponse()), + classOf[DocumentListResponse] -> listResponseWriter[Document].write(nextDocumentListResponse()), + classOf[DocumentIssueListResponse] -> listResponseWriter[DocumentIssue].write(nextDocumentIssueListResponse()), + classOf[DocumentHistoryListResponse] -> listResponseWriter[DocumentHistory].write( + nextDocumentHistoryListResponse()), + classOf[RichExtractedDataListResponse] -> listResponseWriter[RichExtractedData].write( + nextRichExtractedDataListResponse()) ) ++ customCommonObjectsExamples } @@ -130,19 +192,19 @@ 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[PatientListResponse] -> listResponseWriter[Patient].write(nextPatientListResponse()), - classOf[PatientLabelListResponse] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), + 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[PatientListResponse] -> listResponseWriter[Patient].write(nextPatientListResponse()), + classOf[PatientLabelListResponse] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), classOf[RichPatientLabelListResponse] -> listResponseWriter[RichPatientLabel].write( nextRichPatientLabelListResponse()), classOf[RichPatientCriterionListResponse] -> listResponseWriter[RichPatientCriterion].write( diff --git a/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala index b0effdd..c6dce7b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala @@ -2,18 +2,9 @@ package xyz.driver.pdsuidomain import java.time.LocalDateTime -import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue import xyz.driver.pdsuicommon.db.Pagination -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData -import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial -import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis -import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel -@SuppressWarnings(Array("org.wartremover.warts.FinalCaseClass")) -case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) +final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) object ListResponse { @@ -30,38 +21,4 @@ object ListResponse { } } - trait MedicalRecordListResponse extends ListResponse[MedicalRecord] - trait MedicalRecordIssueListResponse extends ListResponse[MedicalRecordIssue] - trait MedicalRecordHistoryListResponse extends ListResponse[MedicalRecordHistory] - trait DocumentListResponse extends ListResponse[Document] - trait DocumentIssueListResponse extends ListResponse[DocumentIssue] - trait DocumentHistoryListResponse extends ListResponse[DocumentHistory] - trait RichExtractedDataListResponse extends ListResponse[RichExtractedData] - trait DocumentTypeListResponse extends ListResponse[DocumentType] - trait ProviderTypeListResponse extends ListResponse[ProviderType] - - trait TrialListResponse extends ListResponse[Trial] - trait TrialIssueListResponse extends ListResponse[TrialIssue] - trait TrialHistoryListResponse extends ListResponse[TrialHistory] - trait ArmListResponse extends ListResponse[Arm] - trait InterventionWithArmsListResponse extends ListResponse[InterventionWithArms] - trait EligibilityArmWithDiseasesListResponse extends ListResponse[EligibilityArmWithDiseases] - trait SlotArmListResponse extends ListResponse[SlotArm] - trait RichCriterionListResponse extends ListResponse[RichCriterion] - trait InterventionTypeListResponse extends ListResponse[InterventionType] - trait StudyDesignListResponse extends ListResponse[StudyDesign] - trait HypothesisListResponse extends ListResponse[Hypothesis] - - trait PatientListResponse extends ListResponse[Patient] - trait PatientIssueListResponse extends ListResponse[PatientIssue] - trait PatientHistoryListResponse extends ListResponse[PatientHistory] - trait PatientLabelListResponse extends ListResponse[PatientLabel] - trait RichPatientLabelListResponse extends ListResponse[RichPatientLabel] - trait RichPatientCriterionListResponse extends ListResponse[RichPatientCriterion] - trait RichPatientEligibleTrialListResponse extends ListResponse[RichPatientEligibleTrial] - trait RichPatientHypothesisListResponse extends ListResponse[RichPatientHypothesis] - trait PatientLabelEvidenceViewListResponse extends ListResponse[PatientLabelEvidenceView] - - trait QueueUploadItemListResponse extends ListResponse[BridgeUploadQueue.Item] - } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala index 0ac2be5..2aaa251 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala @@ -7,6 +7,7 @@ import xyz.driver.entities.common.FullName import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson, UuidId} +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import scala.util.Random @@ -85,10 +86,38 @@ object common { ) } + def nextBridgeUploadQueueItemListResponse(): ListResponse[BridgeUploadQueue.Item] = { + val xs: Seq[BridgeUploadQueue.Item] = Seq.fill(3)(nextBridgeUploadQueueItem()) + nextListResponse(xs) + } + def nextDocumentType(): DocumentType = generators.oneOf[DocumentType](DocumentType.All: _*) def nextProviderType(): ProviderType = generators.oneOf[ProviderType](ProviderType.All: _*) + def nextDocumentTypeListResponse(): ListResponse[DocumentType] = { + val xs: Seq[DocumentType] = Seq.fill(3)(nextDocumentType()) + nextListResponse(xs) + } + + def nextProviderTypeListResponse(): ListResponse[ProviderType] = { + val xs: Seq[ProviderType] = Seq.fill(3)(nextProviderType()) + nextListResponse(xs) + } + def nextTextJson[T](obj: T): TextJson[T] = TextJson(obj) + def nextListResponse[T](xs: Seq[T]): ListResponse[T] = { + 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) + ) + ) + } + } 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 d2a648c..c0c3391 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala @@ -6,6 +6,7 @@ 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.ListResponse import xyz.driver.pdsuidomain.entities.ExtractedData.Meta import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common._ @@ -186,12 +187,12 @@ object recordprocessing { ) } - def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = { + def nextDocumentIssue(): DocumentIssue = { val (startPage, endPage) = nextStartAndEndPagesOption DocumentIssue( id = nextLongId[DocumentIssue], userId = nextStringId[User], - documentId = documentId, + documentId = nextLongId[Document], startPage = startPage, endPage = endPage, lastUpdate = nextLocalDateTime, @@ -281,4 +282,39 @@ object recordprocessing { ) } + def nextMedicalRecordListResponse(): ListResponse[MedicalRecord] = { + val xs: Seq[MedicalRecord] = Seq.fill(3)(nextMedicalRecord()) + nextListResponse(xs) + } + + def nextMedicalRecordIssueListResponse(): ListResponse[MedicalRecordIssue] = { + val xs: Seq[MedicalRecordIssue] = Seq.fill(3)(nextMedicalRecordIssue()) + nextListResponse(xs) + } + + def nextMedicalRecordHistoryListResponse(): ListResponse[MedicalRecordHistory] = { + val xs: Seq[MedicalRecordHistory] = Seq.fill(3)(nextMedicalRecordHistory()) + nextListResponse(xs) + } + + def nextDocumentListResponse(): ListResponse[Document] = { + val xs: Seq[Document] = Seq.fill(3)(nextDocument()) + nextListResponse(xs) + } + + def nextDocumentIssueListResponse(): ListResponse[DocumentIssue] = { + val xs: Seq[DocumentIssue] = Seq.fill(3)(nextDocumentIssue()) + nextListResponse(xs) + } + + def nextDocumentHistoryListResponse(): ListResponse[DocumentHistory] = { + val xs: Seq[DocumentHistory] = Seq.fill(3)(nextDocumentHistory()) + nextListResponse(xs) + } + + def nextRichExtractedDataListResponse(): ListResponse[RichExtractedData] = { + val xs: Seq[RichExtractedData] = Seq.fill(3)(nextRichExtractedData()) + nextListResponse(xs) + } + } 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 f8244f8..d5adc32 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala @@ -14,6 +14,26 @@ object treatmentmatching { import common._ import xyz.driver.core.generators + final case class DraftPatientCriterionList(list: List[DraftPatientCriterion]) + object DraftPatientCriterionList { + import spray.json._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.patientcriterion._ + + implicit val draftPatientCriterionListFormat: RootJsonFormat[DraftPatientCriterionList] = + new RootJsonFormat[DraftPatientCriterionList] { + override def write(obj: DraftPatientCriterionList): JsValue = { + JsArray(obj.list.map(_.toJson).toVector) + } + + override def read(json: JsValue): DraftPatientCriterionList = json match { + case j: JsObject => + DraftPatientCriterionList(draftPatientCriterionListReader.read(j)) + + case _ => deserializationError(s"Expected List of DraftPatientCriterion json object, but got $json") + } + } + } + def nextPatientOrderId: PatientOrderId = PatientOrderId(generators.nextUuid()) def nextPatientAction: PatientHistory.Action = @@ -75,6 +95,10 @@ object treatmentmatching { isVerified = generators.nextOption(generators.nextBoolean()) ) + def nextDraftPatientCriterionList(): DraftPatientCriterionList = { + DraftPatientCriterionList(List.fill(3)(nextDraftPatientCriterion())) + } + def nextPatientCriterionArm(criterionId: LongId[PatientCriterion]): PatientCriterionArm = PatientCriterionArm( patientCriterionId = criterionId, armId = nextLongId[Arm], @@ -167,128 +191,47 @@ object treatmentmatching { def nextPatientListResponse(): ListResponse[Patient] = { val xs: Seq[Patient] = Seq.fill(3)(nextPatient()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[Patient]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextRichPatientLabelListResponse(): ListResponse[RichPatientLabel] = { val xs: Seq[RichPatientLabel] = Seq.fill(3)(nextRichPatientLabel()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[RichPatientLabel]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextPatientLabelListResponse(): ListResponse[PatientLabel] = { val xs: Seq[PatientLabel] = Seq.fill(3)(nextPatientLabel()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[PatientLabel]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextRichPatientCriterionListResponse(): ListResponse[RichPatientCriterion] = { val xs: Seq[RichPatientCriterion] = Seq.fill(3)(nextRichPatientCriterion()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[RichPatientCriterion]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextRichPatientEligibleTrialListResponse(): ListResponse[RichPatientEligibleTrial] = { val xs: Seq[RichPatientEligibleTrial] = Seq.fill(3)(nextRichPatientEligibleTrial()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[RichPatientEligibleTrial]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextRichPatientHypothesisListResponse(): ListResponse[RichPatientHypothesis] = { val xs: Seq[RichPatientHypothesis] = Seq.fill(3)(nextRichPatientHypothesis()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[RichPatientHypothesis]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextPatientLabelEvidenceViewListResponse(): ListResponse[PatientLabelEvidenceView] = { val xs: Seq[PatientLabelEvidenceView] = Seq.fill(3)(nextPatientLabelEvidenceView()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[PatientLabelEvidenceView]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextPatientIssuesListResponse(): ListResponse[PatientIssue] = { val xs: Seq[PatientIssue] = Seq.fill(3)(nextPatientIssue()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[PatientIssue]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } def nextPatientHistoryListResponse(): ListResponse[PatientHistory] = { val xs: Seq[PatientHistory] = Seq.fill(3)(nextPatientHistory()) - val pageSize = generators.nextInt(xs.size, 1) - new ListResponse[PatientHistory]( - items = xs, - meta = ListResponse.Meta( - itemsCount = xs.size, - pageNumber = generators.nextInt(xs.size / pageSize), - pageSize = pageSize, - lastUpdate = generators.nextOption(nextLocalDateTime) - ) - ) + nextListResponse(xs) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala index 84dcb88..3ab50e1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.core.generators._ import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{LongId, User} +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion @@ -182,4 +183,60 @@ object trialcuration { originalName = nextString(), trialId = nextStringId ) + + def nextTrialListResponse(): ListResponse[Trial] = { + val xs: Seq[Trial] = Seq.fill(3)(nextTrial()) + nextListResponse(xs) + } + + def nextTrialIssueListResponse(): ListResponse[TrialIssue] = { + val xs: Seq[TrialIssue] = Seq.fill(3)(nextTrialIssue()) + nextListResponse(xs) + } + + def nextTrialHistoryListResponse(): ListResponse[TrialHistory] = { + val xs: Seq[TrialHistory] = Seq.fill(3)(nextTrialHistory()) + nextListResponse(xs) + } + + def nextArmListResponse(): ListResponse[Arm] = { + val xs: Seq[Arm] = Seq.fill(3)(nextArm()) + nextListResponse(xs) + } + + def nextInterventionWithArmsListResponse(): ListResponse[InterventionWithArms] = { + val xs: Seq[InterventionWithArms] = Seq.fill(3)(nextInterventionWithArms()) + nextListResponse(xs) + } + + def nextEligibilityArmWithDiseasesListResponse(): ListResponse[EligibilityArmWithDiseases] = { + val xs: Seq[EligibilityArmWithDiseases] = Seq.fill(3)(nextEligibilityArmWithDiseases()) + nextListResponse(xs) + } + + def nextSlotArmListResponse(): ListResponse[SlotArm] = { + val xs: Seq[SlotArm] = Seq.fill(3)(nextSlotArm()) + nextListResponse(xs) + } + + def nextRichCriterionListResponse(): ListResponse[RichCriterion] = { + val xs: Seq[RichCriterion] = Seq.fill(3)(nextRichCriterion()) + nextListResponse(xs) + } + + def nextInterventionTypeListResponse(): ListResponse[InterventionType] = { + val xs: Seq[InterventionType] = Seq.fill(3)(nextInterventionType()) + nextListResponse(xs) + } + + def nextStudyDesignListResponse(): ListResponse[StudyDesign] = { + val xs: Seq[StudyDesign] = Seq.fill(3)(nextStudyDesign()) + nextListResponse(xs) + } + + def nextHypothesesListResponse(): ListResponse[Hypothesis] = { + val xs: Seq[Hypothesis] = Seq.fill(3)(nextHypothesis()) + nextListResponse(xs) + } + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala index 39af1c3..e182b4b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala @@ -19,7 +19,7 @@ object arm { case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json") } - def armFormat: RootJsonFormat[Arm] = new RootJsonFormat[Arm] { + implicit val armFormat: RootJsonFormat[Arm] = new RootJsonFormat[Arm] { override def write(obj: Arm): JsValue = JsObject( "id" -> obj.id.toJson, -- cgit v1.2.3 From 14a6927aad61d13e7cec5be8a0da1194e7fba026 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Fri, 20 Oct 2017 14:01:24 +0700 Subject: Apply scalafmt --- .../utils/CustomSwaggerJsonFormats.scala | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 8018034..34c7495 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -192,19 +192,19 @@ 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[PatientListResponse] -> listResponseWriter[Patient].write(nextPatientListResponse()), - classOf[PatientLabelListResponse] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), + 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[PatientListResponse] -> listResponseWriter[Patient].write(nextPatientListResponse()), + classOf[PatientLabelListResponse] -> listResponseWriter[PatientLabel].write(nextPatientLabelListResponse()), classOf[RichPatientLabelListResponse] -> listResponseWriter[RichPatientLabel].write( nextRichPatientLabelListResponse()), classOf[RichPatientCriterionListResponse] -> listResponseWriter[RichPatientCriterion].write( -- cgit v1.2.3