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?