aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-27 17:13:02 -0700
committervlad <vlad@driver.xyz>2017-06-27 17:13:02 -0700
commit5832f63b84d7388441d1200f2442dc1e9de0225c (patch)
tree32f63acdc920c14effc3d0d2822c05c125ad49e4 /src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention
parent9dd50590d4c8f8b9442d7c21ddd1def9dd453d5e (diff)
downloadrest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.gz
rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.bz2
rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.zip
All PDS UI domain models, API case classes, service traits and necessary utils moved to pdsui-commonv0.1.11
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala41
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala20
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala44
3 files changed, 105 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala
new file mode 100644
index 0000000..37a9758
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala
@@ -0,0 +1,41 @@
+package xyz.driver.pdsuidomain.formats.json.intervention
+
+import xyz.driver.pdsuidomain.entities.InterventionWithArms
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+
+final case class ApiIntervention(id: Long,
+ name: String,
+ typeId: Option[Long],
+ description: String,
+ isActive: Boolean,
+ arms: List[Long],
+ trialId: String)
+
+object ApiIntervention {
+
+ implicit val format: Format[ApiIntervention] = (
+ (JsPath \ "id").format[Long] and
+ (JsPath \ "name").format[String] and
+ (JsPath \ "typeId").formatNullable[Long] and
+ (JsPath \ "description").format[String] and
+ (JsPath \ "isActive").format[Boolean] and
+ (JsPath \ "arms").format[List[Long]] and
+ (JsPath \ "trialId").format[String]
+ ) (ApiIntervention.apply, unlift(ApiIntervention.unapply))
+
+ def fromDomain(interventionWithArms: InterventionWithArms): ApiIntervention = {
+ import interventionWithArms.intervention
+ import interventionWithArms.arms
+
+ ApiIntervention(
+ id = intervention.id.id,
+ name = intervention.name,
+ typeId = intervention.typeId.map(_.id),
+ description = intervention.description,
+ isActive = intervention.isActive,
+ arms = arms.map(_.armId.id),
+ trialId = intervention.trialId.id
+ )
+ }
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala
new file mode 100644
index 0000000..ca444eb
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala
@@ -0,0 +1,20 @@
+package xyz.driver.pdsuidomain.formats.json.intervention
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.InterventionType
+
+final case class ApiInterventionType(id: Long, name: String)
+
+object ApiInterventionType {
+
+ implicit val format: Format[ApiInterventionType] = (
+ (JsPath \ "id").format[Long] and
+ (JsPath \ "name").format[String]
+ ) (ApiInterventionType.apply, unlift(ApiInterventionType.unapply))
+
+ def fromDomain(interventionType: InterventionType) = ApiInterventionType(
+ id = interventionType.id.id,
+ name = interventionType.name
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala
new file mode 100644
index 0000000..416237a
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala
@@ -0,0 +1,44 @@
+package xyz.driver.pdsuidomain.formats.json.intervention
+
+import xyz.driver.pdsuicommon.domain.LongId
+import xyz.driver.pdsuidomain.entities.{InterventionArm, InterventionWithArms}
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+
+final case class ApiPartialIntervention(typeId: Option[Long],
+ description: Option[String],
+ isActive: Option[Boolean],
+ arms: Option[List[Long]]) {
+
+ def applyTo(orig: InterventionWithArms): InterventionWithArms = {
+ val origIntervention = orig.intervention
+ val draftArmList = arms.map(_.map(x => InterventionArm(LongId(x), orig.intervention.id)))
+ orig.copy(
+ intervention = origIntervention.copy(
+ typeId = typeId.map(LongId(_)).orElse(origIntervention.typeId),
+ description = description.getOrElse(origIntervention.description),
+ isActive = isActive.getOrElse(origIntervention.isActive)
+ ),
+ arms = draftArmList.getOrElse(orig.arms)
+ )
+ }
+}
+
+object ApiPartialIntervention {
+
+ private val reads: Reads[ApiPartialIntervention] = (
+ (JsPath \ "typeId").readNullable[Long] and
+ (JsPath \ "description").readNullable[String] and
+ (JsPath \ "isActive").readNullable[Boolean] and
+ (JsPath \ "arms").readNullable[List[Long]]
+ ) (ApiPartialIntervention.apply _)
+
+ private val writes: Writes[ApiPartialIntervention] = (
+ (JsPath \ "typeId").writeNullable[Long] and
+ (JsPath \ "description").writeNullable[String] and
+ (JsPath \ "isActive").writeNullable[Boolean] and
+ (JsPath \ "arms").writeNullable[List[Long]]
+ ) (unlift(ApiPartialIntervention.unapply))
+
+ implicit val format: Format[ApiPartialIntervention] = Format(reads, writes)
+}