Saturday, March 21, 2015

Creating a new HL7 FHIR Patient Resource

Now that we have a mapping from an HL7 v2.x ORU PID segment into an HL7 FIHR Patient resource, our next task is to actually try creating a new Patient resource.  With REST, new resources can be created in one of two ways - HTTP POST and HTTP PUT.  HTTP PUT is used when we know the identifier for a given resource and HTTP POST is used when the server generates the identifier.  In the case of HL7 FHIR, all resource identifiers are server generated so we cannot use HTTP PUT and must use HTTP POST.  According to the HL7 FHIR documentation for creating resources, we simply POST the JSON document to the root resource.  Sounds simple enough, we can try this out easily using any number of tools:

1) CURL - Command line utility that lets you make HTTP requests
2) Advanced REST Client - A Google chrome extension that lets you make HTTP requests with a nice UI.

I am going to start with the Advanced REST Client since it is easier to work with.  Lets being by creating a sample Patient resource in JSON:


  "resourceType" : "Patient",
  "text" : { 
    "status" : "generated",
    "div" : ""
  },
  "identifier": [{
    "use" : "usual",
    "label" : "MRN",
    "system" : "urn:oid:0.1.2.3.4.5.6.7",
    "value" : "654321"
  }],
  "name" : [{
    "use" : "official",
    "family" : ["Donald"],
    "given" : ["Duck"]
  }],
  "gender": {
    "coding" : [{
      "system" : "v3/AdministrativeGender",
      "code" : "M",
      "display" : "Male"
    }]
  },
  "maritalStatus" : {
    "coding" : [{
      "system" : "v3/MaritalStatus",
      "code" : "M",
      "display" : "Married"
    }]
  },
  "birthDate": "1944-11-17",
  "deceasedBoolean" : false, 
  "active": "true" 
}

Now using Advanced REST Client, lets POST this to the publicly accessible spark server.  Start up Advanced REST Client and enter the following URL:

http://spark.furore.com/fhir/Patient?_format=application%2fjson%2bfhir

Click the "POST" radio button and paste the above JSON into the "Payload" section.  Change the content type to "application/json"in the combo box and then press the "Send" button.  If all goes well, you should see the URL to the newly created resource in the Location response header:


You can verify that the newly created patient is in fact accessible by making a GET request for the resources URI:


Well that was amazingly easy!  One thing I should mention here is that I left the text.div property empty.  I believe that HTML is supposed to go there that produces a human understandable representation of this resource.  I didn't bother with that for now as this is just a spike and I don't really need this functionality.

Now that we know how to create a Patient resource, we need to look at how we can search for existing ones that we can use instead of always creating a new one.


No comments:

Post a Comment