5

The scenario when I parse and validate HL7 message at once works as expected:

HapiContext hapiContext = new DefaultHapiContext(); PipeParser parser = hapiContext.getPipeParser(); Message message = parser.parse("MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.5\r" + "EVN|A31|200903230934345345345345345\r" + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||"); 

Exception (this is a valid behavior):

Exception in thread "main" ca.uhn.hl7v2.model.DataTypeException: ca.uhn.hl7v2.validation.ValidationException: Validation failed: Primitive value '200903230934345345345345345' requires to be empty or a HL7 datetime string at EVN-2(0) 

But when I try first to parse HL7 message and then validate - validation method returns true and no exceptions are thrown:

HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext((ValidationContext) ValidationContextFactory.noValidation()); PipeParser parser = hapiContext.getPipeParser(); Message message = parser.parse("MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.5\r" + "EVN|A31|200903230934345345345345345\r" + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||"); hapiContext.setValidationRuleBuilder(new DefaultValidationBuilder()); System.out.println(hapiContext.getMessageValidator().validate(message)); 

I need this to generate Acknowledgment messages in case validation fails using message.generateACK() method.

1 Answer 1

4
+25

You disabled validation for parsing with this:

hapiContext.setValidationContext((ValidationContext) ValidationContextFactory.noValidation());

But you are using the same context to validate your message, with validation still disable, that may be the root cause.

Also, did you try this? context.getParserConfiguration().setValidating(false); or true

Sign up to request clarification or add additional context in comments.

1 Comment

1) when I disable validation, I enable it back with setValidationRuleBuilder. Internally it calls setValidationContext, so a different context is used. 2) setValidating(false) instead of setValidationContext(noValidation) disables the validation, but when I set it to true in the next line and call hapiContext.getMessageValidator().validate(message) - it still returns true, no validation exception is thrown.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.