0

I've playing around with FHIR recently, but I can't find a way of cleanly getting the ID of a newly created resource other than extracting it from the header:

Location: http://fhirtest.uhn.ca/baseDstu2/Practitioner/24796/_history/1 
Content-Location: http://fhirtest.uhn.ca/baseDstu2/Practitioner/24796/_history/1 

This is my JS code:

var location_header_split = location_header.split("/")
var id = location_header_split[location_header_split.length-3]

There is a chance that a server might not store history which will cause the above to fail. There is also a chance that the first part of the URL (before the ID) will vary, so using hardcoded value like: location_header_split[5] isn't a good idea. I can add more if statements, but is there a "cleaner" way of getting the ID?

Dawid O
  • 6,091
  • 7
  • 28
  • 36

1 Answers1

2

Yes, in DSTU-1 (the current version of the spec at hl7.org/fhir), this is the only way to get the id of the newly generated resource.

Also, the id is actually the base + the resource type + the logical id. If you isolate the logical id, like you do, this may not be unique at all across resource types, so you should at least use the resource type for the id internally.

If a server does not support history, this only means you cannot successfully GET older versions, but the server will still return you this Location link - effectively giving you access to the "latest" version.

Ewout Kramer
  • 984
  • 6
  • 9