Process a batch of HL7 messages

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.