Managing multiple FHIR resources using Bundle
In the HL7 FHIR R4 specification, bundles are simply a collection of resources. HealthLake supports creating a Bundle resource type in a FHIR REST API request, and using a bundle transaction to perform multiple CRUD operations in a single FHIR REST API request. In a bundle transaction, you must specify the bundle type as batch
in the FHIR REST API request.
All bundle requests are recorded by AWS CloudTrail. To learn more about using CloudTrail with HealthLake, see Logging AWS HealthLake API Calls with AWS CloudTrail.
HL7 FHIR R4 Resources (External)
-
To read the full specification, see Resource Type: Bundle
in the FHIR Documentation Index. -
To read about batch interactions using the FHIR REST API, see Batch interactions using the FHIR REST API
in the FHIR Documentation Index.
The sections below describe how to structure a FHIR REST API request in order to either create a new Bundle resource or to process resources individually using bundle transactions.
Differences between the HealthLake console, the AWS CLI, and the AWS SDKs
The HealthLake console only supports Bundle type operations where the Bundle resource type is specified in the FHIR REST API request URL.
Performing multiple CRUD operations using FHIR bundles
When no resource type is specified in your request URL, the FHIR REST API request is parsed as individual data store transactions. Each CRUD operation provided in the JSON body is evaluated and a specific HTTP status code returned. HealthLake supports the Bundle type batch
.
To perform multiple CRUD operations in a single FHIR REST API request do the following:
The following list shows truncated portions of a request body used in bundle FHIR REST API request. For a full request body, see Creating a bundle request involving multiple CRUD operations.
-
Do not specify a resource type in your
POST
request:POST https://healthlake.
your-region
.amazonaws.com/datastore/your-datastore-id
/r4/ -
In the request body specify the Bundle type as
"type": "batch"
-
In the request body specify resource-specific data for each CRUD interaction starting with the
resource
key. -
Each CRUD operation is specified as a
request
in the request body as follows:{ ... "request" : { "method" : "
HTTP-VERB
", "url" : "FHIR-RESOURCE-TYPE-URL
" } ... }
In the JSON response, you get an HTTP status code for each CRUD operation specified in the request.
HealthLake limits Bundle transactions
-
To learn more about the limits HealthLake places on Bundles, see AWS HealthLake endpoints and quotas.
The following is an example of a Bundle operation containing multiple CRUD operations.
Example – Creating a Bundle request involving multiple CRUD operations.
To make a FHIR REST API request that performs multiple CRUD operations, you must make a POST
request using your data store endpoint, and provide a JSON request body.
You can find your data store's endpoint in the HealthLake console under Data Stores or by using the DescribeFHIRDatastore operation in the AWS HealthLake API Reference.
JSON Response
To confirm the creation of the resources specified in the example bundle transaction, you get 201
Created HTTP status code for each included CRUD operation. When a CRUD operation fails you get 400 series HTTP status indicating why the individual request failed.
{ "resourceType": "Bundle", "type": "batch-response", "timestamp": "2022-06-15T01:31:34.300+00:00", "entry": [ { "response": { "status": "201", "location": "Patient/fd68ce38-ba30-4459-9eeb-476ad9f4f4ca", "lastModified": "2022-06-15T01:31:34.180+00:00" } }, { "response": { "status": "201", "location": "Medication/5bf3b8cc-4076-4219-aba1-e2c53d7916f4", "lastModified": "2022-06-15T01:31:34.180+00:00" } } ] }
Grouping resources as a Bundle resource type
To create a new Bundle resource type, you must specify Bundle
in the FHIR REST API request and provide a valid JSON body containing the resources you want grouped together.
When Bundle is specified in the request URL, the contents of the JSON request body are saved in your HealthLake data store as-is. Therefore, no CRUD operations can be performed on the individual resource types. Bundles of this type are assigned a single new resource ID. Because the resources are saved as-is, you cannot make GET
or POST
requests on individual resources saved in the Bundle resource type.
Note
The HL7 FHIR R4 specification also supports grouping resources using GroupReference
element to point to the individual resources. Using these resources types therefore allow you to modify the individual resources contained within them.
To create a Bundle
resource type, you must specify it in your POST
request and provide a JSON enumerating the resources you want to be included.
Example – Creating a Bundle resource using a POST
request
To create a bundle
resource do the following
-
Format a FHIR REST API request as follows:
POST https://healthlake.
your-region
.amazonaws.com/datastore/your-datastore-id
/r4/Bundle
-
Provide JSON body which specifies the resources you want to group together. This example groups two patient resources.
{ "resourceType": "Bundle", "id": "bundle-transaction", "meta": { "lastUpdated": "2018-03-11T11:22:16Z" }, "type": "document", "entry": [ { "resource": { "resourceType": "Patient", "name": [ { "family": "Smith", "given": [ "Jane" ] } ], "gender": "female", "address": [ { "line": [ "123 Main St." ], "city": "Anycity", "state": "Any State", "postalCode": "12345" } ] } }, { "resource": { "resourceType": "Patient", "name": [ { "family": "Jackson", "given": [ "Mateo" ] } ], "gender": "male", "address": [ { "line": [ "1234 Main St." ], "city": "Anycity", "state": "Any State", "postalCode": "12345" } ] } } ] }