diff options
author | Aleksandr <ognelisar@gmail.com> | 2017-10-12 10:44:54 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2017-10-12 10:44:54 +0700 |
commit | f525ab2604cc5d1366c852bdbcb4d912bbcea800 (patch) | |
tree | 4fe4b35e1f474e2dc85a8885dc4c9002f3ea46c2 /src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala | |
parent | 9198729ebf3d20b650b4467daa0d484a3148f01c (diff) | |
parent | e15415d69ec990d5243e58704e232e619b80aa6f (diff) | |
download | rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.tar.gz rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.tar.bz2 rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.zip |
All merge conflicts are resolved
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala | 57 |
1 files changed, 57 insertions, 0 deletions
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 new file mode 100644 index 0000000..71423e8 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm/ApiEligibilityArm.scala @@ -0,0 +1,57 @@ +package xyz.driver.pdsuidomain.formats.json.eligibilityarm + +import play.api.libs.functional.syntax._ +import play.api.libs.json._ +import xyz.driver.entities.patient.CancerType +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.{EligibilityArm, EligibilityArmDisease, EligibilityArmWithDiseases} + +final case class ApiEligibilityArm(id: Long, + name: String, + originalName: String, + trialId: String, + diseases: Seq[String]) { + + 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 = CancerType + .fromString(disease) + .getOrElse(throw new NoSuchElementException(s"unknown condition $disease")) + EligibilityArmDisease(eligibilityArm.id, condition) + } + ) + } +} + +object ApiEligibilityArm { + + implicit val format: Format[ApiEligibilityArm] = ( + (JsPath \ "id").format[Long] and + (JsPath \ "name").format[String] and + (JsPath \ "originalName").format[String] and + (JsPath \ "trialId").format[String] and + (JsPath \ "diseases").format[Seq[String]] + )(ApiEligibilityArm.apply, unlift(ApiEligibilityArm.unapply)) + + 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) + ) + } +} |