Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleSTEP 4: Filter unwanted messages

Now that we have our HL7 message parsed and identified, let’s create a filters.lua file to apply filtering rules on inbound messages.

We are going to

  1. First create a new file, call it filters and make sure it is a .lua file type. Use the technique from Filtering Messages to create a rule to filter out messages not identified as an ADTA01.

Code Block
languagelua
-- This module contains sample filtering rules.  
-- Use your own filter conditions and error messages.

local filter ={}

function filter.filterMessage(msgType) 
   if msgType ~= 'ADTA01' then
      iguana.logError('Unexpected message type.')
      return true
   end
   return false
end

return filter
  1. Call your filter.filterMessage function in main:

    • First assign the required filters.lua module to the variable filter so you can call it.

    • Use an if statement and the not operator to check the name of the message type. If the msgType is not equal to ADTA01, the filter function will return false and not continue executing the block of code.

Code Block
languagelua
local filter = require 'filters'

function main(Data)

   -- Parse the HL7 message
   local msg, msgType = hl7.parse{vmd='hl7.vmd', data=Data}
   
   -- Filter out unwanted messages
   if not filter.filterMessage(msgType) then  
      -- Transform the message to JSON     
      -- Write the data to a destination
   end
   
end

If you add additional sample data to the Translator, you can test to see how your interface reacts to different message types by viewing the annotations.

Expand
titleSTEP 5: Apply Create the outbound JSON and apply mappings to Transform generate the message

For the purpose of this tutorial we will perform some example mappings for a simple JSON object.

  1. Paste the following JSON template at the top outside of main to use as the outbound message schema:

Code Block
local jsonTemplate = [[
{   
  "sendingFacility": "",
  "receivingFacility": "",
  "patientId": "",
  "firstName": "",
  "lastName": "",
  "birthdate": ""
}
]]

Now inside your filter if statement under the comment -- Transform the message to JSON, add the transformation logic:

  1. First, parse the JSON template so its ready to be populated with the HL7 data:

Code Block
-- Transform the message to JSON 
local msgOut = json.parse{data=jsonTemplate}
  1. Create a mapADT.lua file to store your mapping functions. Its good practice to modularize mappings into separate functions for readability and future maintenance. Here we are going to split the mapping into functions for each HL7 segment.

Code Block
local mapper = {}

-- Map the incoming data to the outgoing JSON
-- Organize mapping functions by HL7 segment 

function mapper.mapMSH(MSH, msgOut)
   msgOut.sendingFacility   = MSH[3][1]:nodeValue()
   msgOut.receivingFacility = MSH[6][1]:nodeValue()
   return msgOut
end 

function mapper.mapPID(PID, msgOut) 
   msgOut.patientId = PID[3][1]:nodeValue()
   msgOut.firstName = PID[5][2]:nodeValue()
   msgOut.lastName  = PID[5][1][1]:nodeValue()
   msgOut.birthdate = PID[7][1]:nodeValue()
   msgOut.race      = PID[10][1]:nodeValue()   
   return msgOut
end

return mapper
Info

In this example, we are using simple assignment mapping, assigning values from the inbound HL7 message to the outbound JSON. There are many different strategies to map messages. Please see Mapping Messages for more strategies.

  1. Now call these mapper functions in main:

    • First assign the required mapADT.lua module to the variable mapper so you can call it.

    • Call each mapping function, passing the appropriate HL7 segments.

Code Block
-- call mapping functions 
mapper.mapMSH(msg.MSH, msgOut)
mapper.mapPID(msg.PID, msgOut)

Use the annotations to see the results of your mappings. You can also use trace(msgOut) to view your JSON in the annotation window at any point during processing.

...