Format HL7 without the "|" trailing character

Added by iNTERFACEWARE

How to format an HL7 message without the trailing "|" at the end of each line

Source Code
function main(Data)   
   local Msg = hl7.parse  {vmd = 'example/demo.vmd', data = Data}
   
   -- Out1 contains the message without trailing "|" delimiters
   local Out1 = Msg:flatwire()
   
   -- Out2 contains the message with the default formatting.
   local Out2 = Msg:S()
end

function node.flatwire(Node) 
   local R = ''
   for i=1, #Node do
      if Node[i]:nodeType() == 'segment' and not Node[i]:isNull() then
         R = R..Node[i]:S()
         R = R:sub(1, #R-1)  -- get rid of trailing delimiters
         R = R..'\r'
      elseif Node[i]:nodeType() == 'segment_repeated' then
         R = R..Node[i]:flatwire()
      elseif Node[i]:nodeType() == 'segment_group' then
         R = R..Node[i]:flatwire()
      end
   end
   return R
end
Description
How to format an HL7 message without the trailing "|" at the end of each line