diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-12-14 10:26:44 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-12-14 10:26:44 +0700 |
commit | ed1ad48ac9f5a03839bbe176b363af6c84220e6b (patch) | |
tree | f6bb6ff1fc22f5d204d6e9e5f5d330d027048be1 /src/main/scala/xyz/driver/pdsuidomain/services | |
parent | 7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c (diff) | |
parent | 51d5d1ddba83f539405c6d395933e1f8a456c871 (diff) | |
download | rest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.tar.gz rest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.tar.bz2 rest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.zip |
Merge branch 'master' into support-service-exceptions
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/services')
6 files changed, 158 insertions, 91 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala new file mode 100644 index 0000000..b3e6673 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala @@ -0,0 +1,16 @@ +package xyz.driver.pdsuidomain.services + +import xyz.driver.core.rest.AuthorizedServiceRequestContext +import xyz.driver.entities.users.AuthUserInfo +import xyz.driver.pdsuicommon.domain.UuidId +import xyz.driver.pdsuidomain.entities.{Patient => PdsuiPatient} +import xyz.driver.pdsuidomain.entities.eligibility.EligibleTrial + +import scala.concurrent.Future + +trait EligibilitySnapshotService { + + def eligibilitySnapshot(patientId: UuidId[PdsuiPatient])( + implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Seq[EligibleTrial]] + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala index f07f6fa..8d1288a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala @@ -96,11 +96,9 @@ object PatientEligibleTrialService { case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError - case object PatientNotFoundError - extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError + case object PatientNotFoundError extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError - case object AuthorizationError - extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError + case object AuthorizationError extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError final case class CommonError(userMessage: String) extends UpdateReply with DomainError @@ -127,7 +125,7 @@ trait PatientEligibleTrialService { def getCriterionListByGroupId(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])( implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetCriterionListOfGroupReply] - def update(origEligibleTrialWithTrial: RichPatientEligibleTrial, - draftPatientTrialArmGroup: PatientTrialArmGroupView)( + def update(origEligibleTrialWithTrial: RichPatientEligibleTrial, draftPatientTrialArmGroup: PatientTrialArmGroupView)( implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala new file mode 100644 index 0000000..2187ec2 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala @@ -0,0 +1,34 @@ +package xyz.driver.pdsuidomain.services.rest + +import akka.http.scaladsl.model.{HttpMethods, HttpRequest, Uri} +import akka.stream.Materializer +import xyz.driver.core.rest.{AuthorizedServiceRequestContext, ServiceTransport} +import xyz.driver.entities.users.AuthUserInfo +import xyz.driver.pdsuicommon.domain.UuidId +import xyz.driver.pdsuidomain.entities.eligibility.EligibleTrial +import xyz.driver.pdsuidomain.entities.{Patient, eligibility} +import xyz.driver.pdsuidomain.services.EligibilitySnapshotService + +import scala.concurrent.{ExecutionContext, Future} + +class RestEligibilitySnapshotService(transport: ServiceTransport, baseUrl: Uri)( + implicit protected val materializer: Materializer, + protected val exec: ExecutionContext) extends EligibilitySnapshotService with RestHelper { + + import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ + import spray.json.DefaultJsonProtocol._ + import xyz.driver.pdsuidomain.formats.json.eligibility._ + + override def eligibilitySnapshot(patientId: UuidId[Patient]) + (implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): + Future[Seq[eligibility.EligibleTrial]] = { + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUrl, s"/v1/patient/$patientId/eligibilitySnapshot")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[Seq[EligibleTrial]](response) + } yield { + reply + } + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala deleted file mode 100644 index 06aa6d0..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala +++ /dev/null @@ -1,84 +0,0 @@ -package xyz.driver.pdsuidomain.services.rest - -import akka.http.scaladsl.marshalling.Marshal -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.domain._ -import xyz.driver.pdsuidomain.ListResponse -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService - -import scala.concurrent.{ExecutionContext, Future} - -class RestPatientEligibleTrialService(transport: ServiceTransport, baseUri: Uri)( - implicit protected val materializer: Materializer, - protected val exec: ExecutionContext) - extends PatientEligibleTrialService with RestHelper { - - import PatientEligibleTrialService._ - import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ - import xyz.driver.pdsuidomain.formats.json.listresponse._ - import xyz.driver.pdsuidomain.formats.json.patientcriterion._ - import xyz.driver.pdsuidomain.formats.json.patienteligibletrial._ - - def getAll(patientId: UuidId[Patient], - filter: SearchFilterExpr = SearchFilterExpr.Empty, - sorting: Option[Sorting] = None, - pagination: Option[Pagination] = None)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] = { - val request = HttpRequest(HttpMethods.GET, - endpointUri(baseUri, - s"/v1/patient/$patientId/trial", - filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination))) - for { - response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[ListResponse[RichPatientEligibleTrial]](response) - } yield { - GetListReply.EntityList(reply.items, reply.meta.itemsCount) - } - } - - - def getById(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] = { - val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/trial/$id")) - for { - response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientEligibleTrial](response) - } yield { - GetByIdReply.Entity(reply) - } - } - - def getCriterionListByGroupId(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetCriterionListOfGroupReply] = { - val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/trial/$id/criterion")) - for { - response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[ListResponse[RichPatientCriterion]](response) - } yield { - GetCriterionListOfGroupReply.EntityList(reply.items, reply.meta.itemsCount) - } - } - - def update(origEligibleTrialWithTrial: RichPatientEligibleTrial, - draftPatientTrialArmGroup: PatientTrialArmGroupView)( - implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = { - for { - entity <- Marshal(draftPatientTrialArmGroup).to[RequestEntity] - request = HttpRequest( - HttpMethods.PATCH, - endpointUri(baseUri, s"/v1/patient/${origEligibleTrialWithTrial.group.patientId}/trial/${origEligibleTrialWithTrial.group.id}")) - .withEntity(entity) - response <- transport.sendRequestGetResponse(requestContext)(request) - reply <- apiResponse[RichPatientEligibleTrial](response) - } yield { - UpdateReply.Updated(reply) - } - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala new file mode 100644 index 0000000..b14d35b --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala @@ -0,0 +1,103 @@ +package xyz.driver.pdsuidomain.services.rest + +import akka.http.scaladsl.marshalling.Marshal +import akka.http.scaladsl.model._ +import akka.stream.Materializer +import spray.json.RootJsonReader +import xyz.driver.core.rest.{AuthorizedServiceRequestContext, ServiceTransport} +import xyz.driver.entities.users +import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.ListResponse +import xyz.driver.pdsuidomain.entities.{Trial, TrialIssue} +import xyz.driver.pdsuidomain.services.TrialIssueService + +import scala.concurrent.ExecutionContext + +class RestTrialIssueService(transport: ServiceTransport, baseUri: Uri) + (implicit + protected val materializer: Materializer, + protected val exec: ExecutionContext) + extends TrialIssueService with RestHelper{ + + import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ + import xyz.driver.pdsuidomain.formats.json.listresponse._ + import xyz.driver.pdsuidomain.formats.json.trialissue._ + import xyz.driver.pdsuidomain.services.TrialIssueService._ + + override def create(draft: TrialIssue) + (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = { + val trialId = draft.trialId + + implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId) + + for { + entity <- Marshal(draft).to[RequestEntity] + request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, s"/v1/trial/$trialId/issue")).withEntity(entity) + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[TrialIssue](response) + } yield { + CreateReply.Created(reply) + } + } + + override def getListByTrialId(trialId: StringId[Trial], + filter: SearchFilterExpr, + sorting: Option[Sorting], + pagination: Option[Pagination]) + (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = { + implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId) + + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$trialId/issue", + filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination)) + ) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[ListResponse[TrialIssue]](response) + } yield { + GetListByTrialIdReply.EntityList(reply.items, reply.meta.itemsCount, reply.meta.lastUpdate) + } + } + + override def getById(trialId: StringId[Trial], id: LongId[TrialIssue]) + (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = { + implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId) + + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[TrialIssue](response) + } yield { + GetByIdReply.Entity(reply) + } + } + + override def update(orig: TrialIssue, draft: TrialIssue) + (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = { + val trialId = draft.trialId + val id = orig.id.id + + implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId) + + for { + entity <- Marshal(draft).to[RequestEntity] + request = HttpRequest(HttpMethods.PATCH, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id")).withEntity(entity) + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[TrialIssue](response) + } yield { + UpdateReply.Updated(reply) + } + } + + override def delete(trialId: StringId[Trial], id: LongId[TrialIssue]) + (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = { + val request = HttpRequest(HttpMethods.DELETE, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + _ <- apiResponse[HttpEntity](response) + } yield { + DeleteReply.Deleted + } + } + +} 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 4654c2e..6650d51 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala @@ -110,7 +110,7 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote } val id = origTrial.id.id - val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$id/$action", query)) + val request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, s"/v1/trial/$id/$action", query)) for { response <- transport.sendRequestGetResponse(requestContext)(request) reply <- apiResponse[Trial](response) |