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') 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') 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') 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') 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') 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 From d9bb907bc15445dd2db14be8c033fcfce2fd59c1 Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 5 Oct 2017 17:31:52 -0700 Subject: Removing "predicted" stuff, Refining EligibilityVerificationService --- .../xyz/driver/pdsuidomain/entities/Document.scala | 8 +---- .../pdsuidomain/entities/MedicalRecord.scala | 30 +++++------------ .../fakes/entities/rep/DocumentGen.scala | 7 +--- .../fakes/entities/rep/MedicalRecordGen.scala | 31 ++++-------------- .../formats/json/record/ApiCreateRecord.scala | 2 -- .../formats/json/record/ApiRecord.scala | 2 -- .../formats/json/sprayformats/document.scala | 2 +- .../formats/json/sprayformats/record.scala | 38 +++------------------- .../services/EligibilityVerificationService.scala | 3 +- .../fake/FakeEligibilityVerificationService.scala | 3 +- .../rest/RestEligibilityVerificationService.scala | 5 +-- .../xyz/driver/pdsuidomain/DocumentSuite.scala | 2 +- .../json/sprayformats/DocumentFormatSuite.scala | 16 ++++----- .../json/sprayformats/ListResponseSuite.scala | 2 -- .../sprayformats/MedicalRecordFormatSuite.scala | 12 +++---- 15 files changed, 41 insertions(+), 122 deletions(-) (limited to 'src/test/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala index 168eb38..258aa03 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala @@ -308,13 +308,7 @@ object DocumentType { object Document { - final case class Meta(predicted: Option[Boolean], startPage: Double, endPage: Double) { - - /** - * Return a regular meta: this meta is considered as not predicted - */ - def confirmed: Meta = copy(predicted = predicted.map(_ => false)) - } + final case class Meta(startPage: Double, endPage: Double) class DocumentStatusSerializer extends JsonSerializer[Status] { def serialize(value: Status, gen: JsonGenerator, serializers: SerializerProvider): Unit = { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala index 9b33af4..ed35db4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala @@ -22,55 +22,45 @@ object MedicalRecord { )) trait Meta { @JsonProperty("type") def metaType: String - def predicted: Option[Boolean] - - /** - * Return a regular meta: this meta is considered as not predicted - */ - def confirmed: Meta } object Meta { - final case class Duplicate(predicted: Option[Boolean], - startPage: Double, + final case class Duplicate(startPage: Double, endPage: Double, startOriginalPage: Double, endOriginalPage: Option[Double]) extends Meta { - override val metaType = "duplicate" - override def confirmed: Duplicate = copy(predicted = predicted.map(_ => false)) + override val metaType = "duplicate" } object Duplicate { implicit def toPhiString(x: Duplicate): PhiString = { import x._ - phi"Duplicate(predicted=${x.predicted}, startPage=${Unsafe(startPage)}, endPage=${Unsafe(endPage)}, " + + phi"Duplicate(startPage=${Unsafe(startPage)}, endPage=${Unsafe(endPage)}, " + phi"startOriginalPage=${Unsafe(startOriginalPage)}, endOriginalPage=${Unsafe(endOriginalPage)}" } } - final case class Reorder(predicted: Option[Boolean], items: Seq[Int]) extends Meta { - override val metaType = "reorder" - override def confirmed: Reorder = copy(predicted = predicted.map(_ => false)) + final case class Reorder(items: Seq[Int]) extends Meta { + override val metaType = "reorder" } object Reorder { implicit def toPhiString(x: Reorder): PhiString = { import x._ - phi"Reorder(predicted=${x.predicted}, items=${Unsafe(items.toString)})" + phi"Reorder(items=${Unsafe(items.toString)})" } } - final case class Rotation(predicted: Option[Boolean], items: Map[String, Int]) extends Meta { - override val metaType = "rotation" - override def confirmed: Rotation = copy(predicted = predicted.map(_ => false)) + final case class Rotation(items: Map[String, Int]) extends Meta { + override val metaType = "rotation" } object Rotation { implicit def toPhiString(x: Rotation): PhiString = { import x._ - phi"Rotation(predicted=${x.predicted}, items=${Unsafe(items.toString)})" + phi"Rotation(items=${Unsafe(items.toString)})" } } @@ -166,8 +156,6 @@ final case class MedicalRecord(id: LongId[MedicalRecord], caseId: Option[CaseId], physician: Option[String], meta: Option[TextJson[List[Meta]]], - predictedMeta: Option[TextJson[List[Meta]]], - predictedDocuments: Option[TextJson[List[Document]]], lastUpdate: LocalDateTime) { import MedicalRecord.Status._ 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 94eb029..0dadc41 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 @@ -40,12 +40,7 @@ object DocumentGen { def nextDocumentMeta(): Document.Meta = { val (startPage, endPage) = nextStartAndEndPage() - - Document.Meta( - nextOption(nextBoolean()), - startPage, - endPage - ) + Document.Meta(startPage, endPage) } def nextDocumentMetaJson(): TextJson[Document.Meta] = { diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 2777116..254968a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -49,15 +49,10 @@ object MedicalRecordGen { generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) def nextMedicalRecordMetaReorder(): MedicalRecord.Meta.Reorder = { - val itemsNumber = - maxItemsInCollectionNumber - val items = scala.util.Random - .shuffle(Seq.tabulate(itemsNumber)(identity)) - - MedicalRecord.Meta.Reorder( - predicted = nextOption(nextBoolean), - items = items - ) + val itemsNumber = maxItemsInCollectionNumber + val items = scala.util.Random.shuffle(Seq.tabulate(itemsNumber)(identity)) + + MedicalRecord.Meta.Reorder(items) } def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { @@ -67,7 +62,6 @@ object MedicalRecordGen { nextInt(pageMaxNumber, startPageGen) MedicalRecord.Meta.Duplicate( - predicted = nextOption(nextBoolean), startPage = startPageGen.toDouble, endPage = endPageGen.toDouble, startOriginalPage = startPageGen.toDouble, @@ -76,17 +70,9 @@ object MedicalRecordGen { } def nextMedicalRecordMetaRotation(): MedicalRecord.Meta.Rotation = { - val items = - Array - .tabulate(maxItemsInCollectionNumber)( - index => nextString() -> index - ) - .toMap - - MedicalRecord.Meta.Rotation( - predicted = nextOption(nextBoolean()), - items = items - ) + val items = Array.tabulate(maxItemsInCollectionNumber)(index => nextString() -> index).toMap + + MedicalRecord.Meta.Rotation(items = items) } def nextMedicalRecordMeta(): MedicalRecord.Meta = { @@ -94,7 +80,6 @@ object MedicalRecordGen { } def nextMedicalRecord(): MedicalRecord = { - val id = nextLongId[MedicalRecord] MedicalRecord( id = nextLongId[MedicalRecord], status = nextMedicalRecordStatus(), @@ -108,8 +93,6 @@ object MedicalRecordGen { caseId = nextOption(CaseId(generators.nextString())), physician = nextOption(generators.nextString()), meta = nextOption(nextMedicalRecordMetasJson()), - predictedMeta = nextOption(nextMedicalRecordMetasJson()), - predictedDocuments = nextOption(nextDocuments(id)), lastUpdate = nextLocalDateTime ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala index 2e5943e..1f8c683 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala @@ -22,8 +22,6 @@ final case class ApiCreateRecord(disease: String, patientId: String, requestId: caseId = None, physician = None, meta = None, - predictedMeta = None, - predictedDocuments = None, lastUpdate = LocalDateTime.now() ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala index e7b58cd..fc0a2e7 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala @@ -101,8 +101,6 @@ final case class ApiRecord(id: Long, Some(TextJson(JsonSerializer.deserialize[List[MedicalRecord.Meta]](this.meta))) } }, - predictedMeta = None, - predictedDocuments = None, lastUpdate = this.lastUpdate.toLocalDateTime() ) } 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 6c33fe5..69e8b75 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 @@ -26,7 +26,7 @@ object document { "PN" -> RequiredType.PN ) - implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply) + implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat2(Meta.apply) implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] { override def read(json: JsValue): DocumentType = json match { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala index 8eef44a..65687c1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala @@ -67,7 +67,6 @@ object record { override def write(obj: Duplicate) = JsObject( "type" -> "duplicate".toJson, - "predicted" -> obj.predicted.toJson, "startPage" -> obj.startPage.toJson, "endPage" -> obj.endPage.toJson, "startOriginalPage" -> obj.startOriginalPage.toJson, @@ -76,10 +75,6 @@ object record { override def read(json: JsValue): Duplicate = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val startPage = fields .get("startPage") .map(_.convertTo[Double]) @@ -101,7 +96,6 @@ object record { .map(_.convertTo[Double]) Duplicate( - predicted = predicted, startPage = startPage, endPage = endPage, startOriginalPage = startOriginalPage, @@ -114,27 +108,16 @@ object record { implicit val reorderMetaFormat: RootJsonFormat[Reorder] = new RootJsonFormat[Reorder] { override def write(obj: Reorder) = - JsObject( - "type" -> "reorder".toJson, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) + JsObject("type" -> "reorder".toJson, "items" -> obj.items.toJson) override def read(json: JsValue): Reorder = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val items = fields .get("items") .map(_.convertTo[Seq[Int]]) .getOrElse(deserializationError(s"Reorder meta json object does not contain `items` field: $json")) - Reorder( - predicted = predicted, - items = items - ) + Reorder(items) case _ => deserializationError(s"Expected JsObject as Reorder meta of medical record, but got $json") } @@ -142,27 +125,16 @@ object record { implicit val rotateMetaFormat: RootJsonFormat[Rotation] = new RootJsonFormat[Rotation] { override def write(obj: Rotation) = - JsObject( - "type" -> "rotation".toJson, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) + JsObject("type" -> "rotation".toJson, "items" -> obj.items.toJson) override def read(json: JsValue): Rotation = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val items = fields .get("items") .map(_.convertTo[Map[String, Int]]) .getOrElse(deserializationError(s"Rotation meta json object does not contain `items` field: $json")) - Rotation( - predicted = predicted, - items = items - ) + Rotation(items = items) case _ => deserializationError(s"Expected JsObject as Rotation meta of medical record, but got $json") } @@ -233,8 +205,6 @@ object record { caseId = None, physician = None, meta = None, - predictedMeta = None, - predictedDocuments = None, lastUpdate = LocalDateTime.now() ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala index 7395400..c09dd9a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala @@ -4,6 +4,7 @@ import xyz.driver.core.Id import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.patient.{CancerType, Patient} import xyz.driver.entities.users.AuthUserInfo +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} import xyz.driver.pdsuidomain.entities.Arm @@ -14,6 +15,6 @@ trait EligibilityVerificationService { def getMatchedPatients()(implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): ListT[Future, MatchedPatient] - def getMismatchRankedLabels(patientId: Id[Patient], cancerType: CancerType, excludedArms: Seq[Id[Arm]])( + def getMismatchRankedLabels(patientId: Id[Patient], cancerType: CancerType, excludedArms: Seq[LongId[Arm]])( implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[MismatchRankedLabels] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala index 1e1a3ea..c9b5443 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala @@ -5,6 +5,7 @@ import xyz.driver.core.{Id, generators} import xyz.driver.entities.patient import xyz.driver.entities.patient.Patient import xyz.driver.entities.users.AuthUserInfo +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.eligibility.MismatchRankedLabels import xyz.driver.pdsuidomain.entities.{Arm, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService @@ -21,7 +22,7 @@ class FakeEligibilityVerificationService extends EligibilityVerificationService override def getMismatchRankedLabels(patientId: Id[Patient], cancerType: patient.CancerType, - excludedArms: Seq[Id[Arm]])( + excludedArms: Seq[LongId[Arm]])( implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[eligibility.MismatchRankedLabels] = Future.successful( MismatchRankedLabels( diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala index f6879d0..8869106 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala @@ -8,6 +8,7 @@ import xyz.driver.core.rest.{AuthorizedServiceRequestContext, RestService, Servi import xyz.driver.entities.patient import xyz.driver.entities.patient.Patient import xyz.driver.entities.users.AuthUserInfo +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} import xyz.driver.pdsuidomain.entities.{Arm, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService @@ -33,11 +34,11 @@ class RestEligibilityVerificationService(transport: ServiceTransport, baseUri: U override def getMismatchRankedLabels(patientId: Id[Patient], cancerType: patient.CancerType, - excludedArms: Seq[Id[Arm]])( + excludedArms: Seq[LongId[Arm]])( implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[eligibility.MismatchRankedLabels] = { val query = - Seq("disease" -> cancerType.toString.toUpperCase, "ineligible_arms" -> excludedArms.map(_.value).mkString(",")) + Seq("disease" -> cancerType.toString.toUpperCase, "ineligible_arms" -> excludedArms.map(_.id).mkString(",")) val request = get(baseUri, s"/v1/patients/$patientId/labels", query) optionalResponse[MismatchRankedLabels](transport.sendRequest(ctx)(request)) diff --git a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala index 9fc3388..7d8a418 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala @@ -82,7 +82,7 @@ class DocumentSuite extends BaseSuite { startDate = Some(lastUpdate.toLocalDate.minusDays(2)), endDate = None, lastUpdate = lastUpdate, - meta = Some(TextJson(Document.Meta(None, 1.1, 2.2))) + meta = Some(TextJson(Document.Meta(1.1, 2.2))) ) } } 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 cc1832c..193e066 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 @@ -49,28 +49,24 @@ class DocumentFormatSuite extends FlatSpec with Matchers { parsedCreatedDocument should be(expectedCreatedDocument) val updateDocumentJson = - """{"startDate":"2017-08-10","endDate":"2018-08-10","meta":{"predicted":true,"startPage":1.0,"endPage":2.0}}""".parseJson + """{"startDate":"2017-08-10","endDate":"2018-08-10","meta":{"startPage":1.0,"endPage":2.0}}""".parseJson val expectedUpdatedDocument = orig.copy( startDate = Some(LocalDate.parse("2017-08-10")), endDate = Some(LocalDate.parse("2018-08-10")), - meta = Some(TextJson(Document.Meta(predicted = Some(true), startPage = 1.0, endPage = 2.0))) + meta = Some(TextJson(Document.Meta(startPage = 1.0, endPage = 2.0))) ) val parsedUpdatedDocument = applyUpdateToDocument(updateDocumentJson, orig) parsedUpdatedDocument should be(expectedUpdatedDocument) } "Json format for Document.Meta" should "read and write correct JSON" in { - val meta = Document.Meta(predicted = None, startPage = 1.0, endPage = 2.0) + val meta = Document.Meta(startPage = 1.0, endPage = 2.0) val writtenJson = documentMetaFormat.write(meta) writtenJson should be ("""{"startPage":1.0,"endPage":2.0}""".parseJson) - val metaJsonWithoutPredicted = """{"startPage":1.0,"endPage":2.0}""".parseJson - val parsedMetaWithoutPredicted = documentMetaFormat.read(metaJsonWithoutPredicted) - parsedMetaWithoutPredicted should be(meta) - - val metaJsonWithPredicted = """{"predicted":true,"startPage":1.0,"endPage":2.0}""".parseJson - val parsedMetaWithPredicted = documentMetaFormat.read(metaJsonWithPredicted) - parsedMetaWithPredicted should be(meta.copy(predicted = Some(true))) + val metaJson = """{"startPage":1.0,"endPage":2.0}""".parseJson + val parsedMeta = documentMetaFormat.read(metaJson) + parsedMeta should be(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/ListResponseSuite.scala index 52b2324..2e7481a 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala @@ -80,8 +80,6 @@ class ListResponseSuite extends FlatSpec with Matchers { 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, diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordFormatSuite.scala index 899e5c9..dd074e5 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordFormatSuite.scala @@ -23,8 +23,6 @@ class MedicalRecordFormatSuite extends FlatSpec with Matchers { 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, @@ -52,22 +50,20 @@ class MedicalRecordFormatSuite extends FlatSpec with Matchers { caseId = None, physician = None, meta = None, - predictedMeta = None, - predictedDocuments = None, lastUpdate = LocalDateTime.now() ) val parsedCreatedRecord = recordFormat.read(createRecordJson).copy(lastUpdate = expectedCreatedRecord.lastUpdate) parsedCreatedRecord should be(expectedCreatedRecord) val updateRecordJson = - """{"meta":[{"type":"duplicate","predicted":true,"startPage":1.0,"endPage":2.0,"startOriginalPage":1.0}, + """{"meta":[{"type":"duplicate","startPage":1.0,"endPage":2.0,"startOriginalPage":1.0}, {"type":"reorder","items":[1,2]}, {"type":"rotation","items":{"item1":1,"item2":2}}]}""".parseJson val expectedUpdatedRecord = orig.copy( meta = Some(TextJson(List( - Meta.Duplicate(predicted = Some(true), startPage = 1.0, endPage = 2.0, startOriginalPage = 1.0, endOriginalPage = None), - Meta.Reorder(predicted = None, items = Seq(1, 2)), - Meta.Rotation(predicted = None, items = Map("item1" -> 1, "item2" -> 2)) + Meta.Duplicate(startPage = 1.0, endPage = 2.0, startOriginalPage = 1.0, endOriginalPage = None), + Meta.Reorder(Seq(1, 2)), + Meta.Rotation(Map("item1" -> 1, "item2" -> 2)) ))) ) val parsedUpdatedRecord = applyUpdateToMedicalRecord(updateRecordJson, orig) -- cgit v1.2.3 From 7d8712a62d30b412717e1b730c0ad267cd207aa4 Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 9 Oct 2017 12:24:59 -0700 Subject: Getting rid of the FuzzyValues, Name as a string, and condition --- build.sbt | 2 +- .../xyz/driver/pdsuicommon/domain/FuzzyValue.scala | 40 ---------------------- .../driver/pdsuidomain/entities/DirectReport.scala | 27 +++------------ .../pdsuidomain/entities/ExtractedData.scala | 8 ++--- .../xyz/driver/pdsuidomain/entities/Patient.scala | 6 ++-- .../pdsuidomain/entities/PatientCriterion.scala | 19 +++++----- .../entities/PatientEligibleTrial.scala | 23 +++++++------ .../driver/pdsuidomain/entities/PatientLabel.scala | 10 +++--- .../entities/PatientLabelEvidenceView.scala | 6 ++-- .../pdsuidomain/entities/RawPatientLabel.scala | 31 ----------------- .../export/patient/ExportPatientLabel.scala | 5 --- .../patient/ExportPatientLabelEvidence.scala | 19 +++------- .../ExportPatientLabelEvidenceDocument.scala | 8 ----- .../export/patient/ExportPatientWithLabels.scala | 12 +------ .../driver/pdsuidomain/fakes/entities/common.scala | 5 +-- .../fakes/entities/rep/ExportPatientGen.scala | 6 ++-- .../fakes/entities/rep/ExtractedDataGen.scala | 5 +-- .../json/evidence/ApiPatientLabelEvidence.scala | 3 +- .../formats/json/label/ApiCriterionLabel.scala | 6 ++-- .../formats/json/label/ApiExtractedDataLabel.scala | 12 +++---- .../formats/json/patient/ApiPatient.scala | 21 +++++++++--- .../patient/eligible/ApiPatientEligibleTrial.scala | 8 ++--- .../patient/label/ApiPartialPatientLabel.scala | 15 ++++---- .../json/patient/label/ApiPatientLabel.scala | 32 ++++++++++------- .../label/ApiPatientLabelDefiningCriteria.scala | 8 ++--- .../patient/trial/ApiPartialPatientCriterion.scala | 14 ++++---- .../trial/ApiPartialPatientCriterionList.scala | 9 ++--- .../json/patient/trial/ApiPatientCriterion.scala | 18 +++++----- .../formats/json/sprayformats/common.scala | 10 +----- .../formats/json/sprayformats/export.scala | 1 + .../formats/json/sprayformats/extracteddata.scala | 7 ++-- .../formats/json/sprayformats/patient.scala | 4 ++- .../json/sprayformats/patientcriterion.scala | 7 ++-- .../sprayformats/patientdefiningcriteria.scala | 1 + .../json/sprayformats/patienteligibletrial.scala | 1 + .../formats/json/sprayformats/patientlabel.scala | 7 ++-- .../services/PatientCriterionService.scala | 4 +-- .../json/sprayformats/ExportFormatSuite.scala | 11 +++--- .../sprayformats/ExtractedDataFormatSuite.scala | 11 +++--- .../sprayformats/PatientCriterionFormatSuite.scala | 9 ++--- .../PatientEligibleTrialFormatSuite.scala | 7 ++-- .../json/sprayformats/PatientFormatSuite.scala | 11 +++--- .../sprayformats/PatientLabelFormatSuite.scala | 13 +++---- 43 files changed, 195 insertions(+), 287 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuicommon/domain/FuzzyValue.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala (limited to 'src/test/scala') diff --git a/build.sbt b/build.sbt index bebf2aa..bd7468f 100644 --- a/build.sbt +++ b/build.sbt @@ -19,7 +19,7 @@ lazy val core = (project in file(".")) "org.davidbild" %% "tristate-core" % "0.2.0", "org.davidbild" %% "tristate-play" % "0.2.0" exclude ("com.typesafe.play", "play-json"), "xyz.driver" %% "core" % "1.2.1", - "xyz.driver" %% "domain-model" % "0.17.5", + "xyz.driver" %% "domain-model" % "0.17.8", "ch.qos.logback" % "logback-classic" % "1.1.7", "com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.8.4", "com.github.spullara.mustache.java" % "scala-extensions-2.11" % "0.9.4", diff --git a/src/main/scala/xyz/driver/pdsuicommon/domain/FuzzyValue.scala b/src/main/scala/xyz/driver/pdsuicommon/domain/FuzzyValue.scala deleted file mode 100644 index 36c3de7..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/domain/FuzzyValue.scala +++ /dev/null @@ -1,40 +0,0 @@ -package xyz.driver.pdsuicommon.domain - -import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuicommon.utils.Utils - -sealed trait FuzzyValue - -object FuzzyValue { - case object Yes extends FuzzyValue - case object No extends FuzzyValue - case object Maybe extends FuzzyValue - - private val yes = "Yes" - private val no = "No" - private val maybe = "Maybe" - - val All: Set[FuzzyValue] = - Set(Yes, No, Maybe) - - def fromBoolean(x: Boolean): FuzzyValue = - if (x) Yes else No - - implicit def toPhiString(x: FuzzyValue): PhiString = - Unsafe(Utils.getClassSimpleName(x.getClass)) - - val fromString: PartialFunction[String, FuzzyValue] = { - case fuzzy => - fuzzy.toLowerCase.capitalize match { - case `yes` => Yes - case `no` => No - case `maybe` => Maybe - } - } - - def valueToString(x: FuzzyValue): String = x match { - case Yes => `yes` - case No => `no` - case Maybe => `maybe` - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala index 42ac55b..f35c3fd 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala @@ -2,31 +2,14 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDate +import xyz.driver.entities.assays.AssayType import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuicommon.utils.Utils -import xyz.driver.pdsuidomain.entities.DirectReport.ReportType object DirectReport { - - sealed trait ReportType extends Product with Serializable { - def oneOf(xs: ReportType*): Boolean = xs.contains(this) - - def oneOf(xs: Set[ReportType]): Boolean = xs.contains(this) - } - - object ReportType { - case object IHC extends ReportType - case object DNA extends ReportType - case object CFDNA extends ReportType - - val All = Set(IHC, DNA, CFDNA) - implicit def toPhiString(x: ReportType): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass)) - } - implicit def toPhiString(x: DirectReport): PhiString = { import x._ - phi"DirectReport(id=$id, patientId=$patientId, reportType=$reportType, date=${Unsafe(date)}, " + + phi"DirectReport(id=$id, patientId=$patientId, reportType=${Unsafe(reportType)}, date=${Unsafe(date)}, " + phi"documentType=${Unsafe(documentType)}, providerType=${Unsafe(providerType)}, " + phi"providerName=${Unsafe(providerName)})" } @@ -34,8 +17,8 @@ object DirectReport { final case class DirectReport(id: UuidId[DirectReport], patientId: UuidId[Patient], - reportType: ReportType, + reportType: AssayType, date: LocalDate, - documentType: String, - providerType: String, + documentType: DocumentType, + providerType: ProviderType, providerName: String) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala index fbd468f..352cf55 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala @@ -1,7 +1,7 @@ package xyz.driver.pdsuidomain.entities -import xyz.driver.entities.labels.{Label, LabelCategory} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta @@ -37,7 +37,7 @@ object ExtractedDataLabel { implicit def toPhiString(x: ExtractedDataLabel): PhiString = { import x._ - phi"ExtractedDataLabel(id=$id, dataId=$dataId, labelId=$labelId, categoryId=$categoryId, value=$value)" + phi"ExtractedDataLabel(id=$id, dataId=$dataId, labelId=$labelId, categoryId=$categoryId, value=${Unsafe(value)})" } } @@ -45,4 +45,4 @@ final case class ExtractedDataLabel(id: LongId[ExtractedDataLabel], dataId: LongId[ExtractedData], labelId: Option[LongId[Label]], categoryId: Option[LongId[LabelCategory]], - value: Option[FuzzyValue]) + value: Option[LabelValue]) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala index 6be0b88..193ef11 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala @@ -2,6 +2,8 @@ package xyz.driver.pdsuidomain.entities import java.time.{LocalDate, LocalDateTime} +import xyz.driver.entities.common.FullName +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuicommon.utils.Utils @@ -52,14 +54,14 @@ object Patient { final case class Patient(id: UuidId[Patient], status: Patient.Status, - name: String, + name: FullName[Patient], dob: LocalDate, assignee: Option[StringId[User]], previousStatus: Option[Patient.Status], previousAssignee: Option[StringId[User]], lastActiveUserId: Option[StringId[User]], isUpdateRequired: Boolean, - condition: String, + cancerType: CancerType, orderId: PatientOrderId, lastUpdate: LocalDateTime) { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala index 469b21c..79a19ed 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala @@ -2,7 +2,8 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDateTime -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ object PatientCriterion { @@ -18,15 +19,15 @@ object PatientCriterion { /** * @see https://driverinc.atlassian.net/wiki/display/MTCH/EV+Business+Process */ - def getEligibilityStatus(criterionValue: Option[Boolean], primaryValue: Option[FuzzyValue]): Option[FuzzyValue] = { + def getEligibilityStatus(criterionValue: Option[Boolean], primaryValue: Option[LabelValue]): Option[LabelValue] = { primaryValue match { case None => None - case Some(FuzzyValue.Maybe) => Some(FuzzyValue.Maybe) - case Some(_) if criterionValue.isEmpty => Some(FuzzyValue.Maybe) + case Some(LabelValue.Maybe) => Some(LabelValue.Maybe) + case Some(_) if criterionValue.isEmpty => Some(LabelValue.Maybe) case Some(status) => Some( - FuzzyValue.fromBoolean( - FuzzyValue.fromBoolean( + LabelValue.fromBoolean( + LabelValue.fromBoolean( criterionValue.getOrElse(throw new IllegalArgumentException("Criterion should not be empty"))) == status )) } @@ -47,12 +48,12 @@ final case class PatientCriterion(id: LongId[PatientCriterion], criterionText: String, criterionValue: Option[Boolean], criterionIsDefining: Boolean, - eligibilityStatus: Option[FuzzyValue], - verifiedEligibilityStatus: Option[FuzzyValue], + eligibilityStatus: Option[LabelValue], + verifiedEligibilityStatus: Option[LabelValue], isVerified: Boolean, isVisible: Boolean, lastUpdate: LocalDateTime) { - def isIneligibleForEv: Boolean = eligibilityStatus.contains(FuzzyValue.No) && isVerified + def isIneligibleForEv: Boolean = eligibilityStatus.contains(LabelValue.No) && isVerified } object PatientCriterionArm { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala index 8ee5b3c..ff272a8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala @@ -1,6 +1,7 @@ package xyz.driver.pdsuidomain.entities -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuicommon.logging._ object PatientTrialArm { @@ -37,22 +38,22 @@ object PatientTrialArmGroup { /** * @see https://driverinc.atlassian.net/wiki/display/DMPD/EV+Business+Process */ - def getEligibilityStatusForRc(criterionList: TraversableOnce[PatientCriterion]): Option[FuzzyValue] = { - def isEligible: Boolean = criterionList.forall(_.verifiedEligibilityStatus.contains(FuzzyValue.Yes)) - def isIneligible: Boolean = criterionList.exists(_.verifiedEligibilityStatus.contains(FuzzyValue.No)) + def getEligibilityStatusForRc(criterionList: TraversableOnce[PatientCriterion]): Option[LabelValue] = { + def isEligible: Boolean = criterionList.forall(_.verifiedEligibilityStatus.contains(LabelValue.Yes)) + def isIneligible: Boolean = criterionList.exists(_.verifiedEligibilityStatus.contains(LabelValue.No)) def isUnknown: Boolean = criterionList.forall(_.verifiedEligibilityStatus.isEmpty) - if (isEligible) Some(FuzzyValue.Yes) - else if (isIneligible) Some(FuzzyValue.No) + if (isEligible) Some(LabelValue.Yes) + else if (isIneligible) Some(LabelValue.No) else if (isUnknown) None - else Some(FuzzyValue.Maybe) + else Some(LabelValue.Maybe) } } final case class PatientTrialArmGroup(id: LongId[PatientTrialArmGroup], eligibleTrialId: UuidId[PatientEligibleTrial], - eligibilityStatus: Option[FuzzyValue], - verifiedEligibilityStatus: Option[FuzzyValue], + eligibilityStatus: Option[LabelValue], + verifiedEligibilityStatus: Option[LabelValue], isVerified: Boolean) object PatientTrialArmGroupView { @@ -69,8 +70,8 @@ final case class PatientTrialArmGroupView(id: LongId[PatientTrialArmGroup], patientId: UuidId[Patient], trialId: StringId[Trial], hypothesisId: UuidId[Hypothesis], - eligibilityStatus: Option[FuzzyValue], - verifiedEligibilityStatus: Option[FuzzyValue], + eligibilityStatus: Option[LabelValue], + verifiedEligibilityStatus: Option[LabelValue], isVerified: Boolean) { def applyTo(trialArmGroup: PatientTrialArmGroup) = { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala index d10c7d2..4c0f4ef 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala @@ -1,7 +1,7 @@ package xyz.driver.pdsuidomain.entities -import xyz.driver.entities.labels.Label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} +import xyz.driver.entities.labels.{Label, LabelValue} +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuicommon.logging._ object PatientLabel { @@ -17,8 +17,8 @@ final case class PatientLabel(id: LongId[PatientLabel], patientId: UuidId[Patient], labelId: LongId[Label], score: Int, - primaryValue: Option[FuzzyValue], - verifiedPrimaryValue: Option[FuzzyValue], + primaryValue: Option[LabelValue], + verifiedPrimaryValue: Option[LabelValue], isImplicitMatch: Boolean, isVisible: Boolean) @@ -32,7 +32,7 @@ object PatientLabelEvidence { final case class PatientLabelEvidence(id: LongId[PatientLabelEvidence], patientLabelId: LongId[PatientLabel], - value: FuzzyValue, + value: LabelValue, evidenceText: String, reportId: Option[UuidId[DirectReport]], documentId: Option[LongId[Document]], diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala index 3311d96..2dbe099 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala @@ -2,21 +2,21 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDate -import xyz.driver.entities.labels.Label +import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ object PatientLabelEvidenceView { implicit def toPhiString(x: PatientLabelEvidenceView): PhiString = { import x._ - phi"PatientLabelEvidenceView(id=$id, value=$value, documentId=$documentId, " + + phi"PatientLabelEvidenceView(id=$id, value=${Unsafe(value)}, documentId=$documentId, " + phi"evidenceId=$evidenceId, reportId=$reportId, patientId=$patientId, labelId=$labelId, " + phi"isImplicitMatch=$isImplicitMatch)" } } final case class PatientLabelEvidenceView(id: LongId[PatientLabelEvidence], - value: FuzzyValue, + value: LabelValue, evidenceText: String, documentId: Option[LongId[Document]], evidenceId: Option[LongId[ExtractedData]], diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala deleted file mode 100644 index 689eaa4..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.driver.pdsuidomain.entities - -import java.time.LocalDate - -import xyz.driver.entities.labels.Label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} -import xyz.driver.pdsuicommon.logging._ - -final case class RawPatientLabel(patientId: UuidId[Patient], - labelId: LongId[Label], - value: FuzzyValue, - evidenceId: LongId[ExtractedData], - evidenceText: String, - disease: String, - documentId: LongId[Document], - requestId: RecordRequestId, - documentType: DocumentType, - providerType: ProviderType, - startDate: LocalDate, - endDate: Option[LocalDate]) - -object RawPatientLabel { - - implicit def toPhiString(x: RawPatientLabel): PhiString = { - import x._ - phi"RawPatientLabel(patientId=$patientId, labelId=$labelId, value=$value, evidenceId=${Unsafe(evidenceId)}, " + - phi"evidenceText=${Unsafe(evidenceText)}, documentId=$documentId, requestId=${Unsafe(requestId)}, " + - phi"documentType=${Unsafe(documentType)}, providerType=${Unsafe(providerType)}, " + - phi"startDate=$startDate, endDate=$endDate)" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala index 2edd707..957e607 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala @@ -3,7 +3,6 @@ package xyz.driver.pdsuidomain.entities.export.patient import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.RawPatientLabel final case class ExportPatientLabel(id: LongId[Label], evidences: List[ExportPatientLabelEvidence]) @@ -13,8 +12,4 @@ object ExportPatientLabel extends PhiLogging { import x._ phi"ExportPatientLabel(id=$id, evidences=$evidences)" } - - def fromRaw(labelId: LongId[Label], rawPatientLabels: List[RawPatientLabel]): ExportPatientLabel = { - ExportPatientLabel(id = labelId, evidences = rawPatientLabels.map(ExportPatientLabelEvidence.fromRaw)) - } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidence.scala index fb40339..6472a6b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidence.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidence.scala @@ -1,11 +1,12 @@ package xyz.driver.pdsuidomain.entities.export.patient +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{ExtractedData, RawPatientLabel} +import xyz.driver.pdsuidomain.entities.ExtractedData final case class ExportPatientLabelEvidence(id: LongId[ExtractedData], - value: FuzzyValue, + value: LabelValue, evidenceText: String, document: ExportPatientLabelEvidenceDocument) @@ -13,20 +14,8 @@ object ExportPatientLabelEvidence { implicit def toPhiString(x: ExportPatientLabelEvidence): PhiString = { import x._ - phi"ExportPatientLabelEvidence(id=${Unsafe(id)}, value=$value, " + + phi"ExportPatientLabelEvidence(id=${Unsafe(id)}, value=${Unsafe(value)}, " + phi"evidenceText=${Unsafe(evidenceText)}, document=$document)" } - def fromRaw(x: RawPatientLabel) = ExportPatientLabelEvidence( - id = x.evidenceId, - value = x.value, - evidenceText = x.evidenceText, - document = ExportPatientLabelEvidenceDocument( - x.documentId, - x.requestId, - x.documentType, - x.providerType, - x.startDate - ) - ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala index 7003615..467170b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala @@ -19,12 +19,4 @@ object ExportPatientLabelEvidenceDocument extends PhiLogging { phi"ExportPatientLabelEvidenceDocument(documentId=$documentId, requestId=$requestId, " + phi"documentType=${Unsafe(documentType)}, providerType=${Unsafe(providerType)}, date=$date)" } - - def fromRaw(x: RawPatientLabel) = ExportPatientLabelEvidenceDocument( - documentId = x.documentId, - requestId = x.requestId, - documentType = x.documentType, - providerType = x.providerType, - date = x.startDate - ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala index bd6173b..8fb2660 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala @@ -2,9 +2,7 @@ package xyz.driver.pdsuidomain.entities.export.patient import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{Patient, RawPatientLabel} - -import scala.collection.breakOut +import xyz.driver.pdsuidomain.entities.Patient final case class ExportPatientWithLabels(patientId: UuidId[Patient], labelVersion: Long, @@ -16,12 +14,4 @@ object ExportPatientWithLabels { import x._ phi"ExportPatientWithLabels(patientId=$patientId, version=${Unsafe(labelVersion)}, labels=$labels)" } - - def fromRaw(patientId: UuidId[Patient], rawPatientRefs: List[RawPatientLabel]) = ExportPatientWithLabels( - patientId = patientId, - labelVersion = 1L, // TODO It is needed to replace this mock label version. - labels = rawPatientRefs - .groupBy(_.labelId) - .map(Function.tupled(ExportPatientLabel.fromRaw))(breakOut) - ) } 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 7318ff6..a38d52c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.fakes.entities import java.time.{LocalDate, LocalDateTime, LocalTime} import xyz.driver.core.generators.{nextDouble, nextOption} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{Trial, TrialHistory} import scala.util.Random @@ -52,9 +52,6 @@ object common { ranges.map(_._1) -> ranges.flatMap(_._2) } - def nextFuzzyValue(): FuzzyValue = - generators.oneOf[FuzzyValue](FuzzyValue.All) - def nextStartAndEndPages: (Option[Double], Option[Double]) = genBoundedRangeOption[Double](nextDouble(), nextDouble()) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala index 3fcc4cb..85bab8c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -1,9 +1,9 @@ package xyz.driver.pdsuidomain.fakes.entities.rep +import xyz.driver.core.generators import xyz.driver.core.generators._ -import xyz.driver.entities.labels.Label +import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuidomain.fakes.entities.common._ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} @@ -26,7 +26,7 @@ object ExportPatientGen { def nextExportPatientLabelEvidence(documentId: LongId[Document]): ExportPatientLabelEvidence = { ExportPatientLabelEvidence( id = nextLongId[ExtractedData], - value = nextFuzzyValue(), + value = generators.oneOf[LabelValue](LabelValue.Yes, LabelValue.No, LabelValue.Maybe), evidenceText = nextString(), document = nextExportPatientLabelEvidenceDocument(documentId) ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 8e77445..70ddd10 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -1,7 +1,8 @@ package xyz.driver.pdsuidomain.fakes.entities.rep +import xyz.driver.core.generators import xyz.driver.core.generators._ -import xyz.driver.entities.labels.{Label, LabelCategory} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta @@ -85,7 +86,7 @@ object ExtractedDataGen { dataId = nextLongId[ExtractedData], labelId = nextOption(nextLongId[Label]), categoryId = nextOption(nextLongId[LabelCategory]), - value = nextOption(nextFuzzyValue()) + value = nextOption(generators.oneOf[LabelValue](LabelValue.Yes, LabelValue.No, LabelValue.Maybe)) ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala index e0f23e3..7409e90 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala @@ -3,7 +3,6 @@ package xyz.driver.pdsuidomain.formats.json.evidence import java.time.LocalDate import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue import xyz.driver.pdsuidomain.entities.PatientLabelEvidenceView final case class ApiPatientLabelEvidence(id: Long, @@ -22,7 +21,7 @@ object ApiPatientLabelEvidence { def fromDomain(x: PatientLabelEvidenceView) = ApiPatientLabelEvidence( id = x.id.id, - value = FuzzyValue.valueToString(x.value), + value = x.value.toString, evidenceText = x.evidenceText, documentId = x.documentId.map(_.id), evidenceId = x.evidenceId.map(_.id), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala index d486749..edb0603 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala @@ -1,11 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.{Criterion, CriterionLabel} import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.entities.labels.{Label, LabelCategory} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} /** * @param value Yes|No @@ -34,7 +34,7 @@ object ApiCriterionLabel { labelId = x.labelId.map(_.id), categoryId = x.categoryId.map(_.id), value = x.value.map { x => - FuzzyValue.valueToString(FuzzyValue.fromBoolean(x)) + LabelValue.fromBoolean(x).toString }, isDefining = x.isDefining ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala index f8161af..1497679 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala @@ -1,11 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.{ExtractedData, ExtractedDataLabel} import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.entities.labels.{Label, LabelCategory} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} final case class ApiExtractedDataLabel(id: Option[Long], categoryId: Option[Long], value: Option[String]) { @@ -14,7 +14,7 @@ final case class ApiExtractedDataLabel(id: Option[Long], categoryId: Option[Long dataId = dataId, labelId = id.map(LongId[Label]), categoryId = categoryId.map(LongId[LabelCategory]), - value = value.map(FuzzyValue.fromString) + value = value.flatMap(LabelValue.fromString) ) } @@ -27,8 +27,8 @@ object ApiExtractedDataLabel { Format(Reads .of[String] .filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String])) )(ApiExtractedDataLabel.apply, unlift(ApiExtractedDataLabel.unapply)) @@ -36,6 +36,6 @@ object ApiExtractedDataLabel { def fromDomain(dataLabel: ExtractedDataLabel) = ApiExtractedDataLabel( id = dataLabel.labelId.map(_.id), categoryId = dataLabel.categoryId.map(_.id), - value = dataLabel.value.map(FuzzyValue.valueToString) + value = dataLabel.value.map(_.toString) ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala index db430ae..ad6bc80 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala @@ -7,6 +7,8 @@ import xyz.driver.pdsuicommon.domain.{StringId, UuidId} import xyz.driver.pdsuidomain.entities.{Patient, PatientOrderId} import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsPath} +import xyz.driver.entities.common.FullName +import xyz.driver.entities.patient final case class ApiPatient(id: String, status: String, @@ -24,17 +26,28 @@ final case class ApiPatient(id: String, PatientStatus.statusFromString .applyOrElse(status, (s: String) => throw new NoSuchElementException(s"Unknown status $s")) + private def parseName(name: String): FullName[Patient] = + name.split(" ") match { + case Array() => throw new NoSuchElementException(s"Patient's name cannot be empty") + case Array(first) => FullName.fromStrings[Patient](first, "", "") + case Array(first, last) => FullName.fromStrings[Patient](first, "", last) + case Array(first, middle, last) => FullName.fromStrings[Patient](first, middle, last) + case _ => throw new NoSuchElementException(s"Patient's name is ambiguous") + } + def toDomain = Patient( id = UuidId(this.id), status = extractStatus(this.status), - name = this.name, + name = parseName(this.name), dob = this.dob, assignee = this.assignee.map(StringId(_)), previousStatus = this.previousStatus.map(extractStatus), previousAssignee = this.previousAssignee.map(StringId(_)), lastActiveUserId = this.lastActiveUser.map(StringId(_)), isUpdateRequired = false, - condition = this.condition, + cancerType = patient.CancerType + .fromString(this.condition) + .getOrElse(throw new IllegalArgumentException(s"Unknown cancer type ${this.condition}")), orderId = PatientOrderId(this.orderId), lastUpdate = this.lastUpdate.toLocalDateTime ) @@ -60,14 +73,14 @@ object ApiPatient { def fromDomain(patient: Patient) = ApiPatient( id = patient.id.toString, status = PatientStatus.statusToString(patient.status), - name = patient.name, + name = patient.name.toString(), dob = patient.dob, assignee = patient.assignee.map(_.id), previousStatus = patient.previousStatus.map(PatientStatus.statusToString), previousAssignee = patient.previousAssignee.map(_.id), lastActiveUser = patient.lastActiveUserId.map(_.id), lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")), - condition = patient.condition, + condition = patient.cancerType.toString, orderId = patient.orderId.id ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala index 4136715..55c8149 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala @@ -5,7 +5,7 @@ import java.util.UUID import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial final case class ApiPatientEligibleTrial(id: Long, @@ -30,8 +30,8 @@ object ApiPatientEligibleTrial { Reads .of[String] .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String] )) and @@ -45,7 +45,7 @@ object ApiPatientEligibleTrial { trialTitle = eligibleTrialWithTrial.trial.title, arms = eligibleTrialWithTrial.arms.map(_.armName), hypothesisId = eligibleTrialWithTrial.group.hypothesisId.id, - eligibleTrialWithTrial.group.verifiedEligibilityStatus.map(FuzzyValue.valueToString), + eligibleTrialWithTrial.group.verifiedEligibilityStatus.map(_.toString), eligibleTrialWithTrial.group.isVerified ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala index 91d0a0e..d92872c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala @@ -6,15 +6,14 @@ import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue final case class ApiPartialPatientLabel(primaryValue: Option[String], verifiedPrimaryValue: Tristate[String]) { def applyTo(orig: PatientLabel): PatientLabel = { orig.copy( - primaryValue = primaryValue.map(FuzzyValue.fromString).orElse(orig.primaryValue), - verifiedPrimaryValue = - verifiedPrimaryValue.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedPrimaryValue) + primaryValue = primaryValue.flatMap(LabelValue.fromString).orElse(orig.primaryValue), + verifiedPrimaryValue = verifiedPrimaryValue.cata(x => LabelValue.fromString(x), None, orig.verifiedPrimaryValue) ) } } @@ -26,8 +25,8 @@ object ApiPartialPatientLabel { Format(Reads .of[String] .filter(ValidationError("unknown primary value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String])) and (JsPath \ "verifiedPrimaryValue").formatTristate[String]( @@ -35,8 +34,8 @@ object ApiPartialPatientLabel { Reads .of[String] .filter(ValidationError("unknown verified primary value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String] )) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala index fc8687b..cc8532d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala @@ -4,7 +4,7 @@ import xyz.driver.pdsuidomain.entities.PatientLabel import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue final case class ApiPatientLabel(id: Long, labelId: Long, @@ -20,25 +20,33 @@ object ApiPatientLabel { implicit val apiPatientLabelJsonFormat: Format[ApiPatientLabel] = ( (JsPath \ "id").format[Long] and (JsPath \ "labelId").format[Long] and - (JsPath \ "primaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and - (JsPath \ "verifiedPrimaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and + (JsPath \ "primaryValue").formatNullable[String]( + Format(Reads + .of[String] + .filter(ValidationError("unknown value"))({ + case x if LabelValue.fromString(x).isDefined => true + case _ => false + }), + Writes.of[String])) and + (JsPath \ "verifiedPrimaryValue").formatNullable[String]( + Format(Reads + .of[String] + .filter(ValidationError("unknown value"))({ + case x if LabelValue.fromString(x).isDefined => true + case _ => false + }), + Writes.of[String])) and (JsPath \ "score").format[Int] and (JsPath \ "isImplicitMatch").format[Boolean] and (JsPath \ "isVisible").format[Boolean] and (JsPath \ "isVerified").format[Boolean] - ) (ApiPatientLabel.apply, unlift(ApiPatientLabel.unapply)) + )(ApiPatientLabel.apply, unlift(ApiPatientLabel.unapply)) def fromDomain(patientLabel: PatientLabel, isVerified: Boolean): ApiPatientLabel = ApiPatientLabel( id = patientLabel.id.id, labelId = patientLabel.labelId.id, - primaryValue = patientLabel.primaryValue.map(FuzzyValue.valueToString), - verifiedPrimaryValue = patientLabel.verifiedPrimaryValue.map(FuzzyValue.valueToString), + primaryValue = patientLabel.primaryValue.map(_.toString), + verifiedPrimaryValue = patientLabel.verifiedPrimaryValue.map(_.toString), score = patientLabel.score, isImplicitMatch = patientLabel.isImplicitMatch, isVisible = patientLabel.isVisible, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala index ae64c33..16b9cc9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.patient.label import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities.PatientLabel final case class ApiPatientLabelDefiningCriteria(labelId: Long, value: Option[String]) @@ -16,14 +16,14 @@ object ApiPatientLabelDefiningCriteria { Format(Reads .of[String] .filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String])) )(ApiPatientLabelDefiningCriteria.apply, unlift(ApiPatientLabelDefiningCriteria.unapply)) def fromDomain(x: PatientLabel) = ApiPatientLabelDefiningCriteria( labelId = x.labelId.id, - value = x.verifiedPrimaryValue.map(FuzzyValue.valueToString) + value = x.verifiedPrimaryValue.map(_.toString) ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala index 399bc7d..09538b8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala @@ -6,16 +6,16 @@ import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsPath, Reads, Writes} -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue final case class ApiPartialPatientCriterion(eligibilityStatus: Option[String], verifiedEligibilityStatus: Tristate[String]) { def applyTo(orig: PatientCriterion): PatientCriterion = { orig.copy( - eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString).orElse(orig.eligibilityStatus), + eligibilityStatus = eligibilityStatus.flatMap(LabelValue.fromString).orElse(orig.eligibilityStatus), verifiedEligibilityStatus = - verifiedEligibilityStatus.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedEligibilityStatus) + verifiedEligibilityStatus.cata(x => LabelValue.fromString(x), None, orig.verifiedEligibilityStatus) ) } } @@ -28,8 +28,8 @@ object ApiPartialPatientCriterion { Reads .of[String] .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String] )) and @@ -38,8 +38,8 @@ object ApiPartialPatientCriterion { Reads .of[String] .filter(ValidationError("unknown verified eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String] )) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala index 4b08970..b7616a1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala @@ -1,10 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.patient.trial -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.PatientCriterion import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsPath, Reads, Writes} +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion final case class ApiPartialPatientCriterionList(id: Long, @@ -13,7 +14,7 @@ final case class ApiPartialPatientCriterionList(id: Long, def toDomain: DraftPatientCriterion = DraftPatientCriterion( id = LongId[PatientCriterion](id), - eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString), + eligibilityStatus = eligibilityStatus.flatMap(LabelValue.fromString), isVerified = isVerified ) } @@ -26,8 +27,8 @@ object ApiPartialPatientCriterionList { Reads .of[String] .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String] )) and diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala index 6eeb40b..b9bf772 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala @@ -2,12 +2,12 @@ package xyz.driver.pdsuidomain.formats.json.patient.trial import java.time.{ZoneId, ZonedDateTime} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm} import play.api.data.validation.ValidationError import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsPath, Reads, Writes} -import xyz.driver.entities.labels.Label +import xyz.driver.entities.labels.{Label, LabelValue} final case class ApiPatientCriterion(id: Long, labelId: Long, @@ -39,13 +39,13 @@ object ApiPatientCriterion { (JsPath \ "criterionIsCompound").format[Boolean] and (JsPath \ "arms").format[List[String]] and (JsPath \ "eligibilityStatus").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String])) and (JsPath \ "verifiedEligibilityStatus").formatNullable[String](Format( Reads.of[String].filter(ValidationError("unknown status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false + case x if LabelValue.fromString(x).isDefined => true + case _ => false }), Writes.of[String])) and (JsPath \ "isVerified").format[Boolean] and (JsPath \ "isVisible").format[Boolean] and @@ -61,13 +61,13 @@ object ApiPatientCriterion { criterionId = patientCriterion.criterionId.id, criterionText = patientCriterion.criterionText, criterionValue = patientCriterion.criterionValue.map { x => - FuzzyValue.valueToString(FuzzyValue.fromBoolean(x)) + LabelValue.fromBoolean(x).toString }, criterionIsDefining = patientCriterion.criterionIsDefining, criterionIsCompound = patientCriterion.criterionValue.isEmpty, arms = arms.map(_.armName), - eligibilityStatus = patientCriterion.eligibilityStatus.map(FuzzyValue.valueToString), - verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(FuzzyValue.valueToString), + eligibilityStatus = patientCriterion.eligibilityStatus.map(_.toString), + verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(_.toString), isVerified = patientCriterion.isVerified, isVisible = patientCriterion.isVisible, lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z")) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala index dbd0a43..61e0e7f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import java.time.{LocalDate, LocalDateTime, ZoneId, ZonedDateTime} import spray.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} object common { @@ -55,14 +55,6 @@ object common { } } - implicit def fuzzyValueFormat: RootJsonFormat[FuzzyValue] = new RootJsonFormat[FuzzyValue] { - override def write(value: FuzzyValue): JsString = JsString(FuzzyValue.valueToString(value)) - override def read(json: JsValue): FuzzyValue = json match { - case JsString(value) => FuzzyValue.fromString(value) - case _ => deserializationError(s"Expected value as FuzzyValue, but got $json") - } - } - implicit val integerFormat: RootJsonFormat[Integer] = new RootJsonFormat[Integer] { override def write(obj: Integer): JsNumber = JsNumber(obj.intValue()) override def read(json: JsValue): Integer = json match { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala index 39d5c59..85d614d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala @@ -5,6 +5,7 @@ import xyz.driver.entities.labels.Label import xyz.driver.pdsuidomain.entities.{Arm, Criterion} import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} +import xyz.driver.formats.json.labels._ object export { import DefaultJsonProtocol._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala index d6eadbd..5d5585a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala @@ -1,10 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.entities.labels.{Label, LabelCategory} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData +import xyz.driver.formats.json.labels._ object extracteddata { import DefaultJsonProtocol._ @@ -44,7 +45,7 @@ object extracteddata { val value = fields .get("value") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) ExtractedDataLabel( id = LongId(0), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala index 95c0674..3da76c1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala @@ -3,6 +3,8 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.core.json.EnumJsonFormat import xyz.driver.pdsuidomain.entities._ +import xyz.driver.formats.json.common._ +import xyz.driver.formats.json.patient._ object patient { import DefaultJsonProtocol._ @@ -38,7 +40,7 @@ object patient { "previousAssignee" -> patient.previousAssignee.toJson, "lastActiveUser" -> patient.lastActiveUserId.toJson, "lastUpdate" -> patient.lastUpdate.toJson, - "condition" -> patient.condition.toJson, + "condition" -> patient.cancerType.toJson, "orderId" -> patient.orderId.toJson ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala index affb346..7e8c220 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala @@ -1,9 +1,10 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} +import xyz.driver.formats.json.labels._ object patientcriterion { import DefaultJsonProtocol._ @@ -14,13 +15,13 @@ object patientcriterion { val eligibilityStatus = if (fields.contains("eligibilityStatus")) { fields .get("eligibilityStatus") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) } else orig.eligibilityStatus val verifiedEligibilityStatus = if (fields.contains("verifiedEligibilityStatus")) { fields .get("verifiedEligibilityStatus") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) } else orig.verifiedEligibilityStatus orig.copy( 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 0520ef2..746c7b4 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 @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities.PatientLabel +import xyz.driver.formats.json.labels._ object patientdefiningcriteria { import DefaultJsonProtocol._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala index 041d9da..342d3a8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial +import xyz.driver.formats.json.labels._ object patienteligibletrial { import DefaultJsonProtocol._ 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 b36949e..ff6d24d 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 @@ -1,9 +1,10 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel +import xyz.driver.formats.json.labels._ object patientlabel { import DefaultJsonProtocol._ @@ -13,12 +14,12 @@ object patientlabel { case JsObject(fields) => val primaryValue = fields .get("primaryValue") - .map(_.convertTo[Option[FuzzyValue]]) + .map(_.convertTo[Option[LabelValue]]) .getOrElse(orig.primaryValue) val verifiedPrimaryValue = fields .get("verifiedPrimaryValue") - .map(_.convertTo[Option[FuzzyValue]]) + .map(_.convertTo[Option[LabelValue]]) .getOrElse(orig.verifiedPrimaryValue) orig.copy( diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala index a07eed8..4d0e188 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.services import java.time.LocalDateTime -import xyz.driver.entities.labels.Label +import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ @@ -15,7 +15,7 @@ import scala.concurrent.Future object PatientCriterionService { final case class DraftPatientCriterion(id: LongId[PatientCriterion], - eligibilityStatus: Option[FuzzyValue], + eligibilityStatus: Option[LabelValue], isVerified: Option[Boolean]) { def applyTo(orig: PatientCriterion) = { orig.copy( diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala index a451905..05f5863 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala @@ -5,7 +5,8 @@ import java.util.UUID import spray.json._ import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{DocumentType, ProviderType, RecordRequestId} class ExportFormatSuite extends FlatSpec with Matchers { @@ -27,13 +28,13 @@ class ExportFormatSuite extends FlatSpec with Matchers { evidences = List( ExportPatientLabelEvidence( id = LongId(11), - value = FuzzyValue.Yes, + value = LabelValue.Yes, evidenceText = "evidence text 11", document = document ), ExportPatientLabelEvidence( id = LongId(12), - value = FuzzyValue.No, + value = LabelValue.No, evidenceText = "evidence text 12", document = document ) @@ -44,13 +45,13 @@ class ExportFormatSuite extends FlatSpec with Matchers { evidences = List( ExportPatientLabelEvidence( id = LongId(12), - value = FuzzyValue.Yes, + value = LabelValue.Yes, evidenceText = "evidence text 12", document = document ), ExportPatientLabelEvidence( id = LongId(13), - value = FuzzyValue.Yes, + value = LabelValue.Yes, evidenceText = "evidence text 13", document = document ) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExtractedDataFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExtractedDataFormatSuite.scala index a4b8bab..aa82b98 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExtractedDataFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExtractedDataFormatSuite.scala @@ -2,7 +2,8 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities.ExtractedData.Meta import xyz.driver.pdsuidomain.entities.{ExtractedData, ExtractedDataLabel} import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData @@ -24,14 +25,14 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { dataId = extractedData.id, labelId = None, categoryId = None, - value = Some(FuzzyValue.Yes) + value = Some(LabelValue.Yes) ), ExtractedDataLabel( id = LongId(2), dataId = extractedData.id, labelId = Some(LongId(12)), categoryId = Some(LongId(1)), - value = Some(FuzzyValue.No) + value = Some(LabelValue.No) ) ) val origRichExtractedData = RichExtractedData( @@ -64,14 +65,14 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { dataId = extractedData.id, labelId = Some(LongId(20)), categoryId = Some(LongId(1)), - value = Some(FuzzyValue.Yes) + value = Some(LabelValue.Yes) ), ExtractedDataLabel( id = LongId(0), dataId = extractedData.id, labelId = Some(LongId(12)), categoryId = Some(LongId(1)), - value = Some(FuzzyValue.No) + value = Some(LabelValue.No) ) ) val expectedUpdatedExtractedData = origRichExtractedData.copy( 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 623b3a9..fc206c7 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 @@ -4,7 +4,8 @@ import java.time.LocalDateTime import spray.json._ import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm} import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} @@ -21,7 +22,7 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { criterionText = "criterion text", criterionValue = Some(true), criterionIsDefining = false, - eligibilityStatus = Some(FuzzyValue.Yes), + eligibilityStatus = Some(LabelValue.Yes), verifiedEligibilityStatus = None, isVisible = true, isVerified = true, @@ -40,13 +41,13 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { "isVisible":true,"isVerified":true,"lastUpdate":"2017-08-10T18:00Z","arms":["arm 31","arm 32"]}""".parseJson) val updatePatientCriterionJson = """{"verifiedEligibilityStatus":"No"}""".parseJson - val expectedUpdatedPatientCriterion = orig.copy(verifiedEligibilityStatus = Some(FuzzyValue.No)) + val expectedUpdatedPatientCriterion = orig.copy(verifiedEligibilityStatus = Some(LabelValue.No)) val parsedUpdatePatientCriterion = applyUpdateToPatientCriterion(updatePatientCriterionJson, orig) parsedUpdatePatientCriterion should be(expectedUpdatedPatientCriterion) val updateBulkPatientCriterionJson = """[{"id":1,"eligibilityStatus":"No"},{"id":2,"isVerified":false}]""".parseJson val expectedDraftPatientCriterionList = List( - DraftPatientCriterion(id = LongId(1), eligibilityStatus = Some(FuzzyValue.No), isVerified = None), + DraftPatientCriterion(id = LongId(1), eligibilityStatus = Some(LabelValue.No), isVerified = None), DraftPatientCriterion(id = LongId(2), eligibilityStatus = None, isVerified = Some(false)) ) val parsedDraftPatientCriterionList = draftPatientCriterionListReader.read(updateBulkPatientCriterionJson) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala index ad54946..f48625c 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala @@ -4,7 +4,8 @@ import java.time.LocalDateTime import spray.json._ import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{PatientCriterionArm, PatientTrialArmGroupView, Trial} import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial @@ -38,8 +39,8 @@ class PatientEligibleTrialFormatSuite extends FlatSpec with Matchers { patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), trialId = StringId("NCT000001"), hypothesisId = UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4"), - eligibilityStatus = Some(FuzzyValue.Yes), - verifiedEligibilityStatus = Some(FuzzyValue.Yes), + eligibilityStatus = Some(LabelValue.Yes), + verifiedEligibilityStatus = Some(LabelValue.Yes), isVerified = false ) val arms = List( diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala index 2761d6a..443c8e8 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala @@ -4,6 +4,8 @@ import java.time.{LocalDate, LocalDateTime} import spray.json._ import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.entities.common.FullName +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain.UuidId import xyz.driver.pdsuidomain.entities.{Patient, PatientOrderId} @@ -14,23 +16,24 @@ class PatientFormatSuite extends FlatSpec with Matchers { val orig = Patient( id = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), status = Patient.Status.New, - name = "John Doe", + name = FullName.fromStrings("John", "", "Doe"), dob = LocalDate.parse("1980-06-30"), assignee = None, previousStatus = None, previousAssignee = None, lastActiveUserId = None, isUpdateRequired = false, - condition = "breast", + cancerType = CancerType.Breast, orderId = PatientOrderId("7b54a75d-4197-4b27-9045-b9b6cb131be9"), lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") ) val writtenJson = patientWriter.write(orig) writtenJson should be ( - """{"id":"748b5884-3528-4cb9-904b-7a8151d6e343","dob":"1980-06-30","name":"John Doe","status":"New","assignee":null, + """{"id":"748b5884-3528-4cb9-904b-7a8151d6e343","dob":"1980-06-30", + "name":{"firstName":"John","middleName":"","lastName":"Doe"},"status":"New","assignee":null, "previousStatus":null,"previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z", - "orderId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","condition":"breast"}""".parseJson) + "orderId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","condition":"Breast"}""".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 3ef286d..47b251a 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 @@ -4,7 +4,8 @@ import java.time.LocalDate import spray.json._ import org.scalatest.{FlatSpec, Matchers} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} +import xyz.driver.entities.labels.LabelValue +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuidomain.entities.{PatientLabel, PatientLabelEvidenceView} import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel @@ -16,7 +17,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { id = LongId(1), patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), labelId = LongId(20), - primaryValue = Some(FuzzyValue.Yes), + primaryValue = Some(LabelValue.Yes), verifiedPrimaryValue = None, isVisible = true, score = 1, @@ -29,7 +30,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { "score":1,"isImplicitMatch":false}""".parseJson) val updatePatientLabelJson = """{"verifiedPrimaryValue":"No"}""".parseJson - val expectedUpdatedPatientLabel = orig.copy(verifiedPrimaryValue = Some(FuzzyValue.No)) + val expectedUpdatedPatientLabel = orig.copy(verifiedPrimaryValue = Some(LabelValue.No)) val parsedUpdatePatientLabel = applyUpdateToPatientLabel(updatePatientLabelJson, orig) parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel) } @@ -38,7 +39,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { import patientlabel._ val orig = PatientLabelEvidenceView( id = LongId(1), - value = FuzzyValue.Maybe, + value = LabelValue.Maybe, evidenceText = "evidence text", documentId = Some(LongId(21)), evidenceId = Some(LongId(10)), @@ -63,8 +64,8 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { id = LongId(1), patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), labelId = LongId(20), - primaryValue = Some(FuzzyValue.Yes), - verifiedPrimaryValue = Some(FuzzyValue.Yes), + primaryValue = Some(LabelValue.Yes), + verifiedPrimaryValue = Some(LabelValue.Yes), isVisible = true, score = 1, isImplicitMatch = false -- cgit v1.2.3 From eeeb6d90f1c6882f0b3d765022b114d97e4dba40 Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 9 Oct 2017 12:49:02 -0700 Subject: Getting rid of the FuzzyValues, Name as a string, and condition --- .../utils/CustomSwaggerJsonFormats.scala | 3 +- .../xyz/driver/pdsuidomain/entities/Patient.scala | 2 +- .../pdsuidomain/entities/RawTrialLabel.scala | 32 ------------------- .../xyz/driver/pdsuidomain/entities/Trial.scala | 23 ++------------ .../export/trial/ExportTrialLabelCriterion.scala | 12 +------- .../export/trial/ExportTrialWithLabels.scala | 36 ++-------------------- .../driver/pdsuidomain/fakes/entities/common.scala | 2 -- .../driver/pdsuidomain/fakes/entities/export.scala | 2 +- .../pdsuidomain/fakes/entities/trialcuration.scala | 3 +- .../formats/json/patient/ApiPatient.scala | 12 ++++---- .../formats/json/sprayformats/patient.scala | 2 +- .../formats/json/sprayformats/trial.scala | 9 ++---- .../pdsuidomain/formats/json/trial/ApiTrial.scala | 17 +++++----- .../driver/pdsuidomain/services/TrialService.scala | 5 +-- .../services/fake/FakeTrialService.scala | 7 +++-- .../services/rest/RestTrialService.scala | 9 +++--- .../json/sprayformats/ExportFormatSuite.scala | 2 +- .../PatientEligibleTrialFormatSuite.scala | 3 +- .../json/sprayformats/PatientFormatSuite.scala | 4 +-- .../json/sprayformats/TrialFormatSuite.scala | 5 +-- 20 files changed, 50 insertions(+), 140 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala (limited to 'src/test/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 83c4e6f..6d2a068 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -15,6 +15,7 @@ import xyz.driver.pdsuidomain.formats.json.sprayformats.trial._ import xyz.driver.pdsuidomain.formats.json.sprayformats.trialhistory._ import xyz.driver.pdsuidomain.formats.json.sprayformats.trialissue._ import xyz.driver.core.swagger.CustomSwaggerJsonConverter._ +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData @@ -32,7 +33,7 @@ object CustomSwaggerJsonFormats { ) val customTrialCurationProperties = immutable.Map[Class[_], Property]( classOf[Trial.Status] -> stringProperty(), - classOf[Trial.Condition] -> stringProperty(), + classOf[CancerType] -> stringProperty(), classOf[TrialHistory.Action] -> stringProperty(), classOf[TrialHistory.State] -> stringProperty() ) ++ customCommonProperties diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala index 193ef11..598b11e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Patient.scala @@ -61,7 +61,7 @@ final case class Patient(id: UuidId[Patient], previousAssignee: Option[StringId[User]], lastActiveUserId: Option[StringId[User]], isUpdateRequired: Boolean, - cancerType: CancerType, + disease: CancerType, orderId: PatientOrderId, lastUpdate: LocalDateTime) { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala deleted file mode 100644 index bdbc4ea..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala +++ /dev/null @@ -1,32 +0,0 @@ -package xyz.driver.pdsuidomain.entities - -import java.time.LocalDateTime - -import xyz.driver.entities.labels.Label -import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} -import xyz.driver.pdsuicommon.logging._ - -final case class RawTrialLabel(nctId: StringId[Trial], - trialId: UuidId[Trial], - condition: String, - lastReviewed: LocalDateTime, - armName: String, - armId: LongId[Arm], - labelId: LongId[Label], - value: Option[Boolean], - criterionId: LongId[Criterion], - criteria: String, - criterionArmId: LongId[Arm], - isCompound: Boolean, - isDefining: Boolean) - -object RawTrialLabel { - - implicit def toPhiString(x: RawTrialLabel): PhiString = { - import x._ - phi"RawTrialLabel(nctId=$nctId, trialId=$trialId, condition=${Unsafe(condition)}, lastReviewed=$lastReviewed, " + - phi"armId=$armId, armName=${Unsafe(armName)}, labelId=$labelId, value=$value, " + - phi"criterionId=$criterionId, criteria=${Unsafe(criteria)}, criterionArmId=$criterionArmId, " + - phi"isCompound=$isCompound, isDefining=$isDefining)" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala index db4def2..7584e9c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala @@ -2,10 +2,11 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDateTime +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain.{LongId, StringId, User, UuidId} import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuicommon.utils.Utils -import xyz.driver.pdsuidomain.entities.Trial.{Condition, Status} +import xyz.driver.pdsuidomain.entities.Trial.Status final case class StudyDesign(id: LongId[StudyDesign], name: String) @@ -58,24 +59,6 @@ object Trial { } final case class Locations(locations: List[String]) - - sealed trait Condition - - object Condition { - - case object Breast extends Condition - case object Lung extends Condition - case object Prostate extends Condition - - def fromString(condition: String): Option[Condition] = condition match { - case "Breast" => Some(Breast) - case "Lung" => Some(Lung) - case "Prostate" => Some(Prostate) - case _ => None - } - - val All: Set[Condition] = Set(Breast, Lung, Prostate) - } } final case class Trial(id: StringId[Trial], @@ -86,7 +69,7 @@ final case class Trial(id: StringId[Trial], previousAssignee: Option[StringId[User]], lastActiveUserId: Option[StringId[User]], lastUpdate: LocalDateTime, - condition: Condition, + disease: CancerType, phase: String, hypothesisId: Option[UuidId[Hypothesis]], studyDesignId: Option[LongId[StudyDesign]], diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala index 1f06e0d..385bbbe 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.entities.export.trial import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, RawTrialLabel} +import xyz.driver.pdsuidomain.entities.{Arm, Criterion} final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion], value: Option[Boolean], @@ -20,14 +20,4 @@ object ExportTrialLabelCriterion { phi"TrialLabelCriterion(criterionId=$criterionId, value=$value, labelId=$labelId, " + phi"criteria=${Unsafe(criteria)}, isCompound=$isCompound, isDefining=$isDefining)" } - - def fromRaw(x: RawTrialLabel, armIds: Set[LongId[Arm]]) = ExportTrialLabelCriterion( - criterionId = x.criterionId, - value = x.value, - labelId = x.labelId, - armIds = armIds, - criteria = x.criteria, - isCompound = x.isCompound, - isDefining = x.isDefining - ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala index cf55694..3a9434b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala @@ -4,13 +4,11 @@ import java.time.LocalDateTime import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{RawTrialLabel, Trial} - -import scala.collection.breakOut +import xyz.driver.pdsuidomain.entities.Trial final case class ExportTrialWithLabels(nctId: StringId[Trial], trialId: UuidId[Trial], - condition: String, + disease: String, lastReviewed: LocalDateTime, labelVersion: Long, arms: List[ExportTrialArm], @@ -20,35 +18,7 @@ object ExportTrialWithLabels { implicit def toPhiString(x: ExportTrialWithLabels): PhiString = { import x._ - phi"TrialWithLabels(nctId=$nctId, trialId=$trialId, condition=${Unsafe(condition)}, " + + phi"TrialWithLabels(nctId=$nctId, trialId=$trialId, disease=${Unsafe(disease)}, " + phi"lastReviewed=$lastReviewed, labelVersion=${Unsafe(labelVersion)}, arms=$arms, criteria=$criteria)" } - - def fromRaw(rawData: List[RawTrialLabel]): ExportTrialWithLabels = { - val trials: Set[StringId[Trial]] = rawData.map(_.nctId)(breakOut) - - assert(trials.size == 1, "There are more than one trial in the rawData") - val trial = rawData.head - - ExportTrialWithLabels( - nctId = trial.nctId, - trialId = trial.trialId, - condition = trial.condition, - lastReviewed = trial.lastReviewed, - labelVersion = 1, // TODO It is needed to replace this mock label version. - arms = rawData - .groupBy(_.armId) - .map { - case (armId, rawTrials) => - ExportTrialArm(armId, rawTrials.head.armName) - }(breakOut), - criteria = rawData - .groupBy(x => (x.criterionId, x.labelId)) - .map { - case (_, rawTrialLabels) => - val armIds = rawTrialLabels.map(_.criterionArmId).toSet - ExportTrialLabelCriterion.fromRaw(rawTrialLabels.head, armIds) - }(breakOut) - ) - } } 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 a38d52c..f77c2e0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala @@ -29,8 +29,6 @@ object common { 1 + Random.nextInt(28) // all months have at least 28 days ) - def nextCondition = generators.oneOf[Trial.Condition](Trial.Condition.All) - def nextTrialAction = generators.oneOf[TrialHistory.Action](TrialHistory.Action.All) def nextTrialState = generators.oneOf[TrialHistory.State](TrialHistory.State.All) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala index 7f3c410..a3ba562 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -26,7 +26,7 @@ object export { ExportTrialWithLabels( nctId = nextStringId[Trial], trialId = nextUuidId[Trial], - condition = nextString(100), + disease = nextString(100), lastReviewed = nextLocalDateTime, labelVersion = nextInt(100).toLong, arms = listOf(nextExportTrialArm()), 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 9a5022c..069d1f1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -1,6 +1,7 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.entities.labels.{Label, LabelCategory} +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain.{LongId, User} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion @@ -19,7 +20,7 @@ object trialcuration { previousAssignee = Option(nextStringId[User]), lastActiveUserId = Option(nextStringId[User]), lastUpdate = nextLocalDateTime, - condition = nextCondition, + disease = generators.oneOf[CancerType](CancerType.Breast, CancerType.Lung, CancerType.Prostate), phase = generators.nextString(), hypothesisId = Option(nextUuidId[Hypothesis]), studyDesignId = Option(nextLongId[StudyDesign]), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala index ad6bc80..585d4ed 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala @@ -19,7 +19,7 @@ final case class ApiPatient(id: String, previousAssignee: Option[String], lastActiveUser: Option[String], lastUpdate: ZonedDateTime, - condition: String, + disease: String, orderId: UUID) { private def extractStatus(status: String): Patient.Status = @@ -45,9 +45,9 @@ final case class ApiPatient(id: String, previousAssignee = this.previousAssignee.map(StringId(_)), lastActiveUserId = this.lastActiveUser.map(StringId(_)), isUpdateRequired = false, - cancerType = patient.CancerType - .fromString(this.condition) - .getOrElse(throw new IllegalArgumentException(s"Unknown cancer type ${this.condition}")), + disease = patient.CancerType + .fromString(this.disease) + .getOrElse(throw new IllegalArgumentException(s"Unknown cancer type ${this.disease}")), orderId = PatientOrderId(this.orderId), lastUpdate = this.lastUpdate.toLocalDateTime ) @@ -66,7 +66,7 @@ object ApiPatient { (JsPath \ "previousAssignee").formatNullable[String] and (JsPath \ "lastActiveUser").formatNullable[String] and (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "condition").format[String] and + (JsPath \ "disease").format[String] and (JsPath \ "orderId").format[UUID] )(ApiPatient.apply, unlift(ApiPatient.unapply)) @@ -80,7 +80,7 @@ object ApiPatient { previousAssignee = patient.previousAssignee.map(_.id), lastActiveUser = patient.lastActiveUserId.map(_.id), lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")), - condition = patient.cancerType.toString, + disease = patient.disease.toString, orderId = patient.orderId.id ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala index 3da76c1..2b0dfe5 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala @@ -40,7 +40,7 @@ object patient { "previousAssignee" -> patient.previousAssignee.toJson, "lastActiveUser" -> patient.lastActiveUserId.toJson, "lastUpdate" -> patient.lastUpdate.toJson, - "condition" -> patient.cancerType.toJson, + "disease" -> patient.disease.toJson, "orderId" -> patient.orderId.toJson ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala index 8000a27..d851c2c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala @@ -6,6 +6,7 @@ import spray.json._ import xyz.driver.core.json.EnumJsonFormat import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuidomain.entities._ +import xyz.driver.formats.json.patient._ object trial { import DefaultJsonProtocol._ @@ -24,12 +25,6 @@ object trial { "Archived" -> Status.Archived ) - implicit val conditionFormat = new EnumJsonFormat[Condition]( - "Breast" -> Condition.Breast, - "Lung" -> Condition.Lung, - "Prostate" -> Condition.Prostate - ) - implicit val trialWriter: RootJsonWriter[Trial] = new RootJsonWriter[Trial] { override def write(obj: Trial) = JsObject( @@ -41,7 +36,7 @@ object trial { "previousStatus" -> obj.previousStatus.toJson, "previousAssignee" -> obj.previousAssignee.toJson, "lastActiveUser" -> obj.lastActiveUserId.toJson, - "condition" -> obj.condition.toJson, + "disease" -> obj.disease.toJson, "phase" -> obj.phase.toJson, "hypothesisId" -> obj.hypothesisId.toJson, "studyDesignId" -> obj.studyDesignId.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala index 1b4ac64..a2a1ca9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala @@ -2,11 +2,12 @@ package xyz.driver.pdsuidomain.formats.json.trial import java.time.{ZoneId, ZonedDateTime} import java.util.UUID -import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.Trial import play.api.libs.functional.syntax._ import play.api.libs.json._ +import xyz.driver.entities.patient.CancerType final case class ApiTrial(id: String, externalId: UUID, @@ -16,7 +17,7 @@ final case class ApiTrial(id: String, previousStatus: Option[String], previousAssignee: Option[String], lastActiveUser: Option[String], - condition: String, + disease: String, phase: String, hypothesisId: Option[UUID], studyDesignId: Option[Long], @@ -37,11 +38,9 @@ final case class ApiTrial(id: String, previousAssignee = this.previousAssignee.map(id => StringId(id)), lastActiveUserId = this.lastActiveUser.map(id => StringId(id)), lastUpdate = this.lastUpdate.toLocalDateTime, - condition = Trial.Condition - .fromString(this.condition) - .getOrElse( - throw new NoSuchElementException(s"unknown condition ${this.condition}") - ), + disease = CancerType + .fromString(this.disease) + .getOrElse(throw new NoSuchElementException(s"Unknown disease ${this.disease}")), phase = this.phase, hypothesisId = this.hypothesisId.map(id => UuidId(id)), studyDesignId = this.studyDesignId.map(id => LongId(id)), @@ -67,7 +66,7 @@ object ApiTrial { (JsPath \ "previousStatus").formatNullable[String] and (JsPath \ "previousAssignee").formatNullable[String] and (JsPath \ "lastActiveUser").formatNullable[String] and - (JsPath \ "condition").format[String] and + (JsPath \ "disease").format[String] and (JsPath \ "phase").format[String] and (JsPath \ "hypothesisId").formatNullable[UUID] and (JsPath \ "studyDesignId").formatNullable[Long] and @@ -89,7 +88,7 @@ object ApiTrial { previousAssignee = trial.previousAssignee.map(_.id), lastActiveUser = trial.lastActiveUserId.map(_.id), lastUpdate = ZonedDateTime.of(trial.lastUpdate, ZoneId.of("Z")), - condition = trial.condition.toString, + disease = trial.disease.toString, phase = trial.phase, hypothesisId = trial.hypothesisId.map(_.id), studyDesignId = trial.studyDesignId.map(_.id), diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala index c6ab2d2..92233e4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala @@ -5,6 +5,7 @@ import java.time.LocalDateTime import akka.NotUsed import akka.stream.scaladsl.Source import akka.util.ByteString +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.StringId @@ -108,10 +109,10 @@ trait TrialService { def getById(id: StringId[Trial])(implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply] - def getTrialWithLabels(trialId: StringId[Trial], condition: String)( + def getTrialWithLabels(trialId: StringId[Trial], cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] - def getTrialsWithLabels(condition: String)( + def getTrialsWithLabels(cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] def getPdfSource(trialId: StringId[Trial])( diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index cd62d48..a1efdac 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -7,6 +7,7 @@ import akka.stream.scaladsl.Source import akka.util.ByteString import xyz.driver.core.generators import xyz.driver.entities.labels.Label +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} @@ -29,7 +30,7 @@ class FakeTrialService extends TrialService { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.now(), - condition = Trial.Condition.Breast, + disease = CancerType.Breast, phase = "", hypothesisId = None, studyDesignId = None, @@ -57,11 +58,11 @@ class FakeTrialService extends TrialService { implicit requestContext: AuthenticatedRequestContext): Future[GetListReply] = Future.successful(GetListReply.EntityList(Seq(trial), 1, None)) - override def getTrialWithLabels(trialId: StringId[Trial], condition: String)( + override def getTrialWithLabels(trialId: StringId[Trial], cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] = Future.successful(GetTrialWithLabelsReply.Entity(nextExportTrialWithLabels())) - override def getTrialsWithLabels(condition: String)( + override def getTrialsWithLabels(cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] = Future.successful(GetTrialsWithLabelsReply.EntityList(generators.seqOf(nextExportTrialWithLabels()))) diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala index 42f32fc..ea719e1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala @@ -18,6 +18,7 @@ import xyz.driver.pdsuidomain.formats.json.trial.ApiTrial import xyz.driver.pdsuidomain.services.TrialService import spray.json.DefaultJsonProtocol._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuidomain.formats.json.sprayformats.export._ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit protected val materializer: Materializer, @@ -37,9 +38,9 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote } } - def getTrialWithLabels(trialId: StringId[Trial], disease: String)( + def getTrialWithLabels(trialId: StringId[Trial], cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] = { - val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$disease/$trialId")) + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$cancerType/$trialId")) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[ExportTrialWithLabels](response) @@ -48,9 +49,9 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote } } - def getTrialsWithLabels(disease: String)( + def getTrialsWithLabels(cancerType: CancerType)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] = { - val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$disease")) + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$cancerType")) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[Seq[ExportTrialWithLabels]](response) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala index 05f5863..402e893 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala @@ -107,7 +107,7 @@ class ExportFormatSuite extends FlatSpec with Matchers { val trialWithLabels = ExportTrialWithLabels( nctId = StringId("NCT000001"), trialId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"), - condition = "Breast", + disease = "Breast", lastReviewed = LocalDateTime.parse("2017-08-10T18:00:00"), labelVersion = 1L, arms = arms, diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala index f48625c..31f541f 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientEligibleTrialFormatSuite.scala @@ -5,6 +5,7 @@ import java.time.LocalDateTime import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.entities.labels.LabelValue +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{PatientCriterionArm, PatientTrialArmGroupView, Trial} import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial @@ -22,7 +23,7 @@ class PatientEligibleTrialFormatSuite extends FlatSpec with Matchers { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"), - condition = Trial.Condition.Breast, + disease = CancerType.Breast, phase = "", hypothesisId = Some(UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4")), studyDesignId = Some(LongId(321)), diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala index 443c8e8..ad12b3b 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientFormatSuite.scala @@ -23,7 +23,7 @@ class PatientFormatSuite extends FlatSpec with Matchers { previousAssignee = None, lastActiveUserId = None, isUpdateRequired = false, - cancerType = CancerType.Breast, + disease = CancerType.Breast, orderId = PatientOrderId("7b54a75d-4197-4b27-9045-b9b6cb131be9"), lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") ) @@ -33,7 +33,7 @@ class PatientFormatSuite extends FlatSpec with Matchers { """{"id":"748b5884-3528-4cb9-904b-7a8151d6e343","dob":"1980-06-30", "name":{"firstName":"John","middleName":"","lastName":"Doe"},"status":"New","assignee":null, "previousStatus":null,"previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z", - "orderId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","condition":"Breast"}""".parseJson) + "orderId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","disease":"Breast"}""".parseJson) } } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala index 59cf779..beb69c4 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala @@ -4,6 +4,7 @@ import java.time.LocalDateTime import spray.json._ import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.entities.patient.CancerType import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.Trial @@ -20,7 +21,7 @@ class TrialFormatSuite extends FlatSpec with Matchers { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"), - condition = Trial.Condition.Breast, + disease = CancerType.Breast, phase = "", hypothesisId = Some(UuidId("3b80b2e2-5372-4cf5-a342-6e4ebe10fafd")), studyDesignId = Some(LongId(321)), @@ -39,7 +40,7 @@ class TrialFormatSuite extends FlatSpec with Matchers { "isUpdated":false,"overviewTemplate":"","phase":"","originalStudyDesignId":null, "hypothesisId":"3b80b2e2-5372-4cf5-a342-6e4ebe10fafd","originalTitle":"orig trial title", "studyDesignId":321,"lastActiveUser":null,"externalid":"40892a07-c638-49d2-9795-1edfefbbcc7c", - "id":"NCT000001","condition":"Breast","status":"New","overview":null,"previousAssignee":null,"title":"trial title"}""".parseJson) + "id":"NCT000001","disease":"Breast","status":"New","overview":null,"previousAssignee":null,"title":"trial title"}""".parseJson) val updateTrialJson = """{"hypothesisId":null,"overview":"new overview"}""".parseJson val expectedUpdatedTrial = orig.copy(hypothesisId = None, overview = Some("new overview")) -- cgit v1.2.3 From c404ab936d5c2ebaae8246ed658086d66e7c9a61 Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 9 Oct 2017 20:00:22 -0700 Subject: Update PatientLabelEvidenceView to support to Provider and Document type --- .../driver/pdsuidomain/entities/PatientLabelEvidenceView.scala | 4 ++-- .../formats/json/evidence/ApiPatientLabelEvidence.scala | 4 ++-- .../pdsuidomain/formats/json/sprayformats/patientlabel.scala | 2 ++ .../formats/json/sprayformats/PatientLabelFormatSuite.scala | 9 +++++---- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/test/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala index 2dbe099..6055921 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala @@ -21,9 +21,9 @@ final case class PatientLabelEvidenceView(id: LongId[PatientLabelEvidence], documentId: Option[LongId[Document]], evidenceId: Option[LongId[ExtractedData]], reportId: Option[UuidId[DirectReport]], - documentType: String, + documentType: DocumentType, date: Option[LocalDate], // Document.startDate is optional - providerType: String, + providerType: ProviderType, patientId: UuidId[Patient], labelId: LongId[Label], isImplicitMatch: Boolean) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala index 7409e90..c7a6de9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala @@ -26,8 +26,8 @@ object ApiPatientLabelEvidence { documentId = x.documentId.map(_.id), evidenceId = x.evidenceId.map(_.id), reportId = x.reportId.map(_.toString), - documentType = x.documentType, + documentType = x.documentType.name, date = x.date.get, - providerType = x.providerType + providerType = x.providerType.name ) } 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 ff6d24d..57dca1e 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 @@ -5,6 +5,8 @@ import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel import xyz.driver.formats.json.labels._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.record._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.document._ object patientlabel { import DefaultJsonProtocol._ 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 47b251a..e837861 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,7 +6,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuidomain.entities.{PatientLabel, PatientLabelEvidenceView} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel class PatientLabelFormatSuite extends FlatSpec with Matchers { @@ -44,9 +44,9 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { documentId = Some(LongId(21)), evidenceId = Some(LongId(10)), reportId = None, - documentType = "document type", + documentType = DocumentType.LaboratoryReport, date = Some(LocalDate.parse("2017-08-10")), - providerType = "provider type", + providerType = ProviderType.EmergencyMedicine, patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), labelId = LongId(20), isImplicitMatch = false @@ -55,7 +55,8 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { writtenJson should be ( """{"id":1,"value":"Maybe","evidenceText":"evidence text","documentId":21,"evidenceId":10,"reportId":null, - "documentType":"document type","date":"2017-08-10","providerType":"provider type"}""".parseJson) + "documentType":{"id":3,"name":"Laboratory Report"},"date":"2017-08-10", + "providerType":{"id":26,"name":"Emergency Medicine"}}""".parseJson) } "Json format for PatientLabelDefiningCriteria" should "read and write correct JSON" in { -- cgit v1.2.3 From 6a692412fd7e2ab07a10065d5d2a07d86edd03cc Mon Sep 17 00:00:00 2001 From: Marvin Bertin Date: Tue, 10 Oct 2017 13:27:40 -0700 Subject: add disease list to ExportTrialArm --- .../entities/export/trial/ExportTrialArm.scala | 2 +- .../entities/export/trial/ExportTrialWithLabels.scala | 3 +-- .../xyz/driver/pdsuidomain/fakes/entities/export.scala | 7 +++---- .../pdsuidomain/formats/json/sprayformats/export.scala | 17 +++++------------ .../pdsuidomain/services/fake/FakeTrialService.scala | 4 ++-- .../formats/json/sprayformats/ExportFormatSuite.scala | 11 +++++------ 6 files changed, 17 insertions(+), 27 deletions(-) (limited to 'src/test/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala index 5a9a406..b2ed7fb 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala @@ -4,7 +4,7 @@ import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.Arm -final case class ExportTrialArm(armId: LongId[Arm], armName: String) +final case class ExportTrialArm(armId: LongId[Arm], armName: String, diseaseList: Seq[String]) object ExportTrialArm { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala index 3a9434b..3681945 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala @@ -8,7 +8,6 @@ import xyz.driver.pdsuidomain.entities.Trial final case class ExportTrialWithLabels(nctId: StringId[Trial], trialId: UuidId[Trial], - disease: String, lastReviewed: LocalDateTime, labelVersion: Long, arms: List[ExportTrialArm], @@ -18,7 +17,7 @@ object ExportTrialWithLabels { implicit def toPhiString(x: ExportTrialWithLabels): PhiString = { import x._ - phi"TrialWithLabels(nctId=$nctId, trialId=$trialId, disease=${Unsafe(disease)}, " + + phi"TrialWithLabels(nctId=$nctId, trialId=$trialId}, " + phi"lastReviewed=$lastReviewed, labelVersion=${Unsafe(labelVersion)}, arms=$arms, criteria=$criteria)" } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala index a3ba562..b769893 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -1,15 +1,15 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.entities.labels.Label -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Trial} import xyz.driver.pdsuidomain.entities.export.trial._ +import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Trial} object export { - import xyz.driver.core.generators._ import common._ + import xyz.driver.core.generators._ def nextExportTrialArm(): ExportTrialArm = - ExportTrialArm(armId = nextLongId[Arm], armName = nextString(100)) + ExportTrialArm(armId = nextLongId[Arm], armName = nextString(100), diseaseList = listOf(nextString(100))) def nextExportTrialLabelCriterion(): ExportTrialLabelCriterion = ExportTrialLabelCriterion( @@ -26,7 +26,6 @@ object export { ExportTrialWithLabels( nctId = nextStringId[Trial], trialId = nextUuidId[Trial], - disease = nextString(100), lastReviewed = nextLocalDateTime, labelVersion = nextInt(100).toLong, arms = listOf(nextExportTrialArm()), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala index 85d614d..0fe85ea 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala @@ -2,16 +2,16 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.entities.labels.Label -import xyz.driver.pdsuidomain.entities.{Arm, Criterion} +import xyz.driver.formats.json.labels._ import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} -import xyz.driver.formats.json.labels._ +import xyz.driver.pdsuidomain.entities.{Arm, Criterion} object export { import DefaultJsonProtocol._ import common._ - import record._ import document._ + import record._ implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5(ExportPatientLabelEvidenceDocument.apply) @@ -25,7 +25,7 @@ object export { implicit val patientWithLabelsFormat: RootJsonFormat[ExportPatientWithLabels] = jsonFormat(ExportPatientWithLabels.apply, "patientId", "labelVersion", "labels") - implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat2(ExportTrialArm.apply) + implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat3(ExportTrialArm.apply) implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] = new RootJsonFormat[ExportTrialLabelCriterion] { @@ -82,12 +82,5 @@ object export { } implicit val trialWithLabelsFormat: RootJsonFormat[ExportTrialWithLabels] = - jsonFormat(ExportTrialWithLabels.apply, - "nctId", - "trialId", - "disease", - "lastReviewed", - "labelVersion", - "arms", - "criteria") + jsonFormat(ExportTrialWithLabels.apply, "nctId", "trialId", "lastReviewed", "labelVersion", "arms", "criteria") } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index cb7f8bc..37c3de5 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -69,13 +69,13 @@ class FakeTrialService extends TrialService { ExportTrialWithLabels( StringId[Trial]("NCT" + generators.nextInt(999999).toString), UuidId[Trial](generators.nextUuid()), - generators.oneOf("adenocarcinoma", "breast", "prostate"), LocalDateTime.now(), labelVersion = 1L, generators.listOf( new ExportTrialArm( LongId[Arm](generators.nextInt(999999).toLong), - generators.nextName().value + generators.nextName().value, + generators.listOf(generators.oneOf("adenocarcinoma", "breast", "prostate")) )), generators.listOf( new ExportTrialLabelCriterion( diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala index 402e893..41d7825 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala @@ -3,8 +3,8 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import java.time.{LocalDate, LocalDateTime} import java.util.UUID -import spray.json._ import org.scalatest.{FlatSpec, Matchers} +import spray.json._ import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{DocumentType, ProviderType, RecordRequestId} @@ -81,8 +81,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { "Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in { import xyz.driver.pdsuidomain.entities.export.trial._ val arms = List( - ExportTrialArm(armId = LongId(1), armName = "arm 1"), - ExportTrialArm(armId = LongId(2), armName = "arm 2") + ExportTrialArm(armId = LongId(1), armName = "arm 1", diseaseList = Seq("Breast")), + ExportTrialArm(armId = LongId(2), armName = "arm 2", diseaseList = Seq("Breast")) ) val criteriaList = List( ExportTrialLabelCriterion( @@ -107,7 +107,6 @@ class ExportFormatSuite extends FlatSpec with Matchers { val trialWithLabels = ExportTrialWithLabels( nctId = StringId("NCT000001"), trialId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"), - disease = "Breast", lastReviewed = LocalDateTime.parse("2017-08-10T18:00:00"), labelVersion = 1L, arms = arms, @@ -116,8 +115,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { val writtenJson = trialWithLabelsFormat.write(trialWithLabels) writtenJson should be( - """{"nctId":"NCT000001","trialId":"40892a07-c638-49d2-9795-1edfefbbcc7c","disease":"Breast","lastReviewed":"2017-08-10T18:00Z", - "labelVersion":1,"arms":[{"armId":1,"armName":"arm 1"},{"armId":2,"armName":"arm 2"}],"criteria":[ + """{"nctId":"NCT000001","trialId":"40892a07-c638-49d2-9795-1edfefbbcc7c","lastReviewed":"2017-08-10T18:00Z", + "labelVersion":1,"arms":[{"armId":1,"armName":"arm 1", "diseaseList":["Breast"]},{"armId":2,"armName":"arm 2", "diseaseList":["Breast"]}],"criteria":[ {"value":"Yes","labelId":21,"criterionId":10,"criterionText":"criteria 10 text","armIds":[1,2],"isCompound":false,"isDefining":false}, {"value":"Unknown","labelId":21,"criterionId":11,"criterionText":"criteria 11 text","armIds":[2],"isCompound":true,"isDefining":false}]}""".parseJson) } -- cgit v1.2.3 From 9c95eb7247cb0818af9a9e4afe884698360f994c Mon Sep 17 00:00:00 2001 From: Marvin Bertin Date: Tue, 10 Oct 2017 15:20:08 -0700 Subject: fix exports with EligibilityArms --- .../entities/export/trial/ExportTrialLabelCriterion.scala | 4 ++-- src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala | 4 ++-- .../xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala | 4 ++-- .../xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala | 4 ++-- .../pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/test/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala index 385bbbe..8376e34 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala @@ -3,12 +3,12 @@ package xyz.driver.pdsuidomain.entities.export.trial import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{Arm, Criterion} +import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm} final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion], value: Option[Boolean], labelId: LongId[Label], - armIds: Set[LongId[Arm]], + armIds: Set[LongId[EligibilityArm]], criteria: String, isCompound: Boolean, isDefining: Boolean) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala index 7221d28..5febd8f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.entities.labels.Label import xyz.driver.pdsuidomain.entities.export.trial._ -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, EligibilityArm, Trial} +import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm, Trial} object export { import common._ @@ -16,7 +16,7 @@ object export { criterionId = nextLongId[Criterion], value = nextOption[Boolean](nextBoolean()), labelId = nextLongId[Label], - armIds = setOf(nextLongId[Arm]), + armIds = setOf(nextLongId[EligibilityArm]), criteria = nextString(100), isCompound = nextBoolean(), isDefining = nextBoolean() diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala index 8a67469..1c4b6b4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala @@ -5,7 +5,7 @@ import xyz.driver.entities.labels.Label import xyz.driver.formats.json.labels._ import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} -import xyz.driver.pdsuidomain.entities.{Arm, Criterion} +import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm} object export { import DefaultJsonProtocol._ @@ -68,7 +68,7 @@ object export { longIdFormat[Criterion].read(criterionId), value, longIdFormat[Label].read(labelId), - armIdsVector.map(longIdFormat[Arm].read).toSet, + armIdsVector.map(longIdFormat[EligibilityArm].read).toSet, criterionText, isCompound, isDefining diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index 517b563..0431d95 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -12,7 +12,7 @@ import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, EligibilityArm, Trial} +import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm, Trial} import xyz.driver.pdsuidomain.services.TrialService import scala.concurrent.Future @@ -81,7 +81,7 @@ class FakeTrialService extends TrialService { LongId[Criterion](generators.nextInt(999999).toLong), generators.nextOption(generators.nextBoolean()), LongId[Label](generators.nextInt(999999).toLong), - generators.setOf(LongId[Arm](generators.nextInt(999999).toLong)), + generators.setOf(LongId[EligibilityArm](generators.nextInt(999999).toLong)), generators.nextName().value, generators.nextBoolean(), generators.nextBoolean() diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala index 41d7825..3eaf93f 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala @@ -81,8 +81,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { "Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in { import xyz.driver.pdsuidomain.entities.export.trial._ val arms = List( - ExportTrialArm(armId = LongId(1), armName = "arm 1", diseaseList = Seq("Breast")), - ExportTrialArm(armId = LongId(2), armName = "arm 2", diseaseList = Seq("Breast")) + ExportTrialArm(armId = LongId(1), armName = "arm 1"), + ExportTrialArm(armId = LongId(2), armName = "arm 2") ) val criteriaList = List( ExportTrialLabelCriterion( @@ -116,7 +116,7 @@ class ExportFormatSuite extends FlatSpec with Matchers { val writtenJson = trialWithLabelsFormat.write(trialWithLabels) writtenJson should be( """{"nctId":"NCT000001","trialId":"40892a07-c638-49d2-9795-1edfefbbcc7c","lastReviewed":"2017-08-10T18:00Z", - "labelVersion":1,"arms":[{"armId":1,"armName":"arm 1", "diseaseList":["Breast"]},{"armId":2,"armName":"arm 2", "diseaseList":["Breast"]}],"criteria":[ + "labelVersion":1,"arms":[{"armId":1,"armName":"arm 1"},{"armId":2,"armName":"arm 2"}],"criteria":[ {"value":"Yes","labelId":21,"criterionId":10,"criterionText":"criteria 10 text","armIds":[1,2],"isCompound":false,"isDefining":false}, {"value":"Unknown","labelId":21,"criterionId":11,"criterionText":"criteria 11 text","armIds":[2],"isCompound":true,"isDefining":false}]}""".parseJson) } -- cgit v1.2.3