From 3a9ba980e6ce08361f6f3cdaf6ab2a401101b35c Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 27 Sep 2017 15:50:35 +0700 Subject: PDSUI-2275 Added delivery methods to intervention type entrypoint --- .../driver/pdsuidomain/entities/Intervention.scala | 140 +++++++++++++++++++++ .../json/intervention/ApiInterventionType.scala | 18 ++- .../formats/json/sprayformats/intervention.scala | 33 ++++- 3 files changed, 184 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala index 5dada55..6dc42d0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala @@ -2,10 +2,150 @@ package xyz.driver.pdsuidomain.entities import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod._ final case class InterventionType(id: LongId[InterventionType], name: String) object InterventionType { + + sealed trait InterventionTypeName + case object RadiationTherapy extends InterventionTypeName + case object Chemotherapy extends InterventionTypeName + case object TargetedTherapy extends InterventionTypeName + case object Immunotherapy extends InterventionTypeName + case object Surgery extends InterventionTypeName + case object HormoneTherapy extends InterventionTypeName + case object Other extends InterventionTypeName + case object Radiation extends InterventionTypeName + case object SurgeryProcedure extends InterventionTypeName + + def typeFromString: PartialFunction[String, InterventionTypeName] = { + case "Radiation therapy" => RadiationTherapy + case "Chemotherapy" => Chemotherapy + case "Targeted therapy" => TargetedTherapy + case "Immunotherapy" => Immunotherapy + case "Surgery" => Surgery + case "Hormone therapy" => HormoneTherapy + case "Other" => Other + case "Radiation" => Radiation + case "Surgery/Procedure" => SurgeryProcedure + } + + def typeToString(x: InterventionTypeName): String = x match { + case RadiationTherapy => "Radiation therapy" + case Chemotherapy => "Chemotherapy" + case TargetedTherapy => "Targeted therapy" + case Immunotherapy => "Immunotherapy" + case Surgery => "Surgery" + case HormoneTherapy => "Hormone therapy" + case Other => "Other" + case Radiation => "Radiation" + case SurgeryProcedure => "Surgery/Procedure" + } + + sealed trait DeliveryMethod + object DeliveryMethod { + case object IntravenousInfusionIV extends DeliveryMethod + case object IntramuscularInjection extends DeliveryMethod + case object SubcutaneousInjection extends DeliveryMethod + case object IntradermalInjection extends DeliveryMethod + case object SpinalInjection extends DeliveryMethod + case object Oral extends DeliveryMethod + case object Topical extends DeliveryMethod + case object TransdermalPatch extends DeliveryMethod + case object Inhalation extends DeliveryMethod + case object Rectal extends DeliveryMethod + case object ExternalRadiationTherapy extends DeliveryMethod + case object Brachytherapy extends DeliveryMethod + case object SystemicRadiationTherapyIV extends DeliveryMethod + case object SystemicRadiationTherapyOral extends DeliveryMethod + case object ProtonBeamTherapy extends DeliveryMethod + case object RadioFrequencyAblationRFA extends DeliveryMethod + case object Cryoablation extends DeliveryMethod + case object TherapeuticConventionalSurgery extends DeliveryMethod + case object RoboticAssistedLaparoscopicSurgery extends DeliveryMethod + + def fromString: PartialFunction[String, DeliveryMethod] = { + case "Intravenous Infusion (IV)" => IntravenousInfusionIV + case "Intramuscular Injection" => IntramuscularInjection + case "Subcutaneous Injection" => SubcutaneousInjection + case "Intradermal Injection" => IntradermalInjection + case "Spinal Injection" => SpinalInjection + case "Oral" => Oral + case "Topical" => Topical + case "Transdermal Patch" => TransdermalPatch + case "Inhalation" => Inhalation + case "Rectal" => Rectal + case "External Radiation Therapy" => ExternalRadiationTherapy + case "Brachytherapy" => Brachytherapy + case "Systemic Radiation Therapy (IV)" => SystemicRadiationTherapyIV + case "Systemic Radiation Therapy (Oral)" => SystemicRadiationTherapyOral + case "Proton Beam Therapy" => ProtonBeamTherapy + case "Radio-Frequency Ablation (RFA)" => RadioFrequencyAblationRFA + case "Cryoablation" => Cryoablation + case "Therapeutic Conventional Surgery" => TherapeuticConventionalSurgery + case "Robotic Assisted Laparoscopic Surgery" => RoboticAssistedLaparoscopicSurgery + } + + def methodToString(x: DeliveryMethod): String = x match { + case IntravenousInfusionIV => "Intravenous Infusion (IV)" + case IntramuscularInjection => "Intramuscular Injection" + case SubcutaneousInjection => "Subcutaneous Injection" + case IntradermalInjection => "Intradermal Injection" + case SpinalInjection => "Spinal Injection" + case Oral => "Oral" + case Topical => "Topical" + case TransdermalPatch => "Transdermal Patch" + case Inhalation => "Inhalation" + case Rectal => "Rectal" + case ExternalRadiationTherapy => "External Radiation Therapy" + case Brachytherapy => "Brachytherapy" + case SystemicRadiationTherapyIV => "Systemic Radiation Therapy (IV)" + case SystemicRadiationTherapyOral => "Systemic Radiation Therapy (Oral)" + case ProtonBeamTherapy => "Proton Beam Therapy" + case RadioFrequencyAblationRFA => "Radio-Frequency Ablation (RFA)" + case Cryoablation => "Cryoablation" + case TherapeuticConventionalSurgery => "Therapeutic Conventional Surgery" + case RoboticAssistedLaparoscopicSurgery => "Robotic Assisted Laparoscopic Surgery" + } + } + + val commonMethods = Set[DeliveryMethod]( + IntravenousInfusionIV, + IntramuscularInjection, + SubcutaneousInjection, + IntradermalInjection, + SpinalInjection, + Oral, + Topical, + TransdermalPatch, + Inhalation, + Rectal + ) + + val deliveryMethodGroups: Map[LongId[InterventionType], Set[DeliveryMethod]] = Map( + LongId(1) -> commonMethods, + LongId(2) -> commonMethods, + LongId(3) -> commonMethods, + LongId(4) -> commonMethods, + LongId(5) -> commonMethods, + LongId(6) -> commonMethods, + LongId(7) -> commonMethods, + LongId(8) -> Set( + ExternalRadiationTherapy, + Brachytherapy, + SystemicRadiationTherapyIV, + SystemicRadiationTherapyOral, + ProtonBeamTherapy + ), + LongId(9) -> Set( + RadioFrequencyAblationRFA, + Cryoablation, + TherapeuticConventionalSurgery, + RoboticAssistedLaparoscopicSurgery + ) + ) + implicit def toPhiString(x: InterventionType): PhiString = { import x._ phi"InterventionType(id=$id, name=${Unsafe(name)})" 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..c28c5b4 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 @@ -4,8 +4,9 @@ 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) } @@ -14,11 +15,16 @@ 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 - ) + def fromDomain(interventionType: InterventionType) = { + val typeMethods = InterventionType.deliveryMethodGroups.getOrElse(interventionType.id, Set.empty[DeliveryMethod]) + ApiInterventionType( + id = interventionType.id.id, + name = interventionType.name, + deliveryMethods = typeMethods.map(DeliveryMethod.methodToString).toList + ) + } } 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 daa28e4..4bd5bad 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 @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod import xyz.driver.pdsuidomain.entities._ object intervention { @@ -119,6 +120,36 @@ object intervention { case _ => deserializationError(s"Expected Json Object as partial Intervention, but got $json") } - implicit val interventionTypeFormat: RootJsonFormat[InterventionType] = jsonFormat2(InterventionType.apply) + implicit val interventionTypeFormat: JsonFormat[InterventionType] = new RootJsonFormat[InterventionType] { + override def read(json: JsValue) = json match { + case JsObject(fields) => + val id = fields + .get("id") + .map(_.convertTo[LongId[InterventionType]]) + .getOrElse(deserializationError(s"Intervention type json object does not contain `id` field: $json")) + + val name = fields + .get("name") + .map(_.convertTo[String]) + .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json")) + + InterventionType(id, name) + + case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") + } + + override def write(obj: InterventionType) = { + val typeMethods = InterventionType.deliveryMethodGroups + .getOrElse(obj.id, Set.empty[DeliveryMethod]) + .map(DeliveryMethod.methodToString) + .toList + + JsObject( + "id" -> obj.id.toJson, + "name" -> obj.name.toJson, + "deliveryMethods" -> typeMethods.toJson + ) + } + } } -- cgit v1.2.3 From 1fa90814e5930ad0bbe61ba5b082747781e1dc92 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 27 Sep 2017 16:41:04 +0700 Subject: PDSUI-2275 Review fixes --- .../driver/pdsuidomain/entities/Intervention.scala | 120 ++++++++++++--------- .../pdsuidomain/fakes/entities/trialcuration.scala | 5 +- .../json/intervention/ApiInterventionType.scala | 16 ++- .../formats/json/sprayformats/intervention.scala | 17 +-- .../sprayformats/InterventionFormatSuite.scala | 7 +- 5 files changed, 84 insertions(+), 81 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala index 6dc42d0..f5b486b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala @@ -2,24 +2,83 @@ package xyz.driver.pdsuidomain.entities import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod._ -final case class InterventionType(id: LongId[InterventionType], name: String) +sealed trait InterventionType { + val id: LongId[InterventionType] + val name: String + val deliveryMethod: Set[DeliveryMethod] +} object InterventionType { - sealed trait InterventionTypeName - case object RadiationTherapy extends InterventionTypeName - case object Chemotherapy extends InterventionTypeName - case object TargetedTherapy extends InterventionTypeName - case object Immunotherapy extends InterventionTypeName - case object Surgery extends InterventionTypeName - case object HormoneTherapy extends InterventionTypeName - case object Other extends InterventionTypeName - case object Radiation extends InterventionTypeName - case object SurgeryProcedure extends InterventionTypeName - - def typeFromString: PartialFunction[String, InterventionTypeName] = { + final case object RadiationTherapy extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](1) + val name: String = "Radiation therapy" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object Chemotherapy extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](2) + val name: String = "Chemotherapy" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object TargetedTherapy extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](3) + val name: String = "Targeted therapy" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object Immunotherapy extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](4) + val name: String = "Immunotherapy" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object Surgery extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](5) + val name: String = "Surgery" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object HormoneTherapy extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](6) + val name: String = "Hormone therapy" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object Other extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](7) + val name: String = "Other" + val deliveryMethod: Set[DeliveryMethod] = commonMethods + } + + final case object Radiation extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](8) + val name: String = "Radiation" + val deliveryMethod: Set[DeliveryMethod] = Set( + ExternalRadiationTherapy, + Brachytherapy, + SystemicRadiationTherapyIV, + SystemicRadiationTherapyOral, + ProtonBeamTherapy + ) + } + + final case object SurgeryProcedure extends InterventionType { + val id: LongId[InterventionType] = LongId[InterventionType](9) + val name: String = "Surgery/Procedure" + val deliveryMethod: Set[DeliveryMethod] = Set( + RadioFrequencyAblationRFA, + Cryoablation, + TherapeuticConventionalSurgery, + RoboticAssistedLaparoscopicSurgery + ) + } + + def typeFromString: PartialFunction[String, InterventionType] = { case "Radiation therapy" => RadiationTherapy case "Chemotherapy" => Chemotherapy case "Targeted therapy" => TargetedTherapy @@ -31,18 +90,6 @@ object InterventionType { case "Surgery/Procedure" => SurgeryProcedure } - def typeToString(x: InterventionTypeName): String = x match { - case RadiationTherapy => "Radiation therapy" - case Chemotherapy => "Chemotherapy" - case TargetedTherapy => "Targeted therapy" - case Immunotherapy => "Immunotherapy" - case Surgery => "Surgery" - case HormoneTherapy => "Hormone therapy" - case Other => "Other" - case Radiation => "Radiation" - case SurgeryProcedure => "Surgery/Procedure" - } - sealed trait DeliveryMethod object DeliveryMethod { case object IntravenousInfusionIV extends DeliveryMethod @@ -123,29 +170,6 @@ object InterventionType { Rectal ) - val deliveryMethodGroups: Map[LongId[InterventionType], Set[DeliveryMethod]] = Map( - LongId(1) -> commonMethods, - LongId(2) -> commonMethods, - LongId(3) -> commonMethods, - LongId(4) -> commonMethods, - LongId(5) -> commonMethods, - LongId(6) -> commonMethods, - LongId(7) -> commonMethods, - LongId(8) -> Set( - ExternalRadiationTherapy, - Brachytherapy, - SystemicRadiationTherapyIV, - SystemicRadiationTherapyOral, - ProtonBeamTherapy - ), - LongId(9) -> Set( - RadioFrequencyAblationRFA, - Cryoablation, - TherapeuticConventionalSurgery, - RoboticAssistedLaparoscopicSurgery - ) - ) - implicit def toPhiString(x: InterventionType): PhiString = { import x._ phi"InterventionType(id=$id, name=${Unsafe(name)})" 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 a2bdf43..19dd95e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -130,9 +130,6 @@ object trialcuration { name = generators.nextString() ) - def nextInterventionType(): InterventionType = InterventionType( - id = nextLongId[InterventionType], - name = generators.nextString() - ) + def nextInterventionType(): InterventionType = InterventionType.typeFromString("Other") } 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 c28c5b4..3550437 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,13 +2,12 @@ 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, deliveryMethods: List[String]) { - def toDomain = InterventionType(id = LongId[InterventionType](id), name = name) + def toDomain = InterventionType.typeFromString(name) } object ApiInterventionType { @@ -19,12 +18,9 @@ object ApiInterventionType { (JsPath \ "deliveryMethods").format[List[String]] )(ApiInterventionType.apply, unlift(ApiInterventionType.unapply)) - def fromDomain(interventionType: InterventionType) = { - val typeMethods = InterventionType.deliveryMethodGroups.getOrElse(interventionType.id, Set.empty[DeliveryMethod]) - ApiInterventionType( - id = interventionType.id.id, - name = interventionType.name, - deliveryMethods = typeMethods.map(DeliveryMethod.methodToString).toList - ) - } + def fromDomain(interventionType: InterventionType) = ApiInterventionType( + id = interventionType.id.id, + name = interventionType.name, + deliveryMethods = interventionType.deliveryMethod.map(DeliveryMethod.methodToString).toList + ) } 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 4bd5bad..2bf1f2b 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 @@ -123,33 +123,22 @@ object intervention { implicit val interventionTypeFormat: JsonFormat[InterventionType] = new RootJsonFormat[InterventionType] { override def read(json: JsValue) = json match { case JsObject(fields) => - val id = fields - .get("id") - .map(_.convertTo[LongId[InterventionType]]) - .getOrElse(deserializationError(s"Intervention type json object does not contain `id` field: $json")) - val name = fields .get("name") .map(_.convertTo[String]) .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json")) - InterventionType(id, name) + InterventionType.typeFromString(name) case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") } - override def write(obj: InterventionType) = { - val typeMethods = InterventionType.deliveryMethodGroups - .getOrElse(obj.id, Set.empty[DeliveryMethod]) - .map(DeliveryMethod.methodToString) - .toList - + override def write(obj: InterventionType) = JsObject( "id" -> obj.id.toJson, "name" -> obj.name.toJson, - "deliveryMethods" -> typeMethods.toJson + "deliveryMethods" -> obj.deliveryMethod.map(DeliveryMethod.methodToString).toJson ) - } } } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala index d406162..dad39c8 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala @@ -59,14 +59,11 @@ class InterventionFormatSuite extends FlatSpec with Matchers { } "Json format for InterventionType" should "read and write correct JSON" in { - val interventionType = InterventionType( - id = LongId(9), - name = "type name" - ) + val interventionType = InterventionType.typeFromString("Surgery/Procedure") val writtenJson = interventionTypeFormat.write(interventionType) writtenJson should be( - """{"id":9,"name":"type name","deliveryMethods":["Radio-Frequency Ablation (RFA)", + """{"id":9,"name":"Surgery/Procedure","deliveryMethods":["Radio-Frequency Ablation (RFA)", "Cryoablation","Therapeutic Conventional Surgery","Robotic Assisted Laparoscopic Surgery"]}""".parseJson) val parsedInterventionType = interventionTypeFormat.read(writtenJson) -- cgit v1.2.3 From f10c767bf16f14921a194936188c47dd138ffee7 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 27 Sep 2017 17:10:59 +0700 Subject: PDSUI-2275 Review fixes --- .../driver/pdsuidomain/entities/Intervention.scala | 48 +++++++++++----------- .../pdsuidomain/fakes/entities/trialcuration.scala | 13 +++++- .../json/intervention/ApiInterventionType.scala | 2 +- .../formats/json/sprayformats/intervention.scala | 2 +- 4 files changed, 38 insertions(+), 27 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala index f5b486b..d0eefa9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Intervention.scala @@ -8,57 +8,57 @@ import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod._ sealed trait InterventionType { val id: LongId[InterventionType] val name: String - val deliveryMethod: Set[DeliveryMethod] + val deliveryMethods: Set[DeliveryMethod] } object InterventionType { final case object RadiationTherapy extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](1) - val name: String = "Radiation therapy" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](1) + val name: String = "Radiation therapy" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object Chemotherapy extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](2) - val name: String = "Chemotherapy" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](2) + val name: String = "Chemotherapy" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object TargetedTherapy extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](3) - val name: String = "Targeted therapy" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](3) + val name: String = "Targeted therapy" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object Immunotherapy extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](4) - val name: String = "Immunotherapy" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](4) + val name: String = "Immunotherapy" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object Surgery extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](5) - val name: String = "Surgery" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](5) + val name: String = "Surgery" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object HormoneTherapy extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](6) - val name: String = "Hormone therapy" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](6) + val name: String = "Hormone therapy" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object Other extends InterventionType { - val id: LongId[InterventionType] = LongId[InterventionType](7) - val name: String = "Other" - val deliveryMethod: Set[DeliveryMethod] = commonMethods + val id: LongId[InterventionType] = LongId[InterventionType](7) + val name: String = "Other" + val deliveryMethods: Set[DeliveryMethod] = commonMethods } final case object Radiation extends InterventionType { val id: LongId[InterventionType] = LongId[InterventionType](8) val name: String = "Radiation" - val deliveryMethod: Set[DeliveryMethod] = Set( + val deliveryMethods: Set[DeliveryMethod] = Set( ExternalRadiationTherapy, Brachytherapy, SystemicRadiationTherapyIV, @@ -70,7 +70,7 @@ object InterventionType { final case object SurgeryProcedure extends InterventionType { val id: LongId[InterventionType] = LongId[InterventionType](9) val name: String = "Surgery/Procedure" - val deliveryMethod: Set[DeliveryMethod] = Set( + val deliveryMethods: Set[DeliveryMethod] = Set( RadioFrequencyAblationRFA, Cryoablation, TherapeuticConventionalSurgery, 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 19dd95e..fe5bf09 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -7,6 +7,7 @@ import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion object trialcuration { import xyz.driver.core.generators import common._ + import xyz.driver.pdsuidomain.entities.InterventionType._ def nextTrial(): Trial = Trial( id = nextStringId[Trial], @@ -130,6 +131,16 @@ object trialcuration { name = generators.nextString() ) - def nextInterventionType(): InterventionType = InterventionType.typeFromString("Other") + def nextInterventionType(): InterventionType = generators.oneOf[InterventionType]( + RadiationTherapy, + Chemotherapy, + TargetedTherapy, + Immunotherapy, + Surgery, + HormoneTherapy, + Other, + Radiation, + SurgeryProcedure + ) } 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 3550437..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 @@ -21,6 +21,6 @@ object ApiInterventionType { def fromDomain(interventionType: InterventionType) = ApiInterventionType( id = interventionType.id.id, name = interventionType.name, - deliveryMethods = interventionType.deliveryMethod.map(DeliveryMethod.methodToString).toList + deliveryMethods = interventionType.deliveryMethods.map(DeliveryMethod.methodToString).toList ) } 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 2bf1f2b..62cb9fa 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 @@ -137,7 +137,7 @@ object intervention { JsObject( "id" -> obj.id.toJson, "name" -> obj.name.toJson, - "deliveryMethods" -> obj.deliveryMethod.map(DeliveryMethod.methodToString).toJson + "deliveryMethods" -> obj.deliveryMethods.map(DeliveryMethod.methodToString).toJson ) } -- cgit v1.2.3