Format HL7 message fields as tab delimited

Verified
Added by iNTERFACEWARE

Format specified HL7 message fields in a tab delimited string and push the string to the queue for further processing

Source Code
-- change/add the segments and fields you want to process
local SegmentFieldsFilter = {
MSH={6, 3},
PID={3, 4, 6, 8, 9},
OBX={3, 4, 6, 7, 8, 12}
}

function main(Data)
local Msg,Name=hl7.parse{vmd='19137.vmd', data=Data}

local tabbed = Msg:tabDelimitedFields(SegmentFieldsFilter)
queue.push{data=tabbed}
end

-- extend the builtin "node" libary
-- this function could be placed in a module
function node.tabDelimitedFields(Node, Filter)
local R = ''
for i=1, #Node do
if Node[i]:nodeType() == 'segment' and
not Node[i]:isNull() and
Filter[Node[i]:nodeName()] then
local FieldFilter = Filter[Node[i]:nodeName()]
for j=1,#FieldFilter do
R = R..Node[i][FieldFilter[j]]:S()..'\t'
end
elseif Node[i]:nodeType() == 'segment_repeated' then
R = R..Node[i]:tabDelimitedFields(Filter)
elseif Node[i]:nodeType() == 'segment_group' then
R = R..Node[i]:tabDelimitedFields(Filter)
end
end
R=R:gsub('%^','%\t')
return R
end
Description
Format specified HL7 message fields in a tab delimited string and push the string to the queue for further processing
Usage Details

This example shows how to collect data from specified fields in an HL7 message, then format them as a tab delimited string and push to Iguana queue for further processing.

Note: The sample code is very similar to one of Lev’s tips: Data from selected fields formatted in tab delimited format.

How to use the code:

  • Paste it into a Filter or To Translator script
  • Add some sample HL7 messages
  • Change the SegmentFieldsFilter to process the desired segments and fields
  • Examine the code and annotations to see how it works