From 0ef0059e9b47430e52d6bad4ced5b1be7f3b1a0d Mon Sep 17 00:00:00 2001 From: timgushue Date: Tue, 26 Sep 2017 14:11:40 -0700 Subject: fixing test in CriterionFormatSuite --- .../pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala index d24c4c1..9601834 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, CriterionLabel} +import xyz.driver.pdsuidomain.entities.{EligibilityArm, Criterion, CriterionLabel} import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion class CriterionFormatSuite extends FlatSpec with Matchers { @@ -35,7 +35,7 @@ class CriterionFormatSuite extends FlatSpec with Matchers { isDefining = true ) ) - val arms = List(LongId[Arm](20), LongId[Arm](21), LongId[Arm](21)) + val arms = List(LongId[EligibilityArm](20), LongId[EligibilityArm](21), LongId[EligibilityArm](21)) val richCriterion = RichCriterion( criterion = criterion, armIds = arms, -- cgit v1.2.3 From 979f4112d8aed85a445db7d8c6a19036a4137146 Mon Sep 17 00:00:00 2001 From: timgushue Date: Wed, 27 Sep 2017 11:15:59 -0700 Subject: Removed condition from trial --- src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala | 3 +-- .../xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala | 1 - .../xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala | 1 - .../xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala | 8 -------- .../xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala | 1 - .../json/sprayformats/PatientEligibleTrialFormatSuite.scala | 1 - .../pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala | 3 +-- 7 files changed, 2 insertions(+), 16 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala index db4def2..bd86057 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Trial.scala @@ -5,7 +5,7 @@ import java.time.LocalDateTime 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) @@ -86,7 +86,6 @@ final case class Trial(id: StringId[Trial], previousAssignee: Option[StringId[User]], lastActiveUserId: Option[StringId[User]], lastUpdate: LocalDateTime, - condition: Condition, phase: String, hypothesisId: Option[UuidId[Hypothesis]], studyDesignId: Option[LongId[StudyDesign]], 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 f9a267f..3a2f6bc 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -18,7 +18,6 @@ object trialcuration { previousAssignee = Option(nextStringId[User]), lastActiveUserId = Option(nextStringId[User]), lastUpdate = nextLocalDateTime, - condition = nextCondition, phase = generators.nextString(), hypothesisId = Option(nextUuidId[Hypothesis]), studyDesignId = Option(nextLongId[StudyDesign]), 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 c1751bf..a778000 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 @@ -41,7 +41,6 @@ object trial { "previousStatus" -> obj.previousStatus.toJson, "previousAssignee" -> obj.previousAssignee.toJson, "lastActiveUser" -> obj.lastActiveUserId.toJson, - "condition" -> obj.condition.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..fbf506b 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 @@ -16,7 +16,6 @@ final case class ApiTrial(id: String, previousStatus: Option[String], previousAssignee: Option[String], lastActiveUser: Option[String], - condition: String, phase: String, hypothesisId: Option[UUID], studyDesignId: Option[Long], @@ -37,11 +36,6 @@ 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}") - ), phase = this.phase, hypothesisId = this.hypothesisId.map(id => UuidId(id)), studyDesignId = this.studyDesignId.map(id => LongId(id)), @@ -67,7 +61,6 @@ object ApiTrial { (JsPath \ "previousStatus").formatNullable[String] and (JsPath \ "previousAssignee").formatNullable[String] and (JsPath \ "lastActiveUser").formatNullable[String] and - (JsPath \ "condition").format[String] and (JsPath \ "phase").format[String] and (JsPath \ "hypothesisId").formatNullable[UUID] and (JsPath \ "studyDesignId").formatNullable[Long] and @@ -89,7 +82,6 @@ object ApiTrial { previousAssignee = trial.previousAssignee.map(_.id), lastActiveUser = trial.lastActiveUserId.map(_.id), lastUpdate = ZonedDateTime.of(trial.lastUpdate, ZoneId.of("Z")), - condition = trial.condition.toString, phase = trial.phase, hypothesisId = trial.hypothesisId.map(_.id), studyDesignId = trial.studyDesignId.map(_.id), 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 3793c1f..e10165c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -28,7 +28,6 @@ class FakeTrialService extends TrialService { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.now(), - condition = Trial.Condition.Breast, phase = "", hypothesisId = None, studyDesignId = None, 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..8b00883 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 @@ -21,7 +21,6 @@ class PatientEligibleTrialFormatSuite extends FlatSpec with Matchers { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"), - condition = Trial.Condition.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/TrialFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatSuite.scala index 59cf779..3533c07 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 @@ -20,7 +20,6 @@ class TrialFormatSuite extends FlatSpec with Matchers { previousAssignee = None, lastActiveUserId = None, lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"), - condition = Trial.Condition.Breast, phase = "", hypothesisId = Some(UuidId("3b80b2e2-5372-4cf5-a342-6e4ebe10fafd")), studyDesignId = Some(LongId(321)), @@ -39,7 +38,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","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 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/xyz/driver/pdsuidomain/formats') 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/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 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 From f55212361d6126a05075a1f00f3915484b4f334e Mon Sep 17 00:00:00 2001 From: Marvin Bertin Date: Tue, 10 Oct 2017 17:05:32 -0700 Subject: add json format tests for Slot and Eligibility arms --- .../entities/SlotArmEligibilityArm.scala | 4 +- .../formats/json/sprayformats/eligibilityarm.scala | 44 +++++++++++ .../formats/json/sprayformats/slotarm.scala | 44 +++++++++++ .../parsers/PaginationParserSuite.scala | 68 +++++++++-------- .../parsers/SearchFilterParserSuite.scala | 89 +++++++++++++--------- .../pdsuicommon/parsers/SortingParserSuite.scala | 37 +++++---- .../xyz/driver/pdsuicommon/parsers/TestUtils.scala | 7 +- .../driver/pdsuicommon/utils/StringOpsSuite.scala | 2 +- .../formats/json/sprayformats/ArmFormatSuite.scala | 9 ++- .../json/sprayformats/DocumentFormatSuite.scala | 10 +-- .../sprayformats/DocumentHistoryFormatSuite.scala | 3 +- .../sprayformats/DocumentIssueFormatSuite.scala | 3 +- .../sprayformats/EligibilityArmFormatSuite.scala | 36 +++++++++ .../sprayformats/ExtractedDataFormatSuite.scala | 19 ++--- .../json/sprayformats/HypothesisFormatSuite.scala | 3 +- .../sprayformats/InterventionFormatSuite.scala | 2 +- .../sprayformats/MedicalRecordFormatSuite.scala | 17 +++-- .../MedicalRecordHistoryFormatSuite.scala | 3 +- .../MedicalRecordIssueFormatSuite.scala | 4 +- .../sprayformats/PatientCriterionFormatSuite.scala | 9 ++- .../PatientEligibleTrialFormatSuite.scala | 8 +- .../json/sprayformats/PatientFormatSuite.scala | 2 +- .../PatientHypothesisFormatSuite.scala | 6 +- .../sprayformats/PatientIssueFormatSuite.scala | 9 ++- .../sprayformats/PatientLabelFormatSuite.scala | 10 +-- .../json/sprayformats/SlotArmFormatSuite.scala | 36 +++++++++ .../json/sprayformats/TrialFormatSuite.scala | 6 +- .../sprayformats/TrialHistoryFormatSuite.scala | 3 +- .../json/sprayformats/TrialIssueFormatSuite.scala | 8 +- 29 files changed, 348 insertions(+), 153 deletions(-) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibilityarm.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/EligibilityArmFormatSuite.scala create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/SlotArmFormatSuite.scala (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/SlotArmEligibilityArm.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/SlotArmEligibilityArm.scala index f9aed6c..70114de 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/SlotArmEligibilityArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/SlotArmEligibilityArm.scala @@ -3,9 +3,7 @@ package xyz.driver.pdsuidomain.entities import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuicommon.logging._ -final case class SlotArmEligibilityArm(slotArmId: LongId[SlotArm], - eligibilityArmId: LongId[EligibilityArm]) - +final case class SlotArmEligibilityArm(slotArmId: LongId[SlotArm], eligibilityArmId: LongId[EligibilityArm]) object SlotArmEligibilityArm { implicit def toPhiString(x: SlotArmEligibilityArm): PhiString = { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibilityarm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibilityarm.scala new file mode 100644 index 0000000..acb790a --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibilityarm.scala @@ -0,0 +1,44 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.{EligibilityArm, Trial} + +object eligibilityarm { + import DefaultJsonProtocol._ + import common._ + + def applyUpdateToArm(json: JsValue, orig: EligibilityArm): EligibilityArm = json match { + case JsObject(fields) => + val name = fields + .get("name") + .map(_.convertTo[String]) + .getOrElse(deserializationError(s"Arm json object does not contain `name` field: $json")) + orig.copy(name = name) + + case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json") + } + + def eligibilityArmFormat: RootJsonFormat[EligibilityArm] = new RootJsonFormat[EligibilityArm] { + override def write(obj: EligibilityArm): JsValue = + JsObject( + "id" -> obj.id.toJson, + "name" -> obj.name.toJson, + "originalName" -> obj.originalName.toJson, + "trialId" -> obj.trialId.toJson + ) + + override def read(json: JsValue): EligibilityArm = json.asJsObject.getFields("trialId", "name") match { + case Seq(trialId, name) => + EligibilityArm( + id = LongId(0), + name = name.convertTo[String], + trialId = trialId.convertTo[StringId[Trial]], + originalName = name.convertTo[String] + ) + + case _ => deserializationError(s"Expected Json Object as Arm, but got $json") + } + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala new file mode 100644 index 0000000..192bd6a --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala @@ -0,0 +1,44 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.{SlotArm, Trial} + +object slotarm { + import DefaultJsonProtocol._ + import common._ + + def applyUpdateToArm(json: JsValue, orig: SlotArm): SlotArm = json match { + case JsObject(fields) => + val name = fields + .get("name") + .map(_.convertTo[String]) + .getOrElse(deserializationError(s"Arm json object does not contain `name` field: $json")) + orig.copy(name = name) + + case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json") + } + + def slotArmFormat: RootJsonFormat[SlotArm] = new RootJsonFormat[SlotArm] { + override def write(obj: SlotArm): JsValue = + JsObject( + "id" -> obj.id.toJson, + "name" -> obj.name.toJson, + "originalName" -> obj.originalName.toJson, + "trialId" -> obj.trialId.toJson + ) + + override def read(json: JsValue): SlotArm = json.asJsObject.getFields("trialId", "name") match { + case Seq(trialId, name) => + SlotArm( + id = LongId(0), + name = name.convertTo[String], + trialId = trialId.convertTo[StringId[Trial]], + originalName = name.convertTo[String] + ) + + case _ => deserializationError(s"Expected Json Object as Arm, but got $json") + } + } + +} diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala index 48fc99b..609c8c8 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala @@ -11,36 +11,40 @@ class PaginationParserSuite extends FreeSpecLike with MustMatchers { "parse" - { "pageSize" - { "should parse positive value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "10", - "pageNumber" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "10", + "pageNumber" -> "1" + )) pagination must success pagination.get.pageSize mustBe 10 } "should return a default value if there is no one" in { - val pagination = PaginationParser.parse(Seq( - "pageNumber" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageNumber" -> "1" + )) pagination must success pagination.get.pageSize mustBe 100 } "should return a error for zero value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "0", - "pageNumber" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "0", + "pageNumber" -> "1" + )) checkFailedValidationOnlyOn(pagination, "pageSize") } "should return a error for negative value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "-10", - "pageNumber" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "-10", + "pageNumber" -> "1" + )) checkFailedValidationOnlyOn(pagination, "pageSize") } @@ -48,36 +52,40 @@ class PaginationParserSuite extends FreeSpecLike with MustMatchers { "pageNumber" - { "should parse positive value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "1", - "pageNumber" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "1", + "pageNumber" -> "1" + )) pagination must success pagination.get.pageSize mustBe 1 } "should return a default value if there is no one" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "1" + )) pagination must success pagination.get.pageNumber mustBe 1 } "should return a error for zero value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "1", - "pageNumber" -> "0" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "1", + "pageNumber" -> "0" + )) checkFailedValidationOnlyOn(pagination, "pageNumber") } "should return a error for negative value" in { - val pagination = PaginationParser.parse(Seq( - "pageSize" -> "1", - "pageNumber" -> "-1" - )) + val pagination = PaginationParser.parse( + Seq( + "pageSize" -> "1", + "pageNumber" -> "-1" + )) checkFailedValidationOnlyOn(pagination, "pageNumber") } diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala index 5deaecb..02243aa 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala @@ -30,16 +30,20 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { "should convert column names to snake case" in { import SearchFilterBinaryOperation._ - val filter = SearchFilterParser.parse(Seq( - "filters" -> "status IN Summarized,ReviewCriteria,Flagged,Done", - "filters" -> "previousStatus NOTEQ New", - "filters" -> "previousStatus NOTEQ ReviewSummary" - )) - - assert(filter === Success(SearchFilterExpr.Intersection(List( - SearchFilterExpr.Atom.NAry(Dimension(None, "status"), In, Seq("Summarized", "ReviewCriteria", "Flagged", "Done")), - SearchFilterExpr.Atom.Binary(Dimension(None, "previous_status"), NotEq, "New"), - SearchFilterExpr.Atom.Binary(Dimension(None, "previous_status"), NotEq, "ReviewSummary"))))) + val filter = SearchFilterParser.parse( + Seq( + "filters" -> "status IN Summarized,ReviewCriteria,Flagged,Done", + "filters" -> "previousStatus NOTEQ New", + "filters" -> "previousStatus NOTEQ ReviewSummary" + )) + + assert( + filter === Success(SearchFilterExpr.Intersection(List( + SearchFilterExpr.Atom + .NAry(Dimension(None, "status"), In, Seq("Summarized", "ReviewCriteria", "Flagged", "Done")), + SearchFilterExpr.Atom.Binary(Dimension(None, "previous_status"), NotEq, "New"), + SearchFilterExpr.Atom.Binary(Dimension(None, "previous_status"), NotEq, "ReviewSummary") + )))) } "dimensions" - { "with table name" in check { @@ -50,11 +54,11 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { Prop.forAllNoShrink(dimensionGen) { case (left, right) => val raw = s"$left.$right" - val l = toSnakeCase(left) - val r = toSnakeCase(right) - SearchFilterParser.dimensionParser.parse(raw) match { + val l = toSnakeCase(left) + val r = toSnakeCase(right) + SearchFilterParser.dimensionParser.parse(raw) match { case Parsed.Success(Dimension(Some(`l`), `r`), _) => true - case _ => false + case _ => false } } } @@ -63,7 +67,7 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { val databaseS = Utils.toSnakeCase(s) SearchFilterParser.dimensionParser.parse(s) match { case Parsed.Success(Dimension(None, `databaseS`), _) => true - case _ => false + case _ => false } } } @@ -81,10 +85,11 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { ) Prop.forAllNoShrink(testQueryGen) { query => - SearchFilterParser.parse(Seq("filters" -> query)) + SearchFilterParser + .parse(Seq("filters" -> query)) .map { case SearchFilterExpr.Atom.Binary(_, Eq | NotEq | Like, _) => true - case x => throw new UnexpectedSearchFilterExprException(x) + case x => throw new UnexpectedSearchFilterExprException(x) } .successProp } @@ -96,7 +101,9 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { val testQueryGen = queryGen( dimensionGen = Gen.identifier, opGen = numericBinaryOpsGen, - valueGen = nonEmptyString.filter { s => !s.matches("^\\d+$") } + valueGen = nonEmptyString.filter { s => + !s.matches("^\\d+$") + } ) Prop.forAllNoShrink(testQueryGen) { query => @@ -121,10 +128,11 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { ) Prop.forAllNoShrink(testQueryGen) { query => - SearchFilterParser.parse(Seq("filters" -> query)) + SearchFilterParser + .parse(Seq("filters" -> query)) .map { case _: SearchFilterExpr.Atom.Binary => true - case x => throw new UnexpectedSearchFilterExprException(x) + case x => throw new UnexpectedSearchFilterExprException(x) } .successProp } @@ -140,7 +148,8 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { case Success(_) => () case Failure(t) => t.printStackTrace() } - assert(filter === Success(SearchFilterExpr.Atom.NAry(Dimension(None, "id"), In, Seq(Long.box(1), Long.box(5))))) + assert( + filter === Success(SearchFilterExpr.Atom.NAry(Dimension(None, "id"), In, Seq(Long.box(1), Long.box(5))))) } } @@ -152,10 +161,11 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { ) Prop.forAllNoShrink(testQueryGen) { query => - SearchFilterParser.parse(Seq("filters" -> query)) + SearchFilterParser + .parse(Seq("filters" -> query)) .map { case SearchFilterExpr.Atom.NAry(_, SearchFilterNAryOperation.In, _) => true - case x => throw new UnexpectedSearchFilterExprException(x) + case x => throw new UnexpectedSearchFilterExprException(x) } .successProp } @@ -189,16 +199,19 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { } } - private val CommonBinaryOps = Seq("eq", "noteq", "like") + private val CommonBinaryOps = Seq("eq", "noteq", "like") private val NumericBinaryOps = Seq("gt", "gteq", "lt", "lteq") - private val allBinaryOpsGen: Gen[String] = Gen.oneOf(CommonBinaryOps ++ NumericBinaryOps).flatMap(randomCapitalization) - private val commonBinaryOpsGen: Gen[String] = Gen.oneOf(CommonBinaryOps).flatMap(randomCapitalization) + private val allBinaryOpsGen: Gen[String] = + Gen.oneOf(CommonBinaryOps ++ NumericBinaryOps).flatMap(randomCapitalization) + private val commonBinaryOpsGen: Gen[String] = Gen.oneOf(CommonBinaryOps).flatMap(randomCapitalization) private val numericBinaryOpsGen: Gen[String] = Gen.oneOf(NumericBinaryOps).flatMap(randomCapitalization) private val inValueCharsGen: Gen[Char] = arbitrary[Char].filter(_ != ',') - private val nonEmptyString = arbitrary[String].filter { s => !s.safeTrim.isEmpty } + private val nonEmptyString = arbitrary[String].filter { s => + !s.safeTrim.isEmpty + } private val numericBinaryAtomValuesGen: Gen[String] = arbitrary[Long].map(_.toString) private val inValueGen: Gen[String] = { @@ -208,18 +221,22 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { Gen.containerOfN[Seq, String](size, inValueGen).map(_.mkString(",")) } - private def queryGen(dimensionGen: Gen[String], opGen: Gen[String], valueGen: Gen[String]): Gen[String] = for { - dimension <- dimensionGen - op <- opGen - value <- valueGen - } yield s"$dimension $op $value" + private def queryGen(dimensionGen: Gen[String], opGen: Gen[String], valueGen: Gen[String]): Gen[String] = + for { + dimension <- dimensionGen + op <- opGen + value <- valueGen + } yield s"$dimension $op $value" private def randomCapitalization(input: String): Gen[String] = { Gen.containerOfN[Seq, Boolean](input.length, arbitrary[Boolean]).map { capitalize => - input.view.zip(capitalize).map { - case (currChar, true) => currChar.toUpper - case (currChar, false) => currChar - }.mkString + input.view + .zip(capitalize) + .map { + case (currChar, true) => currChar.toUpper + case (currChar, false) => currChar + } + .mkString } } diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/SortingParserSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/SortingParserSuite.scala index e46015c..f34f8e1 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/parsers/SortingParserSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/SortingParserSuite.scala @@ -12,7 +12,7 @@ class SortingParserSuite extends FreeSpecLike with MustMatchers with Checkers { "single dimension" - commonTests(singleSortingQueryGen) "multiple dimensions in one query" - commonTests(multipleSortingQueryGen) "multiple queries" in { - val r = SortingParser.parse(Set("foo", "bar"), Seq("sort" -> "foo", "sort" ->"bar")) + val r = SortingParser.parse(Set("foo", "bar"), Seq("sort" -> "foo", "sort" -> "bar")) r must failWith[ParseQueryArgException] } } @@ -21,7 +21,7 @@ class SortingParserSuite extends FreeSpecLike with MustMatchers with Checkers { "valid" in check { val inputGen: Gen[(Set[String], String)] = for { validDimensions <- dimensionsGen - sorting <- queryGen(validDimensions) + sorting <- queryGen(validDimensions) } yield (validDimensions, sorting) Prop.forAllNoShrink(inputGen) { @@ -33,7 +33,9 @@ class SortingParserSuite extends FreeSpecLike with MustMatchers with Checkers { "invalid" in check { val inputGen: Gen[(Set[String], String)] = for { validDimensions <- dimensionsGen - invalidDimensions <- dimensionsGen.filter { xs => xs.intersect(validDimensions).isEmpty } + invalidDimensions <- dimensionsGen.filter { xs => + xs.intersect(validDimensions).isEmpty + } sorting <- queryGen(invalidDimensions) } yield (validDimensions, sorting) @@ -46,12 +48,12 @@ class SortingParserSuite extends FreeSpecLike with MustMatchers with Checkers { private val dimensionsGen: Gen[Set[String]] = for { unPrefixedSize <- Gen.choose(0, 3) - prefixedSize <- Gen.choose(0, 3) + prefixedSize <- Gen.choose(0, 3) if (unPrefixedSize + prefixedSize) > 0 unPrefixedDimensions <- Gen.containerOfN[Set, String](unPrefixedSize, Gen.identifier) - prefixes <- Gen.containerOfN[Set, String](prefixedSize, Gen.identifier) + prefixes <- Gen.containerOfN[Set, String](prefixedSize, Gen.identifier) dimensions <- Gen.containerOfN[Set, String](prefixedSize, Gen.identifier) } yield { val prefixedDimensions = prefixes.zip(dimensions).map { @@ -62,30 +64,33 @@ class SortingParserSuite extends FreeSpecLike with MustMatchers with Checkers { private def multipleSortingQueryGen(validDimensions: Set[String]): Gen[String] = { val validDimensionsSeq = validDimensions.toSeq - val indexGen = Gen.oneOf(validDimensionsSeq.indices) + val indexGen = Gen.oneOf(validDimensionsSeq.indices) val multipleDimensionsGen = Gen.nonEmptyContainerOf[Set, Int](indexGen).filter(_.size >= 2).map { indices => indices.map(validDimensionsSeq.apply) } for { - dimensions <- multipleDimensionsGen + dimensions <- multipleDimensionsGen isAscending <- Gen.containerOfN[Seq, Boolean](dimensions.size, arbitrary[Boolean]) } yield { - isAscending.zip(dimensions) + isAscending + .zip(dimensions) .map { - case (true, dimension) => dimension + case (true, dimension) => dimension case (false, dimension) => "-" + dimension } .mkString(",") } } - private def singleSortingQueryGen(validDimensions: Set[String]): Gen[String] = for { - isAscending <- arbitrary[Boolean] - dimensions <- Gen.oneOf(validDimensions.toSeq) - } yield isAscending match { - case true => dimensions - case false => "-" + dimensions - } + private def singleSortingQueryGen(validDimensions: Set[String]): Gen[String] = + for { + isAscending <- arbitrary[Boolean] + dimensions <- Gen.oneOf(validDimensions.toSeq) + } yield + isAscending match { + case true => dimensions + case false => "-" + dimensions + } } diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala index 4892b95..09b60ed 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala @@ -22,8 +22,9 @@ object TestUtils { left.isFailure && left.failed.get.getClass == ct.runtimeClass, left match { case Success(x) => s"$left did not fail" - case Failure(e) => s"$left did fail with ${Utils.getClassSimpleName(e.getClass)}, " + - s"not ${Utils.getClassSimpleName(ct.runtimeClass)}" + case Failure(e) => + s"$left did fail with ${Utils.getClassSimpleName(e.getClass)}, " + + s"not ${Utils.getClassSimpleName(ct.runtimeClass)}" }, left match { case Success(_) => s"$left failed with ${Utils.getClassSimpleName(ct.runtimeClass)}" @@ -33,7 +34,7 @@ object TestUtils { } } - def failWith[ThrowableT <:Throwable](implicit ct: ClassTag[ThrowableT]) = new FailWith[ThrowableT] + def failWith[ThrowableT <: Throwable](implicit ct: ClassTag[ThrowableT]) = new FailWith[ThrowableT] final implicit class TryPropOps(val self: Try[Any]) extends AnyVal { diff --git a/src/test/scala/xyz/driver/pdsuicommon/utils/StringOpsSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/utils/StringOpsSuite.scala index 9bd4382..bd0bd2b 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/utils/StringOpsSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/utils/StringOpsSuite.scala @@ -30,4 +30,4 @@ class StringOpsSuite extends FreeSpecLike { assert("foo".safeTrim == "foo") } } -} \ No newline at end of file +} diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatSuite.scala index e7d37a0..35b0fad 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatSuite.scala @@ -17,19 +17,20 @@ class ArmFormatSuite extends FlatSpec with Matchers { ) val writtenJson = armFormat.write(arm) - writtenJson should be("""{"id":10,"trialId":"NCT000001","name":"arm name","originalName":"orig arm name"}""".parseJson) + writtenJson should be( + """{"id":10,"trialId":"NCT000001","name":"arm name","originalName":"orig arm name"}""".parseJson) val createArmJson = """{"trialId":"NCT000001","name":"arm name"}""".parseJson - val parsedArm = armFormat.read(createArmJson) + val parsedArm = armFormat.read(createArmJson) val expectedCreatedArm = arm.copy( id = LongId(0), originalName = "arm name" ) parsedArm should be(expectedCreatedArm) - val updateArmJson = """{"name":"new arm name"}""".parseJson + val updateArmJson = """{"name":"new arm name"}""".parseJson val expectedUpdatedArm = arm.copy(name = "new arm name") - val parsedUpdateArm = applyUpdateToArm(updateArmJson, arm) + val parsedUpdateArm = applyUpdateToArm(updateArmJson, arm) parsedUpdateArm should be(expectedUpdatedArm) } 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..481e92f 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 @@ -31,7 +31,7 @@ class DocumentFormatSuite extends FlatSpec with Matchers { ) val writtenJson = documentFormat.write(orig) - writtenJson should be ( + 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, "previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z","meta":null}""".parseJson) @@ -58,15 +58,15 @@ class DocumentFormatSuite extends FlatSpec with Matchers { } "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(predicted = None, startPage = 1.0, endPage = 2.0) val writtenJson = documentMetaFormat.write(meta) - writtenJson should be ("""{"startPage":1.0,"endPage":2.0}""".parseJson) + writtenJson should be("""{"startPage":1.0,"endPage":2.0}""".parseJson) - val metaJsonWithoutPredicted = """{"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 metaJsonWithPredicted = """{"predicted":true,"startPage":1.0,"endPage":2.0}""".parseJson val parsedMetaWithPredicted = documentMetaFormat.read(metaJsonWithPredicted) parsedMetaWithPredicted should be(meta.copy(predicted = Some(true))) } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentHistoryFormatSuite.scala index ddbda1d..5975919 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentHistoryFormatSuite.scala @@ -21,8 +21,7 @@ class DocumentHistoryFormatSuite extends FlatSpec with Matchers { ) val writtenJson = documentHistoryFormat.write(documentHistory) - writtenJson should be( - """{"id":10,"executor":"userId-001","documentId":1,"state":"Extract", + writtenJson should be("""{"id":10,"executor":"userId-001","documentId":1,"state":"Extract", "action":"Start","created":"2017-08-10T18:00Z"}""".parseJson) val parsedDocumentHistory = documentHistoryFormat.read(writtenJson) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentIssueFormatSuite.scala index c4c9f7c..54cfe90 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentIssueFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentIssueFormatSuite.scala @@ -29,7 +29,8 @@ class DocumentIssueFormatSuite extends FlatSpec with Matchers { "text":"message text","archiveRequired":false,"startPage":1.0,"endPage":2.0}""".parseJson) val createDocumentIssueJson = """{"text":"message text","startPage":1.0,"endPage":2.0}""".parseJson - val expectedCreatedDocumentIssue = documentIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true) + val expectedCreatedDocumentIssue = + documentIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true) val parsedCreateDocumentIssue = jsValueToDocumentIssue(createDocumentIssueJson, LongId(1), StringId("userId-001")) parsedCreateDocumentIssue should be(expectedCreatedDocumentIssue) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/EligibilityArmFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/EligibilityArmFormatSuite.scala new file mode 100644 index 0000000..bcfb977 --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/EligibilityArmFormatSuite.scala @@ -0,0 +1,36 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.EligibilityArm + +class EligibilityArmFormatSuite extends FlatSpec with Matchers { + import eligibilityarm._ + + "Json format for EligibilityArm" should "read and write correct JSON" in { + val arm = EligibilityArm( + id = LongId(10), + trialId = StringId("NCT000001"), + name = "arm name", + originalName = "orig arm name" + ) + val writtenJson = eligibilityArmFormat.write(arm) + + writtenJson should be( + """{"id":10,"trialId":"NCT000001","name":"arm name","originalName":"orig arm name"}""".parseJson) + + val createArmJson = """{"trialId":"NCT000001","name":"arm name"}""".parseJson + val parsedArm = eligibilityArmFormat.read(createArmJson) + val expectedCreatedArm = arm.copy( + id = LongId(0), + originalName = "arm name" + ) + parsedArm should be(expectedCreatedArm) + + val updateArmJson = """{"name":"new arm name"}""".parseJson + val expectedUpdatedArm = arm.copy(name = "new arm name") + val parsedUpdateArm = applyUpdateToArm(updateArmJson, arm) + parsedUpdateArm should be(expectedUpdatedArm) + } +} 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..c3df80a 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 @@ -40,7 +40,7 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { ) val writtenJson = extractedDataFormat.write(origRichExtractedData) - writtenJson should be ( + 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) @@ -77,14 +77,15 @@ class ExtractedDataFormatSuite extends FlatSpec with Matchers { val expectedUpdatedExtractedData = origRichExtractedData.copy( extractedData = extractedData.copy( evidenceText = Some("new evidence text"), - meta = Some(TextJson(Meta( - keyword = Meta.Keyword(page = 1, pageRatio = None, index = 2, sortIndex = "ASC"), - evidence = Meta.Evidence( - pageRatio = 1.0, - start = Meta.TextLayerPosition(page = 1, index = 3, offset = 2), - end = Meta.TextLayerPosition(page = 2, index = 3, offset = 10) - ) - ))) + meta = Some( + TextJson(Meta( + keyword = Meta.Keyword(page = 1, pageRatio = None, index = 2, sortIndex = "ASC"), + evidence = 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 ) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/HypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/HypothesisFormatSuite.scala index 306fb17..76d90f5 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/HypothesisFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/HypothesisFormatSuite.scala @@ -17,8 +17,7 @@ class HypothesisFormatSuite extends FlatSpec with Matchers { ) val writtenJson = hypothesisFormat.write(hypothesis) - writtenJson should be( - """{"id":"3b80b2e2-5372-4cf5-a342-6e4ebe10fafd","name":"hypothesis name", + writtenJson should be("""{"id":"3b80b2e2-5372-4cf5-a342-6e4ebe10fafd","name":"hypothesis name", "treatmentType":"treatment type","description":"descr"}""".parseJson) val parsedHypothesis = hypothesisFormat.read(writtenJson) 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 dad39c8..5891e1c 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 @@ -60,7 +60,7 @@ class InterventionFormatSuite extends FlatSpec with Matchers { "Json format for InterventionType" should "read and write correct JSON" in { val interventionType = InterventionType.typeFromString("Surgery/Procedure") - val writtenJson = interventionTypeFormat.write(interventionType) + val writtenJson = interventionTypeFormat.write(interventionType) writtenJson should be( """{"id":9,"name":"Surgery/Procedure","deliveryMethods":["Radio-Frequency Ablation (RFA)", 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..feedf2f 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 @@ -32,7 +32,7 @@ class MedicalRecordFormatSuite extends FlatSpec with Matchers { ) val writtenJson = recordFormat.write(orig) - writtenJson should be ( + writtenJson should be( """{"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"}""".parseJson) @@ -64,11 +64,16 @@ class MedicalRecordFormatSuite extends FlatSpec with Matchers { {"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 = 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)) + ))) ) val parsedUpdatedRecord = applyUpdateToMedicalRecord(updateRecordJson, orig) parsedUpdatedRecord should be(expectedUpdatedRecord) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordHistoryFormatSuite.scala index 5cd6c8d..a8634d9 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordHistoryFormatSuite.scala @@ -21,8 +21,7 @@ class MedicalRecordHistoryFormatSuite extends FlatSpec with Matchers { ) val writtenJson = recordHistoryFormat.write(recordHistory) - writtenJson should be( - """{"id":10,"executor":"userId-001","recordId":1,"state":"Clean", + writtenJson should be("""{"id":10,"executor":"userId-001","recordId":1,"state":"Clean", "action":"Start","created":"2017-08-10T18:00Z"}""".parseJson) val parsedRecordHistory = recordHistoryFormat.read(writtenJson) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordIssueFormatSuite.scala index c23ca37..5fa740b 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordIssueFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/MedicalRecordIssueFormatSuite.scala @@ -28,9 +28,9 @@ class MedicalRecordIssueFormatSuite extends FlatSpec with Matchers { """{"id":10,"recordId":1,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false, "text":"message text","archiveRequired":false,"startPage":1.0,"endPage":2.0}""".parseJson) - val createRecordIssueJson = """{"text":"message text","startPage":1.0,"endPage":2.0}""".parseJson + val createRecordIssueJson = """{"text":"message text","startPage":1.0,"endPage":2.0}""".parseJson val expectedCreatedRecordIssue = recordIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true) - val parsedCreateRecordIssue = jsValueToRecordIssue(createRecordIssueJson, LongId(1), StringId("userId-001")) + val parsedCreateRecordIssue = jsValueToRecordIssue(createRecordIssueJson, LongId(1), StringId("userId-001")) parsedCreateRecordIssue should be(expectedCreatedRecordIssue) val updateRecordIssueJson = 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..43f9b48 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 @@ -33,17 +33,18 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientCriterionWriter.write((orig, LongId(21), arms)) - writtenJson should be ( + 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) - val updatePatientCriterionJson = """{"verifiedEligibilityStatus":"No"}""".parseJson + val updatePatientCriterionJson = """{"verifiedEligibilityStatus":"No"}""".parseJson val expectedUpdatedPatientCriterion = orig.copy(verifiedEligibilityStatus = Some(FuzzyValue.No)) - val parsedUpdatePatientCriterion = applyUpdateToPatientCriterion(updatePatientCriterionJson, orig) + val parsedUpdatePatientCriterion = applyUpdateToPatientCriterion(updatePatientCriterionJson, orig) parsedUpdatePatientCriterion should be(expectedUpdatedPatientCriterion) - val updateBulkPatientCriterionJson = """[{"id":1,"eligibilityStatus":"No"},{"id":2,"isVerified":false}]""".parseJson + 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(2), eligibilityStatus = None, isVerified = Some(false)) 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 8b00883..1d28b2e 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 @@ -45,16 +45,16 @@ class PatientEligibleTrialFormatSuite 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 orig = RichPatientEligibleTrial(trial, group, arms) + val orig = RichPatientEligibleTrial(trial, group, arms) val writtenJson = patientEligibleTrialWriter.write(orig) - writtenJson should be ( + writtenJson should be( """{"id":1,"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","trialId":"NCT000001","trialTitle":"trial title", "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","verifiedEligibilityStatus":"Yes","isVerified":false,"arms":["arm 31","arm 32"]}""".parseJson) - val updatePatientEligibleTrialJson = """{"isVerified":true}""".parseJson + val updatePatientEligibleTrialJson = """{"isVerified":true}""".parseJson val expectedUpdatedPatientTrialArmGroup = group.copy(isVerified = true) - val parsedUpdatePatientTrialArmGroup = applyUpdateToTrialArmGroup(updatePatientEligibleTrialJson, group) + val parsedUpdatePatientTrialArmGroup = applyUpdateToTrialArmGroup(updatePatientEligibleTrialJson, group) parsedUpdatePatientTrialArmGroup should be(expectedUpdatedPatientTrialArmGroup) } 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..b1b6b2a 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 @@ -27,7 +27,7 @@ class PatientFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientWriter.write(orig) - writtenJson should be ( + writtenJson should be( """{"id":"748b5884-3528-4cb9-904b-7a8151d6e343","dob":"1980-06-30","name":"John 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) 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..0e628a8 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 @@ -18,13 +18,13 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientHypothesisWriter.write((orig, true)) - writtenJson should be ( + 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,"isRationaleRequired":true}""".parseJson) - val updatePatientHypothesisJson = """{"rationale":"rationale"}""".parseJson + val updatePatientHypothesisJson = """{"rationale":"rationale"}""".parseJson val expectedUpdatedPatientHypothesis = orig.copy(rationale = Some("rationale")) - val parsedUpdatePatientHypothesis = applyUpdateToPatientHypothesis(updatePatientHypothesisJson, orig) + val parsedUpdatePatientHypothesis = applyUpdateToPatientHypothesis(updatePatientHypothesisJson, orig) parsedUpdatePatientHypothesis should be(expectedUpdatedPatientHypothesis) } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientIssueFormatSuite.scala index 1e2a11e..2776dcc 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientIssueFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientIssueFormatSuite.scala @@ -22,13 +22,14 @@ class PatientIssueFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientIssueWriter.write(patientIssue) - writtenJson should be( - """{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false, + writtenJson should be("""{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false, "text":"message text","archiveRequired":false}""".parseJson) - val createPatientIssueJson = """{"text":"message text"}""".parseJson + val createPatientIssueJson = """{"text":"message text"}""".parseJson val expectedCreatedPatientIssue = patientIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true) - val parsedCreatePatientIssue = jsValueToPatientIssue(createPatientIssueJson, UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"), StringId("userId-001")) + val parsedCreatePatientIssue = jsValueToPatientIssue(createPatientIssueJson, + UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"), + StringId("userId-001")) parsedCreatePatientIssue should be(expectedCreatedPatientIssue) val updatePatientIssueJson = 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..67d678c 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 @@ -23,13 +23,13 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientLabelWriter.write((orig, true)) - writtenJson should be ( + writtenJson should be( """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true, "score":1,"isImplicitMatch":false}""".parseJson) - val updatePatientLabelJson = """{"verifiedPrimaryValue":"No"}""".parseJson + val updatePatientLabelJson = """{"verifiedPrimaryValue":"No"}""".parseJson val expectedUpdatedPatientLabel = orig.copy(verifiedPrimaryValue = Some(FuzzyValue.No)) - val parsedUpdatePatientLabel = applyUpdateToPatientLabel(updatePatientLabelJson, orig) + val parsedUpdatePatientLabel = applyUpdateToPatientLabel(updatePatientLabelJson, orig) parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel) } @@ -51,7 +51,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientLabelEvidenceWriter.write(orig) - writtenJson should be ( + 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) } @@ -70,7 +70,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { ) val writtenJson = patientLabelDefiningCriteriaWriter.write(orig) - writtenJson should be ("""{"id":1,"value":"Yes"}""".parseJson) + writtenJson should be("""{"id":1,"value":"Yes"}""".parseJson) } } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/SlotArmFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/SlotArmFormatSuite.scala new file mode 100644 index 0000000..7dd085c --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/SlotArmFormatSuite.scala @@ -0,0 +1,36 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.SlotArm + +class SlotArmFormatSuite extends FlatSpec with Matchers { + import slotarm._ + + "Json format for SlotArm" should "read and write correct JSON" in { + val arm = SlotArm( + id = LongId(10), + trialId = StringId("NCT000001"), + name = "arm name", + originalName = "orig arm name" + ) + val writtenJson = slotArmFormat.write(arm) + + writtenJson should be( + """{"id":10,"trialId":"NCT000001","name":"arm name","originalName":"orig arm name"}""".parseJson) + + val createArmJson = """{"trialId":"NCT000001","name":"arm name"}""".parseJson + val parsedArm = slotArmFormat.read(createArmJson) + val expectedCreatedArm = arm.copy( + id = LongId(0), + originalName = "arm name" + ) + parsedArm should be(expectedCreatedArm) + + val updateArmJson = """{"name":"new arm name"}""".parseJson + val expectedUpdatedArm = arm.copy(name = "new arm name") + val parsedUpdateArm = applyUpdateToArm(updateArmJson, arm) + parsedUpdateArm should be(expectedUpdatedArm) + } +} 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 3533c07..a3da52f 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 @@ -33,16 +33,16 @@ class TrialFormatSuite extends FlatSpec with Matchers { ) val writtenJson = trialWriter.write(orig) - writtenJson should be ( + writtenJson should be( """{"isPartner":false,"assignee":null,"lastUpdate":"2017-08-10T18:16:19Z","previousStatus":null, "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","status":"New","overview":null,"previousAssignee":null,"title":"trial title"}""".parseJson) - val updateTrialJson = """{"hypothesisId":null,"overview":"new overview"}""".parseJson + val updateTrialJson = """{"hypothesisId":null,"overview":"new overview"}""".parseJson val expectedUpdatedTrial = orig.copy(hypothesisId = None, overview = Some("new overview")) - val parsedUpdateTrial = applyUpdateToTrial(updateTrialJson, orig) + val parsedUpdateTrial = applyUpdateToTrial(updateTrialJson, orig) parsedUpdateTrial should be(expectedUpdatedTrial) } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialHistoryFormatSuite.scala index dbb143c..d5ad2ec 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialHistoryFormatSuite.scala @@ -21,8 +21,7 @@ class TrialHistoryFormatSuite extends FlatSpec with Matchers { ) val writtenJson = trialHistoryFormat.write(trialHistory) - writtenJson should be( - """{"id":10,"executor":"userId-001","trialId":"NCT000001","state":"Summarize", + writtenJson should be("""{"id":10,"executor":"userId-001","trialId":"NCT000001","state":"Summarize", "action":"Start","created":"2017-08-10T18:00Z"}""".parseJson) val parsedTrialHistory = trialHistoryFormat.read(writtenJson) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala index 02e14ba..4a9ea4f 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala @@ -24,13 +24,13 @@ class TrialIssueFormatSuite extends FlatSpec with Matchers { ) val writtenJson = trialIssueWriter.write(trialIssue) - writtenJson should be( - """{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false, + writtenJson should be("""{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false, "text":"message text","evidence":"evidence","archiveRequired":false,"meta":"{}"}""".parseJson) - val createTrialIssueJson = """{"text":"message text","evidence":"evidence","meta":"{}"}""".parseJson + val createTrialIssueJson = """{"text":"message text","evidence":"evidence","meta":"{}"}""".parseJson val expectedCreatedTrialIssue = trialIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true) - val parsedCreateTrialIssue = jsValueToTrialIssue(createTrialIssueJson, StringId("NCT000001"), StringId("userId-001")) + val parsedCreateTrialIssue = + jsValueToTrialIssue(createTrialIssueJson, StringId("NCT000001"), StringId("userId-001")) parsedCreateTrialIssue should be(expectedCreatedTrialIssue) val updateTrialIssueJson = -- cgit v1.2.3 From 85c78f58f0428d13795aa0419ff42471513a34d6 Mon Sep 17 00:00:00 2001 From: Marvin Bertin Date: Tue, 10 Oct 2017 18:09:49 -0700 Subject: add diseaseList to ExportTrialArm --- .../driver/pdsuidomain/entities/export/trial/ExportTrialArm.scala | 4 ++-- src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala | 4 +++- .../xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala | 2 +- .../xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala | 3 ++- .../pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats') 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 24fe641..fbac0df 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,12 +4,12 @@ import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.EligibilityArm -final case class ExportTrialArm(armId: LongId[EligibilityArm], armName: String) +final case class ExportTrialArm(armId: LongId[EligibilityArm], armName: String, diseaseList: Seq[String]) object ExportTrialArm { implicit def toPhiString(x: ExportTrialArm): PhiString = { import x._ - phi"ExportTrialArm(armId=$armId, armName=${Unsafe(armName)})" + phi"ExportTrialArm(armId=$armId, armName=${Unsafe(armName)}, diseaseList=${Unsafe(diseaseList)})" } } 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 5febd8f..1fe7533 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -9,7 +9,9 @@ object export { import xyz.driver.core.generators._ def nextExportTrialArm(): ExportTrialArm = - ExportTrialArm(armId = nextLongId[EligibilityArm], armName = nextString(100)) + ExportTrialArm(armId = nextLongId[EligibilityArm], + armName = nextString(100), + diseaseList = listOf(nextString(100))) def nextExportTrialLabelCriterion(): ExportTrialLabelCriterion = ExportTrialLabelCriterion( 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 1c4b6b4..4391453 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 @@ -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] { 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 0431d95..e0efcd1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -74,7 +74,8 @@ class FakeTrialService extends TrialService { generators.listOf( new ExportTrialArm( LongId[EligibilityArm](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 3eaf93f..d78e754 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"), - 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( @@ -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"},{"armId":2,"armName":"arm 2"}],"criteria":[ + "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