Search in sources :

Example 1 with DefaultHapiContext

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

the class HL7ValidateTest 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);
    /*
         * Let's start by adding a validation rule to the default validation
         * that disallows PID-2 to be empty.
         */
    ValidationRuleBuilder builder = new ValidationRuleBuilder() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configure() {
            forVersion(Version.V24).message("ADT", "*").terser("PID-2", not(empty()));
        }
    };
    ValidationContext customValidationContext = ValidationContextFactory.fromBuilder(builder);
    HapiContext customContext = new DefaultHapiContext(customValidationContext);
    final Parser customParser = new GenericParser(customContext);
    return new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
            from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
            from("direct:unmarshalOkCustom").unmarshal(hl7).to("mock:unmarshal");
            from("direct:start1").marshal().hl7(customParser).to("mock:end");
            from("direct:start2").marshal().hl7(true).to("mock:end");
        }
    };
}
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) ValidationRuleBuilder(ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext)

Example 2 with DefaultHapiContext

use of ca.uhn.hl7v2.DefaultHapiContext 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 3 with DefaultHapiContext

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

the class MessageValidatorTest method doPreSetup.

@Override
protected void doPreSetup() throws Exception {
    defaultValidationContext = ValidationContextFactory.defaultValidation();
    defaultContext = new DefaultHapiContext(defaultValidationContext);
    // we validate separately, not during parsing or rendering
    defaultContext.getParserConfiguration().setValidating(false);
    ValidationRuleBuilder builder = new ValidationRuleBuilder() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configure() {
            forVersion(Version.V24).message("ADT", "A01").terser("PID-8", not(empty()));
        }
    };
    customValidationContext = ValidationContextFactory.fromBuilder(builder);
    customContext = new DefaultHapiContext(customValidationContext);
    // we validate separately, not during parsing or rendering
    customContext.getParserConfiguration().setValidating(false);
}
Also used : DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) ValidationRuleBuilder(ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder)

Example 4 with DefaultHapiContext

use of ca.uhn.hl7v2.DefaultHapiContext in project streamsx.health by IBMStreams.

the class TestServer method main.

public static void main(String[] args) {
    try {
        HapiContext ctx = new DefaultHapiContext();
        CanonicalModelClassFactory mcf = new CanonicalModelClassFactory("2.6");
        ctx.setModelClassFactory(mcf);
        ctx.setValidationRuleBuilder(new NoValidationBuilder());
        ctx.setExecutorService(Executors.newCachedThreadPool());
        HL7Service server = ctx.newServer(8082, false);
        server.registerApplication(new HapiMessageHandler(null));
        server.registerConnectionListener(new ConnectionListener() {

            @Override
            public void connectionReceived(Connection c) {
                System.out.println("Connection received.");
            }

            @Override
            public void connectionDiscarded(Connection c) {
                System.out.println("Connection discarded.");
            }
        });
        server.startAndWait();
        ctx.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : NoValidationBuilder(ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) HL7Service(ca.uhn.hl7v2.app.HL7Service) Connection(ca.uhn.hl7v2.app.Connection) ConnectionListener(ca.uhn.hl7v2.app.ConnectionListener) IOException(java.io.IOException) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) CanonicalModelClassFactory(ca.uhn.hl7v2.parser.CanonicalModelClassFactory)

Aggregations

DefaultHapiContext (ca.uhn.hl7v2.DefaultHapiContext)4 HapiContext (ca.uhn.hl7v2.HapiContext)3 GenericParser (ca.uhn.hl7v2.parser.GenericParser)2 Parser (ca.uhn.hl7v2.parser.Parser)2 ValidationRuleBuilder (ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder)2 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Connection (ca.uhn.hl7v2.app.Connection)1 ConnectionListener (ca.uhn.hl7v2.app.ConnectionListener)1 HL7Service (ca.uhn.hl7v2.app.HL7Service)1 CanonicalModelClassFactory (ca.uhn.hl7v2.parser.CanonicalModelClassFactory)1 ValidationContext (ca.uhn.hl7v2.validation.ValidationContext)1 NoValidationBuilder (ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder)1 IOException (java.io.IOException)1