148.11. HL7 검증 서술자 HapiContext (Camel 2.14)
HAPI Context는 항상 ValidationContext (또는 ValidationRuleBuilder)로 구성되므로 유효성 검사 규칙에 간접적으로 액세스할 수 있습니다. 또한 HL7DataFormat을 unmarshalling하면 CamelHL7Context 헤더에서 구성된 HAPI 컨텍스트를 전달하고 이 컨텍스트의 검증 규칙을 쉽게 재사용할 수 있습니다.
import static org.apache.camel.component.hl7.HL7.messageConformsTo;
import static org.apache.camel.component.hl7.HL7.messageConforms
HapiContext hapiContext = new DefaultHapiContext();
hapiContext.getParserConfiguration().setValidating(false); // don't validate during parsing
// customize HapiContext some more ... e.g. enforce that PID-8 in ADT_A01 messages of version 2.4 is not empty
ValidationRuleBuilder builder = new ValidationRuleBuilder() {
@Override
protected void configure() {
forVersion(Version.V24)
.message("ADT", "A01")
.terser("PID-8", not(empty()));
}
};
hapiContext.setValidationRuleBuilder(builder);
HL7DataFormat hl7 = new HL7DataFormat();
hl7.setHapiContext(hapiContext);
from("direct:test1")
.unmarshal(hl7) // uses the GenericParser returned from the HapiContext
.validate(messageConforms()) // uses the validation rules returned from the HapiContext
// equivalent with .validate(messageConformsTo(hapiContext))
// route continues from here