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

Code Repository

Home›Code Repository›hl7.findSegment.lua
Modules

hl7.findSegment.lua

Verified Featured
Added by iNTERFACEWARE

A utility for finding any HL7 segment in a parsed HL7 message node tree.

Source Code
-- The hl7.findSegment module
-- Copyright (c) 2011-2015 iNTERFACEWARE Inc. ALL RIGHTS RESERVED
-- iNTERFACEWARE permits you to use, modify, and distribute this file in accordance
-- with the terms of the iNTERFACEWARE license agreement accompanying the software
-- in which it is used.
 
-- General purpose routine to iterate through a message tree and find a segment matching the Filter function given.
function hl7.findSegment(Msg, Filter)
   local segments = {}
   local cnt = 0
   for i=1, #Msg do
      if (Msg[i]:nodeType() == 'segment'
            and Filter(Msg[i])) then
         cnt = cnt + 1
         segments[cnt] = Msg[i]
      end
   end
   if cnt>0 then 
      -- return single segment to mimic old behaviour
      if cnt==1 then
         return segments[1]
      else
         -- otherwise return table of matching segments
         return segments 
      end
   end
   for i=1, #Msg do
      local T = Msg[i]:nodeType()
      if (T == 'segment_group'
            or T == 'segment_group_repeated'
            or T == 'segment_repeated') then
         local R = hl7.findSegment(Msg[i], Filter)
         if R ~= nil then
            return R
         else 
            return nil
         end
      end
   end
end
 
local hl7_findSegment = {
   Title="hl7.findSegment";
   Usage="hl7.findSegment(Msg, Filter)",
   SummaryLine="Find segment(s) in a parsed HL7 message using a filter function.",
   Desc=[[Find one or more matching segments in a parsed HL7 message using a 
   filter function. 
   <p>If one segment is found it is returned as an hl7 node, if multiple segments
   are found they are returned as a table of hl7 nodes, if no matching segments 
   are found then nil is returned.
   ]];
   Returns = {
      {Desc="Returns one or more identified segments (nodes)  <u>hl7 node or table of nodes</u>."},
   };
   ParameterTable= false,
   Parameters= {
      {Msg= {Desc='Parsed HL7 message node tree <u>hl7 node tree</u>.'}},
      {Filter= {Desc='Filter function to identify segment(s) <u>function</u>.'}},
   };
   Examples={
      [[   -- hl7.findSegment is installed directly into the hl7 namespace
   require 'hl7.findSegment'

   -- http://help.interfaceware.com/code/details/hl7util-lua

   function main(Data)
      local Msg = hl7.parse{vmd='demo.vmd', data=Data}

      -- find the PID segment in the parsed HL7 message
      -- returns a single segment node
      local PID = hl7.findSegment(Msg, FindPID)

      -- find the NK1 segment(s) in the parsed HL7 message
      -- returns a table of segment nodes
      local NK1 = hl7.findSegment(Msg, FindNK1)
   end
      
   -- function to find (match) a PID segment
   function FindPID(Segment)
      if Segment:nodeName() == 'PID' then
         return true
      end
   end
      
   -- function to find (match) a NK1 segment(s)
   function FindNK1(Segment)
      if Segment:nodeName() == 'NK1' then
         return true
      end
   end]],
   };
   SeeAlso={
      {
         Title="hl7.findSegment.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/hl7util-lua"
      },
      {
         Title="hl7.findSegment",
         Link="http://help.interfaceware.com/v6/hl7-findsegment"
      }
   }
}

help.set{input_function=hl7.findSegment, help_data=hl7_findSegment}
Description
A utility for finding any HL7 segment in a parsed HL7 message node tree.
Attachments
hl7util_Filter.zip
Usage Details

The hl7.findSegment module enables us to write some code which will find any segment for us. The message passed to hl7.findSegment() must be parsed into a node tree format using hl7.parse{}, passing (passing an HL7 message in plain text format does not work).

How to use hl7util.lua:

  • Add it to your shared modules in any Translator project
  • Make sure to require 'hl7.findSegment' at the top of your script
  • Parse the HL7 message using hl7.parse{}
  • Use the function hl7.findSegment(Message, FindFunction) to find the desired segment in the parsed message

Example:

-- hl7.findSegment is installed directly into the hl7 namespace
require 'hl7.findSegment'

-- http://help.interfaceware.com/code/details/hl7util-lua

function main(Data)
   local Msg = hl7.parse{vmd='demo.vmd', data=Data}

   -- find the PID segment in the parsed HL7 message
   -- returns a single segment node
   local PID = hl7.findSegment(Msg, FindPID)

   -- find the NK1 segment(s) in the parsed HL7 message
   -- returns a table of segment nodes
   local NK1 = hl7.findSegment(Msg, FindNK1)
end
 
-- function to find (match) a PID segment
function FindPID(Segment)
   if Segment:nodeName() == 'PID' then
      return true
   end
end

-- function to find (match) NK1 segment(s)
function FindNK1(Segment)
   if Segment:nodeName() == 'NK1' then
      return true
   end
end
More Information
Find any segment in an HL7 message
Bookmark
  • Reviews
  • Related Listings
Filter
Sort by: Rating
  • Newest First
  • Oldest First
  • Helpfulness
Write a Review
Rating
Keyword
Filter
Sort by: Highest Rated
  • Newest First
  • Oldest First
  • Title
  • Most Reviews
Rating
iNTERFACEWARE
rtf.lua
Added by iNTERFACEWARE
Modules
A module for converting a RTF file to plain text.
store2.lua
Added by iNTERFACEWARE
Modules
Provides a simple interface to store key/value pairs in a persistent storage mechanism.
hl7.zsegment.lua
Added by iNTERFACEWARE
Modules
Generic Z segment parser. Parses Z segments without needing grammar definitions in the VMD file.
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).
custom_merge.lua
Added by iNTERFACEWARE
Modules
A customizable database merge method for Iguana 5.5.1 and up.
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.
Showing 1 - 20 of 31 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.