HL7 Modules

Using the Translator as an LLP Client

Using the llp.lua module.

You can open TCP/IP connections inside the Translator. This allows things like:

  • Sending messages via the LLP protocol using Translator code instead of the built in LLP client component
  • Handling custom non LLP wrappings etc.

Part of the motivation for doing this may be for out of the box requirements. Say for instance you want log ACK messages, or mark a record in your database to indicate a message was ACKnowledged then this gives you the flexibility to handle these types of requirements.

The following module demonstrates how the Translator can be used to send messages over LLP and receive ACKs.

Sending and Receiving

The LLP module (written “llp”) has just one function, connect(), to open new LLP connections. You give it a table with the hostname (as “host”), port, and an optional “timeout” value (in seconds). If you don’t specify a timeout, all operations are given 5 seconds to complete.

local s = llp.connect{host='frink', port=8086, timeout=20}

Connect returns a table, s, with three functions: s:send(msg) for sending messages; s:recv() for receiving; and s:close() to close the connection.

local llp = require 'llp'

function main(Data)
   local s = llp.connect{host='frink',port=8086}
   local Ack = s:recv()

s:recv() actually returns two values: the message received and a lost-data string. If any data is sent before the LLP message-begin byte (0x0B), that data is placed in the lost-data string. Normally this string is empty, and is mainly useful for debugging LLP connections.

s:close() should be called before opening a new connection to the same location (unless you really want multiple connections). Many hosts will reject multiple connections, and most will become overwhelmed if you make too many. If s is stored globally (with a better name), it can be left open between calls to main(); verify that s is nil (if not s then…) before setting it to llp.connect().

local llp = require 'llp'
local s

function main(Data)
   local Success, Err = pcall(SendMessage, Data)
   if not Success then
      if s then s:close() end
      s = nil
      iguana.logInfo('Message not sent. Reason: '..Err)
      iguana.logInfo('Message sent successfully.')

function SendMessage(Msg)
   if not s then
      s = llp.connect{host='frink',port=8086,timeout=100,live=false}
   local Ack = s:recv()

Simulation and Live Testing

If you try out the above examples yourself, you may notice that no actual LLP connections are made. The LLP module contains a simulator that accepts HL7 messages and returns ACKs. This is provided to avoid accidentally sending test data out while editing your script.

If you want to work with live LLP connections inside the editor, you can enable them by passing live=true into your llp.connect() call.

local s = llp.connect{host='frink', port=8086, live=true}

Get the latest version of the llp.lua module from our repository.

Leave A Comment?