One of our clients came to us looking for a way to convert the text of an incoming message into a TIFF image (.tiff). We came up with a solution that allows you convert any message text (in part or as a whole) into any file format (not just TIFF):
- Create a channel that writes the incoming message to a system file.
- Apply a third party conversion program to convert the file.
- Place the finished conversion into an output folder.
Here’s the specific procedure:
- Download and install an appropriate third party conversion utility.For the code example that we provide below, we chose a free software download from SoftInterface that converts documents to image format (like TIFF). Their website offers a wide variety of conversion tools, should you be looking for other file formats.
- Create and configure a new channel with an LLP Listener source component and a To Translator destination component:Our client requested an LLP source component (that’s why we used it in this example). In reality, you could use any source component for the incoming messages.In this example, we decided to write our script using a Translator destination component. If your particular situation requires another destination component, you could simply add a filter to the channel and write your script there. It is entirely up to you.
- Open the Iguana Editor from the To Translator destination component and commit your first milestone.
- Copy and paste the following code into your script:
Note: The purpose of each section in this script is identified with notes right in the code.
--The main function is the first function called from Iguana. --The Data argument will contain the message to be processed. function main(Data) --Declare file and folder locations. --Use Global Variables for the Source and --Destination folders --Note the escaped back slashes. Source = "C:\\FileIn\\" Destination = 'C:\\FileOut\\' --Write Message to Text File by calling the writeFiles function local File = writeFiles(Data) --run command line util to create tiff Convert2Image(File) end function Convert2Image(F) --This function builds the command that calls the third party --program and then runs isn using the popen function. --Note the use of single and double quotes and escaped charaacters to make this work. --This example uses the CDTI program from SoftInterface. http://www.softinterface.com --SAMPLE Command -> CDTI.EXE /S "C:\InputCoffee.TXT" /F1 /T "C:\Output\Coffee.TIF" /C3 /1 * /5 200 /V local Cmd = 'C:/"Program Files (x86)"/"Softinterface, Inc"/"Convert Document To Image/"CDTI.EXE /S "'.. Source..F..'" /F1 /T "'..Destination..F:sub(1,-4)..'TIF" /C3 /1 * /5 200' local P = io.popen(Cmd) end function writeFiles(Msg) --This function creates a file using os.date and the length as a name. --and then opens it for write, wrties the message, and then closes it. --it returns the created filename. if Msg then FileName = os.date('%Y%m%d%H%M%S-'..Msg:len()..'.txt') local F = io.open(Source..FileName, "w") F:write(Msg) F:close() return FileName end end
In this example, we are converting the entire message; however, with this technique, you could also convert specific parts of an incoming message. For example, you could extract Radiology or Pathology reports out of a ORU message and instantly convert them into a PDF. The final file could be sent to a FTP or sFTP site rather than a local directory.
Note: If the resulting file is to be emailed or sent via web services, you’ll probably have to both encode and encrypt it.