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 +++++++---- .../sprayformats/PatientCriterionFormatSuite.scala | 5 +-- .../PatientHypothesisFormatSuite.scala | 3 +- .../sprayformats/PatientLabelFormatSuite.scala | 3 +- 9 files changed, 87 insertions(+), 67 deletions(-) (limited to 'src') 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) } } } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala index 0f5e4e2..623b3a9 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientCriterionFormatSuite.scala @@ -6,7 +6,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId} import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm} -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion +import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} class PatientCriterionFormatSuite extends FlatSpec with Matchers { import patientcriterion._ @@ -31,7 +31,8 @@ class PatientCriterionFormatSuite extends FlatSpec with Matchers { PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(31), armName = "arm 31"), PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(32), armName = "arm 32") ) - val writtenJson = patientCriterionWriter.write((orig, LongId(21), arms)) + val richPatientCriterion = RichPatientCriterion(orig, LongId(21), arms) + val writtenJson = patientCriterionWriter.write(richPatientCriterion) writtenJson should be ( """{"id":1,"labelId":21,"nctId":"NCT00001","criterionId":101,"criterionText":"criterion text","criterionValue":"Yes", diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala index 2999cc1..1a5b7eb 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala @@ -4,6 +4,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.UuidId import xyz.driver.pdsuidomain.entities.PatientHypothesis +import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis class PatientHypothesisFormatSuite extends FlatSpec with Matchers { import patienthypothesis._ @@ -16,7 +17,7 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { rationale = None, matchedTrials = 1 ) - val writtenJson = patientHypothesisWriter.write((orig, true)) + val writtenJson = patientHypothesisWriter.write(RichPatientHypothesis(orig, true)) writtenJson should be ( """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", 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 e18239c..8b7c138 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 @@ -6,6 +6,7 @@ import spray.json._ import org.scalatest.{FlatSpec, Matchers} import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} import xyz.driver.pdsuidomain.entities.{PatientLabel, PatientLabelEvidenceView} +import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel class PatientLabelFormatSuite extends FlatSpec with Matchers { @@ -21,7 +22,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { score = 1, isImplicitMatch = false ) - val writtenJson = patientLabelWriter.write((orig, true)) + val writtenJson = patientLabelWriter.write(RichPatientLabel(orig, true)) writtenJson should be ( """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true, -- cgit v1.2.3 From 4c02f85886578dbb488ece70d0096e82fbdd852d Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 13:28:10 +0700 Subject: Implemented ListResponse in spray json format --- .../formats/json/sprayformats/ListResponse.scala | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala new file mode 100644 index 0000000..e8778cf --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala @@ -0,0 +1,39 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import java.time.LocalDateTime + +import spray.json.{JsArray, RootJsonFormat, _} +import xyz.driver.pdsuicommon.db.Pagination +import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ + +final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) + +object ListResponse extends DefaultJsonProtocol { + private val itemsField = "items" + private val metaField = "meta" + + final case class Meta(itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) + + object Meta { + def apply(itemsCount: Int, pagination: Pagination, lastUpdate: Option[LocalDateTime]): Meta = { + Meta( + itemsCount, + pagination.pageNumber, + pagination.pageSize, + lastUpdate + ) + } + } + + implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) + + implicit def listResponseMetaWriter[T: RootJsonWriter]: RootJsonWriter[ListResponse[T]] = + new RootJsonWriter[ListResponse[T]] { + override def write(listResponse: ListResponse[T]): JsValue = { + JsObject( + itemsField -> JsArray(listResponse.items.map(_.toJson).toVector), + metaField -> listResponse.meta.toJson + ) + } + } +} -- cgit v1.2.3 From 406e7ecb5861f108d45693cad325fa36da9a6d3d Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 13:29:17 +0700 Subject: code is formatted --- .../xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala index e8778cf..fbfc53e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala @@ -32,7 +32,7 @@ object ListResponse extends DefaultJsonProtocol { override def write(listResponse: ListResponse[T]): JsValue = { JsObject( itemsField -> JsArray(listResponse.items.map(_.toJson).toVector), - metaField -> listResponse.meta.toJson + metaField -> listResponse.meta.toJson ) } } -- 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') 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 3cf0353e3999994ff4441432f574a6e5f4281073 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 14:28:25 +0700 Subject: Fixed spray format of ListResponse --- .../formats/json/sprayformats/ListResponse.scala | 8 +- .../json/sprayformats/ListResponseSuite.scala | 113 +++++++++++++++++++++ 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala index fbfc53e..cedb053 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import java.time.LocalDateTime -import spray.json.{JsArray, RootJsonFormat, _} +import spray.json.{RootJsonFormat, _} import xyz.driver.pdsuicommon.db.Pagination import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ @@ -27,11 +27,11 @@ object ListResponse extends DefaultJsonProtocol { implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) - implicit def listResponseMetaWriter[T: RootJsonWriter]: RootJsonWriter[ListResponse[T]] = - new RootJsonWriter[ListResponse[T]] { + implicit def listResponseMetaWriter[T: JsonWriter]: JsonWriter[ListResponse[T]] = + new JsonWriter[ListResponse[T]] { override def write(listResponse: ListResponse[T]): JsValue = { JsObject( - itemsField -> JsArray(listResponse.items.map(_.toJson).toVector), + itemsField -> listResponse.items.map(_.toJson).toJson, metaField -> listResponse.meta.toJson ) } diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala new file mode 100644 index 0000000..52b2324 --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponseSuite.scala @@ -0,0 +1,113 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import java.time.LocalDateTime +import java.util.UUID + +import spray.json._ +import org.scalatest.{FlatSpec, Matchers} +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.entities.MedicalRecord.Status +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.record.recordFormat + + +class ListResponseSuite extends FlatSpec with Matchers { + + private val lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00") + private val lastUpdateToLocal = "2017-08-10T18:00Z" + + private def metaJsonObjectAsString(meta: ListResponse.Meta) = { + import meta._ + val lastUpdate = meta.lastUpdate + .map(_ => s""","lastUpdate":"$lastUpdateToLocal"""") + .getOrElse("") + + s"""{"itemsCount":$itemsCount,"pageNumber":$pageNumber,"pageSize":$pageSize$lastUpdate}""" + } + + + "Json format for ListResponse.Meta" should "read and write correct JSON" in { + val meta1 = + ListResponse.Meta( + itemsCount = 5, + pageNumber = 6, + pageSize = 7, + lastUpdate = None + ) + + val writtenJson1 = + ListResponse.listResponseMetaFormat.write(meta1) + + writtenJson1 should be( + metaJsonObjectAsString(meta1).parseJson) + + val parsedItem1: ListResponse.Meta = + ListResponse.listResponseMetaFormat.read(writtenJson1) + + meta1 shouldBe parsedItem1 + + + val meta2 = + ListResponse.Meta( + itemsCount = 1, + pageNumber = 4, + pageSize = 3, + lastUpdate = Some(lastUpdate) + ) + + val writtenJson2 = + ListResponse.listResponseMetaFormat.write(meta2) + + writtenJson2 should be( + metaJsonObjectAsString(meta2).parseJson) + + val parsedItem2: ListResponse.Meta = + ListResponse.listResponseMetaFormat.read(writtenJson2) + + meta2 shouldBe parsedItem2 + } + + + "Json format for ListResponse" should "write correct JSON" in { + + val orig = MedicalRecord( + id = LongId(1), + status = Status.New, + assignee = None, + previousStatus = None, + previousAssignee = None, + lastActiveUserId = None, + lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"), + physician = Some("physician"), + meta = None, + predictedMeta = None, + predictedDocuments = None, + disease = "Breast", + requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")), + caseId = None, + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343") + ) + + val recordJsonAsString = + """{"id":1,"status":"New","assignee":null,"previousStatus":null,"previousAssignee":null,"lastActiveUser":null, + "lastUpdate":"2017-08-10T18:00Z","meta":[],"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","caseId":null, + "requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","disease":"Breast","physician":"physician"}""" + + val meta = + ListResponse.Meta( + itemsCount = 5, + pageNumber = 6, + pageSize = 7, + lastUpdate = None + ) + + val listResponse = ListResponse(Seq(orig), meta) + + val writtenJson = ListResponse.listResponseMetaWriter.write(listResponse) + val expectedJson = s"""{"items":[$recordJsonAsString],"meta":${metaJsonObjectAsString(meta)}}""" + + writtenJson should be( + expectedJson.parseJson) + } + +} -- cgit v1.2.3 From 8fdb33cf7cc122ebdb21c03ecaf5f7d2df6684da Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 15:22:55 +0700 Subject: Fixed spray format of ListResponse of listResponseMetaWriter attribute --- .../driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala index cedb053..2a670c4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala @@ -27,8 +27,8 @@ object ListResponse extends DefaultJsonProtocol { implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) - implicit def listResponseMetaWriter[T: JsonWriter]: JsonWriter[ListResponse[T]] = - new JsonWriter[ListResponse[T]] { + implicit def listResponseMetaWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] = + new RootJsonWriter[ListResponse[T]] { override def write(listResponse: ListResponse[T]): JsValue = { JsObject( itemsField -> listResponse.items.map(_.toJson).toJson, -- cgit v1.2.3 From 996af2657cdd779e08e46fc1ba5f47d9e7c5aac5 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 16:08:12 +0700 Subject: Fixed a part of routes, that have wrong spray json writer types --- .../driver/pdsuidomain/formats/json/sprayformats/criterion.scala | 2 +- .../xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala | 2 +- .../pdsuidomain/formats/json/sprayformats/patientcriterion.scala | 4 ++-- .../formats/json/sprayformats/patienteligibletrial.scala | 4 ++-- .../pdsuidomain/formats/json/sprayformats/patienthypothesis.scala | 4 ++-- .../driver/pdsuidomain/formats/json/sprayformats/patientissue.scala | 2 +- .../driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala | 6 +++--- .../xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala | 2 +- .../driver/pdsuidomain/formats/json/sprayformats/trialissue.scala | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala index 8da719c..89c843f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala @@ -10,7 +10,7 @@ object criterion { import DefaultJsonProtocol._ import common._ - implicit val criterionLabelWriter = new JsonWriter[CriterionLabel] { + implicit val criterionLabelWriter = new RootJsonWriter[CriterionLabel] { override def write(obj: CriterionLabel) = JsObject( "labelId" -> obj.labelId.toJson, "categoryId" -> obj.categoryId.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala index 724c391..5cf95a5 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala @@ -26,7 +26,7 @@ object patient { } } - implicit val patientWriter: JsonWriter[Patient] = new JsonWriter[Patient] { + implicit val patientWriter: JsonWriter[Patient] = new RootJsonWriter[Patient] { override def write(patient: Patient): JsValue = JsObject( "id" -> patient.id.toJson, 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 8da153d..affb346 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 @@ -37,8 +37,8 @@ object patientcriterion { override def read(json: JsValue) = json.convertTo[List[JsValue]].map(_.convertTo[DraftPatientCriterion]) } - implicit val patientCriterionWriter: JsonWriter[RichPatientCriterion] = - new JsonWriter[RichPatientCriterion] { + implicit val patientCriterionWriter: RootJsonWriter[RichPatientCriterion] = + new RootJsonWriter[RichPatientCriterion] { override def write(obj: RichPatientCriterion): JsValue = { JsObject( "id" -> obj.patientCriterion.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala index 894e453..041d9da 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala @@ -21,8 +21,8 @@ object patienteligibletrial { case _ => deserializationError(s"Expected Json Object as partial PatientTrialArmGroupView, but got $json") } - implicit val patientEligibleTrialWriter: JsonWriter[RichPatientEligibleTrial] = - new JsonWriter[RichPatientEligibleTrial] { + implicit val patientEligibleTrialWriter: RootJsonWriter[RichPatientEligibleTrial] = + new RootJsonWriter[RichPatientEligibleTrial] { override def write(obj: RichPatientEligibleTrial) = JsObject( "id" -> obj.group.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 a85d8af..82759ab 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 @@ -19,8 +19,8 @@ object patienthypothesis { case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json") } - implicit val patientHypothesisWriter: JsonWriter[RichPatientHypothesis] = - new JsonWriter[RichPatientHypothesis] { + implicit val patientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = + new RootJsonWriter[RichPatientHypothesis] { override def write(obj: RichPatientHypothesis): JsValue = { JsObject( "id" -> obj.patientHypothesis.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala index 7d35bd1..d325a53 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala @@ -40,7 +40,7 @@ object patientissue { } - implicit val patientIssueWriter = new JsonWriter[PatientIssue] { + implicit val patientIssueWriter = new RootJsonWriter[PatientIssue] { override def write(obj: PatientIssue) = JsObject( "id" -> obj.id.toJson, "text" -> obj.text.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 d7ff5a4..f4af376 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 @@ -29,7 +29,7 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val patientLabelWriter: JsonWriter[RichPatientLabel] = new JsonWriter[RichPatientLabel] { + implicit val patientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { override def write(obj: RichPatientLabel): JsValue = { JsObject( "id" -> obj.patientLabel.id.toJson, @@ -44,8 +44,8 @@ object patientlabel { } } - implicit val patientLabelEvidenceWriter: JsonWriter[PatientLabelEvidenceView] = - new JsonWriter[PatientLabelEvidenceView] { + implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] = + new RootJsonWriter[PatientLabelEvidenceView] { override def write(evidence: PatientLabelEvidenceView): JsValue = JsObject( "id" -> evidence.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala index c1751bf..8000a27 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala @@ -30,7 +30,7 @@ object trial { "Prostate" -> Condition.Prostate ) - implicit val trialWriter: JsonWriter[Trial] = new JsonWriter[Trial] { + implicit val trialWriter: RootJsonWriter[Trial] = new RootJsonWriter[Trial] { override def write(obj: Trial) = JsObject( "id" -> obj.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala index 572f44d..d1ca191 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala @@ -44,7 +44,7 @@ object trialissue { } - implicit val trialIssueWriter = new JsonWriter[TrialIssue] { + implicit val trialIssueWriter = new RootJsonWriter[TrialIssue] { override def write(obj: TrialIssue) = JsObject( "id" -> obj.id.toJson, "text" -> obj.text.toJson, -- cgit v1.2.3 From 7446fbcb6f51ae67ae8bf0f54729e774da8e7f73 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 16:23:04 +0700 Subject: Implemented new spray json formats for PatientHypothesis and PatientLabel --- .../json/sprayformats/patienthypothesis.scala | 15 +++++++++++++- .../formats/json/sprayformats/patientlabel.scala | 16 ++++++++++++++- .../PatientHypothesisFormatSuite.scala | 19 +++++++++++++++-- .../sprayformats/PatientLabelFormatSuite.scala | 24 ++++++++++++++++++++-- 4 files changed, 68 insertions(+), 6 deletions(-) (limited to 'src') 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 82759ab..bd448b3 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 @@ -19,7 +19,7 @@ object patienthypothesis { case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json") } - implicit val patientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = + implicit val richPatientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = new RootJsonWriter[RichPatientHypothesis] { override def write(obj: RichPatientHypothesis): JsValue = { JsObject( @@ -33,4 +33,17 @@ object patienthypothesis { } } + implicit val patientHypothesisWriter: RootJsonWriter[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 + ) + } + } + } 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 f4af376..10a0a94 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 @@ -29,7 +29,7 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val patientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { + implicit val richPatientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { override def write(obj: RichPatientLabel): JsValue = { JsObject( "id" -> obj.patientLabel.id.toJson, @@ -44,6 +44,20 @@ 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/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala index 1a5b7eb..fbb5213 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/PatientHypothesisFormatSuite.scala @@ -9,7 +9,7 @@ import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypot class PatientHypothesisFormatSuite extends FlatSpec with Matchers { import patienthypothesis._ - "Json format for PatientHypothesis" should "read and write correct JSON" in { + "Json format for RichPatientHypothesis" should "read and write correct JSON" in { val orig = PatientHypothesis( id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"), patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), @@ -17,7 +17,7 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { rationale = None, matchedTrials = 1 ) - val writtenJson = patientHypothesisWriter.write(RichPatientHypothesis(orig, true)) + val writtenJson = richPatientHypothesisWriter.write(RichPatientHypothesis(orig, isRequired = true)) writtenJson should be ( """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", @@ -29,4 +29,19 @@ class PatientHypothesisFormatSuite extends FlatSpec with Matchers { parsedUpdatePatientHypothesis should be(expectedUpdatedPatientHypothesis) } + "Json format for patientHypothesis" should "read and write correct JSON" in { + val orig = PatientHypothesis( + id = UuidId("815d9715-1089-4775-b120-3afb983b9a97"), + patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"), + hypothesisId = UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4"), + rationale = None, + matchedTrials = 1 + ) + val writtenJson = patientHypothesisWriter.write(orig) + + writtenJson should be ( + """{"id":"815d9715-1089-4775-b120-3afb983b9a97","patientId":"748b5884-3528-4cb9-904b-7a8151d6e343", + "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","rationale":null,"matchedTrials":1}""".parseJson) + } + } 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 8b7c138..ffb1bd4 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 @@ -10,7 +10,7 @@ import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel class PatientLabelFormatSuite extends FlatSpec with Matchers { - "Json format for PatientLabel" should "read and write correct JSON" in { + "Json format for RichPatientLabel" should "read and write correct JSON" in { import patientlabel._ val orig = PatientLabel( id = LongId(1), @@ -22,7 +22,7 @@ class PatientLabelFormatSuite extends FlatSpec with Matchers { score = 1, isImplicitMatch = false ) - val writtenJson = patientLabelWriter.write(RichPatientLabel(orig, true)) + val writtenJson = richPatientLabelWriter.write(RichPatientLabel(orig, isVerified = true)) writtenJson should be ( """{"id":1,"labelId":20,"primaryValue":"Yes","verifiedPrimaryValue":null,"isVisible":true,"isVerified":true, @@ -34,6 +34,26 @@ 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 From a813bb68eb3a63e8eeab5d8fb3db36472296f1db Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 4 Oct 2017 16:39:01 +0700 Subject: Fixed patient spray json format --- .../xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala index 5cf95a5..95c0674 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala @@ -26,7 +26,7 @@ object patient { } } - implicit val patientWriter: JsonWriter[Patient] = new RootJsonWriter[Patient] { + implicit val patientWriter: RootJsonWriter[Patient] = new RootJsonWriter[Patient] { override def write(patient: Patient): JsValue = JsObject( "id" -> patient.id.toJson, -- cgit v1.2.3 From 6f4de1ccfb6efe8f9ddbaec6551a9138a6efa6f8 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Wed, 4 Oct 2017 16:59:16 +0700 Subject: PDSUI-2268 Added institution field to document --- .../scala/xyz/driver/pdsuidomain/entities/Document.scala | 3 +++ .../driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala | 1 + .../pdsuidomain/formats/json/document/ApiDocument.scala | 5 ++++- .../formats/json/document/ApiPartialDocument.scala | 5 +++++ .../pdsuidomain/formats/json/sprayformats/document.scala | 12 ++++++++++++ src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala | 1 + .../formats/json/sprayformats/DocumentFormatSuite.scala | 6 ++++-- 7 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala index eccb254..168eb38 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala @@ -419,6 +419,8 @@ object Document { providerTypeId <- Validators.nonEmpty("providerTypeId")(input.providerTypeId) + institutionName <- Validators.nonEmpty("institutionName")(input.institutionName) + meta <- Validators.nonEmpty("meta")(input.meta) startDate <- Validators.nonEmpty("startDate")(input.startDate) @@ -456,6 +458,7 @@ final case class Document(id: LongId[Document] = LongId(0L), providerName: Option[String], // not null providerTypeId: Option[LongId[ProviderType]], // not null requiredType: Option[Document.RequiredType], + institutionName: Option[String], meta: Option[TextJson[Meta]], // not null startDate: Option[LocalDate], // not null endDate: Option[LocalDate], diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 1ac75ab..94eb029 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -68,6 +68,7 @@ object DocumentGen { providerName = nextOption(nextString()), providerTypeId = nextOption(nextLongId[ProviderType]), requiredType = nextOption(nextDocumentRequiredType()), + institutionName = nextOption(nextString()), meta = nextOption(nextDocumentMetaJson()), startDate = dates._1, endDate = dates._2, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala index 1869ff3..3f1ecfe 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala @@ -2,7 +2,6 @@ package xyz.driver.pdsuidomain.formats.json.document import java.time.{LocalDate, ZoneId, ZonedDateTime} import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson} -import xyz.driver.pdsuicommon.json.JsonSerializer import xyz.driver.pdsuidomain.entities._ import play.api.data.validation.ValidationError @@ -20,6 +19,7 @@ final case class ApiDocument(id: Long, provider: Option[String], providerTypeId: Option[Long], requiredType: Option[String], + institutionName: Option[String], status: Option[String], previousStatus: Option[String], assignee: Option[String], @@ -46,6 +46,7 @@ final case class ApiDocument(id: Long, providerName = this.provider, providerTypeId = this.providerTypeId.map(LongId(_)), requiredType = this.requiredType.map(extractRequiredType), + institutionName = this.institutionName, meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[Document.Meta](x))), startDate = this.startDate, endDate = this.endDate, @@ -74,6 +75,7 @@ object ApiDocument { (JsPath \ "provider").formatNullable[String] and (JsPath \ "providerTypeId").formatNullable[Long] and (JsPath \ "requiredType").formatNullable[String] and + (JsPath \ "institutionName").formatNullable[String] and (JsPath \ "status").formatNullable(statusFormat) and (JsPath \ "previousStatus").formatNullable(statusFormat) and (JsPath \ "assignee").formatNullable[String] and @@ -96,6 +98,7 @@ object ApiDocument { provider = document.providerName, providerTypeId = document.providerTypeId.map(_.id), requiredType = document.requiredType.map(Document.RequiredType.requiredTypeToString), + institutionName = document.institutionName, status = Option(Document.Status.statusToString(document.status)), previousStatus = document.previousStatus.map(Document.Status.statusToString), assignee = document.assignee.map(_.id), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala index eae0c62..032ddf6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala @@ -23,6 +23,7 @@ final case class ApiPartialDocument(recordId: Option[Long], endDate: Tristate[LocalDate], provider: Tristate[String], providerTypeId: Tristate[Long], + institutionName: Tristate[String], status: Option[String], assignee: Tristate[String], meta: Tristate[String]) { @@ -42,6 +43,7 @@ final case class ApiPartialDocument(recordId: Option[Long], providerName = provider.cata(Some(_), None, orig.providerName), providerTypeId = providerTypeId.map(LongId[ProviderType]).cata(Some(_), None, orig.providerTypeId), requiredType = orig.requiredType, + institutionName = institutionName.cata(Some(_), None, orig.institutionName), meta = meta.cata(x => Some(TextJson(JsonSerializer.deserialize[Meta](x))), None, orig.meta), startDate = startDate.cata(Some(_), None, orig.startDate), endDate = endDate.cata(Some(_), None, orig.endDate), @@ -67,6 +69,7 @@ final case class ApiPartialDocument(recordId: Option[Long], providerName = provider.toOption, providerTypeId = providerTypeId.map(LongId[ProviderType]).toOption, requiredType = None, + institutionName = institutionName.toOption, meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption, previousStatus = None, assignee = None, @@ -90,6 +93,7 @@ object ApiPartialDocument { (JsPath \ "endDate").readTristate[LocalDate] and (JsPath \ "provider").readTristate[String] and (JsPath \ "providerTypeId").readTristate[Long] and + (JsPath \ "institutionName").readTristate[String] and (JsPath \ "status").readNullable[String]( Reads .of[String] @@ -115,6 +119,7 @@ object ApiPartialDocument { (JsPath \ "endDate").writeTristate[LocalDate] and (JsPath \ "provider").writeTristate[String] and (JsPath \ "providerTypeId").writeTristate[Long] and + (JsPath \ "institutionName").writeTristate[String] and (JsPath \ "status").writeNullable[String] and (JsPath \ "assignee").writeTristate[String] and (JsPath \ "meta").writeTristate(Writes[String](Json.parse)) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index e3f6a9c..33ee9ba 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala @@ -73,6 +73,11 @@ object document { .map(_.convertTo[Option[LongId[ProviderType]]]) .getOrElse(orig.providerTypeId) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[Option[String]]) + .getOrElse(orig.institutionName) + val meta = fields .get("meta") .map(_.convertTo[Option[TextJson[Meta]]]) @@ -93,6 +98,7 @@ object document { typeId = typeId, providerName = provider, providerTypeId = providerTypeId, + institutionName = institutionName, meta = meta, startDate = startDate, endDate = endDate @@ -111,6 +117,7 @@ object document { "provider" -> document.providerName.toJson, "providerTypeId" -> document.providerTypeId.toJson, "requiredType" -> document.requiredType.toJson, + "institutionName" -> document.institutionName.toJson, "startDate" -> document.startDate.toJson, "endDate" -> document.endDate.toJson, "status" -> document.status.toJson, @@ -145,6 +152,10 @@ object document { .get("providerTypeId") .map(_.convertTo[LongId[ProviderType]]) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[String]) + val meta = fields .get("meta") .map(_.convertTo[TextJson[Meta]]) @@ -168,6 +179,7 @@ object document { providerName = provider, providerTypeId = providerTypeId, requiredType = None, + institutionName = institutionName, meta = meta, previousStatus = None, assignee = None, diff --git a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala index f851680..9fc3388 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala @@ -78,6 +78,7 @@ class DocumentSuite extends BaseSuite { providerName = Some("etst"), providerTypeId = Some(LongId(123)), requiredType = None, + institutionName = Some("institution name"), startDate = Some(lastUpdate.toLocalDate.minusDays(2)), endDate = None, lastUpdate = lastUpdate, diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala index 9394735..cc1832c 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala @@ -24,6 +24,7 @@ class DocumentFormatSuite extends FlatSpec with Matchers { typeId = Some(LongId(10)), providerName = Some("provider 21"), providerTypeId = Some(LongId(21)), + institutionName = Some("institution name"), requiredType = Some(Document.RequiredType.OPN), meta = None, startDate = None, @@ -33,7 +34,7 @@ class DocumentFormatSuite extends FlatSpec with Matchers { writtenJson should be ( """{"id":1,"recordId":101,"physician":"physician","typeId":10,"provider":"provider 21","providerTypeId":21, - "requiredType":"OPN","startDate":null,"endDate":null,"status":"New","assignee":null,"previousStatus":null, + "requiredType":"OPN","institutionName":"institution name","startDate":null,"endDate":null,"status":"New","assignee":null,"previousStatus":null, "previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z","meta":null}""".parseJson) val createDocumentJson = @@ -41,7 +42,8 @@ class DocumentFormatSuite extends FlatSpec with Matchers { val expectedCreatedDocument = orig.copy( id = LongId(0), lastUpdate = LocalDateTime.MIN, - requiredType = None + requiredType = None, + institutionName = None ) val parsedCreatedDocument = documentFormat.read(createDocumentJson) parsedCreatedDocument should be(expectedCreatedDocument) -- 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') 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 From f64dd86a024c9679445cceddb068df1df8a10ebe Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 4 Oct 2017 17:20:59 -0700 Subject: Fixing EvidenceDocument JSON format bug --- .../xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala | 2 +- .../xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index e3f6a9c..99ec749 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala @@ -40,7 +40,7 @@ object document { .fromString(name) .getOrElse(deserializationError(s"Unknown document type: $name")) - case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") + case _ => deserializationError(s"Expected Json Object as Document type, but got $json") } override def write(obj: DocumentType) = diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala index b836e1c..3c2465f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala @@ -21,7 +21,7 @@ object eligibility { implicit val clinicalDocumentFormat: RootJsonFormat[ClinicalEvidenceDocument] = jsonFormat7(ClinicalEvidenceDocument) implicit val evidenceDocumentFormat: RootJsonFormat[EvidenceDocument] = - GadtJsonFormat.create[EvidenceDocument]("documentType") { + GadtJsonFormat.create[EvidenceDocument]("evidenceDocumentType") { case _: MolecularEvidenceDocument => "Molecular" case _: ClinicalEvidenceDocument => "Clinical" } { -- cgit v1.2.3 From 7d6376873a5bdeca2c9a67f0a0db99faa78b5967 Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 5 Oct 2017 00:03:22 -0700 Subject: Support for exporting multiple trials --- .../driver/pdsuidomain/services/TrialService.scala | 17 ++++++++++++ .../services/fake/FakeTrialService.scala | 31 +++++++++++++--------- .../services/rest/RestTrialService.scala | 12 +++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala index 5bd99a8..c6ab2d2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala @@ -68,6 +68,20 @@ object TrialService { extends GetTrialWithLabelsReply with DomainError.AuthorizationError with DefaultAccessDeniedError } + sealed trait GetTrialsWithLabelsReply + object GetTrialsWithLabelsReply { + type Error = GetTrialsWithLabelsReply with DomainError + + final case class EntityList(xs: Seq[ExportTrialWithLabels]) extends GetTrialsWithLabelsReply + + case object NotFoundError extends GetTrialsWithLabelsReply with DomainError.NotFoundError { + def userMessage: String = "Trials for disease are not found" + } + + case object AuthorizationError + extends GetTrialsWithLabelsReply with DomainError.AuthorizationError with DefaultAccessDeniedError + } + sealed trait UpdateReply object UpdateReply { type Error = UpdateReply with DomainError @@ -97,6 +111,9 @@ trait TrialService { def getTrialWithLabels(trialId: StringId[Trial], condition: String)( implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] + def getTrialsWithLabels(condition: String)( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] + def getPdfSource(trialId: StringId[Trial])( implicit requestContext: AuthenticatedRequestContext): Future[Source[ByteString, NotUsed]] diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index 9aeb820..cd62d48 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -58,19 +58,27 @@ class FakeTrialService extends TrialService { Future.successful(GetListReply.EntityList(Seq(trial), 1, None)) override def getTrialWithLabels(trialId: StringId[Trial], condition: String)( - implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] = { - Future.successful( - GetTrialWithLabelsReply.Entity(ExportTrialWithLabels( - StringId[Trial]("NCT" + generators.nextInt(999999).toString), - UuidId[Trial](generators.nextUuid()), - generators.oneOf("adenocarcinoma", "breast", "prostate"), - LocalDateTime.now(), - labelVersion = 1L, - generators.listOf(new ExportTrialArm( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] = + Future.successful(GetTrialWithLabelsReply.Entity(nextExportTrialWithLabels())) + + override def getTrialsWithLabels(condition: String)( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] = + Future.successful(GetTrialsWithLabelsReply.EntityList(generators.seqOf(nextExportTrialWithLabels()))) + + private def nextExportTrialWithLabels() = + ExportTrialWithLabels( + StringId[Trial]("NCT" + generators.nextInt(999999).toString), + UuidId[Trial](generators.nextUuid()), + generators.oneOf("adenocarcinoma", "breast", "prostate"), + LocalDateTime.now(), + labelVersion = 1L, + generators.listOf( + new ExportTrialArm( LongId[Arm](generators.nextInt(999999).toLong), generators.nextName().value )), - generators.listOf(new ExportTrialLabelCriterion( + generators.listOf( + new ExportTrialLabelCriterion( LongId[Criterion](generators.nextInt(999999).toLong), generators.nextOption(generators.nextBoolean()), LongId[Label](generators.nextInt(999999).toLong), @@ -79,8 +87,7 @@ class FakeTrialService extends TrialService { generators.nextBoolean(), generators.nextBoolean() )) - ))) - } + ) def update(origTrial: Trial, draftTrial: Trial)( implicit requestContext: AuthenticatedRequestContext): Future[UpdateReply] = diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala index 7e33919..42f32fc 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala @@ -16,6 +16,7 @@ import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels import xyz.driver.pdsuidomain.formats.json.ListResponse import xyz.driver.pdsuidomain.formats.json.trial.ApiTrial import xyz.driver.pdsuidomain.services.TrialService +import spray.json.DefaultJsonProtocol._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import xyz.driver.pdsuidomain.formats.json.sprayformats.export._ @@ -47,6 +48,17 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote } } + def getTrialsWithLabels(disease: String)( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialsWithLabelsReply] = { + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$disease")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[Seq[ExportTrialWithLabels]](response) + } yield { + GetTrialsWithLabelsReply.EntityList(reply) + } + } + def getPdfSource(trialId: StringId[Trial])( implicit requestContext: AuthenticatedRequestContext): Future[Source[ByteString, NotUsed]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$trialId/source")) -- cgit v1.2.3