This topic contains 0 replies, has 1 voice, and was last updated by  Rolly 4 years, 8 months ago.

Connecting to FHIR Patient using RESTful Web Services

  • One of the new and exciting standards emerging from HL7 is Fast Healthcare Interoperable Resource AKA FHIR. The main emphasis 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 as I put this example together using Iguana 🙂

    Before beginning I would like to give a shout out to Grahame Grieve for kindly providing a publicly available FHIR test server that was used in this example. More information about Grahame’s FHIR server can be found here.

    We use XML as the payload for this example, however JSON is also supported.

    The example below is fairly simple; get a Patient resource, search Patient resources and add a Patient resource.

    To start, I defined a variable (Patient149XMLURL) pointing to a known fictitious patient named Henry Glover (id 149). By using net.http.get function I was able to pull Henry Glover’s info as illustrated below:

    -- The main function is the first function called from Iguana.
    -- The Data argument will contain the message to be processed.
    require 'node'
    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)

    Searching Patient resources is done by adding 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 that was 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

    Module for creating XML containing patient info:

    patientFHIR={}
    
    function patientFHIR.InsertTemplate()
       return xml.parse
       {data = [[
         
          
             #
             
                #
                
                #
             
             
    ]] } end function node.S(ANode) return tostring(ANode) end

    Well, that's it for today, but stay tuned as I'll be posting a JSON example shortly.

    Cheers!
    Rolly

You must be logged in to reply to this topic.