jL7: How to send an HL7 message

We’ll now see how we can send an HL7 message using jL7.
Let’s assume we already have an HL7 message object:

                HL7Message msg = HL7Parser.parseMessage("...", true);

Now we need to create an MLLPTransportable object. This object basically encapsulates the information need to send the message: the message itself the hostname and port number where it should be sent to

                MLLPTransportable transportable = new MLLPTransportable();
                transportable.message = msg;
                transportable.metaData = new MLLPMetaData(host, port);

Now we use an MLLPTransport object in order to actually send this newly created transportable object:

                MLLPTransport transport = new MLLPTransport();
                try {
                } catch (IOException e) {
                        fail("IOException: " + e);

Since the transport object retains the connection to the remote host after sending the message (we do not want to create x connections in order to send x messages in a row), we should close the connection when we’re done with the transport object:

                try {
                } catch (IOException e) {
                        // TODO Auto-generated catch block

That’s it !

Leave a Reply

Your email address will not be published. Required fields are marked *