1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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.labels.Label
import xyz.driver.pdsuicommon.auth._
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.PatientLabelService
import scala.concurrent.{ExecutionContext, Future}
class RestPatientLabelService(transport: ServiceTransport, baseUri: Uri)(
implicit protected val materializer: Materializer,
protected val exec: ExecutionContext)
extends PatientLabelService with RestHelper {
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: AuthenticatedRequestContext): Future[GetListReply] = {
val request = HttpRequest(HttpMethods.GET,
endpointUri(baseUri,
s"/v1/patient/$patientId/labels",
filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination)))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
reply <- apiResponse[ListResponse[RichPatientLabel]](response)
} yield {
GetListReply.EntityList(reply.items, reply.meta.itemsCount)
}
}
def getDefiningCriteriaList(patientId: UuidId[Patient],
hypothesisId: UuidId[Hypothesis],
pagination: Option[Pagination] = None)(
implicit requestContext: AuthenticatedRequestContext): Future[GetDefiningCriteriaListReply] = {
val request = HttpRequest(HttpMethods.GET,
endpointUri(baseUri, s"/patient/$patientId/hypothesis", paginationQuery(pagination)))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
reply <- apiResponse[ListResponse[PatientLabel]](response)
} yield {
GetDefiningCriteriaListReply.EntityList(reply.items, reply.meta.itemsCount)
}
}
def getByLabelIdOfPatient(patientId: UuidId[Patient], labelId: LongId[Label])(
implicit requestContext: AuthenticatedRequestContext): Future[GetByLabelIdReply] = {
val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/label/$labelId"))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
reply <- apiResponse[RichPatientLabel](response)
} yield {
GetByLabelIdReply.Entity(reply)
}
}
def update(origPatientLabel: PatientLabel, draftPatientLabel: PatientLabel)(
implicit requestContext: AuthenticatedRequestContext): Future[UpdateReply] = {
for {
entity <- Marshal(draftPatientLabel).to[RequestEntity]
request = HttpRequest(
HttpMethods.PATCH,
endpointUri(baseUri, s"/v1/patient/${origPatientLabel.patientId}/label/${origPatientLabel.labelId}"))
.withEntity(entity)
response <- transport.sendRequestGetResponse(requestContext)(request)
reply <- apiResponse[RichPatientLabel](response)
} yield {
UpdateReply.Updated(reply)
}
}
}
|