How can I know the patient id for a newly submitted Patient resource?
Hi folks!
Playing with InterSystems FHIR server.
You can easily install it in IRIS for Health using FHIR template:
zpm "install fhir-server"
NB! For now the IPM command mentioned above works for a namespace called FHIRSERVER only.
I have a FHIR server in a local docker container with endpoint:
localhost:52773/fhir/r4
I send the following Patient resource as a POST request to localhost:52773/fhir/r4/Patient:
Spoiler
{
"resourceType": "Patient",
"name": [
{
"use": "official",
"given": [
"Elon"
],
"family": "Musk"
}
],
"gender": "male",
"birthDate": "1975-01-01",
"telecom": [
{
"use": "mobile",
"system": "phone",
"value": "111222333"
},
{
"system": "email",
"value": "elon.musk@gmail.com"
}
],
"address": [
{
"line": [
"123, Green Street"
],
"city": "New Cape",
"state": "Mars",
"postalCode": "12345"
}
]
}
And I'm getting 201 and no result.
How could I know what is the id of the patient I've just created?
Comments
I think the created resource id is in the header response. I don't remember the header name 🤔
Indeed it is in the Location Header.
From the related FHIR docs:
The server returns a 201 Created HTTP status code, and SHALL also return a Location header which contains the new Logical Id and Version Id of the created resource version:
Location: [base]/[type]/[id]/_history/[vid]
where [id] and [vid] are the newly created id and version id for the resource version. The Location header should be as specific as possible - if the server understands versioning, the version is included. If a server does not track versions, the Location header will just contain [base]/[type]/[id]. The Location MAY be an absolute or relative URL.
Exactly @Tani Frankel !
Thank you for this refresh
Thanks @Tani Frankel !
Hi @Lorenzo Scalese ! Yes! It is in Location header, as @Tani Frankel mentioned.
This is what I received in headers:
http://localhost:52773/fhir/r4/Patient//1983/_history/1
So, the id is 1983.
It is a bit different from what the public FHIR server on hl7.org/fhir returns - it returns the id also in a response.
Not sure though what is the "standard" behavior but if find it convenient enough to have the id in the response.
BTW, I can recommend an HTTP REST sending tool I'm using now - Insomnia. What I like - minimalistic interface and the history of all the HTTP calls:
I think you have to include patient identifier(id) in patient resource
Thanks, @Muhammad Waseem!
the id is being generated for a new patent
As @Tani Frankel mentioned, The newly created resource id should be part of response location key value as below:
HTTP:/1.1 201 Created
Location : localhost:52773/fhir/Patient/122
If the patient id is included, the operation would probably need to be a PUT instead of POST.
Right @Juanito Doolub, Thanks
Another good way is to set the header :
Prefer: return=representationThe payload will be sent you back with the id.
Example :
POST http://localhost:33783/fhir/r4/Patient HTTP/1.1
Content-Type: application/json+fhir
Accept: application/json+fhir
Prefer: return=representation
{
"resourceType": "Patient",
"active": true,
"name": [
{
"use": "official",
"family": "Donald",
"given": [
"Duck"
]
}
]
}Response :
HTTP/1.1201 Created
Date: Wed, 29 Mar 202312:13:40 GMT
Server: Apache
CACHE-CONTROL: no-cache
ETAG: W/"1"
EXPIRES: Thu, 29 Oct 199817:04:19 GMT
LAST-MODIFIED: Wed, 29 Mar 202312:13:40 GMT
LOCATION: http://localhost:33783/fhir/r4/Patient/2011/_history/1
PRAGMA: no-cache
CONTENT-LENGTH: 177
Connection: close
Content-Type: application/fhir+json; charset=UTF-8
{
"resourceType": "Patient",
"active": true,
"name": [
{
"use": "official",
"family": "Donald",
"given": [
"Duck"
]
}
],
"id": "2011",
"meta": {
"lastUpdated": "2023-03-29T12:13:40Z",
"versionId": "1"
}
}Thanks @Guillaume Rongier !
Finally, there is a trick!
Thank you @Guillaume Rongier !
I share this with our dev interoperability team.
