Format HL7 without the "|" trailing character
Verified
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
Attachments
Usage Details
This example uses an extension function node.flatwire()
to remove the “|” trailing character from each line of an HL7 message.
Note: The node.flatwire()
function uses recursion, but you don’t need to understand this to use it.
How to use the code:
- Use a Filter or To Translator script
- Add the code
- Load the sample messages from sample_data.txt
- Alternatively you can also load the attached project which already contains the sample messages
- Inspect the code and annotations to see how it works
More Information