diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-18 15:00:26 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-19 13:02:44 +0700 |
commit | 61d03bffcb6000268bb600d5336fb490056837f9 (patch) | |
tree | dbad0340d28dbe5835c80cf75f93d142a5327578 /src | |
parent | 0c8a7c3f1920e38a0606de91be5793c4f2a1d40a (diff) | |
download | rest-query-61d03bffcb6000268bb600d5336fb490056837f9.tar.gz rest-query-61d03bffcb6000268bb600d5336fb490056837f9.tar.bz2 rest-query-61d03bffcb6000268bb600d5336fb490056837f9.zip |
Created list response for each entity
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 45 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala | 67 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala | 20 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala (renamed from src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala) | 25 | ||||
-rw-r--r-- | src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala (renamed from src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala) | 29 |
5 files changed, 115 insertions, 71 deletions
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 index 4afe0ee..20644dc 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/listresponse.scala @@ -1,32 +1,15 @@ 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.ListResponse import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ -final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) - -object ListResponse { +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 val listResponseMetaFormat: RootJsonFormat[ListResponse.Meta] = jsonFormat4(ListResponse.Meta.apply) implicit def listResponseWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] = new RootJsonWriter[ListResponse[T]] { @@ -52,7 +35,7 @@ object ListResponse { val meta = fields .get(metaField) - .map(_.convertTo[Meta]) + .map(_.convertTo[ListResponse.Meta]) .getOrElse(deserializationError(s"ListResponse json object does not contain `$metaField` field: $json")) ListResponse(items, meta) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala index 40739f6..d6752d6 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseFormatSuite.scala @@ -6,16 +6,19 @@ 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 ListResponseSuite extends FlatSpec with Matchers { + +class ListResponseFormatSuite 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) = { + def metaJsonObjectAsString(meta: ListResponse.Meta) = { import meta._ val lastUpdate = meta.lastUpdate .map(_ => s""","lastUpdate":"$lastUpdateToLocal"""") @@ -33,13 +36,11 @@ class ListResponseSuite extends FlatSpec with Matchers { lastUpdate = None ) - val writtenJson1 = - ListResponse.listResponseMetaFormat.write(meta1) + val writtenJson1 = listResponseMetaFormat.write(meta1) writtenJson1 should be(metaJsonObjectAsString(meta1).parseJson) - val parsedItem1: ListResponse.Meta = - ListResponse.listResponseMetaFormat.read(writtenJson1) + val parsedItem1: ListResponse.Meta = listResponseMetaFormat.read(writtenJson1) meta1 shouldBe parsedItem1 @@ -51,13 +52,11 @@ class ListResponseSuite extends FlatSpec with Matchers { lastUpdate = Some(lastUpdate) ) - val writtenJson2 = - ListResponse.listResponseMetaFormat.write(meta2) + val writtenJson2 = listResponseMetaFormat.write(meta2) writtenJson2 should be(metaJsonObjectAsString(meta2).parseJson) - val parsedItem2: ListResponse.Meta = - ListResponse.listResponseMetaFormat.read(writtenJson2) + val parsedItem2: ListResponse.Meta = listResponseMetaFormat.read(writtenJson2) meta2 shouldBe parsedItem2 } @@ -81,10 +80,7 @@ class ListResponseSuite extends FlatSpec with Matchers { 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 recordJsonAsString = recordFormat.write(orig) val meta = ListResponse.Meta( @@ -96,9 +92,8 @@ class ListResponseSuite extends FlatSpec with Matchers { val listResponse = ListResponse(Seq(orig), meta) - - val writtenJson = ListResponse.listResponseWriter.write(listResponse) - val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${metaJsonObjectAsString(meta)}}""" + val writtenJson = listResponseWriter[MedicalRecord].write(listResponse) + val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${listResponseMetaFormat.write(meta)}}""" writtenJson should be(expectedJson.parseJson) } |