Class EncodedMessageComparator

java.lang.Object
ca.uhn.hl7v2.util.EncodedMessageComparator

public class EncodedMessageComparator extends Object
Tools for testing message strings for semantic equivalence without assuming the correctness of parsers.
Author:
Bryan Tripp
  • Constructor Details

  • Method Details

    • standardize

      public static String standardize(String message) throws SAXException
      Returns a "standardized" equivalent of the given message string. For delimited messages, the returned value is the shortest string that has an equivalent meaning in HL7. For XML-encoded messages, the returned value is equivalent XML output using a standard pretty-print format. An automatic determination is made about whether the given string is XML or ER7 (i.e. traditionally) encoded.
      Parameters:
      message - an XML-encoded or ER7-encoded message string
      Throws:
      SAXException
    • standardizeER7

      public static String standardizeER7(String message)
      Returns the shortest string that is semantically equivalent to a given ER7-encoded message string.
    • standardizeXML

      public static String standardizeXML(String message)
      Returns a semantic equivalent of a given XML-encoded message in a default format. Attributes, comments, and processing instructions are not considered to change the HL7 meaning of the message, and are removed in the standardized representation.
    • equivalent

      public static boolean equivalent(String message1, String message2) throws HL7Exception

      Compares two HL7 messages to see if they are equivalent (in terms of their HL7 meaning). Semantically irrelevant differences (e.g. spaces in an XML tag; extra field delimiters at the end of a segment; XML vs. ER7 encoding; XML attributes) are ignored. This check is performed without assuming the correctness of the HAPI parsers, and can therefore be used to test them. This is done by parsing a message, encoding it again, and comparing the result with this original.

      If one message is in XML and the other in ER7, the former is converted to ER7 to perform the comparison. This process relies on the HAPI parsers. However, the parsed message is first encoded as XML and compared to the original, so that the integrity of the parser can be verified. An exception is thrown if this comparison is unsuccessful.

      Returns:
      true if given messages are semantically equivalent
      Throws:
      HL7Exception