aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-10-11 16:56:06 +0700
committerGitHub <noreply@github.com>2017-10-11 16:56:06 +0700
commit3375f1beeab7af9a6732d6fce8762c3a3038e1f3 (patch)
treee4f1ad85a2ea17c76bcc844420d5f97bfd116e23 /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats
parentbbbcaf35a6081dba24dbb9a9aeb9d25fc2ca60be (diff)
parent85c78f58f0428d13795aa0419ff42471513a34d6 (diff)
downloadrest-query-3375f1beeab7af9a6732d6fce8762c3a3038e1f3.tar.gz
rest-query-3375f1beeab7af9a6732d6fce8762c3a3038e1f3.tar.bz2
rest-query-3375f1beeab7af9a6732d6fce8762c3a3038e1f3.zip
Merge pull request #37 from drivergroup/add-slot-eligibility-armsv0.8.1
Add slot eligibility arms
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala6
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibilityarm.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala19
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala4
6 files changed, 100 insertions, 21 deletions
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 89c843f..a43e92a 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
@@ -80,7 +80,7 @@ object criterion {
val arms = fields
.get("arms")
- .map(_.convertTo[Option[List[LongId[Arm]]]].getOrElse(List.empty[LongId[Arm]]))
+ .map(_.convertTo[Option[List[LongId[EligibilityArm]]]].getOrElse(List.empty[LongId[EligibilityArm]]))
.getOrElse(orig.armIds)
val labels = fields
@@ -143,8 +143,8 @@ object criterion {
val arms = fields
.get("arms")
- .map(_.convertTo[List[LongId[Arm]]])
- .getOrElse(List.empty[LongId[Arm]])
+ .map(_.convertTo[List[LongId[EligibilityArm]]])
+ .getOrElse(List.empty[LongId[EligibilityArm]])
val labels = fields
.get("labels")
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/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala
index 85d614d..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
@@ -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.{Criterion, EligibilityArm}
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] {
@@ -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
@@ -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/formats/json/sprayformats/intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala
index 62cb9fa..2ced434 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala
@@ -56,7 +56,7 @@ object intervention {
val arms = fields
.get("arms")
- .map(_.convertTo[List[LongId[Arm]]].map(x => InterventionArm(armId = x, interventionId = LongId(0))))
+ .map(_.convertTo[List[LongId[SlotArm]]].map(x => InterventionArm(armId = x, interventionId = LongId(0))))
.getOrElse(List.empty[InterventionArm])
InterventionWithArms(
@@ -104,7 +104,7 @@ object intervention {
val origIntervention = orig.intervention
val arms = fields
.get("arms")
- .map(_.convertTo[List[LongId[Arm]]].map(x => InterventionArm(x, orig.intervention.id)))
+ .map(_.convertTo[List[LongId[SlotArm]]].map(x => InterventionArm(x, orig.intervention.id)))
orig.copy(
intervention = origIntervention.copy(
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/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala
index d851c2c..b25ed1d 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala
@@ -6,12 +6,11 @@ import spray.json._
import xyz.driver.core.json.EnumJsonFormat
import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
import xyz.driver.pdsuidomain.entities._
-import xyz.driver.formats.json.patient._
object trial {
import DefaultJsonProtocol._
- import common._
import Trial._
+ import common._
implicit val trialStatusFormat = new EnumJsonFormat[Status](
"New" -> Status.New,
@@ -36,7 +35,6 @@ object trial {
"previousStatus" -> obj.previousStatus.toJson,
"previousAssignee" -> obj.previousAssignee.toJson,
"lastActiveUser" -> obj.lastActiveUserId.toJson,
- "disease" -> obj.disease.toJson,
"phase" -> obj.phase.toJson,
"hypothesisId" -> obj.hypothesisId.toJson,
"studyDesignId" -> obj.studyDesignId.toJson,