First Steps: Building a Simple Interface

Queue the Data

Now that we’ve got the logic in place to produce the desired output, we are ready to push the results from our Filter component back into our channel’s queue. From there, it will travel out to our channel’s Destination component (an outgoing LLP socket).

Add the following line of code to your script:

Screen Shot 2014-06-11 at 12.46.55

What is happening here? Because the Iguana queue only works with raw string data, we must use Lua’s tostring() function to convert our outgoing messages before we can use the queue.push{} function to push them back onto the queue.

Tip: Since converting node trees into strings is such a common task, Iguana includes a “node” module that allows you to use the :S() method as a shorthand for tostring(). Curious? Check out this article: Using the :S() method as shorthand for tostring().

Sample Code

Here is a copy-and-paste version of the code so far:

function main(Data)
   -- (1) Parse the HL7 message
   local Msg, Name = hl7.parse{vmd = 'demo.vmd', data = Data}
   local Out = hl7.message{vmd = 'demo.vmd', name = Name}

   -- (2) Map the incoming message to the outgoing message
   Out.MSH:mapTree(Msg.MSH)
   Out.PID:mapTree(Msg.PID)

   -- (3) Alter the MSH segment data
   Out.MSH[3][1] = "First Steps"
   Out.MSH[4][1] = "Administration"
   trace(Out) 

   -- (4) Modify the PID data
   -- modify sex coding to use HL7 standard codes "M", "F", & "U"
   local Sex = Out.PID[8]:nodeValue()
   if Sex == 'female' then
      Out.PID[8] = 'F'
   elseif Sex == 'male' then
      Out.PID[8] = 'M'
   else
      Out.PID[8] = 'U' -- Unknown
   end

   -- (5) Push the outgoing message into the Iguana queue
   queue.push{data = tostring(Out)}
end

Congratulations! You’ve written your first working script! Let’s review what you’ve learned before moving on to Part Two of this tutorial.

Leave A Comment?