• Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Forums
  • Training
  • Create a Ticket
iNTERFACEWARE Help Center
  • Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Forums
  • Training
  • Create a Ticket

Code Repository

Home›Code Repository›hl7.zsegment.lua
Modules

hl7.zsegment.lua

Verified Featured
Added by iNTERFACEWARE

Generic Z segment parser. Parses Z segments without needing grammar definitions in the VMD file.

Source Code
-- Generic Z segment parser
-- http://help.interfaceware.com/kb/generic-z-segment-parser

hl7.zsegment = {}

local function ParseDelim(Data, DelimArray, Index, Compact)
   if Index == 0 then
      return Data
   end
   local Children = Data:split(DelimArray[Index])
   local Result = {}
   if #Children > 1  then
      for i =1, #Children do
         Result[i] = ParseDelim(Children[i], DelimArray, Index-1, Compact)   
      end
   else
      if Compact then
         Result = ParseDelim(Data, DelimArray, Index-1, Compact)
      else
         Result[1] = ParseDelim(Data, DelimArray, Index-1, Compact)
      end
   end
   
   return Result
end

local function AddZSegment(List, Segment, Compact)
   local Fields = Segment:split('|')
   local SegmentName = Fields[1]
   for i=2, #Fields do 
      Fields[i-1] = ParseDelim(Fields[i], {'&','^','~'}, 3, Compact)
   end
   if not List[SegmentName] then
      List[SegmentName] = {} 
   end
   List[SegmentName][#List[SegmentName]+1] = Fields
end

function hl7.zsegment.parse(T)
   local Segments = T.data:split("\r")
   local ZSegments = {}
   for i = 1,#Segments do
      if Segments[i]:sub(1,1) == 'Z' then
         AddZSegment(ZSegments, Segments[i], T.compact)
      end
   end
   return ZSegments
end

local HELP_DEF=[[{
   "Desc": "Parses an HL7/EDI/X12 message and extracts Z segments which it returns in a Lua table. 
   <p>This module gives us two parsing options: \"Expanded\" (compact=false) which pushes all the
   data down to the leaf level, \"Compact\" (compact=true) where we keep the data at a higher 
   level (this assumes there are no sub fields and repeating fields) 
   <p>Using the \"Expanded\" mode is safer as it gives consistent results for messages with/without
   sub-fields and repeating fields. \"Compact\" mode however will fail (give different results) for
   messages with/without sub-fields and repeating fields. <p>If you have optional sub-fields or 
   repeats then you need to use the \"Expanded\" mode.",
   "Returns": [
      {
         "Desc": "A lua table with the Z segments parsed out <u>table</u>."
      }
   ],
   "SummaryLine": "Parses an HL7/EDI/X12 message for Z-zegments without a vmd.",
   "SeeAlso": [
      {
         "Title": "hl7.zsegment.lua - in our code repository.",
         "Link": "http://help.interfaceware.com/code/details/hl7-zsegment-lua"
      },
      {
         "Title": "Z Segment Parser.",
         "Link": "http://help.interfaceware.com/v6/z-segment-parser"
      }
   ],
   "Title": "hl7.zsegment.parse",
   "Usage": "hl7.zsegment.parse{data=<value>, compact=<true|false>}",
   "Parameters": [
      {
         "data": {
            "Desc": "A message to be parsed <u>string</u>. "
         }
      },
      {
         "compact": {
            "Desc": "If <b>false</b> then the parsed tree will push all data to the lowest level <u>boolean</u>. "
         }
      }
   ],
   "Examples": [
      "<pre>local Msg = hl7.zsegment.parse{data=Data, compact=false}</pre>"
   ],
   "ParameterTable": true
}]]

help.set{input_function=hl7.zsegment.parse, help_data=json.parse{data=HELP_DEF}}
Description
Generic Z segment parser. Parses Z segments without needing grammar definitions in the VMD file.
Usage Details

This module parses Z segments without defining a grammar. Without a grammar it’s difficult to know if a given field contains subfields, sub sub fields, is repeating etc. Because of this the parser can be invoked in two modes using the boolean compact flag.

  • 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

How to use the code:

  • Add the module to a Filter,  To Translator or LLP script
  • Use the hl7.zsegment.parse{} function to parse Z segments

Here is some sample code for main():

-- The parser gets inserted into the built in "hl7" namespace.
require 'hl7.zsegment'

-- This module is useful if you'd like to be able to parse Z segments without going through the trouble of editing a VMD file
-- https://help.interfaceware.com/kb/generic-z-segment-parser for more information

local Xml=[[
<Kin firstName='' lastName=''/>
]]

-- Because we don't know the grammar of the segments this module gives us the choice of pushing all the data
-- down to the lowest level leaf (compact=false)  This is safest but makes for verbose paths
-- Or we can keep the data at a higher level (assuming there are not sub fields and repeating fields)
function main(Data)
   -- This shows the compact parsing mode
   local CompactZED = hl7.zsegment.parse{data=Data, compact=true}   
   local X = xml.parse{data=Xml}
   X.Kin.firstName = CompactZED.ZID[1][2][2][1]
  
   -- This shows the non compact parsing mode
   local ExpandedZED = hl7.zsegment.parse{data=Data, compact=false}
   X.Kin.firstName = ExpandedZED.ZID[1][2][2][1][1]
end
More Information
A generic Z segment parser
Bookmark
  • Reviews
  • Related Listings
Filter
Sort by: Newest First
  • Oldest First
  • Rating
  • Helpfulness
Write a Review
Rating
Keyword
Filter
Sort by: Newest First
  • Oldest First
  • Title
  • Most Reviews
  • Highest Rated
Rating
iNTERFACEWARE
Dollysingh
Added by Dollysingh
Modules
Guwahati independent escorts on Sduko come up with the services more than the erotic encounter. They create a friendly environment to make their clien
store2.lua
Added by iNTERFACEWARE
Modules
Provides a simple interface to store key/value pairs in a persistent storage mechanism.
stream.lua
Added by iNTERFACEWARE
Modules
This module performs basic stream processing, read, write, save to file, convert to text etc.
age.lua
Added by iNTERFACEWARE
Modules
This module calculates age from DOB, it returns years, months and partial years (i.e., 17, 3, 17.296272)
sqlite.lua
Added by iNTERFACEWARE
Modules
A module to create a SQLite database and generate the tables specified in a VMD
batch.lua
Added by iNTERFACEWARE
Modules
A module to help processing batched HL7 messages
auth.lua
Added by iNTERFACEWARE
Modules
A module that does basic authentication for incoming web requests
llp.lua
Added by iNTERFACEWARE
Modules
Allows you to use LLP connections from a Translator script
edifact.lua
Added by iNTERFACEWARE
Modules
Convert EDI messages to HL7 format so you can process them like an HL7 message (and convert them back to EDI afterwards)
test_all.lua
Added by iNTERFACEWARE
Modules
Test a script against all the sample messages loaded for the component
hl7.serialize.lua
Added by iNTERFACEWARE
Modules
Serializes an HL7 message using specified non-standard delimiters and/or escape characters
scheduler.lua
Added by iNTERFACEWARE
Modules
Schedule jobs to run at a specified time of day, very useful for batch processing
validate.lua
Added by iNTERFACEWARE
Modules
A template module for testing HL7 message conformance, you will need to extend it to match your requirements
throttle.lua
Added by iNTERFACEWARE
Modules
Throttle a process during peak hours, by slowing down the code.
resubmit.lua
Added by iNTERFACEWARE
Modules
Resubmit a logged message to an Iguana channel using the unique reference number (refmsgid).
rtf.lua
Added by iNTERFACEWARE
Modules
A module for converting a RTF file to plain text.
codemap.lua
Added by iNTERFACEWARE
Modules
This module is used to map one set of codes to another set of codes, or to validate code membership in a set
throttleDB.lua
Added by iNTERFACEWARE
Modules
Throttle database access by reducing the number of inserts during peak hours
scrub.lua
Added by iNTERFACEWARE
Modules
The “scrub” module given below redacts sensitive information from HL7 messages.
csv_parse.lua
Added by iNTERFACEWARE
Modules
A module for parsing well-formed CSV files.
Showing 1 - 20 of 32 results
«12»

Topics

  • expandGetting Started
  • expandAdministration
    • expandInstallation
    • expandLicensing
    • expandUpgrades
    • expandDeployment
    • expandConfiguration Management
      • expandCustom Configuration
    • expandBackup and Restore
    • expandSecurity
      • expandHIPAA Compliance
    • expandTroubleshooting
  • expandDeveloping Interfaces
    • expandArchitecture
    • expandInterfaces
      • expandHL7
      • expandDatabase
        • expandConnect
      • expandWeb Services
      • expandCDA
      • expandX12
      • expandOther Interfaces
      • expandUtilities
    • expandRepositories
      • expandBuiltin Repositories
        • expandIguana Upgrade
        • expandIguana Tutorials
        • expandIguana Tools
        • expandIguana Protocols
        • expandIguana Files
        • expandIguana Date/Time
        • expandIguana Webservices
        • expandIguana Excel
      • expandRemote Repositories
      • expandCS Team Repositories
        • expandIguana Channels
    • expandSample Code
      • expandModules
      • expandUsing built-in functions
      • expandWorking with XML
    • expandLua Programming
    • expandPerformance
  • expandFAQs and TIPs
    • expandFrequently Asked Questions
      • expandInstalls and Upgrades
      • expandWeb Services
      • expandConfiguration
      • expandChannels
      • expandTranslator
      • expandOther
      • expandDatabase
      • expandAdministration
      • expandLogs
      • expandChameleon
    • expandTips
      • expandChannels
      • expandChameleon
      • expandWeb Services
      • expandSecurity
      • expandProgramming
      • expandOther
      • expandAdministration
  • expandReference
    • expandIguana Enterprise and Professional
    • expandProgram Settings
    • expandChannel Settings
    • expandDashboard
    • expandChannels
    • expandTranslator
    • expandLogs
      • expandLog Encryption
    • expandHTTP API
    • expandCDA API
    • expandError Messages
    • expandChameleon
    • expandIguana Change Log

Other Links

  • Training Center
  • News & Announcements
  • iNTERFACEWARE Blog
  • Older Documention (IGUANA v4 & Chameleon)
Copyright © iNTERFACEWARE Inc.