Package com.ibm.fhir.model.util
Class ValidationSupport
- java.lang.Object
-
- com.ibm.fhir.model.util.ValidationSupport
-
public final class ValidationSupport extends Object
Static helper methods for validating model objects during construction
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALL_LANG_VALUE_SET_URL
static String
BCP_47_URN
static String
DATA_ABSENT_REASON_EXTENSION_URL
static String
UCUM_CODE_SYSTEM_URL
static String
UCUM_UNITS_VALUE_SET_URL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static void
checkId(String s)
Any combination of letters, numerals, "-" and ".", with a length limit of 64 characters.static void
checkMaxLength(String value)
static void
checkMinLength(String value)
static void
checkReferenceType(Reference reference, String elementName, String... referenceTypes)
static void
checkString(String s)
A sequence of Unicode charactersstatic void
checkUri(String s)
String of characters used to identify a name or a resourcestatic void
checkValue(Integer value, int minValue)
static void
checkValue(String value, Pattern pattern)
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.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.static <T> T
checkValueType(T value, Class<?>... types)
static void
checkXHTMLContent(String value)
static <T extends Element>
TchoiceElement(T element, String elementName, Class<?>... types)
static boolean
hasOnlyDataAbsentReasonExtension(Element element)
static void
prohibited(Element element, String elementName)
static <T extends Element>
voidprohibited(List<T> elements, String elementName)
static void
requireChildren(Resource resource)
static <T extends Element>
TrequireChoiceElement(T element, String elementName, Class<?>... types)
static <T> List<T>
requireNonEmpty(List<T> elements, String elementName)
static <T> List<T>
requireNonNull(List<T> elements, String elementName)
static <T> T
requireNonNull(T element, String elementName)
static void
requireValueOrChildren(Element element)
static void
validateBase64EncodedString(String value)
-
-
-
Field Detail
-
ALL_LANG_VALUE_SET_URL
public static final String ALL_LANG_VALUE_SET_URL
- See Also:
- Constant Field Values
-
UCUM_UNITS_VALUE_SET_URL
public static final String UCUM_UNITS_VALUE_SET_URL
- See Also:
- Constant Field Values
-
BCP_47_URN
public static final String BCP_47_URN
- See Also:
- Constant Field Values
-
UCUM_CODE_SYSTEM_URL
public static final String UCUM_CODE_SYSTEM_URL
- See Also:
- Constant Field Values
-
DATA_ABSENT_REASON_EXTENSION_URL
public static final String DATA_ABSENT_REASON_EXTENSION_URL
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkString
public static void checkString(String s)
A sequence of Unicode characterspattern: [ \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 resourcepattern: \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
-
prohibited
public static void prohibited(Element element, String elementName)
- Throws:
IllegalStateException
- if the passed element is not null
-
prohibited
public static <T extends Element> void prohibited(List<T> elements, String elementName)
- Throws:
IllegalStateException
- if the passed list is not empty
-
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 codeselementName
- the name of the elementvalueSet
- the URL of the value set to check membership againstsystem
- the value set systemcodes
- 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 codeselementName
- the name of the elementvalueSet
- the URL of the value set to check membership againstsystem
- the value set systemcodes
- 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)
-
-