HL7Page edited by Martin KrasserChanges (3)
Full ContentHL7 ComponentThe hl7 component is used for working with the HL7 MLLP protocol and the HL7 model using the HAPI library. This component supports the following:
Maven users will need to add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-hl7</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
To use the data format, simply instantiate an instance and invoke the marhsal or unmarshl operation in the route builder: 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. 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. Notice there is a shorthand syntax in Camel for well-known data formats that is commonly used. from("direct:hl7in").marshal().hl7().to("jms:queue:hl7out"); from("jms:queue:hl7out").unmarshal().hl7().to("patientLookupService"); Message HeadersThe unmarshal operation adds these MSH fields as headers on the Camel message: Camel 1.x
Camel 2.0
All headers are String types. If a header value is missing, its value is null. OptionsThe HL7 Data Format supports the following options:
DependenciesTo 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). <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-hl7</artifactId> <version>2.2.0</version> </dependency> Since HAPI 0.6, the library has been split into a base library and several structures libraries, one for each HL7v2 message version:
By default camel-hl7 only references the HAPI base library. Applications are responsible for including structures libraries themselves. For example, if a application works with HL7v2 message versions 2.4 and 2.5 then the following dependencies must be added: <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-structures-v24</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-structures-v25</artifactId> <version>1.0</version> </dependency> OSGiAn OSGi bundle containing the base library, all structures libraries and required dependencies (on the bundle classpath) can be downloaded from the HAPI Maven repository as well. <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-osgi-base</artifactId> <version>1.0.1</version> </dependency> SamplesIn the following example we send a HL7 request to a HL7 listener and retrieves a response. We use plain String types in this example: String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4"; String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||"; StringBuilder in = new StringBuilder(); in.append(line1); in.append("\n"); in.append(line2); String out = (String)template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString()); 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 hl7service = for instance using Spring and letting the bean id = hl7service. Our business logic is a plain POJO only using the HAPI library so we have these operations defined: public class MyHL7BusinessLogic { // This is a plain POJO that has NO imports whatsoever on Apache Camel. // its a plain POJO only importing the HAPI library so we can much easier work with the HL7 format. public Message handleA19(Message msg) throws Exception { // here you can have your business logic for A19 messages assertTrue(msg instanceof QRY_A19); // just return the same dummy response return createADR19Message(); } public Message handleA01(Message msg) throws Exception { // here you can have your business logic for A01 messages assertTrue(msg instanceof ADT_A01); // just return the same dummy response return createADT01Message(); } } Then we set up the Camel routes using the RouteBuilder as follows: DataFormat hl7 = new HL7DataFormat(); // we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec") // we use the HL7 data format to unmarshal from HL7 stream to the HAPI Message model // this ensures that the camel message has been enriched with hl7 specific headers to // make the routing much easier (see below) .unmarshal(hl7) // using choice as the content base router .choice() // where we choose that A19 queries invoke the handleA19 method on our hl7service bean .when(header("CamelHL7TriggerEvent").isEqualTo("A19")) .beanRef("hl7service", "handleA19") .to("mock:a19") // and A01 should invoke the handleA01 method on our hl7service bean .when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01") .beanRef("hl7service", "handleA01") .to("mock:a19") // other types should go to mock:unknown .otherwise() .to("mock:unknown") // end choice block .end() // marhsal response back .marshal(hl7); Notice that we use the HL7 DataFormat to enrich our Camel Message with the MSH fields preconfigued on the Camel Message. This lets us much more easily define our routes using the fluent builders. Sample using plain String objectsIn this sample we use plain String objects as the data format, that we send, process and receive. As the sample is part of a unit test, there is some code for assertions, but you should be able to understand what happens. First we send the plain string, Hello World, to the HL7MLLPCodec and receive the response as a plain string, Bye World. MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Bye World"); // send plain hello world as String Object out = template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", "Hello World"); assertMockEndpointsSatisfied(); // and the response is also just plain String assertEquals("Bye World", out); Here we process the incoming data as plain String and send the response also as plain String: from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec") .process(new Processor() { public void process(Exchange exchange) throws Exception { // use plain String as message format String body = exchange.getIn().getBody(String.class); assertEquals("Hello World", body); // return the response as plain string exchange.getOut().setBody("Bye World"); } }) .to("mock:result"); See Also
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > HL7 confluence
- [CONF] Apache Camel > HL7 confluence