Skip to content

Commit 6037760

Browse files
[ERSSUP-61674]-[JW/AO]-[Retrieve Binary R4 API design]-[FV]
1 parent 7ad5dbf commit 6037760

File tree

10 files changed

+138
-3
lines changed

10 files changed

+138
-3
lines changed

sandbox/src/routes/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const retrieveOboUsers = require('./r4/retrieveOboUsers')
4242
const retrieveHealthcareService = require('./r4/retrieveHealthcareService')
4343
const searchForHealthcareServices = require('./r4/searchForHealthcareServices')
4444
const searchServiceRequest = require('./r4/searchServiceRequest')
45+
const retrieveBinary = require('./r4/retrieveBinary')
46+
const retrieveBinaryHelper = require('./r4/retrieveBinaryHelper')
4547

4648
const routes = [].concat(
4749
getStatus,
@@ -80,7 +82,9 @@ const routes = [].concat(
8082
retrieveAppointment,
8183
retrieveAdviceAndGuidanceOverviewPdf,
8284
searchServiceRequest,
83-
createAdviceAndGuidance
85+
createAdviceAndGuidance,
86+
retrieveBinary,
87+
retrieveBinaryHelper
8488
)
8589

8690
module.exports = routes
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const businessFunctionValidator = require('../../services/businessFunctionValidator')
2+
3+
module.exports = [
4+
/**
5+
* Sandbox implementation for retrieveBinary A039 (R4) endpoint
6+
*/
7+
{
8+
method: 'GET',
9+
path: '/FHIR/R4/Binary/{attachmentUuid}',
10+
handler: (request, h) => {
11+
12+
const allowedBusinessFunctions = ["REFERRING_CLINICIAN", "REFERRING_CLINICIAN_ADMIN", "SERVICE_PROVIDER_CLINICIAN", "SERVICE_PROVIDER_CLINICIAN_ADMIN"]
13+
14+
const validationResult = businessFunctionValidator.validateBusinessFunction(request, h, allowedBusinessFunctions)
15+
if (validationResult) {
16+
return validationResult
17+
}
18+
19+
const uuid = request.params.attachmentUuid;
20+
const url = request.url.href;
21+
const objectStore = "/ObjectStore/RetrieveBinary/d497bbe3-f88b-45f1-b3d4-9c563e4c0f5f";
22+
const location = url.split('/FHIR')[0] + objectStore;
23+
24+
if (uuid === '704c3791-0873-45e9-9a04-b51996f8d93f' && request.method === 'get') {
25+
const response = h.response().code(307)
26+
response.headers["Location"] = location;
27+
return response
28+
} else {
29+
return h.file('SandboxErrorOutcome.json').code(422);
30+
}
31+
32+
}
33+
}
34+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = [
2+
/**
3+
* Sandbox implementation for retrieveBinary (R4) endpoint helper,
4+
* with an ObjectStore 'mock', allowing redirection and example file retrieval.
5+
*/
6+
{
7+
method: 'GET',
8+
path: '/ObjectStore/RetrieveBinary/{fileDownloadUuid}',
9+
handler: (request, h) => {
10+
11+
const uuid = request.params.fileDownloadUuid
12+
const exampleResponsePath = 'retrieveAttachment/responses/example_attachment.pdf'
13+
const filename = 'example_attachment.pdf'
14+
const responseCode = 200
15+
16+
if (uuid === 'd497bbe3-f88b-45f1-b3d4-9c563e4c0f5f') {
17+
return h.file(exampleResponsePath, {
18+
mode: 'attachment',
19+
filename: filename,
20+
etagMethod: false
21+
}).code(responseCode);
22+
}
23+
}
24+
}
25+
]

scripts/populate_placeholders.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def main():
4343
"[[HYPERLINK_A038]]": "[Retrieve appointment (A038)](#get-/STU3/Appointment/-id-)",
4444
"[[HYPERLINK_A040]]": "[Retrieve “on-behalf-of” practitioner user information (A040)](#get-/R4/Practitioner)",
4545
"[[HYPERLINK_A041]]": "[Search for service requests (A041)](#get-/R4/ServiceRequest)",
46+
"[[HYPERLINK_A042]]": "[Request pre-signed URL to download file from document store (A042)](#get-/R4/Binary/-id-)",
4647
"[[HYPERLINK_A043]]": "[Retrieve advice and guidance overview PDF (A043)](#post-/STU3/CommunicationRequest/-ubrn-/$ers.generateCRI)",
4748
"[[HYPERLINK_A044]]": "[Create advice and guidance request (A044)](#post-/STU3/CommunicationRequest/$ers.createAdviceAndGuidance)",
4849
"[[HYPERLINK_ONBOARDING]]": "[onboarding](#overview--onboarding)",

scripts/validate_oas_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
http_methods = ["post", "put", "patch", "get", "head", "delete"]
4949

5050
# List containing http success response codes
51-
http_success_codes = ["200", "201"]
51+
http_success_codes = ["200", "201", "307"]
5252

5353
# Open OAS JSON file
5454
try:
@@ -158,6 +158,7 @@ def get_success_code(endpoint, http_method):
158158
].keys()
159159
)
160160
filtered_code = filter(lambda x: x in http_success_codes, endpoint_return_codes)
161+
161162
return list(filtered_code)[0]
162163

163164

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
security:
2+
- bearerAuth: []
3+
description: |
4+
### TODO Add later
5+
summary: A042 - Request pre-signed URL to download file from document store
6+
operationId: a042-request-pre-signed-url-for-file-download
7+
parameters:
8+
- $ref: '../headers/request/BearerAuthorization.yaml'
9+
- $ref: '../headers/request/BusinessFunction.yaml'
10+
- $ref: '../headers/request/CorrelationID.yaml'
11+
- $ref: '../headers/request/OdsCode.yaml'
12+
- $ref: '../headers/request/OnBehalfOfUserID.yaml'
13+
- $ref: '../pathParameters/AttachmentUuid.yaml'
14+
responses:
15+
'307':
16+
$ref: '../responses/retrieveBinary/307Response.yaml'
17+
'400':
18+
$ref: '../responses/retrieveBinary/400Response.yaml'
19+
'401':
20+
$ref: '../responses/Unauthorized.yaml'
21+
'403':
22+
$ref: '../responses/Forbidden.yaml'
23+
'404':
24+
$ref: '../responses/NotFound.yaml'
25+
'429':
26+
$ref: '../responses/TooManyRequests.yaml'
27+
'500':
28+
$ref: '../responses/InternalServerError.yaml'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
in: path
2+
name: id
3+
description: |
4+
Reference for an attachment, as provided in the response from [[HYPERLINK_A039]].
5+
required: true
6+
schema:
7+
type: string
8+
example: '704c3791-0873-45e9-9a04-b51996f8d93f'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
description: Response redirects user agent to the large file attachment URL in the Object Store via the Location header.
2+
headers:
3+
x-correlation-id:
4+
$ref: '../../headers/response/CorrelationID.yaml'
5+
x-request-id:
6+
$ref: '../../headers/response/RequestID.yaml'
7+
Location:
8+
description: The large file attachment location in the Object Store.
9+
required: true
10+
schema:
11+
type: string
12+
example: '<ObjectStoreURL>'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
description: |
2+
Where status code 400 (Bad Request) is returned then an [NHSDigital-OperationOutcome](https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome) will be included in the body, as detailed below.
3+
Check diagnostics property for specific information regarding the error.
4+
5+
| issue.details.coding.code | issue.code | Description |
6+
| ------------------------- | ------------ | ----------------------------------------------------- |
7+
| REC_BAD_REQUEST | required | TODO:63315 |
8+
headers:
9+
x-correlation-id:
10+
$ref: '../../headers/response/CorrelationID.yaml'
11+
x-request-id:
12+
$ref: '../../headers/response/RequestID.yaml'
13+
Content-Type:
14+
$ref: '../../headers/response/ContentTypeFhirJson.yaml'
15+
content:
16+
application/fhir+json:
17+
schema:
18+
$ref: '../../NHSDigital-OperationOutcome.yaml'
19+
example:
20+
$ref: '../../../examples/NHSDigital-OperationOutcome-400.json'

specification/e-referrals-service-api.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ paths:
425425
/R4/ServiceRequest:
426426
get:
427427
$ref: 'components/r4/schemas/endpoints/a041-search-service-request.yaml'
428-
428+
/R4/Binary/{id}:
429+
get:
430+
$ref: 'components/r4/schemas/endpoints/a042-request-pre-signed-url-for-file-download.yaml'
429431
components:
430432
securitySchemes:
431433
bearerAuth:

0 commit comments

Comments
 (0)