Eliot’s Tips and Tricks

Finding members by name

This childIndex node extension method can be used to verify the existence of a child node with a given name:

Here’s the code in a format which can be copied:

local function trace(a,b,c,d) return end

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

   checkForPID(Msg)
end

function checkForPID(msg)
   if msg:childIndex('PID') then
      trace('Has PID')
   end
end

function node.childIndex(Node, Name)
   for i=1, #Node do
      if Node[i]:nodeName() == Name then 
         return i 
      end
   end
   return nil
end

Note: We included the node function node.childIndex() in the main module for convenience, best practice is to put it in the “node” module.

Tagged:

One Comment

  1. Pingback: Will You Share Your Code? - iNTERFACEWARE Inc.

Leave A Comment?