Easy HL7 with Saddle

If you're working in the Healthcare sector, you probably heard about HL7, the famous standard for healthcare informatics interoperability. You might know that Saddle provides an HL7 connector for Mule, but what we have today is a free, open-source, standalone, used through Java API or command line, HL7 Client and Server that will fit in all your use cases. You don't need Mule, another ESB, or anything (not even a Java project) to use it! Let's explore this.

Where can I find it?

Very easy: you have direct access to it in the download section.

HL7 Server

The server is highly configurable:

  • Change the listening port
  • Possibility to save the received data
  • Answer the client with:
    • fixed text
    • the content of a file
    • even your own code

Moreover, each request is handled in a separate thread so it will accept several simultaneous calls. We made it quite easy to use.

Using the command line

For a server running on the default port and answering the client with a file, simply run:

java -cp HL7Tester.jar lu.tudor.santec.hl7.HL7Server -file /home/user/Test/ACK.txt

To print all options, use the -h switch:

java -cp HL7Tester.jar lu.tudor.santec.hl7.HL7Server -h

This will give you the following:

Option Usage Default Description
-h

Prints the help information
-port Optional 4242 The port to listen to
-host Optional Machine default host The host to listen to
-file Conditional: either this or -text should be present
The file that the server will answer to the client
-text Conditional: either this or -file should be present
The fixed text that the server will answer to the client

Using the Java API

The Java API provides an important functionality over the command line: the possibility to use your own code to build the response that the server has to send. You simply write a class implementing the method buildHL7Response() from the interface lu.tudor.santec.hl7.HL7ResponseBuilder.

This method gets the data received as a parameter and returns the response as a String. A null return value will result in the server not responding at all. Let's see an example on how to use the server.

HL7Server server = new HL7Server(4242);
server.startUsingCustomResponse(new MyResponse());

For example purpose, here is a dummy implementation of MyResponse:

@Override
public String buildHL7Response(String arg0) {
    if("test".equals(arg0)) {
        return "It was just a test";
    } else {
        return "MSH|...";
    }
}

There are 3 possibilities for you to start the server:

Method Description
startUsingCustomResponse(HL7ResponseBuilder builder) Start the server and respond to the client using your custom code
startUsingFileResponse(String path) Start the server and respond to the client using the content of the file denoted by the path
startUsingTextResponse(String text) Start the server and respond to the client using a static text

Tip: if needed, you can start the server in a new Thread and later on, stop it gracefull using the shutdown() method.

Logging

If you want more information about what is coming inside or going outside your server, you can use the logger for the following:

Class Level Event
HL7Server info
Server listening on a port
HL7Request info Message the server received
HL7Request info Response the server send back

HL7 Client

The HL7 client basically sends a message and waits for the server to give the response. It's bundled with the following features:

  • Specify host and port
  • Define a timeout
  • Keep the socket open between different calls
  • Save the server response to a file
  • Send a file or a text

Using the command line

For a client running on default host and port, sending text and saving the server response:

java -cp HL7Tester.jar lu.tudor.santec.hl7.HL7Client -save /home/user/Test/testFromCLI.txt -text TestMessage

To print all options, use the -h switch:

java -cp HL7Tester.jar lu.tudor.santec.hl7.HL7Client -h

This will give you the following:

Option Usage Default Description
-h

Prints the help information
-host Optional 127.0.0.1 The host to contact
-port Optional 4242 The port to listen to
-file Conditional: either this or -text should be present
The file that the client will send
-text Conditional: either this or -file should be present
The fixed text that the client will send
-timeout Optional no timeout The client timeout
-save Optional no saving The path to the file where the server response will be saved

Using the Java API

The Java API provides the same possibilities as the command line, plus the sending method returns the response from the server. For example, in the following code we start a client on localhost, port 4000, and set a timeout of 5s:

HL7Client client = new HL7Client("127.0.0.1", 4000);
client.setTimeout(5000);
String result = client.sendText("This is a sample message");

There are 2 ways to call the server:

Method Description
sendText(String text) The sent message is a static text
sendFile(String path) The sent message is read from a file

Don't hesitate to look at the javadoc for more details.

Logging

You have the following logging possibilities:

Class Level Event
HL7Client info
Message the client sent
HL7Client info Message the client received
HL7Client fine The response has been saved to a file

 

We hope that this will help you with your healthcare use cases. Feel free to share any remarks or suggestions here or on our forum.

In the meantime, don't forget to have a look at our other standalone tool, for (very) easy file parsing and mapping. Again, no need for Mule (or any server/software), just a jar that you import in your Java project!

Add comment

Security code
Refresh