From bc4f67fe6755a34d410e75ce9b475b3e1c2d38e3 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 13:16:42 +0700 Subject: Replace tuples in services replies to rich-classes --- .../formats/json/sprayformats/PatientCriterionFormatSuite.scala | 5 +++-- .../formats/json/sprayformats/PatientHypothesisFormatSuite.scala | 3 ++- .../formats/json/sprayformats/PatientLabelFormatSuite.scala | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/test/scala/xyz') diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala index 0f5e4e2..623b3a9 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala @@ -6,7 +6,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId} import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm} -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion +import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} class PatientCriterionFormatSuite extends FlatSpec with Matchers { import patientcriterion._ @@ -31,7 +31,8 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(31), armName = "arm 31"), PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(32), armName = "arm 32") ) - val writtenJson = patientCriterionWriter.write((orig, LongId(21), arms)) + val richPatientCriterion = RichPatientCriterion(orig, LongId(21), arms) + val writtenJson = patientCriterionWriter.write(richPatientCriterion) writtenJson should be ( """{"id":1,"labelId":21,"nctId":"NCT00001","criterionId":101,"criterionText":"criterion text","criterionValue":"Yes", diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala index 2999cc1..1a5b7eb 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala @@ -4,6 +4,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.UuidId import xyz.driver.pdsuidomain.entities.PatientHypothesis +import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis class PatientHypothesisFormatSuite extends FlatSpec with Matchers { import patienthypothesis._ @@ -16,7 +17,7 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { rationale = None, matchedTrials = 1 ) - val writtenJson = patientHypothesisWriter.write((orig, true)) + val writtenJson = patientHypothesisWriter.write(RichPatientHypothesis(orig, true)) writtenJson should be ( """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala index e18239c..8b7c138 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala @@ -6,6 +6,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} import xyz.driver.pdsuidomain.entities.{PatientLabel, PatientLabelEvidenceView} +import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel class PatientLabelFormatSuite extends FlatSpec with Matchers { @@ -21,7 +22,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { score = 1, isImplicitMatch = false ) - val writtenJson = patientLabelWriter.write((orig, true)) + val writtenJson = patientLabelWriter.write(RichPatientLabel(orig, true)) writtenJson should be ( """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true, -- cgit v1.2.3 From 3cf0353e3999994ff4441432f574a6e5f4281073 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 14:28:25 +0700 Subject: Fixed spray format of ListResponse --- .../formats/json/sprayformats/ListResponse.scala | 8 +- .../json/sprayformats/ListResponseSuite.scala | 113 +++++++++++++++++++++ 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala (limited to 'src/test/scala/xyz') 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 fbfc53e..cedb053 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 @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import java.time.LocalDateTime -import spray.json.{JsArray, RootJsonFormat, _} +import spray.json.{RootJsonFormat, _} import xyz.driver.pdsuicommon.db.Pagination import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ @@ -27,11 +27,11 @@ object ListResponse extends DefaultJsonProtocol { implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) - implicit def listResponseMetaWriter[T: RootJsonWriter]: RootJsonWriter[ListResponse[T]] = - new RootJsonWriter[ListResponse[T]] { + implicit def listResponseMetaWriter[T: JsonWriter]: JsonWriter[ListResponse[T]] = + new JsonWriter[ListResponse[T]] { override def write(listResponse: ListResponse[T]): JsValue = { JsObject( - itemsField -> JsArray(listResponse.items.map(_.toJson).toVector), + itemsField -> listResponse.items.map(_.toJson).toJson, metaField -> listResponse.meta.toJson ) } 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 new file mode 100644 index 0000000..52b2324 --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala @@ -0,0 +1,113 @@ +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, + predictedMeta = None, + predictedDocuments = None, + disease = "Breast", + requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")), + caseId = None, + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343") + ) + + 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"}""" + + val meta = + ListResponse.Meta( + itemsCount = 5, + pageNumber = 6, + pageSize = 7, + lastUpdate = None + ) + + val listResponse = ListResponse(Seq(orig), meta) + + val writtenJson = ListResponse.listResponseMetaWriter.write(listResponse) + val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${metaJsonObjectAsString(meta)}}""" + + writtenJson should be( + expectedJson.parseJson) + } + +} -- cgit v1.2.3 From 7446fbcb6f51ae67ae8bf0f54729e774da8e7f73 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 16:23:04 +0700 Subject: Implemented new spray json formats for PatientHypothesis and PatientLabel --- .../json/sprayformats/patienthypothesis.scala | 15 +++++++++++++- .../formats/json/sprayformats/patientlabel.scala | 16 ++++++++++++++- .../PatientHypothesisFormatSuite.scala | 19 +++++++++++++++-- .../sprayformats/PatientLabelFormatSuite.scala | 24 ++++++++++++++++++++-- 4 files changed, 68 insertions(+), 6 deletions(-) (limited to 'src/test/scala/xyz') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala index 82759ab..bd448b3 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala @@ -19,7 +19,7 @@ object patienthypothesis { case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json") } - implicit val patientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = + implicit val richPatientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = new RootJsonWriter[RichPatientHypothesis] { override def write(obj: RichPatientHypothesis): JsValue = { JsObject( @@ -33,4 +33,17 @@ object patienthypothesis { } } + implicit val patientHypothesisWriter: RootJsonWriter[PatientHypothesis] = + new RootJsonWriter[PatientHypothesis] { + override def write(obj: PatientHypothesis): JsValue = { + JsObject( + "id" -> obj.id.toJson, + "patientId" -> obj.patientId.toJson, + "hypothesisId" -> obj.hypothesisId.toJson, + "matchedTrials" -> obj.matchedTrials.toJson, + "rationale" -> obj.rationale.toJson + ) + } + } + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala index f4af376..10a0a94 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala @@ -29,7 +29,7 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val patientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { + implicit val richPatientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { override def write(obj: RichPatientLabel): JsValue = { JsObject( "id" -> obj.patientLabel.id.toJson, @@ -44,6 +44,20 @@ object patientlabel { } } + implicit val patientLabelWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { + override def write(obj: PatientLabel): JsValue = { + JsObject( + "id" -> obj.id.toJson, + "labelId" -> obj.labelId.toJson, + "primaryValue" -> obj.primaryValue.toJson, + "verifiedPrimaryValue" -> obj.verifiedPrimaryValue.toJson, + "score" -> obj.score.toJson, + "isImplicitMatch" -> obj.isImplicitMatch.toJson, + "isVisible" -> obj.isVisible.toJson + ) + } + } + implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] = new RootJsonWriter[PatientLabelEvidenceView] { override def write(evidence: PatientLabelEvidenceView): JsValue = diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala index 1a5b7eb..fbb5213 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala @@ -9,7 +9,7 @@ import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypot class PatientHypothesisFormatSuite extends FlatSpec with Matchers { import patienthypothesis._ - "Json format for PatientHypothesis" should "read and write correct JSON" in { + "Json format for RichPatientHypothesis" should "read and write correct JSON" in { val orig = PatientHypothesis( id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"), patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), @@ -17,7 +17,7 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { rationale = None, matchedTrials = 1 ) - val writtenJson = patientHypothesisWriter.write(RichPatientHypothesis(orig, true)) + val writtenJson = richPatientHypothesisWriter.write(RichPatientHypothesis(orig, isRequired = true)) writtenJson should be ( """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", @@ -29,4 +29,19 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { parsedUpdatePatientHypothesis should be(expectedUpdatedPatientHypothesis) } + "Json format for patientHypothesis" should "read and write correct JSON" in { + val orig = PatientHypothesis( + id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"), + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), + hypothesisId = UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4"), + rationale = None, + matchedTrials = 1 + ) + val writtenJson = patientHypothesisWriter.write(orig) + + writtenJson should be ( + """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", + "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","rationale":null,"matchedTrials":1}""".parseJson) + } + } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala index 8b7c138..ffb1bd4 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala @@ -10,7 +10,7 @@ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel class PatientLabelFormatSuite extends FlatSpec with Matchers { - "Json format for PatientLabel" should "read and write correct JSON" in { + "Json format for RichPatientLabel" should "read and write correct JSON" in { import patientlabel._ val orig = PatientLabel( id = LongId(1), @@ -22,7 +22,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { score = 1, isImplicitMatch = false ) - val writtenJson = patientLabelWriter.write(RichPatientLabel(orig, true)) + val writtenJson = richPatientLabelWriter.write(RichPatientLabel(orig, isVerified = true)) writtenJson should be ( """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true, @@ -34,6 +34,26 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel) } + "Json format for PatientLabel" should "read and write correct JSON" in { + import patientlabel._ + val orig = PatientLabel( + id = LongId(1), + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), + labelId = LongId(20), + primaryValue = Some(FuzzyValue.Yes), + verifiedPrimaryValue = None, + isVisible = true, + score = 1, + isImplicitMatch = false + ) + val writtenJson = patientLabelWriter.write(orig) + + writtenJson should be ( + """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true, + "score":1,"isImplicitMatch":false}""".parseJson) + } + + "Json format for PatientLabelEvidence" should "read and write correct JSON" in { import patientlabel._ val orig = PatientLabelEvidenceView( -- cgit v1.2.3 From 6f4de1ccfb6efe8f9ddbaec6551a9138a6efa6f8 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 16:59:16 +0700 Subject: PDSUI-2268 Added institution field to document --- .../scala/xyz/driver/pdsuidomain/entities/Document.scala | 3 +++ .../driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala | 1 + .../pdsuidomain/formats/json/document/ApiDocument.scala | 5 ++++- .../formats/json/document/ApiPartialDocument.scala | 5 +++++ .../pdsuidomain/formats/json/sprayformats/document.scala | 12 ++++++++++++ src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala | 1 + .../formats/json/sprayformats/DocumentFormatSuite.scala | 6 ++++-- 7 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src/test/scala/xyz') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala index eccb254..168eb38 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala @@ -419,6 +419,8 @@ object Document { providerTypeId <- Validators.nonEmpty("providerTypeId")(input.providerTypeId) + institutionName <- Validators.nonEmpty("institutionName")(input.institutionName) + meta <- Validators.nonEmpty("meta")(input.meta) startDate <- Validators.nonEmpty("startDate")(input.startDate) @@ -456,6 +458,7 @@ final case class Document(id: LongId[Document] = LongId(0L), providerName: Option[String], // not null providerTypeId: Option[LongId[ProviderType]], // not null requiredType: Option[Document.RequiredType], + institutionName: Option[String], meta: Option[TextJson[Meta]], // not null startDate: Option[LocalDate], // not null endDate: Option[LocalDate], diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 1ac75ab..94eb029 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -68,6 +68,7 @@ object DocumentGen { providerName = nextOption(nextString()), providerTypeId = nextOption(nextLongId[ProviderType]), requiredType = nextOption(nextDocumentRequiredType()), + institutionName = nextOption(nextString()), meta = nextOption(nextDocumentMetaJson()), startDate = dates._1, endDate = dates._2, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala index 1869ff3..3f1ecfe 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala @@ -2,7 +2,6 @@ package xyz.driver.pdsuidomain.formats.json.document import java.time.{LocalDate, ZoneId, ZonedDateTime} import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson} -import xyz.driver.pdsuicommon.json.JsonSerializer import xyz.driver.pdsuidomain.entities._ import play.api.data.validation.ValidationError @@ -20,6 +19,7 @@ final case class ApiDocument(id: Long, provider: Option[String], providerTypeId: Option[Long], requiredType: Option[String], + institutionName: Option[String], status: Option[String], previousStatus: Option[String], assignee: Option[String], @@ -46,6 +46,7 @@ final case class ApiDocument(id: Long, providerName = this.provider, providerTypeId = this.providerTypeId.map(LongId(_)), requiredType = this.requiredType.map(extractRequiredType), + institutionName = this.institutionName, meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[Document.Meta](x))), startDate = this.startDate, endDate = this.endDate, @@ -74,6 +75,7 @@ object ApiDocument { (JsPath \ "provider").formatNullable[String] and (JsPath \ "providerTypeId").formatNullable[Long] and (JsPath \ "requiredType").formatNullable[String] and + (JsPath \ "institutionName").formatNullable[String] and (JsPath \ "status").formatNullable(statusFormat) and (JsPath \ "previousStatus").formatNullable(statusFormat) and (JsPath \ "assignee").formatNullable[String] and @@ -96,6 +98,7 @@ object ApiDocument { provider = document.providerName, providerTypeId = document.providerTypeId.map(_.id), requiredType = document.requiredType.map(Document.RequiredType.requiredTypeToString), + institutionName = document.institutionName, status = Option(Document.Status.statusToString(document.status)), previousStatus = document.previousStatus.map(Document.Status.statusToString), assignee = document.assignee.map(_.id), 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 eae0c62..032ddf6 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 @@ -23,6 +23,7 @@ final case class ApiPartialDocument(recordId: Option[Long], endDate: Tristate[LocalDate], provider: Tristate[String], providerTypeId: Tristate[Long], + institutionName: Tristate[String], status: Option[String], assignee: Tristate[String], meta: Tristate[String]) { @@ -42,6 +43,7 @@ final case class ApiPartialDocument(recordId: Option[Long], providerName = provider.cata(Some(_), None, orig.providerName), providerTypeId = providerTypeId.map(LongId[ProviderType]).cata(Some(_), None, orig.providerTypeId), requiredType = orig.requiredType, + institutionName = institutionName.cata(Some(_), None, orig.institutionName), meta = meta.cata(x => Some(TextJson(JsonSerializer.deserialize[Meta](x))), None, orig.meta), startDate = startDate.cata(Some(_), None, orig.startDate), endDate = endDate.cata(Some(_), None, orig.endDate), @@ -67,6 +69,7 @@ final case class ApiPartialDocument(recordId: Option[Long], providerName = provider.toOption, providerTypeId = providerTypeId.map(LongId[ProviderType]).toOption, requiredType = None, + institutionName = institutionName.toOption, meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption, previousStatus = None, assignee = None, @@ -90,6 +93,7 @@ object ApiPartialDocument { (JsPath \ "endDate").readTristate[LocalDate] and (JsPath \ "provider").readTristate[String] and (JsPath \ "providerTypeId").readTristate[Long] and + (JsPath \ "institutionName").readTristate[String] and (JsPath \ "status").readNullable[String]( Reads .of[String] @@ -115,6 +119,7 @@ object ApiPartialDocument { (JsPath \ "endDate").writeTristate[LocalDate] and (JsPath \ "provider").writeTristate[String] and (JsPath \ "providerTypeId").writeTristate[Long] and + (JsPath \ "institutionName").writeTristate[String] and (JsPath \ "status").writeNullable[String] and (JsPath \ "assignee").writeTristate[String] and (JsPath \ "meta").writeTristate(Writes[String](Json.parse)) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index e3f6a9c..33ee9ba 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala @@ -73,6 +73,11 @@ object document { .map(_.convertTo[Option[LongId[ProviderType]]]) .getOrElse(orig.providerTypeId) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[Option[String]]) + .getOrElse(orig.institutionName) + val meta = fields .get("meta") .map(_.convertTo[Option[TextJson[Meta]]]) @@ -93,6 +98,7 @@ object document { typeId = typeId, providerName = provider, providerTypeId = providerTypeId, + institutionName = institutionName, meta = meta, startDate = startDate, endDate = endDate @@ -111,6 +117,7 @@ object document { "provider" -> document.providerName.toJson, "providerTypeId" -> document.providerTypeId.toJson, "requiredType" -> document.requiredType.toJson, + "institutionName" -> document.institutionName.toJson, "startDate" -> document.startDate.toJson, "endDate" -> document.endDate.toJson, "status" -> document.status.toJson, @@ -145,6 +152,10 @@ object document { .get("providerTypeId") .map(_.convertTo[LongId[ProviderType]]) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[String]) + val meta = fields .get("meta") .map(_.convertTo[TextJson[Meta]]) @@ -168,6 +179,7 @@ object document { providerName = provider, providerTypeId = providerTypeId, requiredType = None, + institutionName = institutionName, meta = meta, previousStatus = None, assignee = None, diff --git a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala index f851680..9fc3388 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala @@ -78,6 +78,7 @@ class DocumentSuite extends BaseSuite { providerName = Some("etst"), providerTypeId = Some(LongId(123)), requiredType = None, + institutionName = Some("institution name"), startDate = Some(lastUpdate.toLocalDate.minusDays(2)), endDate = None, lastUpdate = lastUpdate, diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala index 9394735..cc1832c 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala @@ -24,6 +24,7 @@ class DocumentFormatSuite extends FlatSpec with Matchers { typeId = Some(LongId(10)), providerName = Some("provider 21"), providerTypeId = Some(LongId(21)), + institutionName = Some("institution name"), requiredType = Some(Document.RequiredType.OPN), meta = None, startDate = None, @@ -33,7 +34,7 @@ class DocumentFormatSuite extends FlatSpec with Matchers { writtenJson should be ( """{"id":1,"recordId":101,"physician":"physician","typeId":10,"provider":"provider 21","providerTypeId":21, - "requiredType":"OPN","startDate":null,"endDate":null,"status":"New","assignee":null,"previousStatus":null, + "requiredType":"OPN","institutionName":"institution name","startDate":null,"endDate":null,"status":"New","assignee":null,"previousStatus":null, "previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z","meta":null}""".parseJson) val createDocumentJson = @@ -41,7 +42,8 @@ class DocumentFormatSuite extends FlatSpec with Matchers { val expectedCreatedDocument = orig.copy( id = LongId(0), lastUpdate = LocalDateTime.MIN, - requiredType = None + requiredType = None, + institutionName = None ) val parsedCreatedDocument = documentFormat.read(createDocumentJson) parsedCreatedDocument should be(expectedCreatedDocument) -- cgit v1.2.3 From c5462a496aeb4d43f023bb427bf12fc87b482b61 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 18:29:52 +0700 Subject: Deleted duplicate spray format and fixed reply of patient eligible trial service --- .../json/sprayformats/patientdefiningcriteria.scala | 2 +- .../json/sprayformats/patienthypothesis.scala | 10 +++++----- .../formats/json/sprayformats/patientlabel.scala | 14 -------------- .../services/PatientEligibleTrialService.scala | 5 ++--- .../json/sprayformats/PatientLabelFormatSuite.scala | 20 -------------------- 5 files changed, 8 insertions(+), 43 deletions(-) (limited to 'src/test/scala/xyz') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala index b97570a..0520ef2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala @@ -7,7 +7,7 @@ object patientdefiningcriteria { import DefaultJsonProtocol._ import common._ - implicit val patientLabelDefiningCriteriaWriter: JsonWriter[PatientLabel] = new JsonWriter[PatientLabel] { + implicit val patientLabelDefiningCriteriaWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { override def write(obj: PatientLabel) = JsObject( "id" -> obj.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala index bd448b3..b8c0058 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala @@ -37,11 +37,11 @@ object patienthypothesis { new RootJsonWriter[PatientHypothesis] { override def write(obj: PatientHypothesis): JsValue = { JsObject( - "id" -> obj.id.toJson, - "patientId" -> obj.patientId.toJson, - "hypothesisId" -> obj.hypothesisId.toJson, - "matchedTrials" -> obj.matchedTrials.toJson, - "rationale" -> obj.rationale.toJson + "id" -> obj.id.toJson, + "patientId" -> obj.patientId.toJson, + "hypothesisId" -> obj.hypothesisId.toJson, + "matchedTrials" -> obj.matchedTrials.toJson, + "rationale" -> obj.rationale.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala index 10a0a94..b36949e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala @@ -44,20 +44,6 @@ object patientlabel { } } - implicit val patientLabelWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { - override def write(obj: PatientLabel): JsValue = { - JsObject( - "id" -> obj.id.toJson, - "labelId" -> obj.labelId.toJson, - "primaryValue" -> obj.primaryValue.toJson, - "verifiedPrimaryValue" -> obj.verifiedPrimaryValue.toJson, - "score" -> obj.score.toJson, - "isImplicitMatch" -> obj.isImplicitMatch.toJson, - "isVisible" -> obj.isVisible.toJson - ) - } - } - implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] = new RootJsonWriter[PatientLabelEvidenceView] { override def write(evidence: PatientLabelEvidenceView): JsValue = diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala index abb3f8a..d9013c6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala @@ -1,12 +1,12 @@ package xyz.driver.pdsuidomain.services -import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuicommon.error.DomainError import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.{Trial, _} +import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion import scala.concurrent.Future @@ -71,8 +71,7 @@ object PatientEligibleTrialService { sealed trait GetCriterionListOfGroupReply object GetCriterionListOfGroupReply { - final case class EntityList(xs: Seq[(PatientCriterion, LongId[Label], List[PatientCriterionArm])], totalFound: Int) - extends GetCriterionListOfGroupReply + final case class EntityList(xs: Seq[RichPatientCriterion], totalFound: Int) extends GetCriterionListOfGroupReply type Error = GetCriterionListOfGroupReply with DomainError diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala index ffb1bd4..3ef286d 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala @@ -34,26 +34,6 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel) } - "Json format for PatientLabel" should "read and write correct JSON" in { - import patientlabel._ - val orig = PatientLabel( - id = LongId(1), - patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), - labelId = LongId(20), - primaryValue = Some(FuzzyValue.Yes), - verifiedPrimaryValue = None, - isVisible = true, - score = 1, - isImplicitMatch = false - ) - val writtenJson = patientLabelWriter.write(orig) - - writtenJson should be ( - """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true, - "score":1,"isImplicitMatch":false}""".parseJson) - } - - "Json format for PatientLabelEvidence" should "read and write correct JSON" in { import patientlabel._ val orig = PatientLabelEvidenceView( -- cgit v1.2.3