Search in sources :

Example 6 with HapiContext

use of ca.uhn.hl7v2.HapiContext in project camel by apache.

the class HL7DataFormat method unmarshal.

public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
    byte[] body = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, inputStream);
    String charsetName = HL7Charset.getCharsetName(body, guessCharsetName(body, exchange));
    String bodyAsString = new String(body, charsetName);
    Message message = HL7Converter.parse(bodyAsString, parser);
    // add MSH fields as message out headers
    Terser terser = new Terser(message);
    for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
        exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
    }
    exchange.getOut().setHeader(HL7_CONTEXT, hapiContext);
    exchange.getOut().setHeader(Exchange.CHARSET_NAME, charsetName);
    return message;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Terser(ca.uhn.hl7v2.util.Terser) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with HapiContext

use of ca.uhn.hl7v2.HapiContext in project camel by apache.

the class HL7XmlDataFormatTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(new NoValidation());
    Parser p = new GenericParser(hapiContext);
    hl7 = new HL7DataFormat();
    hl7.setParser(p);
    return new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
            from("direct:unmarshalOkXml").unmarshal(hl7).to("mock:unmarshal");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser)

Example 8 with HapiContext

use of ca.uhn.hl7v2.HapiContext in project wildfly-camel by wildfly-extras.

the class HL7IntegrationTest method testMarshalUnmarshal.

@Test
@SuppressWarnings("resource")
public void testMarshalUnmarshal() throws Exception {
    final String msg = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";
    final HL7DataFormat format = new HL7DataFormat();
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(format).unmarshal(format).to("mock:result");
        }
    });
    camelctx.start();
    try {
        HapiContext context = new DefaultHapiContext();
        Parser p = context.getGenericParser();
        Message hapimsg = p.parse(msg);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Message result = (Message) producer.requestBody("direct:start", hapimsg);
        Assert.assertEquals(hapimsg.toString(), result.toString());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(ca.uhn.hl7v2.model.Message) HL7DataFormat(org.apache.camel.model.dataformat.HL7DataFormat) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Parser(ca.uhn.hl7v2.parser.Parser) Test(org.junit.Test)

Aggregations

DefaultHapiContext (ca.uhn.hl7v2.DefaultHapiContext)7 HapiContext (ca.uhn.hl7v2.HapiContext)7 Message (ca.uhn.hl7v2.model.Message)5 Parser (ca.uhn.hl7v2.parser.Parser)3 PipeParser (ca.uhn.hl7v2.parser.PipeParser)3 IOException (java.io.IOException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 CanonicalModelClassFactory (ca.uhn.hl7v2.parser.CanonicalModelClassFactory)2 GenericParser (ca.uhn.hl7v2.parser.GenericParser)2 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)2 InputStream (java.io.InputStream)2 Charset (java.nio.charset.Charset)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FlowFile (org.apache.nifi.flowfile.FlowFile)2 HapiMessage (org.apache.nifi.hl7.hapi.HapiMessage)2 HL7Message (org.apache.nifi.hl7.model.HL7Message)2 InputStreamCallback (org.apache.nifi.processor.io.InputStreamCallback)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1 Connection (ca.uhn.hl7v2.app.Connection)1