Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Feb 26, 2023

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?

Product version: IRIS 2022.3

Comments

Tani Frankel  Feb 26, 2023 to Lorenzo Scalese

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.

0
Evgeny Shvarov  Feb 27, 2023 to Evgeny Shvarov

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:

0
Muhammad Waseem · Feb 26, 2023

I think you have to include patient identifier(id) in patient resource

0
Muhammad Waseem  Feb 27, 2023 to Evgeny Shvarov

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

0
Juanito Doolub  Feb 26, 2023 to Muhammad Waseem

If the patient id is included, the operation would probably need to be a PUT instead of POST.

0
Guillaume Rongier · Mar 29, 2023

Another good way is to set the header :

Prefer: return=representation

The 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"
  }
}
0