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:
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 |
---|
title | Use 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 |
---|
| local FileName = component.fields() |
|
Expand |
---|
title | Read in the file using the FIL library with FILread |
---|
|
The FIL libraryLibrary makes it really easy to inhale the file: Code Block |
---|
| local Content = FILread("main.lua"); |
|
Expand |
---|
title | Examine 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 escaped mode of: The string viewing window |
Expand |
---|
title | Then we split the contents on the \n with local List = Content:split("\n") |
---|
|
See String:split(). The List contains a Lua table as list with the messages. Code Block |
---|
| local List = Content:split("\n")
trace(#List) |
|
Expand |
---|
title | With a for loop we can push these messages into the queue: |
---|
|
See Lua table as list Code Block |
---|
| for i=1, #List do
queue.push{data=List[i]}
end |
And now we have a working test component! |
...
Expand |
---|
title | Add some custom logging |
---|
|
Let’s add some Custom Logging Just added lines 7 and 11 to the script: Code Block |
---|
| 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 |
|
Expand |
---|
title | And some custom status |
---|
|
See Custom Status Code Block |
---|
| 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 |
|
...