diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2018-01-18 17:41:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-18 17:41:15 +0200 |
commit | 57b1a08669ddb3fb54cf79a2f42cb473e0ced3f5 (patch) | |
tree | 74c839223186e73c017b2e07a5cd43e9754498e5 /src/main/scala | |
parent | 5bbb0bc66db5b49eb0e3f197be17798fb8093f2a (diff) | |
parent | 7d9c3a7a0de129eef06d5b2eac92aafec1229098 (diff) | |
download | rest-query-57b1a08669ddb3fb54cf79a2f42cb473e0ced3f5.tar.gz rest-query-57b1a08669ddb3fb54cf79a2f42cb473e0ced3f5.tar.bz2 rest-query-57b1a08669ddb3fb54cf79a2f42cb473e0ced3f5.zip |
Merge pull request #73 from drivergroup/PDSUI-2432v0.15.1
PDSUI-2432 Removed *-Reply classes of TM
Diffstat (limited to 'src/main/scala')
20 files changed, 154 insertions, 687 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala index ecc30df..46b86a6 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala @@ -69,13 +69,20 @@ trait Directives { } def domainExceptionHandler(req: String): ExceptionHandler = { - def errorResponse(ex: Throwable) = - ErrorsResponse(Seq(ResponseError(None, ex.getMessage, 1)), req) + def errorResponse(msg: String, code: Int) = + ErrorsResponse(Seq(ResponseError(None, msg, code)), req) ExceptionHandler { - case ex: InvalidActionException => complete(StatusCodes.Forbidden -> errorResponse(ex)) - case ex: ResourceNotFoundException => complete(StatusCodes.NotFound -> errorResponse(ex)) - case ex: InvalidInputException => complete(StatusCodes.BadRequest -> errorResponse(ex)) - case NonFatal(ex) => complete(StatusCodes.InternalServerError -> errorResponse(ex)) + case ex: InvalidActionException => + complete(StatusCodes.Forbidden -> errorResponse(ex.message, 403)) + + case ex: ResourceNotFoundException => + complete(StatusCodes.NotFound -> errorResponse(ex.message, 404)) + + case ex: InvalidInputException => + complete(StatusCodes.BadRequest -> errorResponse(ex.message, 400)) + + case NonFatal(ex) => + complete(StatusCodes.InternalServerError -> errorResponse(ex.getMessage, 500)) } } diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index f617a20..27560d5 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -18,9 +18,6 @@ import xyz.driver.pdsuidomain.formats.json.record._ import xyz.driver.pdsuidomain.formats.json.document._ import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData -import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial -import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel import scala.collection.immutable diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala index 193e8cb..e6d466a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientCriterion.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDateTime -import xyz.driver.entities.labels.LabelValue +import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ @@ -57,6 +57,33 @@ final case class PatientCriterion(id: LongId[PatientCriterion], def isIneligibleForEv: Boolean = eligibilityStatus === LabelValue.No && isVerified } +final case class DraftPatientCriterion(id: LongId[PatientCriterion], + eligibilityStatus: Option[LabelValue], + isVerified: Option[Boolean]) { + def applyTo(orig: PatientCriterion) = { + orig.copy( + eligibilityStatus = eligibilityStatus.getOrElse(orig.eligibilityStatus), + isVerified = isVerified.getOrElse(orig.isVerified) + ) + } +} + +object DraftPatientCriterion { + implicit def toPhiString(x: DraftPatientCriterion): PhiString = { + phi"DraftPatientCriterion(id=${x.id}, eligibilityStatus=${Unsafe(x.eligibilityStatus)}, isVerified=${x.isVerified})" + } +} + +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})" + } +} + object PatientCriterionArm { implicit def toPhiString(x: PatientCriterionArm): PhiString = { diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala index 179056a..4f62a9e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala @@ -82,3 +82,13 @@ final case class PatientTrialArmGroupView(id: LongId[PatientTrialArmGroup], ) } } + +final case class RichPatientEligibleTrial(trial: Trial, + group: PatientTrialArmGroupView, + arms: List[PatientCriterionArm]) + +object RichPatientEligibleTrial { + implicit def toPhiString(x: RichPatientEligibleTrial): PhiString = { + phi"RichPatientEligibleTrial(group=${x.group}, trial=${x.trial}, arms=${x.arms})" + } +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala index df86175..8d64389 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala @@ -22,6 +22,14 @@ final case class PatientLabel(id: LongId[PatientLabel], isImplicitMatch: Boolean, isVisible: Boolean) +final case class RichPatientLabel(patientLabel: PatientLabel, isVerified: Boolean) + +object RichPatientLabel { + implicit def toPhiString(x: RichPatientLabel): PhiString = { + phi"RichPatientLabel(patientLabel=${x.patientLabel}, isVerified=${x.isVerified})" + } +} + object PatientLabelEvidence { implicit def toPhiString(x: PatientLabelEvidence): PhiString = { import x._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala index f2d6a1b..190add6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/treatmentmatching.scala @@ -6,9 +6,6 @@ import xyz.driver.fakes import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial -import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel import eu.timepit.refined.{refineMV, refineV} import xyz.driver.core.auth.User diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala index 1004c5b..035310b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala @@ -5,7 +5,6 @@ import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.formats.json.labels._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} object patientcriterion { import DefaultJsonProtocol._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala index 4c006f9..d719c5c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala @@ -3,7 +3,6 @@ package xyz.driver.pdsuidomain.formats.json import spray.json._ import xyz.driver.formats.json.labels._ import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial object patienteligibletrial { import DefaultJsonProtocol._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala index 6499318..615b3a2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala @@ -4,7 +4,6 @@ import spray.json._ import xyz.driver.entities.labels.LabelValue import xyz.driver.formats.json.labels._ import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel import xyz.driver.formats.json.labels._ import xyz.driver.pdsuidomain.formats.json.record._ import xyz.driver.pdsuidomain.formats.json.document._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala index 68e7b50..915dc20 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala @@ -1,132 +1,28 @@ package xyz.driver.pdsuidomain.services -import java.time.LocalDateTime - import xyz.driver.core.rest.AuthorizedServiceRequestContext -import xyz.driver.entities.labels.{Label, LabelValue} import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.error.DomainError -import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import scala.concurrent.Future -object PatientCriterionService { - - final case class DraftPatientCriterion(id: LongId[PatientCriterion], - eligibilityStatus: Option[LabelValue], - isVerified: Option[Boolean]) { - def applyTo(orig: PatientCriterion) = { - orig.copy( - eligibilityStatus = eligibilityStatus.getOrElse(orig.eligibilityStatus), - isVerified = isVerified.getOrElse(orig.isVerified) - ) - } - } - - object DraftPatientCriterion { - implicit def toPhiString(x: DraftPatientCriterion): PhiString = { - phi"DraftPatientCriterion(id=${x.id}, eligibilityStatus=${Unsafe(x.eligibilityStatus)}, isVerified=${x.isVerified})" - } - } - - trait DefaultPatientNotFoundError { - def userMessage: String = "Patient not found" - } - - trait DefaultNotFoundError { - def userMessage: String = "Patient criterion not found" - } - - trait DefaultAccessDeniedError { - 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[RichPatientCriterion], totalFound: Int, lastUpdate: Option[LocalDateTime]) - extends GetListReply - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends GetListReply with DomainError.NotFoundError with DefaultPatientNotFoundError - - final case class CommonError(userMessage: String) extends GetListReply with DomainError - - } - - sealed trait GetByIdReply - object GetByIdReply { - type Error = GetByIdReply with DomainError - - final case class Entity(x: RichPatientCriterion) extends GetByIdReply - - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object NotFoundError extends GetByIdReply with DomainError.NotFoundError with DefaultNotFoundError - - case object PatientNotFoundError - extends GetByIdReply with DomainError.NotFoundError with DefaultPatientNotFoundError - - 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) => phi"GetByIdReply.Entity($x)" - } - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - - final case class Updated(x: RichPatientCriterion) extends UpdateReply - - case object UpdatedList extends UpdateReply - - case object AuthorizationError - extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends UpdateReply with DomainError.NotFoundError with DefaultPatientNotFoundError - - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - } -} - trait PatientCriterionService { - import PatientCriterionService._ - def getAll(patientId: UuidId[Patient], origFilter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientCriterion]] def getById(patientId: UuidId[Patient], id: LongId[PatientCriterion])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[RichPatientCriterion]] def updateList(patientId: UuidId[Patient], draftEntities: List[DraftPatientCriterion])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Unit] def update(origEntity: PatientCriterion, draftEntity: PatientCriterion, patientId: UuidId[Patient])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[RichPatientCriterion] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala index 8d1288a..e73d537 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala @@ -4,128 +4,26 @@ import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.users.AuthUserInfo 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 xyz.driver.pdsuidomain.ListResponse +import xyz.driver.pdsuidomain.entities._ import scala.concurrent.Future -object PatientEligibleTrialService { - - trait DefaultNotFoundError { - def userMessage: String = "Patient eligible trial not found" - } - - trait DefaultPatientNotFoundError { - def userMessage: String = "Patient not found" - } - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - final case class RichPatientEligibleTrial(trial: Trial, - group: PatientTrialArmGroupView, - arms: List[PatientCriterionArm]) - - object RichPatientEligibleTrial { - implicit def toPhiString(x: RichPatientEligibleTrial): PhiString = { - phi"RichPatientEligibleTrial(group=${x.group}, trial=${x.trial}, arms=${x.arms})" - } - } - - sealed trait GetListReply - object GetListReply { - final case class EntityList(xs: Seq[RichPatientEligibleTrial], totalFound: Int) extends GetListReply - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends GetListReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetListReply with DomainError - } - - sealed trait GetByIdReply - object GetByIdReply { - final case class Entity(x: RichPatientEligibleTrial) extends GetByIdReply - - type Error = GetByIdReply with DomainError - - case object NotFoundError extends GetByIdReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends GetByIdReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - 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) => phi"GetByIdReply.Entity($x)" - } - } - - sealed trait GetCriterionListOfGroupReply - object GetCriterionListOfGroupReply { - final case class EntityList(xs: Seq[RichPatientCriterion], totalFound: Int) extends GetCriterionListOfGroupReply - - type Error = GetCriterionListOfGroupReply with DomainError - - case object AuthorizationError - extends GetCriterionListOfGroupReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object NotFoundError - extends GetCriterionListOfGroupReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends GetCriterionListOfGroupReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetCriterionListOfGroupReply with DomainError - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - - final case class Updated(updated: RichPatientEligibleTrial) extends UpdateReply - - case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - - implicit def toPhiString(reply: UpdateReply): PhiString = reply match { - case Updated(x) => phi"Updated($x)" - case x: Error => DomainError.toPhiString(x) - } - } -} - trait PatientEligibleTrialService { - import PatientEligibleTrialService._ - def getAll(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientEligibleTrial]] def getById(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[RichPatientEligibleTrial]] def getCriterionListByGroupId(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetCriterionListOfGroupReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientCriterion]] def update(origEligibleTrialWithTrial: RichPatientEligibleTrial, draftPatientTrialArmGroup: PatientTrialArmGroupView)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[RichPatientEligibleTrial] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala index 9ad6a56..3f44e58 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHistoryService.scala @@ -1,45 +1,20 @@ package xyz.driver.pdsuidomain.services -import java.time.LocalDateTime - import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuicommon.error.DomainError +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities.{Patient, PatientHistory} import scala.concurrent.Future -object PatientHistoryService { - - trait DefaultNotFoundError { - def userMessage: String = "Patient history not found" - } - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - sealed trait GetListReply - object GetListReply { - final case class EntityList(xs: Seq[PatientHistory], totalFound: Int, lastUpdate: Option[LocalDateTime]) - extends GetListReply - - final case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - } - -} - trait PatientHistoryService { - import PatientHistoryService._ - def getListByPatientId(id: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[PatientHistory]] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala index 2dcfcb5..0191b5a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientHypothesisService.scala @@ -4,97 +4,22 @@ import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuicommon.error.DomainError -import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities.{Hypothesis, Patient, PatientHypothesis} import scala.concurrent.Future -object PatientHypothesisService { - - trait DefaultNotFoundError { - def userMessage: String = "Patient hypothesis not found" - } - - trait DefaultPatientNotFoundError { - def userMessage: String = "Patient not found" - } - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - sealed trait GetListReply - object GetListReply { - final case class EntityList(xs: Seq[PatientHypothesis], totalFound: Int) extends GetListReply - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends GetListReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetListReply with DomainError - } - - sealed trait GetByIdReply - object GetByIdReply { - final case class Entity(x: PatientHypothesis) extends GetByIdReply - - type Error = GetByIdReply with DomainError - - case object NotFoundError extends GetByIdReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends GetByIdReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - 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) => phi"GetByIdReply.Entity($x)" - } - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - - final case class Updated(updated: PatientHypothesis) extends UpdateReply - - case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - - implicit def toPhiString(reply: UpdateReply): PhiString = reply match { - case Updated(x) => phi"Updated($x)" - case x: Error => DomainError.toPhiString(x) - } - } -} - trait PatientHypothesisService { - import PatientHypothesisService._ - def getAll(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[PatientHypothesis]] def getById(patientId: UuidId[Patient], hypothesisId: UuidId[Hypothesis])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[PatientHypothesis]] def update(origPatientHypothesis: PatientHypothesis, draftPatientHypothesis: PatientHypothesis)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[PatientHypothesis] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientIssueService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientIssueService.scala index cf47c94..b2ba357 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientIssueService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientIssueService.scala @@ -1,95 +1,32 @@ package xyz.driver.pdsuidomain.services -import java.time.LocalDateTime - import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuicommon.error.DomainError +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities.{Patient, PatientIssue} import scala.concurrent.Future -object PatientIssueService { - - trait DefaultNotFoundError { - def userMessage: String = "PatientIssue not found" - } - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - sealed trait CreateReply - object CreateReply { - type Error = CreateReply with DomainError - final case class Created(x: PatientIssue) extends CreateReply - case object AuthorizationError - extends CreateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - final case class CommonError(userMessage: String) extends CreateReply with DomainError - } - - sealed trait GetByIdReply - object GetByIdReply { - type Error = GetByIdReply with DomainError - final case class Entity(x: PatientIssue) extends GetByIdReply - case object NotFoundError extends GetByIdReply with DomainError.NotFoundError with DefaultNotFoundError - final case class CommonError(userMessage: String) extends GetByIdReply with DomainError - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - } - - sealed trait GetListByPatientIdReply - object GetListByPatientIdReply { - type Error = GetListByPatientIdReply with DomainError - final case class EntityList(xs: Seq[PatientIssue], totalFound: Int, lastUpdate: Option[LocalDateTime]) - extends GetListByPatientIdReply - case object NotFoundError extends GetListByPatientIdReply with DomainError.NotFoundError with DefaultNotFoundError - case object AuthorizationError - extends GetListByPatientIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - final case class Updated(updated: PatientIssue) extends UpdateReply - case object AuthorizationError - extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - } - - sealed trait DeleteReply - object DeleteReply { - type Error = DeleteReply with DomainError - case object Deleted extends DeleteReply - case object AuthorizationError - extends DeleteReply with DomainError.AuthorizationError with DefaultAccessDeniedError - case object NotFoundError extends DeleteReply with DomainError.NotFoundError with DefaultNotFoundError - final case class CommonError(userMessage: String) extends DeleteReply with DomainError - } -} - trait PatientIssueService { - import PatientIssueService._ - def create(draft: PatientIssue)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[CreateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[PatientIssue] def getById(patientId: UuidId[Patient], id: LongId[PatientIssue])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[PatientIssue]] def getListByPatientId(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListByPatientIdReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[PatientIssue]] def update(orig: PatientIssue, draft: PatientIssue)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[PatientIssue] def delete(patientId: UuidId[Patient], id: LongId[PatientIssue])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[DeleteReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Unit] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala index 1ddf401..a999bf9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala @@ -5,62 +5,20 @@ import xyz.driver.entities.labels.Label import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuicommon.error.DomainError +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import scala.concurrent.Future -object PatientLabelEvidenceService { - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - trait DefaultPatientNotFoundError { - def userMessage: String = "Patient not found" - } - - sealed trait GetByIdReply - object GetByIdReply { - final case class Entity(x: PatientLabelEvidenceView) extends GetByIdReply - - type Error = GetByIdReply with DomainError - - final case class NotFoundError(userMessage: String) extends GetByIdReply with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetByIdReply with DomainError - - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - } - - sealed trait GetListReply - object GetListReply { - final case class EntityList(xs: Seq[PatientLabelEvidenceView], totalFound: Int) extends GetListReply - - type Error = GetListReply with DomainError - - case object PatientNotFoundError - extends GetListReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String) extends GetListReply with DomainError - } -} - trait PatientLabelEvidenceService { - import PatientLabelEvidenceService._ - def getById(patientId: UuidId[Patient], labelId: LongId[Label], id: LongId[PatientLabelEvidence])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[PatientLabelEvidenceView]] def getAll(patientId: UuidId[Patient], labelId: LongId[Label], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[PatientLabelEvidenceView]] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala index 048374a..0eeac53 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala @@ -5,123 +5,27 @@ import xyz.driver.entities.labels.Label import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.error.DomainError -import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import scala.concurrent.Future -object PatientLabelService { - - trait DefaultNotFoundError { - def userMessage: String = "Patient label not found" - } - - trait DefaultPatientNotFoundError { - def userMessage: String = "Patient not found" - } - - trait DefaultAccessDeniedError { - 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[RichPatientLabel], totalFound: Int) extends GetListReply - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends GetListReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetListReply with DomainError - } - - sealed trait GetDefiningCriteriaListReply - object GetDefiningCriteriaListReply { - final case class EntityList(xs: Seq[PatientLabel], totalFound: Int) extends GetDefiningCriteriaListReply - - case object AuthorizationError - extends GetDefiningCriteriaListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - case object PatientNotFoundError - extends GetDefiningCriteriaListReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - final case class CommonError(userMessage: String) extends GetDefiningCriteriaListReply with DomainError - } - - sealed trait GetByLabelIdReply - object GetByLabelIdReply { - final case class Entity(x: RichPatientLabel) extends GetByLabelIdReply - - type Error = GetByLabelIdReply with DomainError - - case object NotFoundError extends GetByLabelIdReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends GetByLabelIdReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends GetByLabelIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String) extends GetByLabelIdReply with DomainError - - implicit def toPhiString(reply: GetByLabelIdReply): PhiString = reply match { - case x: DomainError => phi"GetByIdReply.Error($x)" - case Entity(x) => phi"GetByIdReply.Entity($x)" - } - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - - final case class Updated(updated: RichPatientLabel) extends UpdateReply - - case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError - - case object PatientNotFoundError - extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - - implicit def toPhiString(reply: UpdateReply): PhiString = reply match { - case Updated(x) => phi"Updated($x)" - case x: Error => DomainError.toPhiString(x) - } - } -} - trait PatientLabelService { - import PatientLabelService._ - def getAll(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientLabel]] def getDefiningCriteriaList(patientId: UuidId[Patient], hypothesisId: UuidId[Hypothesis], - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetDefiningCriteriaListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[PatientLabel]] def getByLabelIdOfPatient(patientId: UuidId[Patient], labelId: LongId[Label])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByLabelIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[RichPatientLabel]] def update(origPatientLabel: PatientLabel, draftPatientLabel: PatientLabel)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[RichPatientLabel] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala index e23fc7a..6f95fdb 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala @@ -1,104 +1,39 @@ package xyz.driver.pdsuidomain.services -import java.time.LocalDateTime - import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.error.DomainError -import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ import scala.concurrent.Future -object PatientService { - - trait DefaultNotFoundError { - def userMessage: String = "Patient not found" - } - - trait DefaultAccessDeniedError { - def userMessage: String = "Access denied" - } - - sealed trait GetListReply - object GetListReply { - final case class EntityList(xs: Seq[Patient], totalFound: Int, lastUpdate: Option[LocalDateTime]) - extends GetListReply - - case object AuthorizationError - extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError - } - - sealed trait GetByIdReply - object GetByIdReply { - final case class Entity(x: Patient) extends GetByIdReply - - type Error = GetByIdReply with DomainError - - case object NotFoundError extends GetByIdReply with DefaultNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError - - final case class CommonError(userMessage: String)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]) - extends GetByIdReply with DomainError - - implicit def toPhiString(reply: GetByIdReply): PhiString = reply match { - case x: DomainError => phi"GetByIdReply.Error($x)" - case Entity(x) => phi"GetByIdReply.Entity($x)" - } - } - - sealed trait UpdateReply - object UpdateReply { - type Error = UpdateReply with DomainError - - final case class Updated(updated: Patient) extends UpdateReply - - case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError - - case object AuthorizationError - extends UpdateReply with DefaultAccessDeniedError with DomainError.AuthorizationError - - final case class CommonError(userMessage: String) extends UpdateReply with DomainError - - implicit def toPhiString(reply: UpdateReply): PhiString = reply match { - case Updated(x) => phi"Updated($x)" - case x: Error => DomainError.toPhiString(x) - } - } -} - trait PatientService { - import PatientService._ - def getById(id: UuidId[Patient])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[Patient]] def getAll(filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[Patient]] def unassign(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] def start(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] def submit(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] def restart(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] def flag(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] def resolve(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientCriterionService.scala index 6629cf5..cc66142 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientCriterionService.scala @@ -5,7 +5,7 @@ import akka.http.scaladsl.model._ import akka.stream.Materializer import xyz.driver.core.rest.{Pagination => _, _} import xyz.driver.entities.users.AuthUserInfo -import xyz.driver.pdsuicommon.db._ +import xyz.driver.pdsuicommon.db.{Pagination, _} import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ @@ -22,60 +22,59 @@ class RestPatientCriterionService(transport: ServiceTransport, baseUri: Uri)( import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import xyz.driver.pdsuidomain.formats.json.patientcriterion._ import xyz.driver.pdsuidomain.formats.json.listresponse._ - import xyz.driver.pdsuidomain.services.PatientCriterionService._ def getAll(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] = { + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientCriterion]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/criterion", - filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination))) + filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(Some(pagination)))) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[ListResponse[RichPatientCriterion]](response) } yield { - GetListReply.EntityList(reply.items, reply.meta.itemsCount, reply.meta.lastUpdate) + reply } } def getById(patientId: UuidId[Patient], id: LongId[PatientCriterion])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[RichPatientCriterion]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/criterion/$id")) for { response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientCriterion](response) + entity <- apiResponse[RichPatientCriterion](response) } yield { - GetByIdReply.Entity(reply) + Option(entity) } } def updateList(patientId: UuidId[Patient], draftEntities: List[DraftPatientCriterion])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Unit] = { for { entity <- Marshal(draftEntities).to[RequestEntity] request = HttpRequest(HttpMethods.PATCH, endpointUri(baseUri, s"/v1/patient/$patientId/criterion")) .withEntity(entity) response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientCriterion](response) + _ <- apiResponse[RichPatientCriterion](response) } yield { - UpdateReply.Updated(reply) + () } } def update(origEntity: PatientCriterion, draftEntity: PatientCriterion, patientId: UuidId[Patient])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[RichPatientCriterion] = { for { entity <- Marshal(draftEntity).to[RequestEntity] request = HttpRequest( HttpMethods.PATCH, endpointUri(baseUri, s"/v1/patient/$patientId/criterion/${origEntity.criterionId}")).withEntity(entity) response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientCriterion](response) + entity <- apiResponse[RichPatientCriterion](response) } yield { - UpdateReply.Updated(reply) + entity } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientLabelService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientLabelService.scala index a6ef5b4..932e123 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientLabelService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientLabelService.scala @@ -6,7 +6,7 @@ import akka.stream.Materializer import xyz.driver.core.rest.{Pagination => _, _} import xyz.driver.entities.labels.Label import xyz.driver.entities.users.AuthUserInfo -import xyz.driver.pdsuicommon.db._ +import xyz.driver.pdsuicommon.db.{Pagination, _} import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ @@ -22,53 +22,52 @@ class RestPatientLabelService(transport: ServiceTransport, baseUri: Uri)( import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import xyz.driver.pdsuidomain.formats.json.listresponse._ import xyz.driver.pdsuidomain.formats.json.patientlabel._ - import xyz.driver.pdsuidomain.services.PatientLabelService._ def getAll(patientId: UuidId[Patient], filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] = { + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[RichPatientLabel]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/label", - filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination))) + filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(Some(pagination)))) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[ListResponse[RichPatientLabel]](response) } yield { - GetListReply.EntityList(reply.items, reply.meta.itemsCount) + reply } } def getDefiningCriteriaList(patientId: UuidId[Patient], hypothesisId: UuidId[Hypothesis], - pagination: Option[Pagination] = None)( + pagination: Pagination = Pagination.Default)( implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo] - ): Future[GetDefiningCriteriaListReply] = { + ): Future[ListResponse[PatientLabel]] = { val request = HttpRequest(HttpMethods.GET, - endpointUri(baseUri, s"/patient/$patientId/hypothesis", paginationQuery(pagination))) + endpointUri(baseUri, s"/patient/$patientId/hypothesis", paginationQuery(Some(pagination)))) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[ListResponse[PatientLabel]](response) } yield { - GetDefiningCriteriaListReply.EntityList(reply.items, reply.meta.itemsCount) + reply } } def getByLabelIdOfPatient(patientId: UuidId[Patient], labelId: LongId[Label])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByLabelIdReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[RichPatientLabel]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/label/$labelId")) for { response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientLabel](response) + entity <- apiResponse[RichPatientLabel](response) } yield { - GetByLabelIdReply.Entity(reply) + Option(entity) } } def update(origPatientLabel: PatientLabel, draftPatientLabel: PatientLabel)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[RichPatientLabel] = { for { entity <- Marshal(draftPatientLabel).to[RequestEntity] request = HttpRequest( @@ -76,9 +75,9 @@ class RestPatientLabelService(transport: ServiceTransport, baseUri: Uri)( endpointUri(baseUri, s"/v1/patient/${origPatientLabel.patientId}/label/${origPatientLabel.labelId}")) .withEntity(entity) response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientLabel](response) + entity <- apiResponse[RichPatientLabel](response) } yield { - UpdateReply.Updated(reply) + entity } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientService.scala index 8460872..67f4e38 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientService.scala @@ -5,7 +5,7 @@ import akka.http.scaladsl.model._ import akka.stream.Materializer import xyz.driver.core.rest.{Pagination => _, _} import xyz.driver.entities.users.AuthUserInfo -import xyz.driver.pdsuicommon.db._ +import xyz.driver.pdsuicommon.db.{Pagination, _} import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities._ @@ -19,62 +19,60 @@ class RestPatientService(transport: ServiceTransport, baseUri: Uri)(implicit pro import xyz.driver.pdsuidomain.formats.json.listresponse._ import xyz.driver.pdsuidomain.formats.json.patient._ - import xyz.driver.pdsuidomain.services.PatientService._ - def getById(id: UuidId[Patient])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Option[Patient]] = { val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$id")) for { response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[Patient](response) + entity <- apiResponse[Patient](response) } yield { - GetByIdReply.Entity(reply) + Option(entity) } } def getAll(filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] = { + pagination: Pagination = Pagination.Default)( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[ListResponse[Patient]] = { val request = HttpRequest( HttpMethods.GET, - endpointUri(baseUri, "/v1/patient", filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination))) + endpointUri(baseUri, "/v1/patient", filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(Some(pagination)))) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[ListResponse[Patient]](response) } yield { - GetListReply.EntityList(reply.items, reply.meta.itemsCount, reply.meta.lastUpdate) + reply } } private def editAction(orig: Patient, action: String)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = { + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = { val id = orig.id.toString val request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, s"/v1/patient/$id/$action")) for { response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[Patient](response) + entity <- apiResponse[Patient](response) } yield { - UpdateReply.Updated(reply) + entity } } def unassign(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "unassign") def start(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "start") def submit(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "submit") def restart(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "restart") def flag(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "flag") def resolve(origPatient: Patient)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Patient] = editAction(origPatient, "resolve") } |