aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/services')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala24
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala16
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala20
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala17
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala31
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala12
7 files changed, 91 insertions, 34 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala
index 6d85f85..a07eed8 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)"
}
}
@@ -83,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
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/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/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 9253f88..59f300b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala
@@ -57,19 +57,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),
@@ -78,8 +86,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"))