This page explains how to bulk-delete FHIR resources from a FHIR store using a long-running operation.
You can delete multiple FHIR resources in a single operation based on filters like resource type and last updated time. This is useful for data lifecycle management and cost savings.
Before you begin
Before you can bulk-delete FHIR resources, ensure the following:
- You must have the
healthcare.fhirStores.bulkDeletepermission on the FHIR store. - If you specify a
gcsDestination, the Cloud Healthcare Service Agent service account must have theroles/storage.objectAdminrole on the destination bucket. For more information, see FHIR store Cloud Storage permissions.
Bulk-deleting FHIR resources
To bulk-delete FHIR resources, use the projects.locations.datasets.fhirStores.bulkDelete method.
This method returns a long-running operation (LRO). You can track the status of the LRO using the operation name returned by the API call.
The following sample shows how to make a POST request to bulk-delete all Observation and Encounter resources in a FHIR store that were last updated before a specific timestamp.
REST
Before using any of the request data, make the following replacements:
PROJECT_ID: the ID of your Google Cloud projectLOCATION: the dataset locationDATASET_ID: the FHIR store's parent datasetFHIR_STORE_ID: the FHIR store ID
Request JSON body:
{
"type": "Observation,Encounter",
"versionConfig": "ALL",
"until": "2025-01-01T00:00:00Z",
"gcsDestination": {
"uriPrefix": "gs://BUCKET/DIRECTORY"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"type": "Observation,Encounter",
"versionConfig": "ALL",
"until": "2025-01-01T00:00:00Z",
"gcsDestination": {
"uriPrefix": "gs://BUCKET/DIRECTORY"
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID:bulkDelete"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"type": "Observation,Encounter",
"versionConfig": "ALL",
"until": "2025-01-01T00:00:00Z",
"gcsDestination": {
"uriPrefix": "gs://BUCKET/DIRECTORY"
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID:bulkDelete" | Select-Object -Expand Content
Viewing the LRO status
To view the status of the bulk-delete operation, use the operations.get method with the operation name returned from the bulkDelete call.
REST
Before using any of the request data, make the following replacements:
PROJECT_ID: the ID of your Google Cloud projectLOCATION: the dataset locationDATASET_ID: the FHIR store's parent datasetOPERATION_ID: the ID returned from the long-running operation
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID" | Select-Object -Expand Content
Tracking deleted resources
When the bulk-delete operation completes, if a gcsDestination was specified, a summary file is generated in Cloud Storage. This file contains a list of the resource IDs for the current version resources that were deleted during the operation.
Limitations
Referential integrity is not guaranteed during a bulk-delete operation. It is recommended to use this operation only when referential integrity is not required or is known to be satisfied after the operation.