Transforming messages

Added by iNTERFACEWARE

How to transform part of an HL7 message (similar principles apply to other message types)

Source Code
require 'stringutil'

function main(Data)
   -- Parse the HL7 message
   local Msg, Name = hl7.parse{vmd = 'example/demo.vmd', data = Data}
   local Out       = hl7.message{vmd = 'example/demo.vmd', name = Name}
   
   -- Map the complete message
   Out:mapTree(Msg)
   
   -- Transform the message data
   
   -- Correct misspelling of the Race Code
   if Out.PID[10][1][1]:nodeValue():lower() == "mix" then
      Out.PID[10][1][1] = "Mixed"
   end
   
   -- Capitalize patient Given Name and Surname
   Out.PID[5][1][2] = Out.PID[5][1][2]:nodeValue():capitalize()
   Out.PID[5][1][1][1] = Out.PID[5][1][1][1]:nodeValue():capitalize()
   
   -- Push the outgoing message into the Iguana queue
   queue.push(Out)
end