This component supports the following:
Maven users will need to add the following dependency to their
HL7 MLLP protocol
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 mina/mina2 component where we just use the
The HL7 MLLP codec has the following options:
Exposing a HL7 listener
In our Spring XML file, we configure an endpoint to listen for HL7 requests using TCP:
Notice that we use TCP on
Above we also configure the charset encoding to use (
The endpoint hl7listener can then be used in a route as a consumer, as this Java DSL example illustrates:
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:
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:
Notice that this class uses just imports from the HAPI library and not from Camel.
HL7 Model using java.lang.String
The HL7MLLP codec uses plain
See samples for such an example.
HL7v2 Model using HAPI
The HL7v2 model uses Java objects from the HAPI library. Using this library, we can encode and decode from the EDI format (ER7) that is mostly used with HL7v2.
The sample below is a request to lookup a patient with the patient ID
Using the HL7 model we can work with the data as a
If you know the message type in advance, you can be more type-safe:
Camel has built-in type converters, so when this operation is invoked:
Camel will convert the received HL7 data from
The HL7 component ships with a HL7 data format that can be used to format between
To use the data format, simply instantiate an instance and invoke the marshal or unmarshal operation in the route builder:
In the sample above, the HL7 is marshalled from a HAPI Message object to a byte stream and put on a JMS queue.
Here we unmarshal the byte stream into a HAPI Message object that is passed to our patient lookup service.
Notice there is a shorthand syntax in Camel for well-known data formats that is commonly used.
The unmarshal operation adds these MSH fields as headers on the Camel message:
All headers are
The HL7 Data Format supports the following options:
To use HL7 in your Camel routes you'll need to add a dependency on camel-hl7 listed above, which implements this data format.
The HAPI library since Version 0.6 has been split into a base library and several structure libraries, one for each HL7v2 message version:
Alternatively, an OSGi bundle containing the base library, all structures libraries and required dependencies (on the bundle classpath) can be downloaded from the central Maven repository.
Terser language (Camel 2.11)
HAPI provides a Terser class that provides access to fields using a commonly used terse location specification syntax. The Terser language allows to use this syntax to extract values from messages and to use them as expressions and predicates for filtering, content-based routing etc.
HL7 Validation predicate (Camel 2.11)
Often it is preferable to parse a HL7v2 message and validate it against a HAPI ValidationContext in a separate step afterwards.
HL7 Acknowledgement expression (Camel 2.11)
A common task in HL7v2 processing is to generate an acknowledgement message as response to an incoming HL7v2 message, e.g. based on a validation result. The
In the following example we send a HL7 request to a HL7 listener and retrieves a response. We use plain
In the next sample, we want to route HL7 requests from our HL7 listener to our business logic. We have our business logic in a plain POJO that we have registered in the registry as
Our business logic is a plain POJO only using the HAPI library so we have these operations defined:
Then we set up the Camel routes using the
Notice that we use the HL7 DataFormat to enrich our Camel Message with the MSH fields preconfigured on the Camel Message. This lets us much more easily define our routes using the fluent builders.
Sample using plain String objects
In this sample we use plain
Here we process the incoming data as plain String and send the response also as plain String: