Process a batch of HL7 messages

Verified
Added by iNTERFACEWARE

How to process a batch of HL7 messages by removing the batch header and splitting it into separate messages.

Source Code
-- this code follows best practice by using local
-- functions first followed by main() at the end

require 'stringutil'
local batch = require 'batch'

local function MapData(Msg)
   local msg, name = hl7.parse{vmd='example/demo.vmd', data= Msg}
   local out = db.tables{vmd='example/demo.vmd', name=name}
   --[[ Do some mapping and 'return' 
   result to calling function]]   
   return out
end

local function processMsg(Msg)
   local Tables = MapData(Msg) 
   --[[  Some data can be written to database
   conn.merge{data=Tables,live=true}]]   
   return 
end

conn = db.connect{
   api=db.MY_SQL,
   name='test', 
   user='',
   password='',
   live=true}
 
function main(Data)
   -- convert non-conformant terminators to "\r"
   Data = batch.convertTerminators(Data)
 
   -- split batch into array of messages
   local Msgs = batch.splitBatch(Data)
 
   -- process messages
   for i=1,#Msgs do
      processMsg(Msgs[i])
   end
end
Description
How to process a batch of HL7 messages by removing the batch header and splitting it into separate messages.
Usage Details

This code processes a batch of HL7 messages by removing the batch header and splitting the batch separate messages.

How to use the code:

  • Create/use a MySQL database with credentials that match the code
  • Load the project zip file into a Filter component, or paste in the code
  • If you paste in the code you will also need to:
    • Load the sample data from SampleData.txt
    • Create the batch module and load the batch.lua code
  • Inspect the code to see how it works