Format HL7 message fields as tab delimited

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