Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request parameters filename and fileSize #463

Open
wants to merge 6 commits into
base: feature/xapi-file-upload
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sandbox/src/mocks/r4/NHSDigital-OperationOutcome-422.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"resourceType": "OperationOutcome",
"meta": {
"lastUpdated": "2022-03-01T10:00:00.42Z"
},
"issue": [
{
"severity": "error",
"code": "required",
"diagnostics": "Example diagnostics message.",
"details": {
"coding": [
{
"system": "https://fhir.nhs.uk/CodeSystem/http-error-codes",
"code": "REC_UNPROCESSABLE_ENTITY"
}
]
}
}
]
}
24 changes: 24 additions & 0 deletions sandbox/src/mocks/r4/NHSDigital-OperationOutcome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"resourceType": "OperationOutcome",
"meta": {
"profile": [
"https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome"
],
"lastUpdated": "2022-03-01T10:00:00.42Z"
},
"issue": [
{
"severity": "error",
"code": "forbidden",
"diagnostics": "Example diagnostics message.",
"details": {
"coding": [
{
"system": "https://fhir.nhs.uk/CodeSystem/http-error-codes",
"code": "REC_BAD_REQUEST"
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resourceType": "Parameters",
"parameter": [
{
"name": "filename",
"valueString": "example.pdf"
},
{
"name": "fileSize",
"valueUnsignedInt": 10485760
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resourceType": "Parameters",
"parameter": [
{
"name": "uploadUri",
"valueUri": "<preSignedUri>"
},
{
"name": "reference",
"valueUri": "/Binary/ce2fbda9-7c18-46ab-ae04-5b08df61e0d4"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"id": "123e4567-e89b-12d3-a456-426614174002",
"resourceType": "Bundle",
"meta": {
"profile": [
"https://fhir.hl7.org.uk/StructureDefinition/UKCore-Bundle"
],
"lastUpdated": "2022-03-01T10:00:00.42Z"
},
"timestamp": "2022-04-06T15:42:00.42Z",
"link": [
{
"relation": "self",
"url": "_baseUrl_/FHIR/R4/ServiceRequest?identifier=https://fhir.nhs.uk/Id/UBRN%7C000000070000"
}
],
"total": 1,
"type": "searchset",
"entry": [
{
"fullUrl": "_baseUrl_/ServiceRequest/r.832db7fa-ebdd-44b6-ab3b-8329c2d43149",
"resource": {
"id": "r.832db7fa-ebdd-44b6-ab3b-8329c2d43149",
"meta": {
"profile": [
"https://fhir.nhs.uk/StructureDefinition/NHSDigital-ServiceRequest"
],
"versionId": "5"
},
"resourceType": "ServiceRequest",
"extension": [
{
"url": "https://fhir.nhs.uk/StructureDefinition/Extension-ServiceRequest-Priority",
"valueCoding": {
"system": "https://fhir.nhs.uk/CodeSystem/eRS-Priority",
"code": "ROUTINE",
"display": "Routine"
}
}
],
"contained": [
{
"resourceType": "PractitionerRole",
"id": "PractitionerRole-R69-000000000101",
"meta": {
"profile": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole-Minimal"
},
"practitioner": {
"identifier": {
"system": "https://fhir.nhs.uk/Id/sds-user-id",
"value": "000000000101"
}
},
"organization": {
"identifier": {
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
"value": "R69"
}
}
}
],
"identifier": [
{
"system": "https://fhir.nhs.uk/Id/UBRN",
"value": "000000070000"
}
],
"status": "active",
"intent": "order",
"category": [
{
"coding": [
{
"system": "http://snomed.info/sct",
"code": "3457005",
"display": "Patient referral"
}
]
}
],
"priority": "routine",
"subject": {
"identifier": {
"system": "https://fhir.nhs.uk/Id/nhs-number",
"value": "9912003888"
}
},
"authoredOn": "2022-01-11T10:00:00.000Z",
"requester": {
"reference": "#PractitionerRole-R69-000000000101"
}
},
"search": {
"mode": "match"
}
}
]
}
10 changes: 9 additions & 1 deletion sandbox/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const retrieveBusinessFunctions = require('./r4/retrieveBusinessFunctions')
const retrieveOboUsers = require('./r4/retrieveOboUsers')
const retrieveHealthcareService = require('./r4/retrieveHealthcareService')
const searchForHealthcareServices = require('./r4/searchForHealthcareServices')
const searchServiceRequest = require('./r4/searchServiceRequest')
const requestUploadUri = require('./r4/requestUploadUri')
const retrieveBinary = require('./r4/retrieveBinary')
const retrieveBinaryHelper = require('./r4/retrieveBinaryHelper')

const routes = [].concat(
getStatus,
Expand Down Expand Up @@ -76,7 +80,11 @@ const routes = [].concat(
cancelAppointmentActionLater,
cancelReferral,
retrieveAppointment,
retrieveAdviceAndGuidanceOverviewPdf
retrieveAdviceAndGuidanceOverviewPdf,
searchServiceRequest,
requestUploadUri,
retrieveBinary,
retrieveBinaryHelper
)

module.exports = routes
37 changes: 37 additions & 0 deletions sandbox/src/routes/mockResponseUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require('fs')
const lodash = require('lodash')

module.exports = {
mapExampleResponse(request, exampleResponseMap) {

if (request && request.payload) {
for (const [requestBodyPath, response] of Object.entries(exampleResponseMap)) {
try {
const exampleRequestBody = JSON.parse(fs.readFileSync(requestBodyPath))
var requestBody = request.payload;

if ('object' != (typeof requestBody)) {
requestBody = JSON.parse(request.payload)
}

if (lodash.isEqual(requestBody, exampleRequestBody)) {
return response;
}
} catch (err) {
console.error(err)
throw err
}
}
}

return null;
},

mapExampleGetResponse(parameterValue, exampleResponseMap) {
for (const [requestParameter, responseBodyPath] of Object.entries(exampleResponseMap)) {
if (parameterValue === requestParameter) {
return responseBodyPath;
}
}
}
}
29 changes: 29 additions & 0 deletions sandbox/src/routes/r4/requestUploadUri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mockResponseProvider = require('./services/mockResponseProvider')
const businessFunctionValidator = require('../../services/businessFunctionValidator')

function requestUploadUri(request, h) {
const allowedBusinessFunctions = ["REFERRING_CLINICIAN", "REFERRING_CLINICIAN_ADMIN", "SERVICE_PROVIDER_CLINICIAN", "SERVICE_PROVIDER_CLINICIAN_ADMIN"]

const validationResult = businessFunctionValidator.validateBusinessFunction(request, h, allowedBusinessFunctions)
if (validationResult) {
return validationResult
}

if(request.method == 'post') {
var responsePath = mockResponseProvider.getExampleResponseForRequestUploadUri(request)
if (responsePath) {
return h.file(responsePath, { etagMethod: false }).code(200).type('application/fhir+json')
}
}

return h.file('SandboxErrorOutcome.json').code(422)
}


module.exports = [
{
method: 'POST',
path: '/FHIR/R4/ServiceRequest/{id}/$ers.generateUploadURI',
handler: requestUploadUri
}
]
34 changes: 34 additions & 0 deletions sandbox/src/routes/r4/retrieveBinary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const businessFunctionValidator = require('../../services/businessFunctionValidator')

module.exports = [
/**
* Sandbox implementation for retrieveBinary A039 (R4) endpoint
*/
{
method: 'GET',
path: '/FHIR/R4/Binary/{attachmentUuid}',
handler: (request, h) => {

const allowedBusinessFunctions = ["REFERRING_CLINICIAN", "REFERRING_CLINICIAN_ADMIN", "SERVICE_PROVIDER_CLINICIAN", "SERVICE_PROVIDER_CLINICIAN_ADMIN"]

const validationResult = businessFunctionValidator.validateBusinessFunction(request, h, allowedBusinessFunctions)
if (validationResult) {
return validationResult
}

const uuid = request.params.attachmentUuid;
const url = request.url.href;
const objectStore = "/ObjectStore/RetrieveBinary/d497bbe3-f88b-45f1-b3d4-9c563e4c0f5f";
const location = url.split('/FHIR')[0] + objectStore;

if (uuid === '704c3791-0873-45e9-9a04-b51996f8d93f' && request.method === 'get') {
const response = h.response().code(307)
response.headers["Location"] = location;
return response
} else {
return h.file('SandboxErrorOutcome.json').code(422);
}

}
}
]
25 changes: 25 additions & 0 deletions sandbox/src/routes/r4/retrieveBinaryHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = [
/**
* Sandbox implementation for retrieveBinary (R4) endpoint helper,
* with an ObjectStore 'mock', allowing redirection and example file retrieval.
*/
{
method: 'GET',
path: '/ObjectStore/RetrieveBinary/{fileDownloadUuid}',
handler: (request, h) => {

const uuid = request.params.fileDownloadUuid
const exampleResponsePath = 'retrieveAttachment/responses/example_attachment.pdf'
const filename = 'example_attachment.pdf'
const responseCode = 200

if (uuid === 'd497bbe3-f88b-45f1-b3d4-9c563e4c0f5f') {
return h.file(exampleResponsePath, {
mode: 'attachment',
filename: filename,
etagMethod: false
}).code(responseCode);
}
}
}
]
29 changes: 29 additions & 0 deletions sandbox/src/routes/r4/searchServiceRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mockResponseProvider = require('./services/mockResponseProvider')
const businessFunctionValidator = require('../../services/businessFunctionValidator')

function searchServiceRequest(request, h) {
const allowedBusinessFunctions = ["REFERRING_CLINICIAN", "REFERRING_CLINICIAN_ADMIN", "SERVICE_PROVIDER_CLINICIAN", "SERVICE_PROVIDER_CLINICIAN_ADMIN"]

const validationResult = businessFunctionValidator.validateBusinessFunction(request, h, allowedBusinessFunctions)
if (validationResult) {
return validationResult
}

if(request.method == 'get') {
var responsePath = mockResponseProvider.getExampleResponseForSearchServiceRequest(request)
if (responsePath) {
return h.file(responsePath, { etagMethod: false }).code(200).type('application/fhir+json')
}
}

return h.file('SandboxErrorOutcome.json').code(422)
}


module.exports = [
{
method: 'GET',
path: '/FHIR/R4/ServiceRequest',
handler: searchServiceRequest
}
]
30 changes: 30 additions & 0 deletions sandbox/src/routes/r4/services/mockResponseProvider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const mockResponseUtils = require('../../mockResponseUtils')

module.exports = {

getExampleResponseForRetrieveBusinessFunctions: function () {
Expand Down Expand Up @@ -40,5 +42,33 @@ module.exports = {
}

return null
},

getExampleResponseForSearchServiceRequest: function (request) {
let ubrn;
const identifier = request.query.identifier;

if (identifier.includes('|')) {
ubrn = identifier.split('|')[1]
}
else {
ubrn = identifier
}

if (ubrn === '000000070000') {
return 'r4/searchServiceRequest/responses/ResponseExample.json'
}

return {}
},

getExampleResponseForRequestUploadUri: function (request) {
const id = request.params.id
if (id === 'r.f6dc823a-e673-4f74-9edc-a49525edd2a5') {
var responseMap = {
'src/mocks/r4/requestUploadUri/requests/RequestExample.json': 'r4/requestUploadUri/responses/ResponseExample.json'
}
return mockResponseUtils.mapExampleResponse(request, responseMap)
}
}
}
Loading