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 --- .../services/PatientCriterionService.scala | 21 ++++++++++++++------- .../services/PatientHypothesisService.scala | 16 ++++++++++++---- .../pdsuidomain/services/PatientLabelService.scala | 20 ++++++++++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/services') 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 From 008af38c4a8d61590bac71791af261f00a8517ea Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 13:39:39 +0700 Subject: Replace tuples in UpdateReply of PatientCriterionService --- .../xyz/driver/pdsuidomain/services/PatientCriterionService.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/services') diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala index af926b8..a07eed8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala @@ -90,8 +90,7 @@ object PatientCriterionService { object UpdateReply { type Error = UpdateReply with DomainError - final case class Updated(x: PatientCriterion, labelId: LongId[Label], armList: List[PatientCriterionArm]) - extends UpdateReply + final case class Updated(x: RichPatientCriterion) extends UpdateReply case object UpdatedList extends UpdateReply -- cgit v1.2.3 From c5462a496aeb4d43f023bb427bf12fc87b482b61 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 18:29:52 +0700 Subject: Deleted duplicate spray format and fixed reply of patient eligible trial service --- .../json/sprayformats/patientdefiningcriteria.scala | 2 +- .../json/sprayformats/patienthypothesis.scala | 10 +++++----- .../formats/json/sprayformats/patientlabel.scala | 14 -------------- .../services/PatientEligibleTrialService.scala | 5 ++--- .../json/sprayformats/PatientLabelFormatSuite.scala | 20 -------------------- 5 files changed, 8 insertions(+), 43 deletions(-) (limited to 'src/main/scala/xyz/driver/pdsuidomain/services') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala index b97570a..0520ef2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala @@ -7,7 +7,7 @@ object patientdefiningcriteria { import DefaultJsonProtocol._ import common._ - implicit val patientLabelDefiningCriteriaWriter: JsonWriter[PatientLabel] = new JsonWriter[PatientLabel] { + implicit val patientLabelDefiningCriteriaWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { override def write(obj: PatientLabel) = JsObject( "id" -> obj.id.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 bd448b3..b8c0058 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 @@ -37,11 +37,11 @@ object patienthypothesis { new RootJsonWriter[PatientHypothesis] { override def write(obj: PatientHypothesis): JsValue = { JsObject( - "id" -> obj.id.toJson, - "patientId" -> obj.patientId.toJson, - "hypothesisId" -> obj.hypothesisId.toJson, - "matchedTrials" -> obj.matchedTrials.toJson, - "rationale" -> obj.rationale.toJson + "id" -> obj.id.toJson, + "patientId" -> obj.patientId.toJson, + "hypothesisId" -> obj.hypothesisId.toJson, + "matchedTrials" -> obj.matchedTrials.toJson, + "rationale" -> obj.rationale.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 10a0a94..b36949e 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 @@ -44,20 +44,6 @@ object patientlabel { } } - implicit val patientLabelWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { - override def write(obj: PatientLabel): JsValue = { - JsObject( - "id" -> obj.id.toJson, - "labelId" -> obj.labelId.toJson, - "primaryValue" -> obj.primaryValue.toJson, - "verifiedPrimaryValue" -> obj.verifiedPrimaryValue.toJson, - "score" -> obj.score.toJson, - "isImplicitMatch" -> obj.isImplicitMatch.toJson, - "isVisible" -> obj.isVisible.toJson - ) - } - } - implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] = new RootJsonWriter[PatientLabelEvidenceView] { override def write(evidence: PatientLabelEvidenceView): JsValue = diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala index abb3f8a..d9013c6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala @@ -1,12 +1,12 @@ package xyz.driver.pdsuidomain.services -import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuicommon.error.DomainError import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.{Trial, _} +import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion import scala.concurrent.Future @@ -71,8 +71,7 @@ object PatientEligibleTrialService { sealed trait GetCriterionListOfGroupReply object GetCriterionListOfGroupReply { - final case class EntityList(xs: Seq[(PatientCriterion, LongId[Label], List[PatientCriterionArm])], totalFound: Int) - extends GetCriterionListOfGroupReply + final case class EntityList(xs: Seq[RichPatientCriterion], totalFound: Int) extends GetCriterionListOfGroupReply type Error = GetCriterionListOfGroupReply with DomainError diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala index ffb1bd4..3ef286d 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientLabelFormatSuite.scala @@ -34,26 +34,6 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel) } - "Json format for PatientLabel" should "read and write correct JSON" in { - import patientlabel._ - val orig = PatientLabel( - id = LongId(1), - patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), - labelId = LongId(20), - primaryValue = Some(FuzzyValue.Yes), - verifiedPrimaryValue = None, - isVisible = true, - score = 1, - isImplicitMatch = false - ) - val writtenJson = patientLabelWriter.write(orig) - - writtenJson should be ( - """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true, - "score":1,"isImplicitMatch":false}""".parseJson) - } - - "Json format for PatientLabelEvidence" should "read and write correct JSON" in { import patientlabel._ val orig = PatientLabelEvidenceView( -- cgit v1.2.3