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");
}
};
}
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);
}
Aggregations