From 133b4fe8487db9df80c1f39f64bbe7d6fc039952 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Mon, 23 Oct 2017 14:46:32 +0700 Subject: Added 'inclusion' field to PatientCriterion --- .../formats/json/sprayformats/PatientCriterionFormatSuite.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') 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 b254013..27e27c2 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 @@ -26,7 +26,8 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { verifiedEligibilityStatus = None, isVisible = true, isVerified = true, - lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") + lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"), + inclusion = Some(true) ) val arms = List( PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(31), armName = "arm 31"), @@ -38,7 +39,7 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { writtenJson should be( """{"id":1,"labelId":21,"nctId":"NCT00001","criterionId":101,"criterionText":"criterion text","criterionValue":"Yes", "criterionIsDefining":false,"criterionIsCompound":false,"eligibilityStatus":"Yes","verifiedEligibilityStatus":null, - "isVisible":true,"isVerified":true,"lastUpdate":"2017-08-10T18:00Z","arms":["arm 31","arm 32"]}""".parseJson) + "isVisible":true,"isVerified":true,"lastUpdate":"2017-08-10T18:00Z","arms":["arm 31","arm 32"],"inclusion":true}""".parseJson) val updatePatientCriterionJson = """{"verifiedEligibilityStatus":"No"}""".parseJson val expectedUpdatedPatientCriterion = orig.copy(verifiedEligibilityStatus = Some(LabelValue.No)) -- cgit v1.2.3 From b99235a22bfabeb175c297660d9dccc27c7b4daf Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 23 Oct 2017 19:40:57 +0700 Subject: Fixed update delivery method --- .../pdsuidomain/formats/json/sprayformats/intervention.scala | 5 +++-- .../formats/json/sprayformats/InterventionFormatSuite.scala | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala index e557e47..fccdda4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala @@ -99,7 +99,8 @@ object intervention { val deliveryMethod = fields .get("deliveryMethod") - .map(_.convertTo[String]) + .map(_.convertTo[Option[String]]) + .getOrElse(orig.intervention.deliveryMethod) val origIntervention = orig.intervention val arms = fields @@ -112,7 +113,7 @@ object intervention { typeId = typeId.orElse(origIntervention.typeId), dosage = dosage.getOrElse(origIntervention.dosage), isActive = isActive.getOrElse(origIntervention.isActive), - deliveryMethod = deliveryMethod.orElse(origIntervention.deliveryMethod) + deliveryMethod = deliveryMethod ), arms = arms.getOrElse(orig.arms) ) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala index 4532da4..edce9c1 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala @@ -19,7 +19,7 @@ class InterventionFormatSuite extends FlatSpec with Matchers { dosage = "", originalDosage = "", isActive = true, - deliveryMethod = Some("pill") + deliveryMethod = Some("Inhalation") ) val arms = List( InterventionArm(interventionId = intervention.id, armId = LongId(20)), @@ -34,11 +34,11 @@ class InterventionFormatSuite extends FlatSpec with Matchers { writtenJson should be( """{"id":1,"name":"intervention name","typeId":10,"dosage":"","isActive":true,"arms":[20,21,22], - "trialId":"NCT000001","deliveryMethod":"pill","originalName":"orig name","originalDosage":"","originalType":"orig type"}""".parseJson) + "trialId":"NCT000001","deliveryMethod":"Inhalation","originalName":"orig name","originalDosage":"","originalType":"orig type"}""".parseJson) val createInterventionJson = """{"id":1,"name":"intervention name","typeId":10,"dosage":"","isActive":true,"arms":[20,21,22], - "trialId":"NCT000001","deliveryMethod":"pill"}""".parseJson + "trialId":"NCT000001","deliveryMethod":"Inhalation"}""".parseJson val parsedCreateIntervention = interventionFormat.read(createInterventionJson) val expectedCreateIntervention = parsedCreateIntervention.copy( intervention = intervention.copy(id = LongId(0), originalType = None, originalName = "intervention name"), @@ -46,9 +46,9 @@ class InterventionFormatSuite extends FlatSpec with Matchers { ) parsedCreateIntervention should be(expectedCreateIntervention) - val updateInterventionJson = """{"dosage":"descr","arms":[21,22]}""".parseJson + val updateInterventionJson = """{"dosage":"descr","deliveryMethod":null,"arms":[21,22]}""".parseJson val expectedUpdatedIntervention = orig.copy( - intervention = intervention.copy(dosage = "descr"), + intervention = intervention.copy(dosage = "descr", deliveryMethod = None), arms = List( InterventionArm(interventionId = intervention.id, armId = LongId(21)), InterventionArm(interventionId = intervention.id, armId = LongId(22)) -- cgit v1.2.3 From 3c2a7fdfccc87cb8ec9e8e48c31c622555078c54 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 24 Oct 2017 11:33:55 +0700 Subject: Added field 'inclusion' to ExportTrialLabelCriterion --- .../export/trial/ExportTrialLabelCriterion.scala | 5 +- .../driver/pdsuidomain/fakes/entities/export.scala | 3 +- .../formats/json/sprayformats/export.scala | 86 ++++++++++++++++------ .../services/fake/FakeTrialService.scala | 3 +- .../json/sprayformats/ExportFormatSuite.scala | 12 ++- 5 files changed, 78 insertions(+), 31 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') 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 8376e34..98bd084 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 @@ -11,13 +11,14 @@ final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion], armIds: Set[LongId[EligibilityArm]], criteria: String, isCompound: Boolean, - isDefining: Boolean) + isDefining: Boolean, + inclusion: Option[Boolean]) object ExportTrialLabelCriterion { implicit def toPhiString(x: ExportTrialLabelCriterion): PhiString = { import x._ phi"TrialLabelCriterion(criterionId=$criterionId, value=$value, labelId=$labelId, " + - phi"criteria=${Unsafe(criteria)}, isCompound=$isCompound, isDefining=$isDefining)" + phi"criteria=${Unsafe(criteria)}, isCompound=$isCompound, isDefining=$isDefining), inclusion=${Unsafe(inclusion)}" } } 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 2c7d0e0..33da392 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -28,7 +28,8 @@ object export { armIds = setOf(nextLongId[EligibilityArm]), criteria = nextString(100), isCompound = nextBoolean(), - isDefining = nextBoolean() + isDefining = nextBoolean(), + inclusion = nextOption(nextBoolean()) ) def nextExportTrialWithLabels(): ExportTrialWithLabels = 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 4391453..9579288 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 @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.entities.labels.Label import xyz.driver.formats.json.labels._ +import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm} @@ -13,6 +14,14 @@ object export { import document._ import record._ + private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = { + deserializationError(s"$className json object do not contain '$field' field: $json") + } + + private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = { + deserializationError(s"Expected Json Object as $className, but got $json") + } + implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5(ExportPatientLabelEvidenceDocument.apply) @@ -29,6 +38,8 @@ object export { implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] = new RootJsonFormat[ExportTrialLabelCriterion] { + implicit val className: String = "ExportTrialLabelCriterion" + override def write(obj: ExportTrialLabelCriterion): JsValue = JsObject( "value" -> obj.value @@ -43,40 +54,69 @@ object export { "criterionText" -> obj.criteria.toJson, "armIds" -> obj.armIds.toJson, "isCompound" -> obj.isCompound.toJson, - "isDefining" -> obj.isDefining.toJson + "isDefining" -> obj.isDefining.toJson, + "inclusion" -> obj.inclusion.toJson ) override def read(json: JsValue): ExportTrialLabelCriterion = { + json match { + case JsObject(fields) => + val value = fields + .get("value") + .map(_.convertTo[String]) + .map { + case "Yes" => Option(true) + case "No" => Option(false) + case "Unknown" => Option.empty[Boolean] + } + .getOrElse(deserializationErrorFieldMessage("value", json)) - val fields = Seq("value", "labelId", "criterionId", "criterionText", "armIds", "isCompound", "isDefining") - - json.asJsObject.getFields(fields: _*) match { - case Seq(JsString(valueString), - labelId, - criterionId, - JsString(criterionText), - JsArray(armIdsVector), - JsBoolean(isCompound), - JsBoolean(isDefining)) => - val value = valueString match { - case "Yes" => Option(true) - case "No" => Option(false) - case "Unknown" => Option.empty[Boolean] - } + val labelId = fields + .get("labelId") + .map(_.convertTo[LongId[Label]]) + .getOrElse(deserializationErrorFieldMessage("labelId", json)) + + val criterionId = fields + .get("criterionId") + .map(_.convertTo[LongId[Criterion]]) + .getOrElse(deserializationErrorFieldMessage("criterionId", json)) + + val criterionText = fields + .get("criterionText") + .map(_.convertTo[String]) + .getOrElse(deserializationErrorFieldMessage("criterionText", json)) + + val armIds = fields + .get("armIds") + .map(_.convertTo[Set[LongId[EligibilityArm]]]) + .getOrElse(deserializationErrorFieldMessage("armIds", json)) + + val isCompound = fields + .get("isCompound") + .map(_.convertTo[Boolean]) + .getOrElse(deserializationErrorFieldMessage("isCompound", json)) + + val isDefining = fields + .get("isDefining") + .map(_.convertTo[Boolean]) + .getOrElse(deserializationErrorFieldMessage("isDefining", json)) + + val inclusion = fields + .get("inclusion") + .flatMap(_.convertTo[Option[Boolean]]) ExportTrialLabelCriterion( - longIdFormat[Criterion].read(criterionId), + criterionId, value, - longIdFormat[Label].read(labelId), - armIdsVector.map(longIdFormat[EligibilityArm].read).toSet, + labelId, + armIds, criterionText, isCompound, - isDefining + isDefining, + inclusion ) - case _ => - deserializationError( - s"Cannot find required fields ${fields.mkString(", ")} in ExportTrialLabelCriterion object!") + case _ => deserializationErrorEntityMessage(json) } } } 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 e0efcd1..e23449c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -85,7 +85,8 @@ class FakeTrialService extends TrialService { generators.setOf(LongId[EligibilityArm](generators.nextInt(999999).toLong)), generators.nextName().value, generators.nextBoolean(), - generators.nextBoolean() + generators.nextBoolean(), + generators.nextOption(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 d78e754..767f832 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 @@ -92,7 +92,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { armIds = Set(LongId(1), LongId(2)), criteria = "criteria 10 text", isCompound = false, - isDefining = false + isDefining = false, + inclusion = Some(false) ), ExportTrialLabelCriterion( criterionId = LongId(11), @@ -101,7 +102,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { armIds = Set(LongId(2)), criteria = "criteria 11 text", isCompound = true, - isDefining = false + isDefining = false, + inclusion = None ) ) val trialWithLabels = ExportTrialWithLabels( @@ -117,8 +119,10 @@ class ExportFormatSuite extends FlatSpec with Matchers { 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":[ - {"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) + {"value":"Yes","labelId":21,"criterionId":10,"criterionText":"criteria 10 text","armIds":[1,2],"isCompound":false, + "isDefining":false,"inclusion":false}, + {"value":"Unknown","labelId":21,"criterionId":11,"criterionText":"criteria 11 text","armIds":[2],"isCompound":true, + "isDefining":false,"inclusion":null}]}""".parseJson) } } -- cgit v1.2.3 From 72e4fe43bb03d2922a46f54e5a2f51a13c6df63a Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 24 Oct 2017 17:35:37 +0700 Subject: Implemented tests for MedicalRecord.Meta; Fixed MedicalRecord.Meta.Duplicate spray format --- .../formats/json/sprayformats/record.scala | 2 +- .../MedicalRecordMetaFormatSuite.scala | 85 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') 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 d00aa14..60ae437 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 @@ -94,7 +94,7 @@ object record { val endOriginalPage = fields .get("endOriginalPage") - .map(_.convertTo[Double]) + .flatMap(_.convertTo[Option[Double]]) Duplicate( startPage = startPage, diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala new file mode 100644 index 0000000..845bffc --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala @@ -0,0 +1,85 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import org.scalatest.{FlatSpec, Matchers} +import spray.json._ +import xyz.driver.pdsuidomain.entities.MedicalRecord.Meta +import record._ + +class MedicalRecordMetaFormatSuite + extends FlatSpec + with Matchers { + + "Json format for MedicalRecord.Meta" should "read and write correct JSON" in { + val duplicate1 = Meta.Duplicate( + startPage = 1.0d, + endPage = 2.0d, + startOriginalPage = 1.0d, + endOriginalPage = Some(2.0d) + ) + + val duplicate2 = Meta.Duplicate( + startPage = 1.0d, + endPage = 2.0d, + startOriginalPage = 1.0d, + endOriginalPage = None + ) + + val reorder = Meta.Reorder( + Seq(1, 2) + ) + + val rotation = Meta.Rotation( + Map("item1" -> 1, "item2" -> 2) + ) + + val writtenDuplicateJson1 = + duplicateMetaFormat.write(duplicate1) + + val writtenDuplicateJson2 = + duplicateMetaFormat.write(duplicate2) + + val writtenReorderJson = + reorderMetaFormat.write(reorder) + + val writtenRotationJson = + rotateMetaFormat.write(rotation) + + writtenDuplicateJson1 should be( + """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":2.0}""".parseJson) + + writtenDuplicateJson2 should be( + """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":null}""".parseJson) + + writtenReorderJson should be( + """{"type":"reorder","items":[1,2]}""".parseJson) + + writtenRotationJson should be( + """{"type":"rotation","items":{"item1":1,"item2":2}}""".parseJson) + + val parsedDuplicateJson1 = + duplicateMetaFormat.read(writtenDuplicateJson1) + + val parsedDuplicateJson2 = + duplicateMetaFormat.read(writtenDuplicateJson2) + + val parsedReorderJson = + reorderMetaFormat.read(writtenReorderJson) + + val parsedRotationJson = + rotateMetaFormat.read(writtenRotationJson) + + duplicate1 should be(parsedDuplicateJson1) + + duplicate2 should be(parsedDuplicateJson2) + + reorder should be(parsedReorderJson) + + rotation should be(parsedRotationJson) + + duplicate1 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate1))) + duplicate2 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate2))) + reorder should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(reorder))) + rotation should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(rotation))) + } + +} -- cgit v1.2.3 From 91d58df031f5fdac59d70289bf9a7377a3529a9a Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 26 Oct 2017 09:55:50 +0700 Subject: Moved MedicalRecord.Meta tests to MedicalRecordFormatSuite --- .../sprayformats/MedicalRecordFormatSuite.scala | 74 +++++++++++++++++++ .../MedicalRecordMetaFormatSuite.scala | 85 ---------------------- 2 files changed, 74 insertions(+), 85 deletions(-) delete mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') 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 9616e70..363e352 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 @@ -12,6 +12,80 @@ class MedicalRecordFormatSuite extends FlatSpec with Matchers { import record._ import MedicalRecord._ + "Json format for MedicalRecord.Meta" should "read and write correct JSON" in { + val duplicate1 = Meta.Duplicate( + startPage = 1.0d, + endPage = 2.0d, + startOriginalPage = 1.0d, + endOriginalPage = Some(2.0d) + ) + + val duplicate2 = Meta.Duplicate( + startPage = 1.0d, + endPage = 2.0d, + startOriginalPage = 1.0d, + endOriginalPage = None + ) + + val reorder = Meta.Reorder( + Seq(1, 2) + ) + + val rotation = Meta.Rotation( + Map("item1" -> 1, "item2" -> 2) + ) + + val writtenDuplicateJson1 = + duplicateMetaFormat.write(duplicate1) + + val writtenDuplicateJson2 = + duplicateMetaFormat.write(duplicate2) + + val writtenReorderJson = + reorderMetaFormat.write(reorder) + + val writtenRotationJson = + rotateMetaFormat.write(rotation) + + writtenDuplicateJson1 should be( + """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":2.0}""".parseJson) + + writtenDuplicateJson2 should be( + """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":null}""".parseJson) + + writtenReorderJson should be( + """{"type":"reorder","items":[1,2]}""".parseJson) + + writtenRotationJson should be( + """{"type":"rotation","items":{"item1":1,"item2":2}}""".parseJson) + + val parsedDuplicateJson1 = + duplicateMetaFormat.read(writtenDuplicateJson1) + + val parsedDuplicateJson2 = + duplicateMetaFormat.read(writtenDuplicateJson2) + + val parsedReorderJson = + reorderMetaFormat.read(writtenReorderJson) + + val parsedRotationJson = + rotateMetaFormat.read(writtenRotationJson) + + duplicate1 should be(parsedDuplicateJson1) + + duplicate2 should be(parsedDuplicateJson2) + + reorder should be(parsedReorderJson) + + rotation should be(parsedRotationJson) + + duplicate1 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate1))) + duplicate2 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate2))) + reorder should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(reorder))) + rotation should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(rotation))) + } + + "Json format for MedicalRecord" should "read and write correct JSON" in { val orig = MedicalRecord( id = LongId(1), diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala deleted file mode 100644 index 845bffc..0000000 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordMetaFormatSuite.scala +++ /dev/null @@ -1,85 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import org.scalatest.{FlatSpec, Matchers} -import spray.json._ -import xyz.driver.pdsuidomain.entities.MedicalRecord.Meta -import record._ - -class MedicalRecordMetaFormatSuite - extends FlatSpec - with Matchers { - - "Json format for MedicalRecord.Meta" should "read and write correct JSON" in { - val duplicate1 = Meta.Duplicate( - startPage = 1.0d, - endPage = 2.0d, - startOriginalPage = 1.0d, - endOriginalPage = Some(2.0d) - ) - - val duplicate2 = Meta.Duplicate( - startPage = 1.0d, - endPage = 2.0d, - startOriginalPage = 1.0d, - endOriginalPage = None - ) - - val reorder = Meta.Reorder( - Seq(1, 2) - ) - - val rotation = Meta.Rotation( - Map("item1" -> 1, "item2" -> 2) - ) - - val writtenDuplicateJson1 = - duplicateMetaFormat.write(duplicate1) - - val writtenDuplicateJson2 = - duplicateMetaFormat.write(duplicate2) - - val writtenReorderJson = - reorderMetaFormat.write(reorder) - - val writtenRotationJson = - rotateMetaFormat.write(rotation) - - writtenDuplicateJson1 should be( - """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":2.0}""".parseJson) - - writtenDuplicateJson2 should be( - """{"startOriginalPage":1.0,"endPage":2.0,"startPage":1.0,"type":"duplicate","endOriginalPage":null}""".parseJson) - - writtenReorderJson should be( - """{"type":"reorder","items":[1,2]}""".parseJson) - - writtenRotationJson should be( - """{"type":"rotation","items":{"item1":1,"item2":2}}""".parseJson) - - val parsedDuplicateJson1 = - duplicateMetaFormat.read(writtenDuplicateJson1) - - val parsedDuplicateJson2 = - duplicateMetaFormat.read(writtenDuplicateJson2) - - val parsedReorderJson = - reorderMetaFormat.read(writtenReorderJson) - - val parsedRotationJson = - rotateMetaFormat.read(writtenRotationJson) - - duplicate1 should be(parsedDuplicateJson1) - - duplicate2 should be(parsedDuplicateJson2) - - reorder should be(parsedReorderJson) - - rotation should be(parsedRotationJson) - - duplicate1 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate1))) - duplicate2 should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(duplicate2))) - reorder should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(reorder))) - rotation should be(recordMetaTypeFormat.read(recordMetaTypeFormat.write(rotation))) - } - -} -- cgit v1.2.3 From b6943690e5e572f6edc9fe985d33a6349a4a6812 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 26 Oct 2017 17:44:42 +0700 Subject: Reimplemented entity ExtractedData.Meta --- .../pdsuidomain/entities/ExtractedData.scala | 2 +- .../fakes/entities/recordprocessing.scala | 6 ++--- .../sprayformats/ExtractedDataFormatSuite.scala | 27 ++++++++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala index 352cf55..569375a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala @@ -17,7 +17,7 @@ final case class ExtractedData(id: LongId[ExtractedData] = LongId(0L), object ExtractedData { - final case class Meta(keyword: Meta.Keyword, evidence: Meta.Evidence) + final case class Meta(keyword: Option[Meta.Keyword], evidence: Option[Meta.Evidence]) object Meta { final case class Evidence(pageRatio: Double, start: TextLayerPosition, end: TextLayerPosition) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala index 86583c1..3a018fa 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/recordprocessing.scala @@ -245,13 +245,13 @@ object recordprocessing { def nextExtractedDataMeta(): Meta = { ExtractedData.Meta( - nextExtractedDataMetaKeyword(), - nextExtractedDataMetaEvidence() + nextOption(nextExtractedDataMetaKeyword()), + nextOption(nextExtractedDataMetaEvidence()) ) } def nextExtractedDataMetaJson(): TextJson[Meta] = - nextTextJson(ExtractedData.Meta(nextExtractedDataMetaKeyword(), nextExtractedDataMetaEvidence())) + nextTextJson(nextExtractedDataMeta()) def nextExtractedData(): ExtractedData = { ExtractedData( 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 1feca6a..d87b6c7 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 @@ -9,6 +9,7 @@ import xyz.driver.pdsuidomain.entities.{ExtractedData, ExtractedDataLabel} import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData class ExtractedDataFormatSuite extends FlatSpec with Matchers { + import extracteddata._ "Json format for ExtractedData" should "read and write correct JSON" in { @@ -17,8 +18,18 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { documentId = LongId(101), keywordId = Some(LongId(201)), evidenceText = Some("evidence text"), - meta = None - ) + meta = Option(TextJson(Meta( + evidence = None, + keyword = + Some(Meta.Keyword( + page = 1, + pageRatio = Some(1.6161616161616161d), + index = 0, + sortIndex = "1080000" + )) + ) + ))) + val extractedDataLabels = List( ExtractedDataLabel( id = LongId(1), @@ -43,11 +54,13 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { writtenJson should be( """{"id":1,"documentId":101,"keywordId":201,"evidence":"evidence text","meta":null, - "labels":[{"id":null,"categoryId":null,"value":"Yes"},{"id":12,"categoryId":1,"value":"No"}]}""".parseJson) + "labels":[{"id":null,"categoryId":null,"value":"Yes"},{"id":12,"categoryId":1,"value":"No"}], + "meta":{"keyword":{"index":0,"page":1,"pageRatio":1.6161616161616161,"sortIndex":"1080000"}}}""".parseJson) val createExtractedDataJson = """{"documentId":101,"keywordId":201,"evidence":"evidence text", - "labels":[{"value":"Yes"},{"id":12,"categoryId":1,"value":"No"}]}""".parseJson + "labels":[{"value":"Yes"},{"id":12,"categoryId":1,"value":"No"}], + "meta":{"keyword":{"index":0,"page":1,"pageRatio":1.6161616161616161,"sortIndex":"1080000"}}}""".parseJson val expectedCreatedExtractedData = origRichExtractedData.copy( extractedData = extractedData.copy(id = LongId(0)), labels = extractedDataLabels.map(_.copy(id = LongId(0), dataId = LongId(0))) @@ -80,12 +93,12 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { evidenceText = Some("new evidence text"), meta = Some( TextJson(Meta( - keyword = Meta.Keyword(page = 1, pageRatio = None, index = 2, sortIndex = "ASC"), - evidence = Meta.Evidence( + keyword = Some(Meta.Keyword(page = 1, pageRatio = None, index = 2, sortIndex = "ASC")), + evidence = Some(Meta.Evidence( pageRatio = 1.0, start = Meta.TextLayerPosition(page = 1, index = 3, offset = 2), end = Meta.TextLayerPosition(page = 2, index = 3, offset = 10) - ) + )) ))) ), labels = updatedExtractedDataLabels -- cgit v1.2.3