Generic Z Segment Parser

This is has been on my TODO list for a while. Write a generic Lua module that can be used to parse any arbitrary Z segment.

It’s not all that hard to write one of these and I think many of our users have written their own. This is my spin on it.

If you install the Channel Manager you can see an example channel called Z Segment Parser which has the module and an example of calling it.

You can see some example code calling the parser right here.

The code for the parser itself doesn’t amount to much.

You can see it in hl7/zsegment.lua.  It has a help file in JSON which is in other/hl7/zsegment/parse.json.

One of the challenges with parsing Z segments without defining a grammar is that it’s difficult to know if a given field can contain subfields, sub sub fields, is repeating etc.  As such the parser can be invoked with flag called compact which can be true or false.

  • In non compact mode all field data is pushed down to the bottom most leaf nodes.
  • In compact mode if a field doesn’t have repeats, sub sub fields then the parser optimistically assumes there are no such fields

Here’s a screen shot of the parser in action:

Screen Shot 2014-05-23 at 12.44.38 PM

Comments and questions are welcome.

Tagged:

Leave A Comment?

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