This is a really old post, but I think it is something that developers might be struggling with if they need to create a repository based on another FHIR source. Making a new ID every time doesn't work in this kind of use case.
I use the PUT method instead of POST. I use it by default because it maintains the ID from the source system, and will update a record if the ID exists. I set the ID into the url: /csp/healthshare/fhirserver/fhir/r4/Patient/ID because it doesn't seem to work without it.
Here's an example. The error handling still needs work, but you get the idea:
ClassMethod savePatientObj(patient As %DynamicObject) As %String { // Get the record ID s ID=patient.id s url="/csp/healthshare/fhirserver/fhir/r4" s path="/Patient/"_ID try { s clientObj=##class(HS.FHIRServer.RestClient.FHIRService).CreateInstance(url) d clientObj.SetResponseFormat("JSON"),clientObj.SetRequestFormat("JSON") s clientRequestObj=clientObj.MakeRequest("PUT",patient,path,"") s clientResponseObj=clientObj.InvokeRequest(clientRequestObj) s response=clientResponseObj.Json } catch err { w !, "Error name: ", ?20, err.Name, !, "Error code: ", ?20, err.Code, !, "Error location: ", ?20, err.Location, !, "Additional data: ", ?20, err.Data,! zw err } Return response }
Please hit me back if you want to work on this more.
This is a really old post, but I think it is something that developers might be struggling with if they need to create a repository based on another FHIR source. Making a new ID every time doesn't work in this kind of use case.
I use the PUT method instead of POST. I use it by default because it maintains the ID from the source system, and will update a record if the ID exists. I set the ID into the url: /csp/healthshare/fhirserver/fhir/r4/Patient/ID because it doesn't seem to work without it.
Here's an example. The error handling still needs work, but you get the idea:
ClassMethod savePatientObj(patient As %DynamicObject) As %String { s path="/Patient/"_ID
// Get the record ID
s ID=patient.id s url="/csp/healthshare/fhirserver/fhir/r4"
try { s clientObj=##class(HS.FHIRServer.RestClient.FHIRService).CreateInstance(url)
d clientObj.SetResponseFormat("JSON"),clientObj.SetRequestFormat("JSON")
s clientRequestObj=clientObj.MakeRequest("PUT",patient,path,"")
s clientResponseObj=clientObj.InvokeRequest(clientRequestObj)
s response=clientResponseObj.Json }
catch err {
w !, "Error name: ", ?20, err.Name, !,
"Error code: ", ?20, err.Code, !,
"Error location: ", ?20, err.Location, !,
"Additional data: ", ?20, err.Data,!
zw err }
Return response
}
Please hit me back if you want to work on this more.