Deletes and referential integrity
The FHIR delete operation performs a "logical" delete. This means that data is not physically removed from the database.
For example, suppose the HDR-FHIR server containing a patient resource with the ID Patient/1. And HDR-FHIR server also contains Encounter/1 and Encounter/2, as well as Observation/3 and MedicationAdministration/4, and all these resources have a reference to the resource Patient/1. We will call these resources are child resources.
If you try to DELETE Patient/1 (using a standard FHIR DELETE operation), the request is denied, assuming that there is a resource link between the child resources and the patient.
This results in an HTTP 409 Conflict with a response similar to the following:
Example: DELETE 410 Gone response with an HTTP 409 Conflict
![Example: DELETE 410 Gone response with an HTTP 409 Conflict Example: DELETE 410 Gone response with an HTTP 409 Conflict](img/delete_410_http409conflict_example.png)
If you want to force a delete of Patient/1, you have several options:
- You can manually delete all the child resources before trying to delete the Patient.
- You can disable referential integrity checking in the HDR-FHIR server by changing enforce referential integrity check in delete setting on the FHIR Server. This means that any delete on resource is allowed, even if other resources still have references left.
- You can use a transactional delete.
- You can use cascading deletes.
Parent topic: Deleting data