Using Character Class

Lua Character Class can be very helpful to tokenize data.

HL7 ver2.x Standards are backward compatible, so there is no practical use to select a vmd file that conforms to one of older versions of HL7 Standard. It is good enough to use the ‘latest and greatest’.

However, I made this example as a little exercise to demonstrate matching different vmd files automatically, driven by content of HL7 message itself (i.e., to match HL7 version specified in HL7 message.)

We start with having a vmd file for each version of HL7 ver. 2.x Standard, and select as argument for hl7.parse() the one that corresponds to HL7 version specified in this particular HL7 message.

Above, we call to single function HL7ver(), it can be added to the hl7util Module:

… and the code snippet:

hl7util = {}

function hl7util.HL7ver(self)
   t  = {}
   for v in string.gmatch(self, '2%p%d?%p?%d' ) do
      t[#t+1] = v

   return t[1]

Leave A Comment?