Deleting a FHIR resource
The FHIR delete
interaction removes an existing FHIR resource from a HealthLake
data store. For additional information, see delete
To delete a FHIR resource
-
Collect HealthLake
region
anddatastoreId
values. For more information, see Getting data store properties. -
Determine the type of FHIR
Resource
to delete and collect the associatedid
value. For more information, see Resource types. -
Construct a URL for the request using the collected values for HealthLake
region
anddatastoreId
. Also include the FHIRResource
type and its associatedid
. To view the entire URL path in the following example, scroll over the Copy button.DELETE https://healthlake.
region
.amazonaws.com/datastore/datastoreId
/r4/Resource
/id
-
Send the request. The FHIR
delete
interaction uses aDELETE
request with either AWS Signature Version 4 or SMART on FHIR authorization. The followingcurl
example removes an existing FHIRPatient
resource from a HealthLake data store. To view the entire example, scroll over the Copy button.
Deleting FHIR resources based on conditions
Conditional delete is particularly useful when you don't know the specific FHIR resource ID but have other identifying information about the resource you want to delete.
Conditional delete allows you to delete an existing resource based on search criteria rather than by logical FHIR ID. When the server processes the delete request, it performs a search using standard search capabilities for the resource type to resolve a single logical ID for the request.
How conditional delete works
The server's action depends on how many matches it finds:
-
No matches: The server attempts an ordinary delete and responds appropriately (404 Not Found for non-existent resource, 204 No Content for already deleted resource)
-
One match: The server performs an ordinary delete on the matching resource
-
Multiple matches: Returns a 412 Precondition Failed error indicating the client's criteria were not selective enough
Response scenarios
AWS HealthLake handles conditional delete operations with the following response patterns:
Successful Operations
-
When your search criteria successfully identify a single active resource, the system returns 204 No Content after completing the deletion, just like standard delete operations.
ID-Based Conditional Delete
When performing conditional delete based on id
with additional parameters (createdAt
, tag
, or _lastUpdated
):
-
204 No Content: Resource was already deleted
-
404 Not Found: Resource doesn't exist
-
409 Conflict: ID matches but other parameters don't match
Non-ID-Based Conditional Delete
When id
is not provided or when using parameters other than createdAt
, tag
, or _lastUpdated
:
-
404 Not Found: No matches found
Conflict Situations
Several scenarios result in 412 Precondition Failed responses:
-
Multiple resources match your search criteria (criteria not specific enough)
-
Version conflicts when using ETag headers with
If-Match
-
Resource updates occurring between search and delete operations
Example of a Successful Conditional Delete
The following example deletes a Patient resource based on specific criteria:
DELETE https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Patient?name=peter&birthdate=2000-01-01&phone=1234567890
This request deletes a Patient resource where:
Name is "peter"
Birth date is January 1, 2000
Phone number is 1234567890
Best Practices
-
Use specific search criteria to avoid multiple matches and prevent 412 errors.
-
Consider ETag headers for version control when needed to handle concurrent modifications.
-
Handle error responses appropriately:
For 404: Refine your search criteria
For 412: Make criteria more specific or resolve version conflicts
-
Prepare for timing conflicts in high-concurrency environments where resources may be modified between search and delete operations.