Thank you! This helped.
My route ended up looking like this:
package org.mainegeneral.camel;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import ca.uhn.hl7v2.model.Message;
import org.apache.camel.builder.RouteBuilder;
import ca.uhn.hl7v2.util.Terser;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import java.util.Base64;
import org.apache.camel.spi.DataFormat;
import ca.uhn.hl7v2.parser.Parser;
public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("mllp://MGH16557:8888")
.log("..Received HL7 message with control id
${header.CamelMllpMessageControlId}")
.convertBodyTo(String.class)
.unmarshal()
.hl7(false)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn().getBody(Message.class);
ca.uhn.hl7v2.util.Terser terser = new Terser(message);
String obx5 = terser.get("/.OBX-5-5");
String EDMId = terser.get("/.OBR-3") + ".pdf";
String voucher = terser.get("/.OBR-2");
byte[] decoded = Base64.getDecoder().decode(obx5);
exchange.getOut().setBody(decoded);
exchange.getOut().setHeader("voucher", voucher);
exchange.getOut().setHeader("CamelFileName", EDMId );
}
} )
.log("..Processed voucher ${header.voucher} to file
${header.CamelFileName}")
.to("file:target/messages/others");
}
}
On Tuesday, June 19, 2018, 3:32:11 PM EDT, Quinn Stevenson
<[email protected]> wrote:
I’d have to work out all the XML syntax for this, but you should be able to
use the HAPI Terser ( <terser> element in the XML) to extract the field you
want.
I’d probably do this in a bean - it’s easy to do the HL7 Decode at that point.
Something like
String myMethod(@Body ca.uhn.hl7v2.model.Message hapiMessage) {
ca.uhn.hl7v2.util.Terser terser = new Terser(hapiMessage);
String obx5 = terser.get(“/OBX-5-5”);
String decoded = Base64.getDecoder().decode(obx5);
}
I know that the above probably won’t run (just made it up for the email) - but
hopefully it give’s you an idea.
> On Jun 19, 2018, at 8:06 AM, John F. Berry <[email protected]>
> wrote:
>
> I appologize.. Newbie here to the open source/project world. Long time
> programmer in other realms.
>
> I have a base64 encoded pdf that will be sent to me via HL7 in the OBX-5-5
> field of this message body that I need to decode and create an actual pdf
> file on a filesystem. I have tried various themes of attempting to access
> the unmarshalled structure, but that's where the trail gets cold.
> I haven't attached any "code" since it is more representative of thrashing to
> get some sort of result rather than intelligent design. I created two maven
> archetypes (Camel java DSL and Camel spring) and attempted to re-engineer the
> sample file read-decision-log-write route and take this one step at a time.
> Currently I can receive HL7, ACK, unmarshal, log the message body, marshal,
> and write to entire HL7 message to a file. I wish to receive the HL7, ACK,
> unmarshal, isolate OBX-5-5, decode it's contents back to binary, and write
> this to a new file on the file system with a filename and .pdf extension, and
> dispose of the HL7 message (end the route here).
> I've owned :"Camel in Action" for years now, but have not been able yet to
> apply it's wisdom to my situations. Perhaps a little hand-holding will help
> me see the landscape of this technology. I am missing something, as to what
> exactly, I've been struggling to figure out.
> So I've been parallel developing two maven projects, one Java DSL and one
> Spring. Here's the latest skeleton I have for the Spring version:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- Configures the Camel Context-->
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
>http://www.springframework.org/schema/beans/spring-beans.xsd
> http://camel.apache.org/schema/spring
>http://camel.apache.org/schema/spring/camel-spring.xsd">
>
> <bean id="hl7decoder"
> class="org.apache.camel.component.hl7.HL7MLLPNettyDecoderFactory"/>
> <bean id="hl7encoder"
> class="org.apache.camel.component.hl7.HL7MLLPNettyEncoderFactory"/>
> <!--<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec"/>
> -->
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>
> <endpoint id="hl7listener" uri="mllp://10.105.13.206:8888" />
> <route>
> <from uri="hl7listener"/>
> <convertBodyTo type="java.lang.String" />
> <unmarshal>
> <hl7 validate = "false" />
> </unmarshal>
> <log message="${body}" />
> <marshal><hl7 /> </marshal>
> <log message="Other message"/>
> <!-- <convertBodyTo type="java.lang.String"/> -->
> <to uri="file:target/messages/others"/>
> </route>
> </camelContext>
>
> </beans>
>
>
> Ideas? Thanks!
>