This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Batch bundle support (#602)
- Loading branch information
1 parent
46a2ac0
commit be2b645
Showing
5 changed files
with
301 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { getFhirClient } from './utils'; | ||
|
||
jest.setTimeout(60 * 1000); | ||
|
||
const generateGetRequests = (id: string, amount: number) => { | ||
const requests = []; | ||
for (let i = 0; i < amount; i += 1) { | ||
requests.push({ | ||
request: { | ||
method: 'GET', | ||
url: `/Patient/${id}`, | ||
}, | ||
}); | ||
} | ||
return requests; | ||
}; | ||
|
||
const generateGetResponses = (id: string, amount: number) => { | ||
const responses = []; | ||
for (let i = 0; i < amount; i += 1) { | ||
responses.push({ | ||
response: { | ||
status: '200 OK', | ||
location: `Patient/${id}`, | ||
etag: '1', | ||
}, | ||
}); | ||
} | ||
return responses; | ||
}; | ||
|
||
describe('Batch bundles', () => { | ||
let client: AxiosInstance; | ||
beforeAll(async () => { | ||
client = await getFhirClient(); | ||
}); | ||
|
||
// expect get and delete to fail in this batch, but batch should succeed | ||
const firstBatch = { | ||
resourceType: 'Bundle', | ||
type: 'batch', | ||
entry: [ | ||
{ | ||
request: { | ||
method: 'GET', | ||
url: '/Patient/someRandomResource', | ||
}, | ||
}, | ||
{ | ||
request: { | ||
method: 'DELETE', | ||
url: '/Patient/someResource', | ||
}, | ||
}, | ||
{ | ||
resource: { | ||
id: 'createdResource', | ||
resourceType: 'Patient', | ||
text: { | ||
status: 'generated', | ||
div: '<div xmlns="http://www.w3.org/1999/xhtml">Some narrative</div>', | ||
}, | ||
active: true, | ||
name: [ | ||
{ | ||
use: 'official', | ||
family: 'Chalmers', | ||
given: ['Peter', 'James'], | ||
}, | ||
], | ||
gender: 'male', | ||
birthDate: '1974-12-25', | ||
}, | ||
request: { | ||
method: 'POST', | ||
url: '/Patient/', | ||
}, | ||
}, | ||
{ | ||
resource: { | ||
id: 'resourceToDelete', | ||
resourceType: 'Patient', | ||
text: { | ||
status: 'generated', | ||
div: '<div xmlns="http://www.w3.org/1999/xhtml">Some narrative</div>', | ||
}, | ||
active: true, | ||
name: [ | ||
{ | ||
use: 'official', | ||
family: 'Chalmers', | ||
given: ['Peter', 'James'], | ||
}, | ||
], | ||
gender: 'male', | ||
birthDate: '1974-12-25', | ||
}, | ||
request: { | ||
method: 'POST', | ||
url: '/Patient/', | ||
}, | ||
}, | ||
{ | ||
resource: { | ||
id: 'resourceToGet', | ||
resourceType: 'Patient', | ||
text: { | ||
status: 'generated', | ||
div: '<div xmlns="http://www.w3.org/1999/xhtml">Some narrative</div>', | ||
}, | ||
active: true, | ||
name: [ | ||
{ | ||
use: 'official', | ||
family: 'Chalmers', | ||
given: ['Peter', 'James'], | ||
}, | ||
], | ||
gender: 'male', | ||
birthDate: '1974-12-25', | ||
}, | ||
request: { | ||
method: 'POST', | ||
url: '/Patient/', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
test('post multiple batches with failures', async () => { | ||
const response = await client.post('/', firstBatch); | ||
expect(response.data).toMatchObject({ | ||
resourceType: 'Bundle', | ||
type: 'batch-response', | ||
entry: [ | ||
{ | ||
response: { | ||
status: '404 Not Found', | ||
location: 'Patient/someRandomResource', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '404 Not Found', | ||
location: 'Patient/someResource', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '201 Created', | ||
etag: '1', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '201 Created', | ||
etag: '1', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '201 Created', | ||
etag: '1', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
const createdResourceId = response.data.entry[2].response.location; | ||
const deleteResourceId = response.data.entry[3].response.location; | ||
const getResourceId = response.data.entry[4].response.location; | ||
|
||
const secondBatch = { | ||
resourceType: 'Bundle', | ||
type: 'batch', | ||
entry: [ | ||
{ | ||
request: { | ||
method: 'GET', | ||
url: `/${getResourceId}`, | ||
}, | ||
}, | ||
{ | ||
request: { | ||
method: 'DELETE', | ||
url: `/${deleteResourceId}`, | ||
}, | ||
}, | ||
{ | ||
resource: { | ||
id: `${createdResourceId.replace('Patient/', '')}`, | ||
resourceType: 'Patient', | ||
text: { | ||
status: 'generated', | ||
div: '<div xmlns="http://www.w3.org/1999/xhtml">Some narrative</div>', | ||
}, | ||
active: true, | ||
name: [ | ||
{ | ||
use: 'official', | ||
family: 'Chalmers', | ||
given: ['Peter', 'James'], | ||
}, | ||
], | ||
gender: 'female', | ||
birthDate: '1974-12-25', | ||
}, | ||
request: { | ||
method: 'PUT', | ||
url: `/${createdResourceId}`, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const secondResponse = await client.post('/', secondBatch); | ||
expect(secondResponse.data).toMatchObject({ | ||
resourceType: 'Bundle', | ||
type: 'batch-response', | ||
entry: [ | ||
{ | ||
response: { | ||
status: '200 OK', | ||
location: `${getResourceId}`, | ||
etag: '1', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '200 OK', | ||
location: `${deleteResourceId}`, | ||
etag: '1', | ||
}, | ||
}, | ||
{ | ||
response: { | ||
status: '200 OK', | ||
location: `${createdResourceId}`, | ||
etag: '2', | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('bulk test', async () => { | ||
const postRequest = { | ||
resourceType: 'Patient', | ||
active: true, | ||
name: [ | ||
{ | ||
family: 'Emily', | ||
given: ['Tester'], | ||
}, | ||
], | ||
gender: 'female', | ||
birthDate: '1995-09-24', | ||
id: 'test', | ||
}; | ||
|
||
const response = await client.post('/Patient', postRequest); | ||
expect(response.status).toEqual(201); | ||
const { id } = response.data; | ||
const requests = generateGetRequests(id, 101); | ||
const batchResponse = await client.post('/', { | ||
resourceType: 'Bundle', | ||
type: 'batch', | ||
entry: requests, | ||
}); | ||
expect(batchResponse.status).toEqual(200); | ||
expect(batchResponse.data).toMatchObject({ | ||
resourceType: 'Bundle', | ||
type: 'batch-response', | ||
entry: generateGetResponses(id, 101), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6280,27 +6280,35 @@ fhir-works-on-aws-interface@^10.0.0: | |
winston "^3.3.3" | ||
winston-transport "^4.4.0" | ||
|
||
[email protected]: | ||
version "3.10.1" | ||
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-persistence-ddb/-/fhir-works-on-aws-persistence-ddb-3.10.1.tgz#1bcfa13a8ba791e6904b1c8a0a57169254e3b3a9" | ||
integrity sha512-ry0qivUYVXM+0e3xMsRN193+eFkw0fnir1qNhXKwwiOs953pDIzlG6MB7Er5OiHnvOL8KaqM/QRSgUdujsc9dw== | ||
fhir-works-on-aws-interface@^12.1.0: | ||
version "12.1.0" | ||
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-interface/-/fhir-works-on-aws-interface-12.1.0.tgz#74ff054cdf22eae0122c9ec32562475bcdd2cccf" | ||
integrity sha512-LYbmbNz+CzPvH0QH+Sn8zEFzdfSUDd17hC5xjbMrxHOzQSuNEpIELbQ/rdtiNXc+V3xFsQubYsXoHl69wHZN3w== | ||
dependencies: | ||
winston "^3.3.3" | ||
winston-transport "^4.4.0" | ||
|
||
[email protected]: | ||
version "3.11.0" | ||
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-persistence-ddb/-/fhir-works-on-aws-persistence-ddb-3.11.0.tgz#517d3039cc0f09ade43d5768cf28e3a731067067" | ||
integrity sha512-UIEyBuCxR1XfuMrNyzVbq/LGJg2uDJrNFa3R4USt0lMomP4ZlTDIu7s4n3/vvcEHgewFPmyzNqvfgzRdH7UJpg== | ||
dependencies: | ||
"@elastic/elasticsearch" "7.13.0" | ||
"@types/aws-lambda" "^8.10.83" | ||
aws-elasticsearch-connector "^8.2.0" | ||
aws-sdk "^2.1000.0" | ||
aws-xray-sdk "^3.3.3" | ||
fhir-works-on-aws-interface "^12.0.0" | ||
fhir-works-on-aws-interface "^12.1.0" | ||
flat "^5.0.2" | ||
lodash "^4.17.20" | ||
mime-types "^2.1.26" | ||
promise.allsettled "^1.0.2" | ||
uuid "^3.4.0" | ||
|
||
fhir-works-on-aws-routing@6.4.1: | ||
version "6.4.1" | ||
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-routing/-/fhir-works-on-aws-routing-6.4.1.tgz#f2fcdc031015b2fc67f6284995b34c72fc3f030e" | ||
integrity sha512-j4CxZQ7tB11QXqSVClGv2qsAORYlQmNl5OIC1G3m2zUR/XQ877tOBaxvXuJoQowQm86dCMTp2GAZprBU/NBirw== | ||
fhir-works-on-aws-routing@6.5.0: | ||
version "6.5.0" | ||
resolved "https://registry.yarnpkg.com/fhir-works-on-aws-routing/-/fhir-works-on-aws-routing-6.5.0.tgz#98ed2e765b729337d3f932853140e97c7933313b" | ||
integrity sha512-PBe09TZ+SsZ78GxgZDlZb7jXF0y2oAtZDveGvdfg/MRlATlYZLo2OBO+nBSIj4Ag6S92H3LGPV3mq+XFQjvhMQ== | ||
dependencies: | ||
"@types/cors" "^2.8.7" | ||
"@types/express-serve-static-core" "^4.17.2" | ||
|
@@ -6311,7 +6319,7 @@ [email protected]: | |
cors "^2.8.5" | ||
errorhandler "^1.5.1" | ||
express "^4.17.1" | ||
fhir-works-on-aws-interface "^12.0.0" | ||
fhir-works-on-aws-interface "^12.1.0" | ||
flat "^5.0.0" | ||
http-errors "^1.8.0" | ||
lodash "^4.17.15" | ||
|