aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksandr <ognelisar@gmail.com>2017-10-23 14:49:40 +0700
committerAleksandr <ognelisar@gmail.com>2017-10-23 14:49:40 +0700
commit7f8b3b9621ad31328dd135a67152f97e0419d5c9 (patch)
tree9deecc62f7cf2518effe4ed7568ee5fdc8e3b3f7 /src
parent133b4fe8487db9df80c1f39f64bbe7d6fc039952 (diff)
parentd1537fa8bbf7c7097fe7ddb410e40c82381d79f2 (diff)
downloadrest-query-7f8b3b9621ad31328dd135a67152f97e0419d5c9.tar.gz
rest-query-7f8b3b9621ad31328dd135a67152f97e0419d5c9.tar.bz2
rest-query-7f8b3b9621ad31328dd135a67152f97e0419d5c9.zip
Merge branch 'master' into PDSUI-2330
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala127
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala24
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala29
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala40
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala125
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala57
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala2
-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/main/scala/xyz/driver/pdsuidomain/services/HypothesisService.scala39
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala36
-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
14 files changed, 368 insertions, 174 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
index 180ebf9..3eb1a65 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
@@ -144,7 +144,9 @@ object ACL extends PhiLogging {
object Hypothesis
extends BaseACL(
label = "hypothesis",
- read = Set(TrialSummarizer, TrialAdmin) ++ TreatmentMatchingRoles
+ read = Set(TrialSummarizer, TrialAdmin) ++ TreatmentMatchingRoles,
+ create = Set(TrialAdmin),
+ delete = Set(TrialAdmin)
)
object Criterion
diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
index e9a4132..67da717 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
@@ -3,6 +3,7 @@ package xyz.driver.pdsuicommon.http
import akka.http.scaladsl.server._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.model._
+import xyz.driver.core.app.DriverApp
import xyz.driver.core.rest.ContextHeaders
import xyz.driver.entities.users.AuthUserInfo
import xyz.driver.pdsuicommon.auth._
@@ -88,7 +89,7 @@ trait Directives {
val text = Json.stringify(implicitly[Writes[ErrorsResponse]].writes(err))
HttpEntity(ContentTypes.`application/json`, text)
}
- RejectionHandler.default.mapRejectionResponse {
+ DriverApp.rejectionHandler.mapRejectionResponse {
case res @ HttpResponse(_, _, ent: HttpEntity.Strict, _) =>
res.copy(entity = wrapContent(ent.data.utf8String))
case x => x // pass through all other types of responses
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
index d2e70f2..34c7495 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
@@ -6,14 +6,13 @@ 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.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._
@@ -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,32 +192,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..c6dce7b
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/ListResponse.scala
@@ -0,0 +1,24 @@
+package xyz.driver.pdsuidomain
+
+import java.time.LocalDateTime
+
+import xyz.driver.pdsuicommon.db.Pagination
+
+final 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
+ )
+ }
+ }
+
+}
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 8ba1d82..86583c1 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._
@@ -187,12 +188,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,
@@ -282,4 +283,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 b10c7de..36ef3d9 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
@@ -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 =
@@ -76,6 +96,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],
@@ -168,128 +192,47 @@ object treatmentmatching {
def nextPatientListResponse(): ListResponse[Patient] = {
val xs: Seq[Patient] = Seq.fill(3)(nextPatient())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextRichPatientLabelListResponse(): ListResponse[RichPatientLabel] = {
val xs: Seq[RichPatientLabel] = Seq.fill(3)(nextRichPatientLabel())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextPatientLabelListResponse(): ListResponse[PatientLabel] = {
val xs: Seq[PatientLabel] = Seq.fill(3)(nextPatientLabel())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextRichPatientCriterionListResponse(): ListResponse[RichPatientCriterion] = {
val xs: Seq[RichPatientCriterion] = Seq.fill(3)(nextRichPatientCriterion())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextRichPatientEligibleTrialListResponse(): ListResponse[RichPatientEligibleTrial] = {
val xs: Seq[RichPatientEligibleTrial] = Seq.fill(3)(nextRichPatientEligibleTrial())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextRichPatientHypothesisListResponse(): ListResponse[RichPatientHypothesis] = {
val xs: Seq[RichPatientHypothesis] = Seq.fill(3)(nextRichPatientHypothesis())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextPatientLabelEvidenceViewListResponse(): ListResponse[PatientLabelEvidenceView] = {
val xs: Seq[PatientLabelEvidenceView] = Seq.fill(3)(nextPatientLabelEvidenceView())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextPatientIssuesListResponse(): ListResponse[PatientIssue] = {
val xs: Seq[PatientIssue] = Seq.fill(3)(nextPatientIssue())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ nextListResponse(xs)
}
def nextPatientHistoryListResponse(): ListResponse[PatientHistory] = {
val xs: Seq[PatientHistory] = Seq.fill(3)(nextPatientHistory())
- val pageSize = generators.nextInt(xs.size, 1)
- ListResponse(
- items = xs,
- meta = ListResponse.Meta(
- itemsCount = xs.size,
- pageNumber = generators.nextInt(xs.size / pageSize),
- pageSize = pageSize,
- lastUpdate = generators.nextOption(nextLocalDateTime)
- )
- )
+ 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 0ec1782..eeec577 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
@@ -179,4 +180,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/document/ApiPartialDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala
index ecbdaed..34bebab 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala
@@ -77,7 +77,7 @@ final case class ApiPartialDocument(recordId: Option[Long],
previousAssignee = None,
lastActiveUserId = None,
lastUpdate = LocalDateTime.MIN,
- labelVersion = 0
+ labelVersion = 1
)
} else {
throw new JsonValidationException(validationErrors)
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,
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/main/scala/xyz/driver/pdsuidomain/services/HypothesisService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/HypothesisService.scala
index 52cd6c8..572edb6 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/HypothesisService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/HypothesisService.scala
@@ -2,12 +2,21 @@ package xyz.driver.pdsuidomain.services
import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext
import xyz.driver.pdsuicommon.db.Sorting
+import xyz.driver.pdsuicommon.domain.UuidId
import xyz.driver.pdsuicommon.error.DomainError
import xyz.driver.pdsuidomain.entities.Hypothesis
import scala.concurrent.Future
object HypothesisService {
+ trait DefaultNotFoundError {
+ def userMessage: String = "Hypothesis not found"
+ }
+
+ trait DefaultAccessDeniedError {
+ def userMessage: String = "Access denied"
+ }
+
sealed trait GetListReply
object GetListReply {
final case class EntityList(xs: Seq[Hypothesis], totalFound: Int) extends GetListReply
@@ -16,6 +25,32 @@ object HypothesisService {
def userMessage: String = "Access denied"
}
}
+
+ sealed trait CreateReply
+ object CreateReply {
+ final case class Created(x: Hypothesis) extends CreateReply
+
+ type Error = CreateReply with DomainError
+
+ case object AuthorizationError
+ extends CreateReply with DefaultAccessDeniedError with DomainError.AuthorizationError
+
+ final case class CommonError(userMessage: String) extends CreateReply with DomainError
+ }
+
+ sealed trait DeleteReply
+ object DeleteReply {
+ case object Deleted extends DeleteReply
+
+ type Error = DeleteReply with DomainError
+
+ case object NotFoundError extends DeleteReply with DefaultNotFoundError with DomainError.NotFoundError
+
+ case object AuthorizationError
+ extends DeleteReply with DefaultAccessDeniedError with DomainError.AuthorizationError
+
+ final case class CommonError(userMessage: String) extends DeleteReply with DomainError
+ }
}
trait HypothesisService {
@@ -24,4 +59,8 @@ trait HypothesisService {
def getAll(sorting: Option[Sorting] = None)(
implicit requestContext: AuthenticatedRequestContext): Future[GetListReply]
+
+ def create(draftHypothesis: Hypothesis)(implicit requestContext: AuthenticatedRequestContext): Future[CreateReply]
+
+ def delete(id: UuidId[Hypothesis])(implicit requestContext: AuthenticatedRequestContext): Future[DeleteReply]
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala
index 1b8c943..9cef4c8 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala
@@ -1,14 +1,18 @@
package xyz.driver.pdsuidomain.services.rest
import scala.concurrent.{ExecutionContext, Future}
-
+import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.stream.Materializer
import xyz.driver.core.rest._
import xyz.driver.pdsuicommon.auth._
import xyz.driver.pdsuicommon.db._
-import xyz.driver.pdsuidomain.formats.json.ListResponse
-import xyz.driver.pdsuidomain.formats.json.hypothesis.ApiHypothesis
+import xyz.driver.pdsuicommon.domain.UuidId
+import xyz.driver.pdsuidomain.entities.Hypothesis
+import xyz.driver.pdsuidomain.ListResponse
+import xyz.driver.pdsuidomain.formats.json.sprayformats.listresponse._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.hypothesis._
import xyz.driver.pdsuidomain.services.HypothesisService
class RestHypothesisService(transport: ServiceTransport, baseUri: Uri)(
@@ -16,7 +20,6 @@ class RestHypothesisService(transport: ServiceTransport, baseUri: Uri)(
protected val exec: ExecutionContext)
extends HypothesisService with RestHelper {
- import xyz.driver.pdsuicommon.serialization.PlayJsonSupport._
import xyz.driver.pdsuidomain.services.HypothesisService._
def getAll(sorting: Option[Sorting] = None)(
@@ -24,9 +27,30 @@ class RestHypothesisService(transport: ServiceTransport, baseUri: Uri)(
val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, "/v1/hypothesis", sortingQuery(sorting)))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[ListResponse[ApiHypothesis]](response)
+ reply <- apiResponse[ListResponse[Hypothesis]](response)
+ } yield {
+ GetListReply.EntityList(reply.items, reply.meta.itemsCount)
+ }
+ }
+
+ def create(draftHypothesis: Hypothesis)(implicit requestContext: AuthenticatedRequestContext): Future[CreateReply] = {
+ for {
+ entity <- Marshal(draftHypothesis).to[RequestEntity]
+ request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, "/v1/hypothesis")).withEntity(entity)
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[Hypothesis](response)
+ } yield {
+ CreateReply.Created(reply)
+ }
+ }
+
+ def delete(id: UuidId[Hypothesis])(implicit requestContext: AuthenticatedRequestContext): Future[DeleteReply] = {
+ val request = HttpRequest(HttpMethods.DELETE, endpointUri(baseUri, s"/v1/hypothesis/$id"))
+ for {
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ _ <- apiResponse[HttpEntity](response)
} yield {
- GetListReply.EntityList(reply.items.map(_.toDomain), reply.meta.itemsCount)
+ DeleteReply.Deleted
}
}
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)
}