Update resource only if it exists, or create if not exists

839 views
Skip to first unread message

Łukasz Dywicki

unread,
Mar 14, 2018, 8:37:26 PM3/14/18
to HAPI FHIR
I do have a use case which I can not yet fully test, as it's in the works.

Making long story short - I do receive data from external system and I need to import it into FHIR server. Every record I get have external identifier which is appended to resource.

I would like to use transaction endpoint to update resource if it exists or create if not exisats. I know that conditional creation is fine, I tested it, but I have doubts on conditional update without version and search url (Patient?identifier=foo) instead of singular resource (Patient/x). Sample bundle could look like below - first make conditional update and then conditional create (to avoid update of already created resource).

{
  "resourceType": "Bundle",
  "entry": [{
    "fullUrl": "....",
    "resource": {},
    "request": {
      "method": "PUT",
      "url": "Patient?identifier=foo",
      //"If-Match": "??"
    }
   },{
    "fullUrl": "....",
    "resource": {},
    "request": {
      "method": "POST",
      "url": "Patient",
      "If-None-Exist": "identifier=foo"
    }
   }]
}

Main thing in whole scenario is - I do not care about data which could be overriden (because it shouldn't be updated). I just need to create a new snapshot with data I received from 3rd party, thus I don't care about previous version.

Cheers,
Lukasz

James Agnew

unread,
Mar 14, 2018, 9:14:44 PM3/14/18
to Łukasz Dywicki, HAPI FHIR
Unless im missing something, that just sounds like a standard conditional update (no transaction needed). Are there semantics in a conditional update that don't work like you expect?

sent from my phone.

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/05abda8b-8bea-4fb8-a947-aa6801d9b584%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Łukasz Dywicki

unread,
Mar 15, 2018, 9:12:24 AM3/15/18
to HAPI FHIR
Hey James,
At the time I am importing data I do not know if Patient record exists or not. That's why I can not assume that update will always work, more over I don't know precise resource id but only identifier from external system.

Best regards,
Lukasz

James Agnew

unread,
Mar 15, 2018, 11:17:56 AM3/15/18
to Łukasz Dywicki, HAPI FHIR
Hi Lukasz,

A conditional update will create the patient if they don't already exist (i.e. no resources match the search criteria), so that should work fine.

Cheers,
James

To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages