Netrequire Server

Catalogue > hl7util.lua

Useful utilities for dealing with HL7 including the ability to find HL7 segments.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
-- $Revision: 1.6 $
-- $Date: 2014-09-10 16:56:05 $

--
-- The hl7util module
-- Copyright (c) 2011-2012 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.
--

--[[ This module has some helpful routines when dealing with HL7.  Use these examples as a guide to making your own utilities ]]--

hl7util = {}

-- General purpose routine to iterate through a message tree
-- to find a segment matching the Filter function given.
function hl7util.findSegment(Msg, Filter)
   for i=1, #Msg do
      if (Msg[i]:nodeType() == 'segment'
          and Filter(Msg[i])) then
         return Msg[i]
      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 = hl7util.findSegment(Msg[i], Filter)
         if R ~= nil then
            return R
         end
      end
   end
end

return hl7util