diff options
Diffstat (limited to 'src')
5 files changed, 88 insertions, 37 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/EligibilityArm.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/EligibilityArm.scala index 2f5924c..329c15c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/EligibilityArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/EligibilityArm.scala @@ -4,6 +4,7 @@ import java.time.LocalDateTime import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.entities.Trial.Condition final case class EligibilityArm(id: LongId[EligibilityArm], name: String, @@ -18,3 +19,24 @@ object EligibilityArm { phi"Arm(id=$id, name=${Unsafe(x.name)}, trialId=${Unsafe(x.trialId)})" } } + +final case class EligibilityArmDisease(eligibilityArmId: LongId[EligibilityArm], disease: Condition) + +object EligibilityArmDisease { + + implicit def toPhiString(x: EligibilityArmDisease): PhiString = { + phi"EligibilityArmDisease(eligibilityArmId=${Unsafe(x.eligibilityArmId)}, disease=${Unsafe(x.disease)})" + } + +} + +final case class EligibilityArmWithDiseases(eligibilityArm: EligibilityArm, + eligibilityArmDiseases: Seq[EligibilityArmDisease]) + +object EligibilityArmWithDiseases { + + implicit def toPhiString(x: EligibilityArmWithDiseases): PhiString = { + import x._ + phi"EligibilityArmWithDiseases(eligibilityArm=$eligibilityArm, eligibilityArmDiseases=$eligibilityArmDiseases)" + } +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala index e7eb022..4d6d0a2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala @@ -1,20 +1,27 @@ package xyz.driver.pdsuidomain.formats.json.eligibilityarm -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.EligibilityArm import play.api.libs.functional.syntax._ import play.api.libs.json._ +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.{EligibilityArm, EligibilityArmDisease, EligibilityArmWithDiseases, Trial} -final case class ApiEligibilityArm(id: Long, name: String, originalName: String, trialId: String) { +final case class ApiEligibilityArm(id: Long, name: String, originalName: String, trialId: String, diseases: Seq[String]) { - def toDomain: EligibilityArm = EligibilityArm( - id = LongId(this.id), - name = this.name, - originalName = this.originalName, - trialId = StringId(this.trialId), - deleted = None // if we have an ApiEligibilityArm object, the EligibilityArm itself has not been deleted - ) + def toDomain: EligibilityArmWithDiseases = { + val eligibilityArm = EligibilityArm( + id = LongId(this.id), + name = this.name, + originalName = this.originalName, + trialId = StringId(this.trialId), + deleted = None // if we have an ApiEligibilityArm object, the EligibilityArm itself has not been deleted + ) + EligibilityArmWithDiseases(eligibilityArm, this.diseases.map { disease => + val condition = Trial.Condition.fromString(disease) + .getOrElse(throw new NoSuchElementException(s"unknown condition $disease")) + EligibilityArmDisease(eligibilityArm.id, condition) + }) + } } object ApiEligibilityArm { @@ -23,13 +30,19 @@ object ApiEligibilityArm { (JsPath \ "id").format[Long] and (JsPath \ "name").format[String] and (JsPath \ "originalName").format[String] and - (JsPath \ "trialId").format[String] + (JsPath \ "trialId").format[String] and + (JsPath \ "diseases").format[Seq[String]] )(ApiEligibilityArm.apply, unlift(ApiEligibilityArm.unapply)) - def fromDomain(arm: EligibilityArm): ApiEligibilityArm = ApiEligibilityArm( - id = arm.id.id, - name = arm.name, - originalName = arm.originalName, - trialId = arm.trialId.id - ) + def fromDomain(eligibilityArmWithDiseases: EligibilityArmWithDiseases): ApiEligibilityArm = { + import eligibilityArmWithDiseases.{eligibilityArm, eligibilityArmDiseases} + + ApiEligibilityArm( + id = eligibilityArm.id.id, + name = eligibilityArm.name, + originalName = eligibilityArm.originalName, + trialId = eligibilityArm.trialId.id, + diseases = eligibilityArmDiseases.map(_.disease.toString) + ) + } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityCreateArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityCreateArm.scala index 6f55c10..6cf71a2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityCreateArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityCreateArm.scala @@ -1,17 +1,25 @@ package xyz.driver.pdsuidomain.formats.json.eligibilityarm import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.EligibilityArm +import xyz.driver.pdsuidomain.entities.{EligibilityArm, EligibilityArmDisease, EligibilityArmWithDiseases, Trial} import play.api.libs.json.{Format, Json} -final case class ApiCreateEligibilityArm(name: String, trialId: String) { +final case class ApiCreateEligibilityArm(name: String, trialId: String, diseases: Seq[String]) { - def toDomain = EligibilityArm( - id = LongId(0), - name = name, - trialId = StringId(trialId), - originalName = name - ) + def toDomain: EligibilityArmWithDiseases = { + val eligibilityArm = EligibilityArm( + id = LongId(0), + name = name, + trialId = StringId(trialId), + originalName = name + ) + + EligibilityArmWithDiseases(eligibilityArm, diseases.map { disease => + val condition = Trial.Condition.fromString(disease) + .getOrElse(throw new NoSuchElementException(s"unknown condition $disease")) + EligibilityArmDisease(eligibilityArm.id, condition) + }) + } } object ApiCreateEligibilityArm { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiPartialEligibilityArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiPartialEligibilityArm.scala index cc3d460..3d9445f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiPartialEligibilityArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiPartialEligibilityArm.scala @@ -1,11 +1,19 @@ package xyz.driver.pdsuidomain.formats.json.eligibilityarm -import xyz.driver.pdsuidomain.entities.EligibilityArm import play.api.libs.json.{Format, Json} +import xyz.driver.pdsuidomain.entities.{EligibilityArmDisease, EligibilityArmWithDiseases, Trial} -final case class ApiPartialEligibilityArm(name: String) { +final case class ApiPartialEligibilityArm(name: String, diseases: Seq[String]) { - def applyTo(arm: EligibilityArm): EligibilityArm = arm.copy(name = name) + def applyTo(armWithDisease: EligibilityArmWithDiseases): EligibilityArmWithDiseases = { + val arm = armWithDisease.eligibilityArm.copy(name = name) + val armDiseases = diseases.map { disease => + EligibilityArmDisease( + armWithDisease.eligibilityArm.id, + Trial.Condition.fromString(disease).getOrElse(throw new NoSuchElementException(s"unknown condition $disease"))) + } + EligibilityArmWithDiseases(arm ,armDiseases) + } } object ApiPartialEligibilityArm { diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityArmService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityArmService.scala index b34b34e..af7cecb 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityArmService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityArmService.scala @@ -5,7 +5,7 @@ import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuicommon.error.DomainError import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.EligibilityArm +import xyz.driver.pdsuidomain.entities.{EligibilityArm, EligibilityArmWithDiseases} import scala.concurrent.Future @@ -22,7 +22,7 @@ object EligibilityArmService { sealed trait GetByIdReply object GetByIdReply { - final case class Entity(x: EligibilityArm) extends GetByIdReply + final case class Entity(x: EligibilityArmWithDiseases) extends GetByIdReply type Error = GetByIdReply with DomainError @@ -39,7 +39,7 @@ object EligibilityArmService { object GetListReply { type Error = GetListReply with DomainError - final case class EntityList(xs: Seq[EligibilityArm], totalFound: Int) extends GetListReply + final case class EntityList(xs: Seq[EligibilityArmWithDiseases], totalFound: Int) extends GetListReply case object AuthorizationError extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError @@ -48,7 +48,7 @@ object EligibilityArmService { sealed trait UpdateReply object UpdateReply { - final case class Updated(updated: EligibilityArm) extends UpdateReply + final case class Updated(updated: EligibilityArmWithDiseases) extends UpdateReply type Error = UpdateReply with DomainError @@ -59,7 +59,7 @@ object EligibilityArmService { final case class CommonError(userMessage: String) extends UpdateReply with DomainError - final case class AlreadyExistsError(x: EligibilityArm) extends UpdateReply with DomainError { + final case class AlreadyExistsError(x: EligibilityArmWithDiseases) extends UpdateReply with DomainError { val userMessage = s"The arm with such name of trial already exists." } @@ -71,7 +71,7 @@ object EligibilityArmService { sealed trait CreateReply object CreateReply { - final case class Created(x: EligibilityArm) extends CreateReply + final case class Created(x: EligibilityArmWithDiseases) extends CreateReply type Error = CreateReply with DomainError @@ -80,7 +80,7 @@ object EligibilityArmService { final case class CommonError(userMessage: String) extends CreateReply with DomainError - final case class AlreadyExistsError(x: EligibilityArm) extends CreateReply with DomainError { + final case class AlreadyExistsError(x: EligibilityArmWithDiseases) extends CreateReply with DomainError { val userMessage = s"The arm with this name of trial already exists." } @@ -117,10 +117,10 @@ trait EligibilityArmService { def getById(armId: LongId[EligibilityArm])( implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply] - def create(draftEligibilityArm: EligibilityArm)( + def create(draftEligibilityArm: EligibilityArmWithDiseases)( implicit requestContext: AuthenticatedRequestContext): Future[CreateReply] - def update(origEligibilityArm: EligibilityArm, draftEligibilityArm: EligibilityArm)( + def update(origEligibilityArm: EligibilityArmWithDiseases, draftEligibilityArm: EligibilityArmWithDiseases)( implicit requestContext: AuthenticatedRequestContext): Future[UpdateReply] def delete(id: LongId[EligibilityArm])(implicit requestContext: AuthenticatedRequestContext): Future[DeleteReply] |