The Iguana Demo

Channel 1: File to Socket

As the basic building block for most interface design, the ability to deliver data from one location to another is a vital integration task. Thanks to Iguana, this task is not only easy to do, but also easy to customize should you need to make tweaks during the delivery process.

This demo channel is designed to demonstrate exactly how this process works.

How It Works

The 01-File to Socket demo channel consists of the following components, each designed to perform a specific task:

Component Type Function
Source ‘From File’ Read raw message data currently stored in an external file directory: iNTERFACEWARE/Iguana/Demo/Messages/
Filter (script) For each incoming message:

  1. Parse the raw data to identify individual messages and fields.
  2. Change each message’s ‘Sending Application’ field (MSH-3) to “MYDEMO”.
  3. Convert altered messages back into raw string format.
  4. Push the string data back into the queue.
Destination ‘To LLP’ For each message:

  1. Pick up the raw string data from the queue.
  2. Package and send the data out to a specific port via TCP/IP: port number 5145 (local)

Understanding the Code

If you are having difficulty understanding this channel’s code, don’t panic. This section explains each line of the script to help you get better oriented.

function main(RawMsgIn)

The main() function is the primary function that Iguana calls when running a script. The rest of your code simply defines the tasks that main() is in charge of executing. In this demo, the main() function receives the incoming raw data (in the format of a string). Any parameter name will work here, but we chose ‘RawMsgIn’.

Note: When writing scripts in the Translator, your sample data will treated as the incoming data.

iguana.stopOnError(false)

Although Iguana will log any errors as usual, this simple Iguana runtime utility ensures that your channel will not stop running.

local MsgIn, MsgType  = hl7.parse{vmd='hl7_demo.vmd', data=RawMsgIn}

This function is responsible for converting the incoming data from a raw string into a node tree. This makes each HL7 message much easier to identify, alter, and map.

To correctly parse the raw data, this function relies on VMD files for guidance. VMD files act as templates that help Iguana correctly identify HL7 messages, segments, and fields from the incoming stream.

local MsgOut = hl7.message{vmd='hl7_demo.vmd', name=MsgType}

In this demo, we will be altering the incoming messages before delivering them back out again. As such, we need a blank slate where we can store the new, altered messages that we create. This function uses a VMD file to create a new blank message, ready for data.

MsgOut:mapTree(MsgIn)

The mapTree() function is a great way to quickly move each leaf or data point from the inbound message to our new outbound message.

MsgOut.MSH[3][1] = 'MyDEMO'

We use this line of code to perform our alteration. Specifically, we want to hard-code every message’s ‘Sending Application’ field (MSH-3) with the value ‘MyDemo’.

-- MsgOut.MSH[12][1] = '2.7'
-- MsgOut.MSH[5][1] = MsgIn.MSH[6][1]

To give you a better idea of how tweaks like this work, we’ve included some additional examples. To see them in action, simply “uncomment” each line by removing the dashes in front of them.

  • The first example hard-codes each message’s ‘Version ID’ field (MSH-12) with the value ‘2.7’. You can change this value to anything you like.
  • The second example maps each incoming message’s ‘Receiving Facility’ field (MSH-6) to the outbound message’s ‘Receiving Application’ field (MSH-5).

Feel free to play around with these values until you are more comfortable with the concept.

local RawMsgOut = tostring(MsgOut)

Now that the desired changes have been made, we need to revert the results back into a string. Why? Because Iguana’s queue can only handle raw string data. The to string() function is exactly what we need: a basic Lua command that converts node trees back into string format.

queue.push{data=RawMsgOut}

You must always push data back into the queue to complete the process. Once back in the queue, your data can travel along the pipeline to the next component in the channel (in this case, the ‘To LLP’ Destination component).