Bulk Resource Modification
Smile CDR includes two operations which can be used to modify large numbers of FHIR resources in a batch operation. These operations use the FHIR Asynchronous Interaction Request Pattern.
The operations described here are powerful and potentially destructive operations that can modify large amounts of data. They are intended to be used to correct data issues, upgrade data, etc., typically as a one-time and well-planned action.
Each operation here requires a specific dedicated permission to be granted to the initiating user, and for the given operation to be specifically enabled on the FHIR Storage module. It is highly recommended that the operations be enabled and the appropriate permissions granted only temporarily when the operation is required to minimize the risk of unintended data modification.
It is also highly recommended to test the operations in a development environment before using them in production, and to take appropriate system backups.
The Bulk Patch operation takes one or more FHIR search URLs, fetches the resources matched by those URLs, and applies a change to the newest version of each returned resource. If a resource is modified by the operation, a new version of the resource will be stored.
In order to use this operation, the Bulk Modify Patch Operation setting must be enabled and the user must have appropriate permissions.
To initiate a Bulk Patch operation, send a POST request to the http://base-url/$hapi.fhir.bulk-patch
endpoint. An HTTP Prefer
request header must be included indicating asynchronous processing. The request body must contain a Parameters resource. See Request Parameters for a list of parameters to include. An example request is shown below.
Name | Type | Cardinality | Description |
---|---|---|---|
url | string | 1..* |
A FHIR search URL that identifies the resources to be patched. For example Patient?active=false or Observation? .
|
patch | Parameters resource | 1..* | A FHIRPath Path document that describes the change to be made to each resource. |
This operation also supports all Common Bulk Modification Request Parameters. |
POST /$hapi.fhir.bulk-patch
Prefer: respond-async
Content-Type: application/fhir+json
(.. Parameters Resource in Request Body ..)
An example request payload with a simple FHIRPath Patch document is shown below.
{
"resType": "Parameters",
"parameter": [ {
"name": "patch",
"resource": {
"resType": "Parameters",
"parameter": [ {
"name": "operation",
"part": [ {
"name": "type",
"valueCode": "replace"
}, {
"name": "path",
"valueString": "Patient.active"
}, {
"name": "value",
"valueCode": "true"
} ]
} ]
}
}, {
"name": "url",
"valueString": "Patient?"
} ]
}
The server will respond with an HTTP 202 Accepted response code. The response will include a Content-Location
header with a URL that can be polled to determine the status of the operation.
An example response is shown below.
202 Accepted
Content-Location: http://example.org/$hapi.fhir.bulk-patch-status?_jobId=33b280a7-1715-4d38-a7d4-6f5d1c705551
Content-Type: application/fhir+json;charset=utf-8
{
"resourceType":"OperationOutcome",
"issue":[
{
"severity":"information",
"code":"informational",
"diagnostics":"$hapi.fhir.bulk-patch job has been accepted. Poll for status at the following URL: http://localhost:8000/$hapi.fhir.bulk-patch.poll-for-status?_jobId=33b280a7-1715-4d38-a7d4-6f5d1c705551"
}
]
}
The Bulk Patch with History Rewrite operation takes one or more FHIR search URLs, fetches the resources matched by those URLs, and applies a change to all versions of each returned resource. Each version is modified by rewriting the history for the resource. This means that existing resource versions are directly modified without creating a new version. This is a potentially destructive operation and should be used with extreme caution.
In order to use this operation, both the History Rewrite and Bulk Modify Patch with History Rewrite Operation settings must be enabled and the user must have appropriate permissions.
To initiate a Bulk Patch operation, send a POST request to the http://base-url/$hapi.fhir.bulk-patch-rewrite-history
endpoint. An HTTP Prefer
request header must be included indicating asynchronous processing. The request body must contain a Parameters resource. See Request Parameters for a list of parameters to include.
Name | Type | Cardinality | Description |
---|---|---|---|
url | string | 1..* |
A FHIR search URL that identifies the resources to be patched. For example Patient?active=false or Observation? .
|
patch | Parameters resource | 1..* | A FHIRPath Path document that describes the change to be made to each resource. |
This operation also supports all Common Bulk Modification Request Parameters. |
POST /$hapi.fhir.bulk-patch-rewrite-history
Prefer: respond-async
Content-Type: application/fhir+json
(.. Parameters Resource in Request Body ..)
The following table outlines request parameters which are common for all Bulk Modification operations.
Name | Type | Cardinality | Description |
---|---|---|---|
url | string | 1..* |
A FHIR search URL that identifies the resources to be patched. For example Patient?active=false or Observation? .
|
batchSize | integer | 0..1 |
If specified, provides an instruction that the server should not process more than this many resources at a time. This instruction is provided for cases where very large resources need to be modified, and the server does not have enough available memory to hold a larger batch in RAM. The default is 500 . Values larger than the default will be ignored and replaced with the default. In other words, it is only possible to use this parameter to reduce the batch size, not to increase it.
|
dryRun | boolean | 0..1 |
If set to true (the default is false ), the operation will not actually modify any resources. Instead it will count the number of resources that would be modified, and can also collect changes. The dryRunMode parameter can be combined with this parameter to influence the behavior of the operation.
|
dryRunMode | code | 0..1 |
This parameter can be used to influence the behavior of the dryRun parameter. The possible values are:
count .
|
limitResourceCount | boolean | 0..1 |
Specifies a maximum number of distinct resources (by ID) that should be examined for modification before the operation is completed. This parameter is intended to be used in conjunction with the dryRun parameter. Note that unless the url parameter contains a _sort directive, the order of resources selected for modification is arbitrary.
|
limitResourceVersionCount | boolean | 0..1 |
This parameter applies only to Bulk Modification operations which rewrite history.
This parameter specifies a maximum number of distinct resources versions per resource that should be examined for modification before the operation is completed. This parameter is intended to be used in conjunction with the dryRun parameter.
|
When initiating a bulk resource modification operation, the server will respond with an HTTP 202 Accepted response code. The response will include a Content-Location
header with a URL that can be polled to determine the status of the operation.
While the operation is in progress, the server will respond with an HTTP 202 Accepted response code. When the operation is complete (whether it has completed successfully or has failed or been canceled), the server will respond with an HTTP 200 OK response code. The response body will contain a FHIR Bundle resource with the results of the operation.
In the case of a successful operation completion, the Bundle will contain an OperationOutcome
resource where OperationOutcome.issue.diagnostics
contains a brief report outlining the results of the job. A sample report is shown below:
Bulk Patch Report
-------------------------------------------------
Start Time : 2025-08-19 14:24:03.404
Duration : 158ms
Total Resources Changed : 2 (2/sec)
Total Resources Unchanged : 1 (1/sec)
Total Failed Changes : 0 (0/sec)
Total Retried Chunks : 0
Total Retried Resources : 0
-------------------------------------------------
ResourceType[Patient]
Changed : 2
Unchanged : 1
-------------------------------------------------
You are about to leave the Smile Digital Health documentation and navigate to the Open Source HAPI-FHIR Documentation.