Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAPI HL7 Validator does not validate parsed messages

Tags:

hl7

hapi

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.

like image 370
Yuriy Avatar asked Oct 28 '22 18:10

Yuriy


1 Answers

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

like image 78
Syl Avatar answered Nov 08 '22 11:11

Syl