Pre-requisites:

HL7 has a list of publicly available servers. We’ll be using HAPI FHIR reference server with R4 endpoint at http://hapi.fhir.org/baseR4. We’ll also be using Insomnia to make requests. You can also use Postman.

  1. Download and install Insomnia.
  2. Copy the base url: http://hapi.fhir.org/baseR4
  3. Open Insomnia, make a new request and paste the base url. Perform a sample GET request to /metadata and you should get the CapabilityStatement Resource. After this we’re good to go.

REST Operations:

1. How to Create a Patient Resource

Let’s take this example resource,

{
    "resourceType":"Patient",
    "name":[
        {
            "use":"official",
            "given":["Sidharth"],
            "family":"Ramesh"
        }
    ],
    "gender":"Male",
    "birthdate":"1997-09-08",
}

As you can see this resource does not have an ID here, But the ID will be generated by the server.

  1. Create a POST request at the /Patient endpoint, so the URL will be: http://hapi.fhir.org/baseR4/Patient.
  2. Paste the Patient Resource as JSON
  3. Click on “Send”

The server would respond saying “201 created” and we’ll get an ID for the Patient as well.

2. How to Create an Observation

{
    "resourceType":"Observation",
    "status":"final",
    "code":{
        "coding":[
        {
            "system":"",
            "code":,
            "display":"Glucose in blood"
        }
    ]
   },
    "subject":{
        "reference": "Patient/001",
        "display":"Sidharth Ramesh"
    },
    "valueQuantity":{
        "value":6.3
    },
    

}

  1. Create a POST request at the /Observation endpoint, so the URL will be: http://hapi.fhir.org/baseR4/Observation.
  2. Copy and paste the above sample Observation JSON.
  3. Make sure you put the ID generated by the server for the patient in the subject.reference field which is currently Patient/001
...
"subject":{
    "reference": "Patient/<id>",
}
...
  1. Click on “Send”

3. How to edit a Particular Resource

Let’s say that you want to edit the value and change it to 4.3.

...
"valueQuantity":{
    "value": 6.3
},
...

We can also change the status in the resource element to “Corrected” since we are editing it.

{
    "resourceType":"Observation",
    "status":"Corrected",
    "code":{
        "coding":[
        {
            "system":"",
            "code":,
            "display":"Glucose in blood"
        }
    ]
   },
    "subject":{
        "reference": "Patient/f001",
        "display":"Sidharth Ramesh"
    },
    "valueQuantity":{
        "value":"4.3"
    },
}

When you want to update a resource, you need to specify the id in the resource element.

{
    "resourceType":"Observation",
    "status":"corrected",
    "id": "<id>",
    "code":{
        "coding":[
        {
            "system":"",
            "code":,
            "display":"Glucose in blood"
        }
    ]
   },
    "subject":{
        "reference": "Patient/f001",
        "display":"Sidharth Ramesh"
    },
    "valueQuantity":{
        "value":6.3
    },
}

  1. The URL also must contain the ID: So the URL becomes: http://hapi.fhir.org/baseR4/Observation/<id>.
  2. Change the method to PUT.
  3. Click on “Send”

The Resource will now be updated.

The GET method also supports search, which is used to search on a fhir server which will be covered in the next blog post.

A video version of this tutorial is available here: