HL7 MLLP protocol - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

HL7 is often used with the HL7 MLLP protocol that is a text based TCP socket based protocol. This component ships with a Mina Codec that conforms to the MLLP protocol so you can easily expose a HL7 listener that accepts HL7 requests over the TCP transport. To expose a HL7 listener service we reuse the existing Camel Mina or Mina2 components where we just use HL7MLLPCodec as codec.

The HL7 MLLP codec has the following options:

Name

Default Value

Description

startByte0x0bThe start byte spanning the HL7 payload.
endByte10x1cThe first end byte spanning the HL7 payload.
endByte20x0dThe 2nd end byte spanning the HL7 payload.
charsetJVM DefaultThe charset name encoding to use for the codec. If not provided, Camel will use the JVM default Charset.
convertLFtoCRtrue (Camel 2.11: false )Will convert \n to \r (0x0d, 13 decimal) as HL7 usually uses \r as segment terminators. The HAPI library requires the use of \r. Default value of true pre-Camel 2.11, false starting with Camel 2.11.
validatetrueWhether HAPI Parser should validate or not.
parserca.uhn. hl7v2. parser. PipeParserStarting with Camel 2.11, to use a custom parser. Must be of type ca.uhn.hl7v2.parser.Parser.

Exposing a HL7 listener

In our Spring XML file, we configure an endpoint to listen for HL7 requests using TCP:

<endpoint id="hl7listener" 
   uri="mina:tcp://localhost:8888?sync=true&codec=#hl7codec"/>
   <!-- for Camel 2.11: use uri="mina2:tcp..." -->   

Notice that we use TCP on localhost on port 8888. We use sync=true to indicate that this listener is synchronous and therefore will return a HL7 response to the caller. Then we setup Mina to use our HL7 codec with codec=#hl7codec. Notice that hl7codec is just a Spring bean ID, so we could have named it mygreatcodecforhl7 or whatever. The codec is also set up in the Spring XML file:

<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
   <property name="charset" value="iso-8859-1"/>
</bean>

And here we configure the charset encoding to use, and iso-8859-1 is commonly used.

The endpoint hl7listener can then be used in a route as a consumer, as this java DSL example illustrates:

from("hl7listener").to("patientLookupService");

This is a very simple route that will listen for HL7 and route it to a service named patientLookupService that is also a Spring bean ID we have configured in the Spring XML as:

<bean id="patientLookupService" 
   class="com.mycompany.healtcare.service.PatientLookupService"/>

Another powerful feature of Camel is that we can have our business logic in POJO classes that is not tied to Camel as shown here:

import ca.uhn.hl7v2.HL7Exception; 
import ca.uhn.hl7v2.model.Message; 
import ca.uhn.hl7v2.model.v24.segment.QRD;
            
public class PatientLookupService {
   public Message lookupPatient(Message input) throws HL7Exception {
      QRD qrd = (QRD)input.get("QRD");
      String patientId = 
         qrd.getWhoSubjectFilter(0).getIDNumber().getValue();

      // find patient data based on the patient id and 
      // create a HL7 model object with the response
      Message response = ... create and set response data
      return response;
   }
}

Notice that this class uses imports from the HAPI library and not from Camel.