diff options
author | timgushue <tim@driver.xyz> | 2017-09-27 09:34:45 -0700 |
---|---|---|
committer | timgushue <tim@driver.xyz> | 2017-09-27 09:34:45 -0700 |
commit | e9d3e19f637614809aab39d9df2d1fcc6c78916e (patch) | |
tree | 29560b9b5bfb1b235c6429506f56fa9dab8d4510 /src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention | |
parent | 0ef0059e9b47430e52d6bad4ced5b1be7f3b1a0d (diff) | |
parent | c24679f1ae7d7ccc4e6693535b0aa3ac0e1ca225 (diff) | |
download | rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.tar.gz rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.tar.bz2 rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.zip |
Merge branch 'master' into add-slot-eligibility-arms
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention')
3 files changed, 19 insertions, 8 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 index f306a71..072ed25 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala @@ -12,6 +12,7 @@ final case class ApiIntervention(id: Long, isActive: Boolean, arms: List[Long], trialId: String, + deliveryMethod: Option[String], originalName: String, originalDosage: String, originalType: Option[String]) { @@ -26,7 +27,8 @@ final case class ApiIntervention(id: Long, originalType = this.originalType.map(id => id.toString), dosage = this.dosage, originalDosage = this.originalDosage, - isActive = this.isActive + isActive = this.isActive, + deliveryMethod = this.deliveryMethod ) InterventionWithArms(intervention, this.arms.map { armId => @@ -47,6 +49,7 @@ object ApiIntervention { (JsPath \ "isActive").format[Boolean] and (JsPath \ "arms").format[List[Long]] and (JsPath \ "trialId").format[String] and + (JsPath \ "deliveryMethod").formatNullable[String] and (JsPath \ "originalName").format[String] and (JsPath \ "originalDosage").format[String] and (JsPath \ "originalType").formatNullable[String] @@ -64,6 +67,7 @@ object ApiIntervention { isActive = intervention.isActive, arms = arms.map(_.armId.id), trialId = intervention.trialId.id, + deliveryMethod = intervention.deliveryMethod, originalName = intervention.originalName, originalDosage = intervention.originalDosage, originalType = intervention.originalType 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 index ebef225..3db8bfa 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala @@ -2,23 +2,25 @@ package xyz.driver.pdsuidomain.formats.json.intervention import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.InterventionType +import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod -final case class ApiInterventionType(id: Long, name: String) { +final case class ApiInterventionType(id: Long, name: String, deliveryMethods: List[String]) { - def toDomain = InterventionType(id = LongId[InterventionType](id), name = name) + def toDomain = InterventionType.typeFromString(name) } object ApiInterventionType { implicit val format: Format[ApiInterventionType] = ( (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] + (JsPath \ "name").format[String] and + (JsPath \ "deliveryMethods").format[List[String]] )(ApiInterventionType.apply, unlift(ApiInterventionType.unapply)) def fromDomain(interventionType: InterventionType) = ApiInterventionType( id = interventionType.id.id, - name = interventionType.name + name = interventionType.name, + deliveryMethods = interventionType.deliveryMethods.map(DeliveryMethod.methodToString).toList ) } 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 index 74f16e1..28a8555 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala @@ -16,6 +16,7 @@ final case class ApiPartialIntervention(name: Option[String], typeId: Option[Long], dosage: Option[String], isActive: Option[Boolean], + deliveryMethod: Option[String], arms: Option[List[Long]]) { def applyTo(orig: InterventionWithArms): InterventionWithArms = { @@ -26,7 +27,8 @@ final case class ApiPartialIntervention(name: Option[String], name = name.getOrElse(origIntervention.name), typeId = typeId.map(LongId(_)).orElse(origIntervention.typeId), dosage = dosage.getOrElse(origIntervention.dosage), - isActive = isActive.getOrElse(origIntervention.isActive) + isActive = isActive.getOrElse(origIntervention.isActive), + deliveryMethod = deliveryMethod.orElse(origIntervention.deliveryMethod) ), arms = draftArmList.getOrElse(orig.arms) ) @@ -50,7 +52,8 @@ final case class ApiPartialIntervention(name: Option[String], originalType = Option(""), dosage = dosage.getOrElse(""), originalDosage = dosage.getOrElse(""), - isActive = isActive.getOrElse(false) + isActive = isActive.getOrElse(false), + deliveryMethod = deliveryMethod ), arms = arms.map(_.map(x => InterventionArm(armId = LongId(x), interventionId = LongId(0)))).getOrElse(List.empty) @@ -69,6 +72,7 @@ object ApiPartialIntervention { (JsPath \ "typeId").readNullable[Long] and (JsPath \ "dosage").readNullable[String] and (JsPath \ "isActive").readNullable[Boolean] and + (JsPath \ "deliveryMethod").readNullable[String] and (JsPath \ "arms").readNullable[List[Long]] )(ApiPartialIntervention.apply _) @@ -78,6 +82,7 @@ object ApiPartialIntervention { (JsPath \ "typeId").writeNullable[Long] and (JsPath \ "dosage").writeNullable[String] and (JsPath \ "isActive").writeNullable[Boolean] and + (JsPath \ "deliveryMethod").writeNullable[String] and (JsPath \ "arms").writeNullable[List[Long]] )(unlift(ApiPartialIntervention.unapply)) |