Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

HL7 DataFormat

The HL7 component ships with a HL7 data format that can be used to format between String and marshal or unmarshal HL7 model objects.

  • marshal = from Message to byte stream (can be used when

...

  • responding using the HL7 MLLP codec)
  • unmarshal = from byte stream to Message (can be used when receiving streamed data from the HL7 MLLP

To use the data format, simply instantiate an instance and invoke the marhsal marshal or unmarshl unmarshal operation in the route builder:

Code Block
java
java

  DataFormat hl7 = new HL7DataFormat();
  ...
  from("direct:hl7in").marshal(hl7).to("jms:queue:hl7out");

In the sample above, the HL7 is marshalled from a HAPI Message object to a byte stream and put on a JMS queue.
The next example is the opposite:

Code Block
java
java

  DataFormat hl7 = new HL7DataFormat();
  ...
  from("jms:queue:hl7out").unmarshal(hl7).to("patientLookupService");

Here we unmarshal the byte stream into a HAPI Message object that is passed to our patient lookup service.

Tip
titleSerializable messages

As of HAPI 2.0 (used by Camel 2.11), the HL7v2 model classes are fully serializable. So you can put HL7v2 messages directly into a JMS queue (i.e. without calling marshal() and read them again directly from the queue (i.e. without calling unmarshal().

Note
titleSegment separators

As of Camel 2.11, unmarshal does not automatically fix segment separators anymore by converting \n to \r. If you
need this conversion, org.apache.camel.component.hl7.HL7#convertLFToCR provides a handy Expression for this purpose.

Note
titleCharset

As of Camel 2.14.1, both marshal and unmarshal evaluate the charset provided in the field MSH-18. If this field is empty, by default the charset contained in the corresponding Camel charset property/header is assumed. You can even change this default behavior by overriding the guessCharsetName method when inheriting from the HL7DataFormat class.

 

There Notice there is a shorthand syntax in Camel for well-known data formats that is are commonly used.
Then you don't need to create an instance of the HL7DataFormat object:

Code Block
java
java

  from("direct:hl7in").marshal().hl7().to("jms:queue:hl7out");
  from("jms:queue:hl7out").unmarshal().hl7().to("patientLookupService");

Message Headers

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

Camel 1.x

Key

MSH field

Example

hl7.msh.sendingApplication

MSH-3

MYSERVER

hl7.msh.sendingFacility

MSH-4

MYSERVERAPP

hl7.msh.receivingApplication

MSH-5

MYCLIENT

hl7.msh.receivingFacility

MSH-6

MYCLIENTAPP

hl7.msh.timestamp

MSH-7

20071231235900

hl7.msh.security

MSH-8

null

hl7.msh.messageType

MSH-9-1

ADT

hl7.msh.triggerEvent

MSH-9-2

A01

hl7.msh.messageControl

MSH-10

1234

hl7.msh.processingId

MSH-11

P

hl7.msh.versionId

MSH-12

2.4

Camel 2.0

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

All headers are String types. If a header value is missing, its value is null.

Options

The HL7 Data Format supports the following options:

Option

Default

Description

validate

true

Camel 2.0: Whether the HAPI Parser should validate.

Dependencies

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

If you use Maven, you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

...