Data from selected fields formatted in tab delimited format

This is small example how to collect data only from particular listed fields; to format the result data as tab delimited; and push to Iguana queue for any further processing.

Note: You will need to run this example in a Filter Component

List of fields in scope specified in SegmentFieldsFilter below – MSH-6, MSH-3, PID-3, …

Our test message is

MSH|^~&|AcmeMed|Lab|Main HIS|St. Micheals|20110213144932||ADT^A03|9B38584D9903051F0D2B52CC0148965775D2D23FE4C51BE060B33B6ED27DA820|P|2.6|
EVN||20110213144532||||20110213145902|
PID|||4525285^^^ADT1||Smith^Tracy||19980210|F||Martian|86 Yonge St.^^ST. LOUIS^MO^51460|||||||10-346-6|284-517-569|
NK1|1|Smith^Gary|Second Cousin|
PV1||E||||||5101^Garland^Mary^F^^DR|||||||||||1318095^^^ADT1|||||||||||||||||||||||||20110213144956|
OBX|||WT^WEIGHT||102|pounds|
OBX|||HT^HEIGHT||32|cm|

… and this is complete screenshot of our project

… and for 2nd OBX segment …

… and final result …

Assumed to use some sort of HL7 message with corresponding vmd file to indicate Segments Grammar.

The vmd file for this example is attached below.

19137.vmd

… and the code snippet for entire project …

function main(Data)
   Msg,Name=hl7.parse{vmd='19137.vmd', data=Data}
   queue.push{data=Convert()}
end

local SegmentFieldsFilter = {
   MSH={6, 3},
   PID={3, 4, 6, 8, 9},
   OBX={3, 4, 6, 7, 8, 12}
}

function Convert()
   return Msg:tabDelimitedFields(SegmentFieldsFilter)
   -- You can strip off the trailing \t character if you want
end

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

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.