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)

   print(patientFHIR,_G)
   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,
                       headers={['Content-Type']='application/xml'},
                       body=P:S()
   }
   print (C,R,H) -- code 201 (c=201) is a successful insert

end

function mapPatientData(Xml,Msg,Name)
   if Name=='ADT' then
      Xml.Patient.active[1]='true'

      Xml.Patient.identifier.use[1]='official'
      Xml.Patient.identifier.label[1]='SSN'
      Xml.Patient.identifier.id[1]=Msg.PID[2][1]

      Xml.Patient.details.name.use.value='official'
      Xml.Patient.details.name.family.value=Msg.PID[5][1][1][1]
      Xml.Patient.details.name.given.value=Msg.PID[5][1][2]

      Xml.Patient.details.birthDate.value=Msg.PID[7][1]

      print(Msg.PID[8])
      Xml.Patient.details.gender.code[1]=Msg.PID[8]     
   end
   return Xml
end

Here is the module for creating XML containing patient info:

patientFHIR={}

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

      <Patient xmlns="http://hl7.org/fhir">
         <active>#</active>
         <identifier>
            <use>#</use>
            <label>#</label>
            <id>#</id>
         </identifier>
         <details>
            <name>
               <use value="official"/>
               <family value="family name"/>
               <given value="given name"/>
            </name>
            <gender>
               <system value="http://hl7.org/fhir/sid/v2-0001"/>
               <code value=""/>
               <display value=""/>
            </gender>
            <birthDate value="Date"/>
         </details>
      </Patient>
     ]]
   }
end

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

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…

Cheers!
Rolly

Leave A Comment?

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