HAPI HL7 Validator does not check parsed messages

The scenario when analyzing and checking the HL7 message immediately 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 to parse the HL7 message first and then check - the check 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 confirmation messages in case the verification is not performed using the message.generateACK () method.

+5
source share
1 answer

You have disabled validation for parsing with this:

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

But you use the same context to check your message, in which the check is not yet disabled, which may be the main reason.

Also, have you tried this? context.getParserConfiguration().setValidating(false); or true

+1
source

Source: https://habr.com/ru/post/1275363/


All Articles