Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Say you have a text file with a bunch of HL7 messages. Each segment ends with \r. And each message ends with \n. Here’s the a sample file attached:

View file
namemessages.hl7

You could use the simulator component and feed it in via an HL7 Server - but honestly it’s probably easier to write you own little simple component and feed the data directly into the component you are testing.

Expand
titleUse a custom field for the input file name

See Custom Fields Here we use ~/test.txt for the default location of the input file. Take a look at Custom Fieldsif you haven’t already.

You access that the field with:

Code Block
languagelua
local FileNameF = component.fields()
Expand
titleRead in the file using the FIL library with FILread

The FIL libraryLibrary makes it really easy to inhale the file:

Code Block
languagelua
local Content = FILread("main.lua"F);
Expand
titleExamine the file contents in the translator - each segment ends in \r but the message ends with \n characters

We can easily see this by looking at the contents of the file using the Escaped Text escaped mode of:

Image Removed

The string viewing window

require "FIL.FILreadWrite" function main(Data) local F = component.fields().InputFile trace(F) local Content = FILread(F)

The List contains a Lua table as list with the messages.

Expand
titleThen we split the contents on the \n with local List = Content:split("\n")

See String:split(). So now our code looks like this:

Code Block
Code Block
languagelua
local List = Content:split("\n")
   trace(#List)    end
In the editor it looks like:
Image Removed

By double clicking of the list coming back we can we the list of messages:

Image Removed
Expand
titleWith a for loop we can push these messages into the queue:

See Lua tables table as listslist

Code Block
languagelua
for i=1, #List do
   queue.push{data=List[i]}
end

And now we have a working test component!

Expand
titleConnect it the component we want to test with - done!

See Linking components if you need a refresher.

Now for a little extra flourish:

Expand
titleAdd some custom logging

Let’s add some Custom Logging

Just added lines 7 and 11 to the script:

Code Block
languagelua
function main(Data)
   local F = component.fields().InputFile
   trace(F)
   local Content = FILread(F)
   local List = Content:split("\n")
   trace(#List)  
   iguana.logInfo("#start About to queue "..#List.." messages");
   for i=1, #List do
      queue.push{data=List[i]}
   end
   iguana.logInfo("#end Finished queueing "..#List.." messages");
end

Now we we run the script we can see custom logging:

Image Removed

See Concatenating strings for more on the “..“ notation to join strings together.

Expand
titleAnd some custom status

See Custom Status

Code Block
languagelua
require "FIL.FILreadWrite"

function Status(N, Total)
   component.setStatus{data="Sending "..N.." of "..Total}  
end

function StatusDone(Total)
   component.setStatus{data="Completed sending "..Total.." messages."}
end

function main(Data)
   local F = component.fields().InputFile
   trace(F)
   local Content = FILread(F)
   local List = Content:split("\n")
   trace(#List)  
   iguana.logInfo("#start About to queue "..#List.." messages");
   for i=1, #List do
      Status(i, #List)
      queue.push{data=List[i]}
   end
   StatusDone(#List)
   iguana.logInfo("#end Finished queueing "..#List.." messages");
end
Expand
titleLike a copy of the code?

The repository is here:

https://bitbucket.org/interfaceware/feeder/src/main/ - Git URL is git@bitbucket.org:interfaceware/feeder.git

See Create component from Git +FROM URL

Expand
titleCouple of videos showing the component in action

This shows using the component and the internals:

internals.mp4

And this one shows using the logs from the component:

logs.mp4

And now we have a simple tool that makes it easy to test our HL7 interfaces. But more importantly this exercise puts together a set of little concepts that once you grasp you can solve not only simple problems, but you can build up the skills to be able solve complex ones as well. There are no bottlenecks you cannot remove.