From bc4f67fe6755a34d410e75ce9b475b3e1c2d38e3 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 13:16:42 +0700 Subject: Replace tuples in services replies to rich-classes --- .../json/sprayformats/patientcriterion.scala | 42 ++++++++++------------ .../json/sprayformats/patienthypothesis.scala | 21 ++++++----- .../formats/json/sprayformats/patientlabel.scala | 23 ++++++------ .../services/PatientCriterionService.scala | 21 +++++++---- .../services/PatientHypothesisService.scala | 16 ++++++--- .../pdsuidomain/services/PatientLabelService.scala | 20 +++++++---- 6 files changed, 80 insertions(+), 63 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala index b091746..8da153d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala @@ -1,10 +1,9 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.entities.labels.Label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuicommon.domain.FuzzyValue import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion +import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} object patientcriterion { import DefaultJsonProtocol._ @@ -38,30 +37,27 @@ object patientcriterion { override def read(json: JsValue) = json.convertTo[List[JsValue]].map(_.convertTo[DraftPatientCriterion]) } - implicit val patientCriterionWriter: JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] = - new JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] { - override def write(obj: (PatientCriterion, LongId[Label], List[PatientCriterionArm])): JsValue = { - val criterion = obj._1 - val labelId = obj._2 - val arms = obj._3 + implicit val patientCriterionWriter: JsonWriter[RichPatientCriterion] = + new JsonWriter[RichPatientCriterion] { + override def write(obj: RichPatientCriterion): JsValue = { JsObject( - "id" -> criterion.id.toJson, - "labelId" -> labelId.toJson, - "nctId" -> criterion.nctId.toJson, - "criterionId" -> criterion.criterionId.toJson, - "criterionText" -> criterion.criterionText.toJson, - "criterionValue" -> criterion.criterionValue.map { + "id" -> obj.patientCriterion.id.toJson, + "labelId" -> obj.labelId.toJson, + "nctId" -> obj.patientCriterion.nctId.toJson, + "criterionId" -> obj.patientCriterion.criterionId.toJson, + "criterionText" -> obj.patientCriterion.criterionText.toJson, + "criterionValue" -> obj.patientCriterion.criterionValue.map { case true => "Yes" case false => "No" }.toJson, - "criterionIsDefining" -> criterion.criterionIsDefining.toJson, - "criterionIsCompound" -> criterion.criterionValue.isEmpty.toJson, - "arms" -> arms.map(_.armName).toJson, - "eligibilityStatus" -> criterion.eligibilityStatus.toJson, - "verifiedEligibilityStatus" -> criterion.verifiedEligibilityStatus.toJson, - "isVerified" -> criterion.isVerified.toJson, - "isVisible" -> criterion.isVisible.toJson, - "lastUpdate" -> criterion.lastUpdate.toJson + "criterionIsDefining" -> obj.patientCriterion.criterionIsDefining.toJson, + "criterionIsCompound" -> obj.patientCriterion.criterionValue.isEmpty.toJson, + "arms" -> obj.armList.map(_.armName).toJson, + "eligibilityStatus" -> obj.patientCriterion.eligibilityStatus.toJson, + "verifiedEligibilityStatus" -> obj.patientCriterion.verifiedEligibilityStatus.toJson, + "isVerified" -> obj.patientCriterion.isVerified.toJson, + "isVisible" -> obj.patientCriterion.isVisible.toJson, + "lastUpdate" -> obj.patientCriterion.lastUpdate.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala index 4f2783c..a85d8af 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis object patienthypothesis { import DefaultJsonProtocol._ @@ -18,18 +19,16 @@ object patienthypothesis { case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json") } - implicit val patientHypothesisWriter: JsonWriter[(PatientHypothesis, Boolean)] = - new JsonWriter[(PatientHypothesis, Boolean)] { - override def write(obj: (PatientHypothesis, Boolean)): JsValue = { - val patientHypothesis = obj._1 - val isRationaleRequired = obj._2 + implicit val patientHypothesisWriter: JsonWriter[RichPatientHypothesis] = + new JsonWriter[RichPatientHypothesis] { + override def write(obj: RichPatientHypothesis): JsValue = { JsObject( - "id" -> patientHypothesis.id.toJson, - "patientId" -> patientHypothesis.patientId.toJson, - "hypothesisId" -> patientHypothesis.hypothesisId.toJson, - "matchedTrials" -> patientHypothesis.matchedTrials.toJson, - "rationale" -> patientHypothesis.rationale.toJson, - "isRationaleRequired" -> isRationaleRequired.toJson + "id" -> obj.patientHypothesis.id.toJson, + "patientId" -> obj.patientHypothesis.patientId.toJson, + "hypothesisId" -> obj.patientHypothesis.hypothesisId.toJson, + "matchedTrials" -> obj.patientHypothesis.matchedTrials.toJson, + "rationale" -> obj.patientHypothesis.rationale.toJson, + "isRationaleRequired" -> obj.isRequired.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala index 3b52833..d7ff5a4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuicommon.domain.FuzzyValue import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel object patientlabel { import DefaultJsonProtocol._ @@ -28,19 +29,17 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val patientLabelWriter: JsonWriter[(PatientLabel, Boolean)] = new JsonWriter[(PatientLabel, Boolean)] { - override def write(obj: (PatientLabel, Boolean)): JsValue = { - val patientLabel = obj._1 - val isVerified = obj._2 + implicit val patientLabelWriter: JsonWriter[RichPatientLabel] = new JsonWriter[RichPatientLabel] { + override def write(obj: RichPatientLabel): JsValue = { JsObject( - "id" -> patientLabel.id.toJson, - "labelId" -> patientLabel.labelId.toJson, - "primaryValue" -> patientLabel.primaryValue.toJson, - "verifiedPrimaryValue" -> patientLabel.verifiedPrimaryValue.toJson, - "score" -> patientLabel.score.toJson, - "isImplicitMatch" -> patientLabel.isImplicitMatch.toJson, - "isVisible" -> patientLabel.isVisible.toJson, - "isVerified" -> isVerified.toJson + "id" -> obj.patientLabel.id.toJson, + "labelId" -> obj.patientLabel.labelId.toJson, + "primaryValue" -> obj.patientLabel.primaryValue.toJson, + "verifiedPrimaryValue" -> obj.patientLabel.verifiedPrimaryValue.toJson, + "score" -> obj.patientLabel.score.toJson, + "isImplicitMatch" -> obj.patientLabel.isImplicitMatch.toJson, + "isVisible" -> obj.patientLabel.isVisible.toJson, + "isVerified" -> obj.isVerified.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala index 6d85f85..af926b8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala @@ -37,13 +37,21 @@ object PatientCriterionService { def userMessage: String = "Access denied" } + final case class RichPatientCriterion(patientCriterion: PatientCriterion, + labelId: LongId[Label], + armList: List[PatientCriterionArm]) + + object RichPatientCriterion { + implicit def toPhiString(x: RichPatientCriterion): PhiString = { + phi"RichPatientCriterion(patientCriterion=${x.patientCriterion}, labelId=${x.labelId}, arms=${x.armList})" + } + } + sealed trait GetListReply object GetListReply { type Error = GetListReply with DomainError - final case class EntityList(xs: Seq[(PatientCriterion, LongId[Label], List[PatientCriterionArm])], - totalFound: Int, - lastUpdate: Option[LocalDateTime]) + final case class EntityList(xs: Seq[RichPatientCriterion], totalFound: Int, lastUpdate: Option[LocalDateTime]) extends GetListReply case object AuthorizationError @@ -60,8 +68,7 @@ object PatientCriterionService { object GetByIdReply { type Error = GetByIdReply with DomainError - final case class Entity(x: PatientCriterion, labelId: LongId[Label], armList: List[PatientCriterionArm]) - extends GetByIdReply + final case class Entity(x: RichPatientCriterion) extends GetByIdReply case object AuthorizationError extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError @@ -74,8 +81,8 @@ object PatientCriterionService { final case class CommonError(userMessage: String) extends GetByIdReply with DomainError implicit def toPhiString(reply: GetByIdReply): PhiString = reply match { - case x: DomainError => phi"GetByIdReply.Error($x)" - case Entity(x, labelId, armList) => phi"GetByIdReply.Entity(entity=$x, labelId=$labelId, armList=$armList)" + case x: DomainError => phi"GetByIdReply.Error($x)" + case Entity(x) => phi"GetByIdReply.Entity($x)" } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala index f782cab..07734ed 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala @@ -23,9 +23,17 @@ object PatientHypothesisService { def userMessage: String = "Access denied" } + final case class RichPatientHypothesis(patientHypothesis: PatientHypothesis, isRequired: Boolean) + + object RichPatientHypothesis { + implicit def toPhiString(x: RichPatientHypothesis): PhiString = { + phi"RichPatientHypothesis(patientHypothesis=${x.patientHypothesis}, isRequired=${x.isRequired})" + } + } + sealed trait GetListReply object GetListReply { - final case class EntityList(xs: Seq[(PatientHypothesis, Boolean)], totalFound: Int) extends GetListReply + final case class EntityList(xs: Seq[RichPatientHypothesis], totalFound: Int) extends GetListReply case object AuthorizationError extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError @@ -38,7 +46,7 @@ object PatientHypothesisService { sealed trait GetByIdReply object GetByIdReply { - final case class Entity(x: PatientHypothesis, isRequired: Boolean) extends GetByIdReply + final case class Entity(x: RichPatientHypothesis) extends GetByIdReply type Error = GetByIdReply with DomainError @@ -53,8 +61,8 @@ object PatientHypothesisService { final case class CommonError(userMessage: String) extends GetByIdReply with DomainError implicit def toPhiString(reply: GetByIdReply): PhiString = reply match { - case x: DomainError => phi"GetByIdReply.Error($x)" - case Entity(x, isRequired) => phi"GetByIdReply.Entity($x, $isRequired)" + case x: DomainError => phi"GetByIdReply.Error($x)" + case Entity(x) => phi"GetByIdReply.Entity($x)" } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala index 2a4d7fc..cede890 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala @@ -24,9 +24,17 @@ object PatientLabelService { def userMessage: String = "Access denied" } + final case class RichPatientLabel(patientLabel: PatientLabel, isVerified: Boolean) + + object RichPatientLabel { + implicit def toPhiString(x: RichPatientLabel): PhiString = { + phi"RichPatientLabel(patientLabel=${x.patientLabel}, isVerified=${x.isVerified})" + } + } + sealed trait GetListReply object GetListReply { - final case class EntityList(xs: Seq[(PatientLabel, Boolean)], totalFound: Int) extends GetListReply + final case class EntityList(xs: Seq[RichPatientLabel], totalFound: Int) extends GetListReply case object AuthorizationError extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError @@ -52,7 +60,7 @@ object PatientLabelService { sealed trait GetByLabelIdReply object GetByLabelIdReply { - final case class Entity(x: PatientLabel, isVerified: Boolean) extends GetByLabelIdReply + final case class Entity(x: RichPatientLabel) extends GetByLabelIdReply type Error = GetByLabelIdReply with DomainError @@ -68,7 +76,7 @@ object PatientLabelService { implicit def toPhiString(reply: GetByLabelIdReply): PhiString = reply match { case x: DomainError => phi"GetByIdReply.Error($x)" - case Entity(x, y) => phi"GetByIdReply.Entity($x, $y)" + case Entity(x) => phi"GetByIdReply.Entity($x)" } } @@ -76,7 +84,7 @@ object PatientLabelService { object UpdateReply { type Error = UpdateReply with DomainError - final case class Updated(updated: PatientLabel, isVerified: Boolean) extends UpdateReply + final case class Updated(updated: RichPatientLabel) extends UpdateReply case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError @@ -89,8 +97,8 @@ object PatientLabelService { final case class CommonError(userMessage: String) extends UpdateReply with DomainError implicit def toPhiString(reply: UpdateReply): PhiString = reply match { - case Updated(x, y) => phi"Updated($x, $y)" - case x: Error => DomainError.toPhiString(x) + case Updated(x) => phi"Updated($x)" + case x: Error => DomainError.toPhiString(x) } } } -- cgit v1.2.3