Stream: implementers
Topic: V2
Aditya Joshi (Apr 06 2020 at 14:09):
HAPI V2 Default validator question. Hi @James Agnew Any help would be great. thanks.
one quick question regarding capability of HAPI V2 Default validator. In below code, there are many errors in message but default validator is not picking up anyone of them.
What all we can validate with default validator?
The below code is picked up from- https://hapifhir.github.io/hapi-hl7v2/xref/ca/uhn/hl7v2/examples/MessageValidation.html
just added my own message.
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.impl.ValidationContextFactory;
public class MessageValidation {
/** * @param args * @throws HL7Exception * @throws ca.uhn.hl7v2.parser.EncodingNotSupportedException */ public static void main(String[] args) throws HL7Exception { HapiContext context = new DefaultHapiContext(); /* * The default validation includes a number of sensible defaults including maximum lengths * on string types, formats for telephone numbers and timestamps, etc. */ context.setValidationContext(ValidationContextFactory.defaultValidation()); PipeParser parser = context.getPipeParser(); /* * Errors in below invalidMessage1: * a. PID-3 is required but missing * b. ORC-1 field must have max two characters code and that too coming from HL7 table 0119. it must not have any components * c. OBR-4 is required but missing * d. OBX-2 having NM^ST as value. The data type of this field is ID and not allow to have components * With all above issues, validator is still parsing the message successfully. */ String invalidMessage= "MSH|^~\\&|Echosens.GateWay||||202002061359||ORU^R01|1234|D|2.3\r\n" +"PID|1|CPHC0011||789987|Deo^Sachin||20150319|male||\r\n" +"ORC|XYZ^abc|||||||||||||||||||\r\n" +"OBR|||||||202002061359|||||||||||||||202002061359|||||\r\n" +"OBX||NM^ST|81894-8^CAP||180|dB/m|100-260|||N|F|||20200206185936|BN\r\n" +"OBX||NM|77615-3^E||5.4|kPa|||||F|||20200206185936|BN\r\n"; // Let's try parsing the invalid message: try { parser.parse(invalidMessage); System.out.println("Successfully parsed valid message"); } catch (HL7Exception e) { // This time, we are expecting an exception, because the message // should fail validation. System.out.println("As expected, the message did not validate: " + e.getMessage()); } }
}
James Agnew (Apr 06 2020 at 15:29):
HAPI HL7v2's validator only handles syntactic validation (i.e. are values conformant with their datatypes and that kind of thing).
For more robust validation you'd need to use conformance profiles, whch TBH I haven't looked at in years...
Last updated: Apr 12 2022 at 19:14 UTC