1

Need to Validate HL7 V2 ADT_A01 version 3 message against a Conformance XML Profile for the same version

I have a Java program that validates the message against the XML, but I am getting a few errors. I cannot proceed further without solving them.

public static void main(String[] args) throws Exception {

    try {

      // Load the conformance profile
      ProfileParser ourProfileParser = new ProfileParser(false);
      RuntimeProfile ourConformanceProfile = ourProfileParser.
          parseClasspath("A01_v23.xml");

      //Read a test non-conformant HL7 from file. See my GitHub page for this file
      String message = readHl7FileDataAsString("C:\\Jai\\ADT\\ADT_A01_v2.5_Conformance_XML\\A01_v23.txt"); 
      PipeParser parser=new PipeParser();
      System.out.println("parser configuration "+parser.getParserConfiguration().toString());
      //parse the HL7 message from the file data
       Message msg = parser.parse(message);

      // Validate the HL7 message using the sample HL7 conformance profile I have provided. See my GitHub page for the XML file
      HL7Exception[] errors = new DefaultValidator().validate(msg, ourConformanceProfile.getMessage());

      // Display all the validation errors that are generated.
      System.out.println("The following validation errors were found during message validation:");

      for (HL7Exception hl7Exception : errors) {
        System.out.println(hl7Exception);
      }


    } catch (Exception e) {
      e.printStackTrace();
    }

  }

Input message is:

MSH|^~\&|NSI^UID^D|A^B^C|RID^UID^h|hm|201907071123||ADT^A01^ADT_A01|MSGA01023|P|2.3
EVN|A01|201907071153|201908081153|02|11|20190708105155
PID|||HO2^^^A^MR||Ada^Pal^Kin^Jr^Mr||196101011153|M|Aam^Pau^Kin^Jr^Mr^MA^Ali^AL|Bl|St^^Blr^Ka^56^Ind^Off|91|^Off^Ph^^91^80^123^567^PHo|^91^Ph^d^91^^080^767^P1|Eng^Hin|M|Hin|124|SSN503|DL3|I|For|Bir|Y|2|C||91|201801012022|Y
PV1||I|6N^01^B23^ICU||||010^ATT^AON^A|018^ATT^AAR^A|||||||||014^END^RON^A|S|100|A|||||||||||||||||ISH^200701102300||GL|||||201907071153|201907080500

Console Output:

The following validation errors were found during message validation:
ca.uhn.hl7v2.conf.check.ProfileNotFollowedException: The type Field Separator has length 3 which exceeds max of 1 at MSH-1(0)
ca.uhn.hl7v2.conf.check.ProfileNotFollowedException: The type Encoding Characters has length 12 which exceeds max of 4 at MSH-2(0)
ca.uhn.hl7v2.conf.check.ProfileNotFollowedException: The type Message Type has length 15 which exceeds max of 9 at MSH-9(0)
Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
Jaiprasad
  • 149
  • 11
  • Can someone help? – Jaiprasad Sep 09 '19 at 14:26
  • What you were using to generate profiles? It seems your profile is not properly formatted, e.g., the field separator is defined as - - why length is "3" in your case? – Shamil Sep 10 '19 at 18:33
  • Once you fix your profile, following errors should be coming back with the given sample message: | Warning: PID.13 [Phone Number - Home] - Captured value more complex than specified data type (TN) unexpected data will be ignored | Warning: PID.14 [Phone Number - Business] - Captured value more complex than specified data type (TN) unexpected data will be ignored | Warning: MSH.9.2 [Message Type.trigger event] - 9.3 is UNACCOUNTED. Data elements beyond 9.2 will be ignored | Error: PV1.20.1 [Financial Class.Financial Class] - CODE value (A) not an element of Table 0064-Financial Class ``` – Shamil Sep 10 '19 at 21:03
  • My xml contains this: DynamicDef AccAck="NE" AppAck="AL" MsgAckMode="Deferred"/> 11.6.1 – Jaiprasad Sep 11 '19 at 09:20
  • It should start with - - defining what your profile is. I'd suggest to regenerate the profile. – Shamil Sep 11 '19 at 14:42

2 Answers2

0

There are two levels of validation you may perform with HAPI.

First one is by simply serializing the ER7 formatted message into the HAPI object which allows to verify required fields and data types. Thus, the sample above should fail telling that MSH.9 in HL7v2.3 does not have the third component.

The second type of validation is based on HL7v2 profile. In order for this part to be successful you need to build such profile by constraining the message model (removing unused segments, marking unused optional fields are not supported, hardening usage and repetition, etc.) However, I've found that profile validation does not always work consistently, probably because of nested segment groups.

I'd suggest to start with the first one and then move on to the profile validation.

Shamil
  • 910
  • 4
  • 17
0

We tried by building a validation profile using message workbench to validate the incoming message against the spec. It seemed more complex and our scope was to work with few segments.

So we came up with our own validation profile and wrote a custom algorithm to validate the message.It validates segments,components,sub-components,datatype,length etc.It worked fine for us.

Jaiprasad
  • 149
  • 11
  • You may always hire me for v2 (Messaging Workbench), v3 (RMIM Designer) or FHIR (Forge) profiling. – Shamil Oct 11 '19 at 15:04