batch.lua

Added by iNTERFACEWARE

A module to help processing batched HL7 messages

Source Code
local batch ={}

function batch.splitBatch(Data)
   -- strip batch info off Data
   local a = Data:split('\r')    
   Data=a[3]
   trace(Data)
   for i=4,#a-2 do
      Data=Data..'\r'..a[i]
   end
   trace(Data)
 
   -- split Data into messages
   local delimiter='MSH|^~\\&|'
   local b=Data:split(delimiter)
 
   -- add MSH segment info
   trace(b)
   for i=2,#b do 
      b[i-1]=delimiter..b[i]
   end
   b[#b]=nil -- delete dup msg
   trace(b)
 
   -- SOME IDEAS THAT COULD BE USEFUL
 
   -- global variable to count messages
   MsgCnt = #b
   trace('Messages Count '..MsgCnt)
 
   -- globals for batch segment info
   FHS=a[1]:split('|')
   BHS=a[2]:split('|')
   FTS=a[#a]:split('|') 
   BTS=a[#a-1]:split('|') 
 
   return b
end
 
function batch.convertTerminators(Data)
   Data = Data:gsub('\r\n','\r')
   return Data:gsub('\n','\r')
end

return batch
Description
A module to help processing batched HL7 messages