Learn

Explore development tutorials, how-tos and case studies

Categories

Key Words

Playing with FHIR – TUT004 : Deleting a Patient Resource

In this tutorial we are going to build on what we learnt in the second tutorial and look at how we delete resources in FHIR. We’ll be using the Patient resource again but the same process applies to any resource type.

Before I delete a resource I am going to create a new one (so I don’t delete anyone else’s data on the public test server).

So as before, I perform a HTTP POST sending the following payload to the FHIR patient endpoint :  http://fhir2.healthintersections.com.au/open/Patient

<Patient xmlns="http://hl7.org/fhir">
    <identifier>
        <system value="https://acme.com/patient"/>
        <value value="12341234"/>
    </identifier>
    <active value="true"/>
    <name>
        <use value="official"/>
        <family value="Tailor"/>
        <given value="Timothy"/>
    </name>
    <gender value="male"/>
    <birthDate value="1935-05-08"/>
    <managingOrganization>
        <reference value="Organization/1"/>
    </managingOrganization>
</Patient>

This gets me a HTTP response code of 201 indicating the record has been successfully created. The HTTP response from the POST is as follows:

<Patient xmlns="http://hl7.org/fhir">
    <id value="1527"/>
    <meta>
        <versionId value="1"/>
        <lastUpdated value="2015-12-02T20:56:08Z"/>
    </meta>
    <identifier>
        <system value="https://acme.com/patient"/>
        <value value="12341234"/>
    </identifier>
    <active value="true"/>
    <name>
        <use value="official"/>
        <family value="Tailor"/>
        <given value="Timothy"/>
    </name>
    <gender value="male"/>
    <birthDate value="1935-05-08"/>
    <managingOrganization>
        <reference value="Organization/1"/>
    </managingOrganization>
</Patient>

Within the response I can now see that the server has allocated an identifier of 1527 to the resource I have created, together with some metadata showing the resource’s version number and a time-stamp of its last update (in our case the time-stamp for its creation).

Given that I have the logical id of the resource I can now read the resource back again using the HTTP GET verb here  http://fhir2.healthintersections.com.au/open/Patient/1527

This returns the resource I created (as per the response from the POST operation) with a HTTP response code of 200 stating the resource has been read successfully. Note that if I perform a GET against a non existent record http://fhir2.healthintersections.com.au/open/Patient/dummy9999 I get a HTTP response of 404 stating the record has not been found.

So now for the delete, its really quite simple. Use the HTTP DELETE verb against the resource that you intend to delete. In my case it is http://fhir2.healthintersections.com.au/open/Patient/1527

An HTTP response code of 204 is returned with an empty body, this indicates that the resource has successfully been deleted.

To test that it has been deleted then you can perform the same HTTP GET request as used earlier http://fhir2.healthintersections.com.au/open/Patient/1527 to check the record has indeed gone.

The HTTP response you will get will now depend on the capabilities of the FHIR endpoint you are using. For a FHIR server that supports “History” you will get a 410 response stating that the resource did exist but has now gone (i.e. been deleted) for a server that does not support History then a 404 response code will be returned.

That’s it for this tutorial. We’ve now covered the following:

  • creating a resource (via POST)
  • reading a resource (via GET)
  • deleting a resource (via DELETE)

In the next tutorial we’ll cover how to update resources and handle resource contention to ensure data is not lost by overlapping updates.

If you have any questions or feedback on this tutorial then please feedback so we can improve the future tutorials.