The Iguana Demo

Channel 4: Test Data Generator

This simple channel produces random HL7 ADT messages and places them into an external folder for the ’01-File to Socket’ channel to pick up and process. We added this channel to ensure that there is a constant stream of HL7 data running through your demo channels while they are active.

How It Works

The 04-Test Data Generator demo channel consists of the following components, each designed to perform a specific task:

Component Type Function
Source ‘From Translator'(script) Polls every 10000 ms (or 10 seconds) to produce a random ADT message and push it to the queue
Filter inactive n/a
Destination ‘To File’ Converts messages to .txt format and places them in an external folder using unique file names for each: iNTERFACEWARE/Iguana/Demo/Messages/

Every channels includes a Filter component; however, since we don’t need any filtering to perform this task, we have left it inactive (default).

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.

require 'node'
require 'ran'

Our first step is to import all the shared modules that we will need:

  • The ‘node’ module converts a node to a string (and escape any characters that need escaped)
  • The ‘ran’ module generates the ADT messages
function main()

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.


This line represents the only instructions we need. It triggers the ‘ran’ module and then pushes the results back into the queue.

This channel’s main script may seem pretty short, but there is a lot of code working under the hood. By putting all that code into its own reusable module (‘ran’), we make sharing and duplicating this task extremely easy. Now you don’t have to write the scripts out by hand; you can simply call the module in your main() function.

About the ‘ran’ module

Let’s walk through the ‘ran’ module to give you a better idea of how we generate random HL7 messages. To access this code, simply click on the module’s hyperlink in the Project Files panel:

ran = {}

This line creates a blank table that we will use to store our functions.

function ran.scrubMSH(MSH)
    MSH[3][1] = ran.choose(ran.Application)
    MSH[4][1] = ran.choose(ran.Facility)
    MSH[5][1] = 'Main HIS'
    MSH[6][1] = 'St. Micheals' 
    MSH[7][1] = ran.TimeStamp()
    MSH[9][1] = 'ADT'
    MSH[9][2] = ran.choose(ran.Event)
    MSH[10] = util.guid(256)
    MSH[11][1] = 'P'
    MSH[12][1] = '2.6'

This function creates the MSH segment.

function ran.scrubEVN(EVN)
    EVN[2][1] = ran.TimeStamp()
    EVN[6][1] = ran.TimeStamp()

This function creates the EVN segment by running the ‘TimeStamp’ function (defined below).

function ran.scrubPID(PID)
    PID[3][1][1] = math.random(9999999)
    PID[5][1][1][1] = ran.lastName()
    PID[7][1] = ran.Date()
    PID[10][1][1] = ran.choose(ran.Race)
    PID[18][1] = ran.AcctNo()
    PID[11][1][3], PID[11][1][4] = ran.location()
    PID[11][1][5] = math.random(99999)
    PID[11][1][1][1] = math.random(999)..
    ' '..ran.choose(ran.Street)
    PID[19] = ran.SSN()

This function creates the PID segment.

function ran.PV1(PV1)
    PV1[8][1][2][1] = ran.lastName()
    PV1[8][1][3] = ran.firstName()
    PV1[8][1][4] = 'F'
    PV1[19][1] = math.random(9999999)
    PV1[44][1] = ran.TimeStamp()

This function creates the PV1 segment.

function ran.NK1(NK1)
    for i = 1, math.random(6) do
        NK1[i][1] = i


This function uses the math.random() to create a random number of NK1 segment(s).

function ran.Kin(NK1)
    NK1[2][1][1][1] = ran.lastName()  
    NK1[2][1][2] = ran.firstName()
    NK1[3][1] = ran.choose(ran.Relation)

This function creates each unique next of kin records to populate the NK1 segments.

ran.Sex = {'M', 'F'}
ran.LastNames = {'Muir','Smith','Adams','Garland', 'Meade', 'Fitzgerald', 'WHITE'}
ran.MaleNames = {'Fred','Jim','Gary','John'}
ran.FemaleNames = {'Mary','Sabrina','Tracy'}
ran.Race = {'AI', 'EU', 'Mixed', 'Martian', 'Unknown'}
ran.Street = {'Delphi Cres.', 'Miller Lane', 'Yonge St.', 'Main Rd.'}
ran.Relation = {'Grandchild', 'Second Cousin', 'Sibling', 'Parent'}
ran.Event = {'A01', 'A03', 'A04', 'A05', 'A06', 'A07', 'A08'}
ran.Facility = {'Lab', 'E&R'}
ran.Application = { 'AcmeMed', 'MedPoke', 'CowZing' }
ran.Locations = { {'Chicago', 'IL'}, {'Toronto', 'ON'}, {'ST. LOUIS', 'MO'}, {'LA', 'CA'} }

These tables store the options that we randomly choose for the outgoing ADT message. You can add additional choices if you need to produce more HL7 transactions, or if you want alter their properties.

function ran.Date()
    local T ='*t')
    local newDate = '19'..rand(T.year,99,2)..
    return newDate
function rand(In, Max, Size)
    local Result = tostring((In + math.random(Max)) % Max)
    if '0' == Result then
        Result = '1'
    while Size > Result:len() do
        Result = '0'..Result
    return Result

These functions are used to randomly choose a date and time.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.