0

Most FHIR servers won't completely remove a FHIR resource from the database when you do a DELETE.

What I'm wondering is this: if I retreive the latest version of a deleted resource using it _history for example: GET Patient/1/_history/2 and want to "restore" it. What's the best way to do that?

Is my only option to create a copy of the deleted patient by removing the ID and doing POST to /Patient or... is there some way to restore the deleted patient and keep its original ID?

Henrik Joreteg
  • 1,698
  • 16
  • 18

1 Answers1

1

This may depend on the FHIR server you're using

With the HAPI FHIR server a deleted resource is still considered to be an existing record, so simply calling PUT on that resource will "un-delete" it and create a new version, adding it to the resource's history.

Other FHIR servers might take a different interpretation.

With the Google Cloud Healthcare API, this would require enabling the "update as create" feature, or upsert operation https://hl7.org/fhir/http.html#upsert. This feature allows you to create a resource with an ID you specify by using PUT instead of POST. The Cloud Healthcare API does not differentiate between deleted and missing records for updates, so "enableUpdateCreate" is required to "re-create" (vs "un-delete") the resource. However, even though it is "re-created", it will still become part of the resource's history.

Nik Klassen
  • 681
  • 8
  • 16
  • Actually, it's not an "update as create" - it's a simple 'update'. You're changing the content at a location that already has a record. (A 'deleted' record is still considered to be a record.) – Lloyd McKenzie Mar 31 '23 at 16:43
  • I've been informed that there was some discussion about this recently, and it appears that our interpretation of the spec up until this point differs from that interpretation. I edited my answer, but kept our implementation in there for completeness, rightly or wrongly. – Nik Klassen Mar 31 '23 at 18:29
  • @NikKlassen I am actually specifically trying to do this on Google Cloud's FHIR APIs. But simply doing a PUT didn't seem to work. How would I enable that? – Henrik Joreteg Apr 01 '23 at 16:22
  • You need to set the [enabledUpdateCreate](https://cloud.google.com/healthcare-api/docs/reference/rest/v1/projects.locations.datasets.fhirStores#:~:text=fhirStores/%7BfhirStoreId%7D.-,enableUpdateCreate,-boolean) config value on your FHIR store. Here are the docs for [editing](https://cloud.google.com/healthcare-api/docs/how-tos/fhir#editing_a_fhir_store) your FHIR store. – Nik Klassen Apr 03 '23 at 17:13