Search in sources :

Example 1 with ValidationRuleBuilder

use of ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder 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 ValidationRuleBuilder

use of ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder 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)

Aggregations

DefaultHapiContext (ca.uhn.hl7v2.DefaultHapiContext)2 ValidationRuleBuilder (ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder)2 HapiContext (ca.uhn.hl7v2.HapiContext)1 GenericParser (ca.uhn.hl7v2.parser.GenericParser)1 Parser (ca.uhn.hl7v2.parser.Parser)1 ValidationContext (ca.uhn.hl7v2.validation.ValidationContext)1 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1