0

I am trying to update Encounter resource on the basis of patient id but it is only creating one new record of Encounter rather than updating the existing one. But if i try to update Encounter on the basis of identifier i.e. unique value representing Encounter resource then it is able to update it.

Why is that? Can anyone explain?

2 Answers2

1

One patient will potentially have many (even hundreds) of encounters. Updates are always driven by the record of the resource itself - every resource (Patient, Encounter, Observation, CarePlan, etc.) has an 'id' element that represents the identifier of that resource on that particular server - sort of like a primary key. Updates are performed by making a RESTful PUT of the new record to a URL that includes that same identifier.

I.e. an update of an Encounter MUST always be performed with a URL of the form:

PUT [somebaseurl]/Encounter/[serverEncounterId]

The patient associated with the encounter will be referenced from within the Encounter object in the body of the RESTful call, but does not appear in the URL.

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
  • but at the time of update i only know the patient id not that unique identifier then how will it solve my problem? Right now i only have one encounter resource associated with that patient. So it should clearly identify the that resource and update it but it is simply creating a new record. – Bindu Sharma Jun 03 '20 at 06:45
  • You have to query before you can perform an update. Otherwise, you can't know what data you're going to be overwriting. – Lloyd McKenzie Jun 03 '20 at 16:03
  • This question triggers something...that I've been "preachin" in all these dev days and forums. The patient-search (or maybe more preferably, patient-match) is probably the key prerequisite for all this stuff. https://www.hl7.org/fhir/patient-operation-match.html Note, there is a patient-match OPERATION which is slightly different from patient-search. But yeah, besides my soapbox...Lloyd is correct. You have to do some "searching" for the encounter if you don't have access to teh enncounter(id, aka surrogate key). – granadaCoder Jun 04 '20 at 13:22
0

As you have discovered, some FHIR servers will allow a 'conditional update':

PUT [somebaseurl]/Encounter?search_key=search_value&...

You will need to add search parameters that filter all Encounters and result in a unique one, which will then be updated. Since, as Lloyd also indicated, a Patient can have multiple associated Encounters, the Patient id is not a suitable parameter for the conditional update. Your Encounter's identifier was unique enough, so that update succeeded.

Mirjam Baltus
  • 2,035
  • 9
  • 13