From b5e0d5f91b52013bc11ef3ea586a54bb001577bc Mon Sep 17 00:00:00 2001 From: vlad Date: Sun, 1 Oct 2017 12:50:54 -0700 Subject: Fixing IN in filters, Model from EVLS added to common, Reusing domain model labels --- src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala index 0dfb33f..7f065d4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.entities +import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.Criterion.Meta.Evidence @@ -10,7 +11,7 @@ final case class Criterion(id: LongId[Criterion], isCompound: Boolean, meta: String) { - def isValid(): Boolean = text.nonEmpty && Option(meta).isDefined + def isValid: Boolean = text.nonEmpty && Option(meta).isDefined } object Criterion { @@ -41,7 +42,7 @@ object CriterionArm { final case class CriterionLabel(id: LongId[CriterionLabel], labelId: Option[LongId[Label]], criterionId: LongId[Criterion], - categoryId: Option[LongId[Category]], + categoryId: Option[LongId[LabelCategory]], value: Option[Boolean], isDefining: Boolean) -- cgit v1.2.3 From 14b460edbebb1d5c39809dbc591b786edec9fa8e Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 2 Oct 2017 15:21:58 +0700 Subject: TRIAL-17 Added 'inclusion' field to Criterion --- .../xyz/driver/pdsuidomain/entities/Criterion.scala | 3 ++- .../pdsuidomain/fakes/entities/trialcuration.scala | 3 ++- .../formats/json/criterion/ApiCriterion.scala | 12 ++++++++---- .../formats/json/criterion/ApiNewCriterion.scala | 9 ++++++--- .../formats/json/criterion/ApiUpdateCriterion.scala | 6 +++++- .../formats/json/sprayformats/criterion.scala | 19 ++++++++++++++++--- .../json/sprayformats/CriterionFormatSuite.scala | 17 ++++++++++++----- 7 files changed, 51 insertions(+), 18 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala index 7f065d4..2432251 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala @@ -9,7 +9,8 @@ final case class Criterion(id: LongId[Criterion], trialId: StringId[Trial], text: Option[String], isCompound: Boolean, - meta: String) { + meta: String, + inclusion: Option[Boolean]) { def isValid: Boolean = text.nonEmpty && Option(meta).isDefined } 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 fcd833a..9a5022c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -45,7 +45,8 @@ object trialcuration { trialId = nextStringId[Trial], text = Option(generators.nextString()), isCompound = generators.nextBoolean(), - meta = generators.nextString() + meta = generators.nextString(), + inclusion = Option(generators.nextBoolean()) ) def nextCriterionLabel(criterionId: LongId[Criterion]): CriterionLabel = CriterionLabel( diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala index 4986b17..43b5494 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala @@ -14,7 +14,8 @@ final case class ApiCriterion(id: Long, text: Option[String], isCompound: Boolean, labels: Seq[ApiCriterionLabel], - trialId: String) { + trialId: String, + inclusion: Option[Boolean]) { def toDomain = RichCriterion( criterion = Criterion( @@ -22,7 +23,8 @@ final case class ApiCriterion(id: Long, trialId = StringId[Trial](trialId), text, isCompound, - meta.getOrElse("") + meta.getOrElse(""), + inclusion ), armIds = arms.map(LongId[Arm]), labels = labels.map(_.toDomain(LongId[Criterion](id))) @@ -40,7 +42,8 @@ object ApiCriterion { (JsPath \ "text").formatNullable[String] and (JsPath \ "isCompound").format[Boolean] and (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] + (JsPath \ "trialId").format[String] and + (JsPath \ "inclusion").formatNullable[Boolean] )(ApiCriterion.apply, unlift(ApiCriterion.unapply)) def fromDomain(richCriterion: RichCriterion) = ApiCriterion( @@ -50,6 +53,7 @@ object ApiCriterion { text = richCriterion.criterion.text, isCompound = richCriterion.criterion.isCompound, labels = richCriterion.labels.map(ApiCriterionLabel.fromDomain), - trialId = richCriterion.criterion.trialId.id + trialId = richCriterion.criterion.trialId.id, + inclusion = richCriterion.criterion.inclusion ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala index ab7641f..d72a9b4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala @@ -13,7 +13,8 @@ final case class ApiNewCriterion(meta: Option[String], text: Option[String], isCompound: Option[Boolean], labels: Seq[ApiCriterionLabel], - trialId: String) { + trialId: String, + inclusion: Option[Boolean]) { def toDomain = RichCriterion( criterion = Criterion( @@ -21,7 +22,8 @@ final case class ApiNewCriterion(meta: Option[String], meta = meta.getOrElse(""), trialId = StringId(trialId), isCompound = isCompound.getOrElse(false), - text = text + text = text, + inclusion = inclusion ), armIds = arms.getOrElse(Seq.empty).map(LongId[Arm]), labels = labels.map(_.toDomain(LongId(Long.MaxValue))) // A developer should specify right criterionId himself @@ -38,6 +40,7 @@ object ApiNewCriterion { (JsPath \ "text").formatNullable[String] and (JsPath \ "isCompound").formatNullable[Boolean] and (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] + (JsPath \ "trialId").format[String] and + (JsPath \ "inclusion").formatNullable[Boolean] )(ApiNewCriterion.apply, unlift(ApiNewCriterion.unapply)) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala index 2bcda56..77989f0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala @@ -14,6 +14,7 @@ final case class ApiUpdateCriterion(meta: Tristate[String], arms: Tristate[Seq[Long]], text: Option[String], isCompound: Option[Boolean], + inclusion: Tristate[Boolean], labels: Tristate[Seq[ApiCriterionLabel]]) { def applyTo(orig: RichCriterion): RichCriterion = RichCriterion( @@ -27,7 +28,8 @@ final case class ApiUpdateCriterion(meta: Tristate[String], meta = meta.cata(identity, "{}", orig.meta), text = text.orElse(orig.text), isCompound = isCompound.getOrElse(orig.isCompound), - trialId = orig.trialId + trialId = orig.trialId, + inclusion = inclusion.cata(x => Some(x), None, orig.inclusion) ) } @@ -45,6 +47,7 @@ object ApiUpdateCriterion { (JsPath \ "arms").readTristate(seqJsonFormat[Long]) and (JsPath \ "text").readNullable[String] and (JsPath \ "isCompound").readNullable[Boolean] and + (JsPath \ "inclusion").readTristate[Boolean] and (JsPath \ "labels").readTristate(seqJsonFormat[ApiCriterionLabel]) )(ApiUpdateCriterion.apply _) @@ -53,6 +56,7 @@ object ApiUpdateCriterion { (JsPath \ "arms").writeTristate(seqJsonFormat[Long]) and (JsPath \ "text").writeNullable[String] and (JsPath \ "isCompound").writeNullable[Boolean] and + (JsPath \ "inclusion").writeTristate[Boolean] and (JsPath \ "labels").writeTristate(seqJsonFormat[ApiCriterionLabel]) )(unlift(ApiUpdateCriterion.unapply)) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala index 743f885..8da719c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala @@ -73,6 +73,11 @@ object criterion { .map(_.convertTo[Option[String]].getOrElse("{}")) .getOrElse(orig.criterion.meta) + val inclusion = fields + .get("inclusion") + .map(_.convertTo[Option[Boolean]]) + .getOrElse(orig.criterion.inclusion) + val arms = fields .get("arms") .map(_.convertTo[Option[List[LongId[Arm]]]].getOrElse(List.empty[LongId[Arm]])) @@ -88,7 +93,8 @@ object criterion { criterion = orig.criterion.copy( meta = meta, text = text, - isCompound = isCompound + isCompound = isCompound, + inclusion = inclusion ), armIds = arms, labels = labels @@ -106,7 +112,8 @@ object criterion { "text" -> obj.criterion.text.toJson, "isCompound" -> obj.criterion.isCompound.toJson, "labels" -> obj.labels.map(_.toJson).toJson, - "trialId" -> obj.criterion.trialId.toJson + "trialId" -> obj.criterion.trialId.toJson, + "inclusion" -> obj.criterion.inclusion.toJson ) override def read(json: JsValue): RichCriterion = json match { @@ -129,6 +136,11 @@ object criterion { .map(_.convertTo[String]) .getOrElse("") + val inclusion = fields + .get("inclusion") + .map(_.convertTo[Option[Boolean]]) + .getOrElse(None) + val arms = fields .get("arms") .map(_.convertTo[List[LongId[Arm]]]) @@ -146,7 +158,8 @@ object criterion { trialId = trialId, text = text, isCompound = isCompound, - meta = meta + meta = meta, + inclusion = inclusion ), armIds = arms, labels = labels 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..708aed9 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 @@ -15,7 +15,8 @@ class CriterionFormatSuite extends FlatSpec with Matchers { trialId = StringId("NCT000001"), text = Some("text"), isCompound = false, - meta = "{}" + meta = "{}", + inclusion = None ) val labels = List( CriterionLabel( @@ -44,12 +45,12 @@ class CriterionFormatSuite extends FlatSpec with Matchers { val writtenJson = richCriterionFormat.write(richCriterion) writtenJson should be( - """{"text":"text","isCompound":false,"trialId":"NCT000001","arms":[20,21,21],"id":10,"meta":"{}", + """{"text":"text","isCompound":false,"trialId":"NCT000001","inclusion":null,"arms":[20,21,21],"id":10,"meta":"{}", "labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true}, {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson) val createCriterionJson = - """{"text":"text","isCompound":false,"trialId":"NCT000001", + """{"text":"text","isCompound":false,"trialId":"NCT000001","inclusion":null, "arms":[20,21,21],"meta":"{}","labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true}, {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson val parsedRichCriterion = richCriterionFormat.read(createCriterionJson) @@ -59,8 +60,14 @@ class CriterionFormatSuite extends FlatSpec with Matchers { ) parsedRichCriterion should be(expectedRichCriterion) - val updateCriterionJson = """{"meta":null,"text":"new text","isCompound":true}""".parseJson - val expectedUpdatedCriterion = richCriterion.copy(criterion = criterion.copy(text = Some("new text"), isCompound = true, meta = "{}")) + val updateCriterionJson = """{"meta":null,"text":"new text","isCompound":true,"inclusion":true}""".parseJson + val expectedUpdatedCriterion = richCriterion.copy( + criterion = criterion.copy( + text = Some("new text"), + isCompound = true, + meta = "{}", + inclusion = Some(true) + )) val parsedUpdateCriterion = applyUpdateToCriterion(updateCriterionJson, richCriterion) parsedUpdateCriterion should be(expectedUpdatedCriterion) } -- cgit v1.2.3