FHIR-implementation in Iguana from the Connectathon (Phoenix 2013)

One of the new and exciting standards emerging from HL7 is Fast Healthcare Interoperable Resource (FHIR). Its main purpose is to simplify the exchange of health information with a lightweight implementation framework that will bring smiles to implementers. It certainly put a smile on my face when I put this example together using Iguana!

Note: I’d like to give a shout out to Grahame Grieve for kindly providing the publicly-available FHIR test server that I used in this example.

It appears this server is down (or moved), but here is a list of publicly available FHIR test servers.

My example is demonstrates the following actions: get a Patient resource, search all Patient resources, and add a Patient resource.

Note: I use XML as the payload for this example, but JSON is also supported.

To get a patient resource, I defined a variable (‘Patient149XMLURL’) that points to a known fictitious patient named Henry Glover (ID: 149).  By using the net.http.get function, I was able to pull Henry Glover’s patient info:

-- The main function is the first function called from Iguana.
-- The Data argument will contain the message to be processed.
require 'patientFHIR'

Patient149XMLURL = 'http://hl7connect.healthintersections.com.au/svc/fhir/patient/@149?_format=xml'
AllPatientsXMLURL = 'http://hl7connect.healthintersections.com.au/svc/fhir/patient/search?_format=xml'
CreatePatientXMLURL = 'http://hl7connect.healthintersections.com.au/svc/fhir/patient?_format=xml'

function main(Data)

   local msg, name = hl7.parse({vmd = 'demo.vmd', data = Data})   

   -- read an individual patient in XML format from FHIR server
   -- reference http://www.hl7.org/implement/standards/fhir/patient.htm
   local R,C,H = net.http.get{url=Patient149XMLURL, live=true}
   print (C,R,H)

To search through Patient resources, I added a search keyword after the resource URL. FHIR defines a resource bundle as the return type:

 -- read all patient records in XML format from FHIR server
   -- reference http://www.hl7.org/implement/standards/fhir/http.htm#search
   R,C,H = net.http.get{url=AllPatientsXMLURL, live=true}
   print (C,R,H)

Finally, I added a patient resource by using net.http.post and passing in patient XML data created in a separate module, patientFHIR:

 -- create a new patient in FHIR server
   -- reference http://www.hl7.org/implement/standards/fhir/http.htm#create
   local P = patientFHIR.InsertTemplate()
   P = mapPatientData(P,msg,name)
   R,C,H = net.http.post{url=CreatePatientXMLURL, live=true,
   print (C,R,H) -- code 201 (c=201) is a successful insert


function mapPatientData(Xml,Msg,Name)
   if Name=='ADT' then




   return Xml

Here is the module for creating XML containing patient info:


function patientFHIR.InsertTemplate()
   return xml.parse
   {data = [[

      <Patient xmlns="http://hl7.org/fhir">
               <use value="official"/>
               <family value="family name"/>
               <given value="given name"/>
               <system value="http://hl7.org/fhir/sid/v2-0001"/>
               <code value=""/>
               <display value=""/>
            <birthDate value="Date"/>

function node.S(ANode)
   return tostring(ANode)

If you want to try all this out, simply import this zip file (with the complete code) into your project: FHIR_Patient_Example_Filter.zip

Well, that’s it for today! Stay tuned as I’ll be posting a JSON example shortly…


Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.