Class Hl7Util


  • public final class Hl7Util
    extends Object
    • Method Detail

      • generateInvalidPayloadExceptionMessage

        public static String generateInvalidPayloadExceptionMessage​(byte[] hl7Bytes)
      • generateInvalidPayloadExceptionMessage

        public static String generateInvalidPayloadExceptionMessage​(byte[] hl7Bytes,
                                                                    int length)
        Verifies that the HL7 payload array

        The MLLP protocol does not allow embedded START_OF_BLOCK or END_OF_BLOCK characters. The END_OF_DATA character is allowed (and expected) because it is also the segment delimiter for an HL7 message

        Parameters:
        hl7Bytes - the HL7 payload to validate
        Returns:
        If the payload is invalid, an error message suitable for inclusion in an exception is returned. If the payload is valid, null is returned;
      • findFieldSeparatorIndicesInSegment

        public static List<Integer> findFieldSeparatorIndicesInSegment​(byte[] hl7MessageBytes,
                                                                       int startingIndex)
        Find the field separator indices in the Segment. NOTE: The last element of the list will be the index of the end of the segment.
        Parameters:
        hl7MessageBytes - the HL7 binary message
        startingIndex - index of the beginning of the HL7 Segment
        Returns:
        List of the field separator indices, which may be empty.
      • findMsh18

        public static String findMsh18​(byte[] hl7Message)
        Find the String value of MSH-18 (Character set).
        Parameters:
        hl7Message - the HL7 binary data to search
        Returns:
        the String value of MSH-18, or an empty String if not found.
      • convertToPrintFriendlyString

        public static String convertToPrintFriendlyString​(String phiString)
      • convertToPrintFriendlyString

        public static String convertToPrintFriendlyString​(byte[] phiBytes)
      • convertToPrintFriendlyString

        public static String convertToPrintFriendlyString​(byte[] phiBytes,
                                                          int startPosition,
                                                          int endPosition)
        Convert a PHI byte[] to a String, replacing specific non-printable characters with readable strings. NOTE: this conversion uses the default character set, so not all characters my convert correctly.
        Parameters:
        phiBytes - the PHI byte[] to log
        startPosition - the starting position/index of the data
        endPosition - the ending position/index of the data - will not be included in String
        Returns:
        a String representation of the byte[]
      • bytesToPrintFriendlyStringBuilder

        public static StringBuilder bytesToPrintFriendlyStringBuilder​(byte[] phiBytes)
        Convert a PHI byte[] to a StringBuilder, replacing specific non-printable characters with readable strings. NOTE: this conversion uses the default character set, so not all characters my convert correctly.
        Parameters:
        phiBytes - the PHI byte[] to log
        Returns:
      • bytesToPrintFriendlyStringBuilder

        public static StringBuilder bytesToPrintFriendlyStringBuilder​(byte[] phiBytes,
                                                                      int startPosition,
                                                                      int endPosition)
        Convert a PHI byte[] to a StringBuilder, replacing specific non-printable characters with readable strings. NOTE: this conversion uses the default character set, so not all characters my convert correctly.
        Parameters:
        phiBytes - the PHI byte[] to log
        startPosition - the starting position/index of the data
        endPosition - the ending position/index of the data - will not be included in StringBuilder
        Returns:
        a String representation of the byte[]
      • appendBytesAsPrintFriendlyString

        public static void appendBytesAsPrintFriendlyString​(StringBuilder builder,
                                                            byte[] phiBytes)
      • appendBytesAsPrintFriendlyString

        public static void appendBytesAsPrintFriendlyString​(StringBuilder builder,
                                                            byte[] phiBytes,
                                                            int startPosition,
                                                            int endPosition)
        Append a PHI byte[] to a StringBuilder, replacing specific non-printable characters with readable strings. NOTE: this conversion uses the default character set, so not all characters my convert correctly.
        Parameters:
        phiBytes - the PHI byte[] to log
        startPosition - the starting position/index of the data
        endPosition - the ending position/index of the data - will not be included in String
      • getCharacterAsPrintFriendlyString

        public static String getCharacterAsPrintFriendlyString​(char c)