aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-10-02 17:26:43 +0700
committerGitHub <noreply@github.com>2017-10-02 17:26:43 +0700
commit1913870abec9e31d080f6858d0fc296445852cc6 (patch)
tree0fd3f012bfa563315e3f9a93b8e1788efe03fa12
parentd0482b45b6f9149f050c5e5a6dbab6f059229282 (diff)
parent14b460edbebb1d5c39809dbc591b786edec9fa8e (diff)
downloadrest-query-1913870abec9e31d080f6858d0fc296445852cc6.tar.gz
rest-query-1913870abec9e31d080f6858d0fc296445852cc6.tar.bz2
rest-query-1913870abec9e31d080f6858d0fc296445852cc6.zip
Merge pull request #33 from drivergroup/TRIAL-17v0.5.4
TRIAL-17 Added 'inclusion' field to Criterion
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala6
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala19
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala17
7 files changed, 51 insertions, 18 deletions
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)
}