Using non-standard HL7 delimiters

Verified
Added by iNTERFACEWARE

How to generate an HL7 message with non-standard delimiters and/or escaping, using serialize.lua

Source Code
require 'hl7.serialize'

function main(Data)
   Msg, Name = hl7.parse{vmd = 'example\\demo.vmd', data = Data}
   
   -- the examples demonstrate how to use hl7.serialize{{}   
   -- NOTE: you will need to customize the code to use delimiters
   -- and/or escape characters to match your requirements
   
   -- use default delimiters
   local Out = hl7.serialize{data = Msg}
   
   -- use non-standard delimiters
   Out = hl7.serialize{data = Msg, 
      delimiters = {'\n', '#', '.', '&', '\'', '*'}}

   -- use different non-standard delimiters
   Out = hl7.serialize{data = Msg, 
      delimiters = {'A', '|', '^', '~', '\\', '&'}}
   
   -- use non-standard escape characters (to escape delimiters)
   Out = hl7.serialize{data = Msg, 
      escaped = {'A', 'B', 'C', 'D', 'E'}}
   
   -- use non-standard delimiters and escape characters
   Out = hl7.serialize{data = Msg, 
      delimiters = {'\n', '&', '\\', '}', '~', '^'},
      escaped = {'A', 'B', 'C', 'D', 'E'}}
      
   -- transmit the messsage:
   --  - push message to queue then send with LLP Client
   --  - push to a web service
   --  - etc
end
Description
How to generate an HL7 message with non-standard delimiters and/or escaping, using serialize.lua
Usage Details

Have you ever needed to generate an HL7 message with non-standard delimiters?  Sometimes the receiving party is expecting their own flavor of HL7 with strange delimiters, so what do you do?  You can use this function, hl7.serialize{}, which will serialize an HL7 message with a provided set of delimiters (and/or a provided set of “escape characters”).

How to use the code:

  • Use a Filter or To Translator script
    • Add the code
    • Add the hl7.serialize.lua module
    • Load the sample messages from SampleData.txt
  • Alternatively you can also load the attached project that contains the module and sample messages
  • Inspect the code and annotations to see how it works