Transforming messages

Verified
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
Description
How to transform part of an HL7 message (similar principles apply to other message types)
Usage Details

This example shows how to transform an HL7 message. The message is parsed into a read-only source HL7 node tree structure, and then copied into writeable  HL7 node tree (using the  mapTree() function) . The code then shows how to transform fields to fix two simple errors. You can adapt the code to do any transformation that you require, like formatting dates, mapping codes, database or web service lookups, etc.

The process for transforming other message types follows the same general pattern.

How to use the code:

  • Use a Filter or To Translator script
    • Add the code
    • Load the sample messages from sample_data.txt
  • Alternatively you can also load the attached project which already contains the sample messages
  • Inspect the code and annotations to see how it works

Note: See the Interface Tutorials (Iguana 5 documentation) section for more information on mapping and transforming other message types.