Class ValidationSupport


  • public final class ValidationSupport
    extends Object
    Static helper methods for validating model objects during construction
    • Method Detail

      • checkString

        public static void checkString​(String s)
        A sequence of Unicode characters
         pattern:  [ \r\n\t\S]+
         
        Throws:
        IllegalStateException - if the passed String is not a valid FHIR String value
      • checkCode

        public static void checkCode​(String s)
        A string which has at least one character and no leading or trailing whitespace and where there is no whitespace other than single spaces in the contents.
         pattern:  [^\s]+(\s[^\s]+)*
         
        Throws:
        IllegalStateException - if the passed String is not a valid FHIR Code value
      • checkId

        public static void checkId​(String s)
        Any combination of letters, numerals, "-" and ".", with a length limit of 64 characters. (This might be an integer, an unprefixed OID, UUID or any other identifier pattern that meets these constraints.) Ids are case-insensitive.
         pattern:  [A-Za-z0-9\-\.]{1,64}
         
        Throws:
        IllegalStateException - if the passed String is not a valid FHIR Id value
      • checkUri

        public static void checkUri​(String s)
        String of characters used to identify a name or a resource
         pattern:  \S*
         
        Throws:
        IllegalStateException - if the passed String is not a valid FHIR uri value
      • checkMaxLength

        public static void checkMaxLength​(String value)
        Throws:
        IllegalStateException - if the passed String is longer than the maximum string length
      • checkMinLength

        public static void checkMinLength​(String value)
        Throws:
        IllegalStateException - if the passed String is shorter than the minimum string length
      • checkValue

        public static void checkValue​(Integer value,
                                      int minValue)
        Throws:
        IllegalStateException - if the passed Integer value is less than the passed minValue
      • checkValue

        public static void checkValue​(String value,
                                      Pattern pattern)
        Throws:
        IllegalStateException - if the passed String value does not match the passed pattern
      • checkValueType

        public static <T> T checkValueType​(T value,
                                           Class<?>... types)
        Throws:
        IllegalStateException - if the type of the passed value is not one of the passed types
      • choiceElement

        public static <T extends Element> T choiceElement​(T element,
                                                          String elementName,
                                                          Class<?>... types)
        Throws:
        IllegalStateException - if the type of the passed element is not one of the passed types
      • checkXHTMLContent

        public static void checkXHTMLContent​(String value)
        Throws:
        IllegalStateException - if the passed String value is not valid XHTML
      • requireChoiceElement

        public static <T extends Element> T requireChoiceElement​(T element,
                                                                 String elementName,
                                                                 Class<?>... types)
        Throws:
        IllegalStateException - if the passed element is null or if its type is not one of the passed types
      • requireNonEmpty

        public static <T> List<T> requireNonEmpty​(List<T> elements,
                                                  String elementName)
        Throws:
        IllegalStateException - if the passed list is empty or contains any null objects
      • requireNonNull

        public static <T> T requireNonNull​(T element,
                                           String elementName)
        Throws:
        IllegalStateException - if the passed element is null
      • requireNonNull

        public static <T> List<T> requireNonNull​(List<T> elements,
                                                 String elementName)
        Throws:
        IllegalStateException - if the passed list contains any null objects
      • requireValueOrChildren

        public static void requireValueOrChildren​(Element element)
        Throws:
        IllegalStateException - if the passed element has no value and no children
      • requireChildren

        public static void requireChildren​(Resource resource)
        Throws:
        IllegalStateException - if the passed element has no children
      • checkValueSetBinding

        public static void checkValueSetBinding​(List<? extends Element> elements,
                                                String elementName,
                                                String valueSet,
                                                String system,
                                                String... valueSetCodes)
        Check that the specified list of elements contain a code that is a member of the specified value set.
        Parameters:
        elements - the list of elements for which to check codes
        elementName - the name of the element
        valueSet - the URL of the value set to check membership against
        system - the value set system
        codes - the value set codes
        Throws:
        IllegalStateExeption - if each element in the list does not include a code from the required value set
      • checkValueSetBinding

        public static void checkValueSetBinding​(Element element,
                                                String elementName,
                                                String valueSet,
                                                String system,
                                                String... codes)
        Check that the specified element contains a code that is a member of the specified value set.
        Parameters:
        element - the element for which to check codes
        elementName - the name of the element
        valueSet - the URL of the value set to check membership against
        system - the value set system
        codes - the value set codes
        Throws:
        IllegalStateExeption - if the element does not include a code from the required value set
      • checkReferenceType

        public static void checkReferenceType​(Reference reference,
                                              String elementName,
                                              String... referenceTypes)
        Throws:
        IllegalStateException - if the resource type found in the reference value does not match the specified Reference.type value or is not one of the allowed reference types for that element
      • validateBase64EncodedString

        public static void validateBase64EncodedString​(String value)
      • hasOnlyDataAbsentReasonExtension

        public static boolean hasOnlyDataAbsentReasonExtension​(Element element)