Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Maven users will need to add the following dependency to their pom.xml for this component:

...

HL7 MLLP protocol

HL7 is often used with the HL7 MLLP protocol, which is a text based TCP socket based protocol. This component ships with a Mina and Netty4 Codec that conforms to the MLLP protocol so you can easily expose an HL7 listener accepting HL7 requests over the TCP transport layer. To expose a HL7 listener service, the camel-mina2 or camel-netty4 component is used with the HL7MLLPCodec (mina2) or HL7MLLPNettyDecoder/HL7MLLPNettyEncoder (Netty4).

...

Name

Default Value

Description

startByte

0x0b

The start byte spanning the HL7 payload.

endByte1

0x1c

The first end byte spanning the HL7 payload.

endByte2

0x0d

The 2nd end byte spanning the HL7 payload.

charset

JVM Default

The encoding (a charset name) to use for the codec. If not provided, Camel will use the JVM default Charset.

produceString

true(as of Camel 2.14.1) If true, the codec creates a string using the defined charset. If false, the codec sends a plain byte array into the route, so that the HL7 Data Format can determine the actual charset from the HL7 message content.

convertLFtoCR

falseWill convert \n to \r (0x0d, 13 decimal) as HL7 stipulates \r as segment terminators. The HAPI library requires the use of \r.

...

In the Spring XML file, we configure a mina2 endpoint to listen for HL7 requests using TCP on port 8888:

...

...

sync=true indicates that this listener is synchronous and therefore will return a HL7 response to the caller. The HL7 codec is setup with codec=#hl7codec. Note that hl7codec is just a Spring bean ID, so it could be named mygreatcodecforhl7 or whatever. The codec is also set up in the Spring XML file:

...

The endpoint hl7MinaLlistener 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. This is also Spring bean ID, configured in the Spring XML as:

...

The business logic can be implemented in POJO classes that do not depend on Camel, as shown here:

...

...

Exposing an HL7 listener using Netty (available from Camel 2.15 onwards)

In the Spring XML file, we configure a netty4 endpoint to listen for HL7 requests using TCP on port 8888:

...

...

sync=true indicates that this listener is synchronous and therefore will return a HL7 response to the caller. The HL7 codec is setup with encoder=#hl7encoder and decoder=#hl7decoder. Note that hl7encoder and hl7decoder are just bean IDs, so they could be named differently. The beans can be set in the Spring XML file:

...

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

...

...

HL7 Model using java.lang.String or byte[]

...

The sample below is a request to lookup a patient with the patient ID 0101701234.

...

Using the HL7 model you can work with a ca.uhn.hl7v2.model.Message object, e.g. to retrieve a patient ID:

...

...

This is powerful when combined with the HL7 listener, because you don't have to work with byte[], String or any other simple object formats. You can just use the HAPI HL7v2 model objects. If you know the message type in advance, you can be more type-safe:

...

...

 

  Include PageHL7 DataFormat

HL7 DataFormat

Message Headers

The unmarshal operation adds these fields from the MSH segment as headers on the Camel message:

...

Key

MSH field

Example

CamelHL7SendingApplication

MSH-3

MYSERVER

CamelHL7SendingFacility

MSH-4

MYSERVERAPP

CamelHL7ReceivingApplication

MSH-5

MYCLIENT

CamelHL7ReceivingFacility

MSH-6

MYCLIENTAPP

CamelHL7Timestamp

MSH-7

20071231235900

CamelHL7Security

MSH-8

null

CamelHL7MessageType

MSH-9-1

ADT

CamelHL7TriggerEvent

MSH-9-2

A01

CamelHL7MessageControl

MSH-10

1234

CamelHL7ProcessingId

MSH-11

P

CamelHL7VersionId

MSH-12

2.4

CamelHL7Context
-

(Camel 2.14) contains the HapiContext that
was used to parse the message

CamelHL7CharsetMSH-18(Camel 2.14.1)
UNICODE UTF-8

...

The HL7 Data Format supports the following options:

...

...

Option

Default

Description

validate

true

Whether the HAPI Parser should validate the message using the default validation rules. It is recommended to use the parser or hapiContext option and initialize it with the desired HAPI ValidationContext

parser

ca.uhn.hl7v2.parser.GenericParser

Custom parser to be used. Must be of type ca.uhn.hl7v2.parser.Parser. Note that GenericParser also allows to parse XML-encoded HL7v2 messages

hapiContextca.uhn.hl7v2.DefaultHapiContextCamel 2.14: Custom HAPI context that can define a custom parser, custom ValidationContext etc. This gives you full control over the HL7 parsing and rendering process.

Dependencies

To use HL7 in your Camel routes you'll need to add a dependency on camel-hl7 listed above, which implements this data format.

...

By default camel-hl7 only references the HAPI base library. Applications are responsible for including structure libraries themselves. For example, if an application works with HL7v2 message versions 2.4 and 2.5 then the following dependencies must be added:

...

...

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

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.

Sample:

...

...

HL7 Validation predicate

Often it is preferable to first parse a HL7v2 message and in a separate step validate it against a HAPI ValidationContext.

Sample:

...

...

HL7 Validation predicate using the HapiContext (Camel 2.14)

The HAPI Context is always configured with a ValidationContext (or a ValidationRuleBuilder), so you can access the validation rules indirectly. Furthermore, when unmarshalling the HL7DataFormat forwards the configured HAPI context in the CamelHL7Context header, and the validation rules of this context can be easily reused:

...

...

 

HL7 Acknowledgement expression

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 ack expression lets us accomplish this very elegantly:

...

More Samples

In the following example, a plain String HL7 request is sent to an HL7 listener that sends back a response:

...

...

In the next sample, HL7 requests from the HL7 listener are routed to the business logic, which is implemented as plain POJO registered in the registry as hl7service.

...

...

Then the Camel routes using the RouteBuilder may look as follows:

...

Note that by using the HL7 DataFormat the Camel message headers are populated with the fields from the MSH segment. The headers are particularly useful for filtering or content-based routing as shown in the example above.

  Include PageEndpoint See Also

Endpoint See Also