Can not delete a person using API

I am trying to delete a person using API. This is a DELETE request.

openmrs-standalone/ws/rest/v1/person/dd709629-1691-11df-97a5-7038c432aabf?purge=true

I have double-checked and that ID really exists. The request is getting failed and this is the reason I’m getting from the logs:

Cannot delete or update a parent row: a foreign key constraint fails (openmrs.encounter, CONSTRAINT encounter_patient FOREIGN KEY (patient_id) REFERENCES patient (patient_id) ON UPDATE CASCADE)

Here’s the full log. delete_error - Pastebin.com

How can I fix it?

I also have the same issue with deleting patients. Anyone have any ideas?

You have to delete all the data pointing to the patient record, e.g., encounters, obs, visits, etc. before you can delete the patient. The purge operations are designed to cascade to most properties of the patient (names, attributes, etc.), but they don’t cascade across other references.

1 Like