Profiles & Operations > Interaction: FHIR Batch Query
Interaction: FHIR Batch Query
A FHIR batch query involves sending multiple FHIR API requests within a single HTTP request, improving efficiency and reducing network traffic. It utilizes a FHIR Bundle resource with the Bundle.type set to batch. For acCDR use cases, the viewer may use this query to retrieve multiple result sets when no single FHIR query meets the requirements.
The batch query should be following these requirements:
- Bundle Structure: The requests are encapsulated within a FHIR Bundle resource. Each individual request (e.g., a search, create, update) is an entry within the bundle.
- Independent Processing: Each entry within a batch bundle is treated as an independent operation. The success or failure of one entry does not impact the others.
- HTTP POST: Batch requests are typically submitted using an HTTP POST command to the base URL of the FHIR server.
- Request Details: Each entry in the bundle includes Bundle.entry.request details, specifying the HTTP method (e.g., GET, POST) and the URL for the individual action. If the method is POST, the entry will also contain the resource to be created or updated.
- Batch Response: The server responds with a Bundle resource containing the individual responses for each request within the original batch.
Example of batch query
One use case when batch query is necessary is when the viewer queries acCDR for encounters that exists in a time period. When the start date and end date are given, viewer needs to retrieve encounters that 1) start on or after the start date, and 2) started before the start date that are either still active, or completed before the end date. In this case, there may not be one query that can retrieve both result sets in one call. This is when the batch query can be used as follows:
Query for Encounters that exist between 2025-01-01 and 2025-10-01 in reverse chronological order by encounter start date (this should include any encounter that start after the start date, and also include encounters that started before the start date, and either ended before the end date, or with no end date (assuming it is still ongoing))
POST [base]
Body:
{
"resourceType": "Bundle",
"type": "batch",
"entry": [
{
"request": {
"method": "GET",
"url": "Encounter?date-start=ge``search_start_date``&_sort=-date"
}
},
{
"request": {
"method": "GET",
"url": "Encounter?date-start=le``search_start_date``&end-date=ge``search_start_date``&_sort=-date"
}
},
{
"request": {
"method": "GET",
"url": "Encounter?date-start=le``search_start_date``&status=in-progress&_sort=-date"
}
}
]
}