iNTERFACEWARE Products Manual > Installing and Using Chameleon > Using Python Scripting > Python Scripting Examples > Message Manipulation > Using HL7 Messages To Send PDFs and Other Binary Files |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
If you need to send a PDF file, an image, or any other binary file to another HL7 application, you can use Chameleon to encode the binary file as a string and transmit it as a segment field of an HL7 message. To do this, you must add the following to your VMD file:
The following Python script reads a binary file, converts it to a string, and defines it to be the value of a segment field:
In this code, the mybinaryfile.pdf file is read (in its entirety) into the line variable. The function encodestring() then converts this into string format. The result is assigned to value, which is the special Python variable that represents the value of the segment field. The next step is to write a Transformation Script that calls this Segment Outbound script:
This Transformation Script calls apply_transform() to run all of the segment scripts that you have defined, including the one shown above. For this method to work, your receiving application must be able to process the HL7 message that you have created. In particular, it must be able to convert the field containing the encoded information back to the original binary file. If the receiving application uses Chameleon to receive its incoming message, the following Python script can be used to convert the field to a binary file:
|