Search in sources :

Example 1 with HL7DataFormat

use of org.apache.camel.component.hl7.HL7DataFormat in project camel by apache.

the class HL7DataFormatAutoConfiguration method configureHL7DataFormatFactory.

@Bean(name = "hl7-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(HL7DataFormat.class)
public DataFormatFactory configureHL7DataFormatFactory(final CamelContext camelContext, final HL7DataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            HL7DataFormat dataformat = new HL7DataFormat();
            if (CamelContextAware.class.isAssignableFrom(HL7DataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with HL7DataFormat

use of org.apache.camel.component.hl7.HL7DataFormat in project quickstarts by jboss-switchyard.

the class CamelServiceRoute method configure.

/**
     * The Camel route is configured via this method.  The from endpoint is required to be a SwitchYard service.
     */
public void configure() {
    DataFormat hl7 = new HL7DataFormat();
    from("switchyard://HL7Route").unmarshal(hl7).process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            String body = exchange.getIn().getBody(String.class);
            PipeParser pipeParser = new PipeParser();
            try {
                // Parse the HL7 message 
                ca.uhn.hl7v2.model.Message message = pipeParser.parse(body);
                if (message instanceof QRY_A19) {
                    // Print out some details from the QRD
                    QRD qrd = (QRD) message.get("QRD");
                    System.out.println("Query Date/Time : " + qrd.getQueryDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Query Format Code : " + qrd.getQueryFormatCode().getValue());
                    System.out.println("Query Priority : " + qrd.getQueryPriority().getValue());
                    System.out.println("Query ID : " + qrd.getQueryID().getValue());
                    System.out.println("Deferred Response Type : " + qrd.getDeferredResponseType().getValue());
                    System.out.println("Deferred Response Date/Time : " + qrd.getDeferredResponseDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Quantity Limited Request : " + qrd.getQuantityLimitedRequest().getQuantity().getValue());
                    System.out.println("Query Results Level : " + qrd.getQueryResultsLevel().getValue());
                    qrd.getQueryID();
                }
            } catch (Exception e) {
                throw e;
            }
            SwitchYardMessage out = new SwitchYardMessage();
            out.setBody(body);
            exchange.setOut(out);
        }
    });
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Processor(org.apache.camel.Processor) PipeParser(ca.uhn.hl7v2.parser.PipeParser) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) Exchange(org.apache.camel.Exchange) DataFormat(org.apache.camel.spi.DataFormat) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) QRY_A19(ca.uhn.hl7v2.model.v24.message.QRY_A19)

Aggregations

HL7DataFormat (org.apache.camel.component.hl7.HL7DataFormat)2 QRY_A19 (ca.uhn.hl7v2.model.v24.message.QRY_A19)1 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 HashMap (java.util.HashMap)1 CamelContextAware (org.apache.camel.CamelContextAware)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 DataFormat (org.apache.camel.spi.DataFormat)1 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 SwitchYardMessage (org.switchyard.common.camel.SwitchYardMessage)1