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 StringALL_LANG_VALUE_SET_URLstatic StringBCP_47_URNstatic StringDATA_ABSENT_REASON_EXTENSION_URLstatic StringUCUM_CODE_SYSTEM_URLstatic StringUCUM_UNITS_VALUE_SET_URL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckCode(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 voidcheckId(String s)Any combination of letters, numerals, "-" and ".", with a length limit of 64 characters.static <T> List<T>checkList(List<T> elements, String elementName, Class<T> type)static voidcheckMaxLength(String value)static voidcheckMinLength(String value)static <T> List<T>checkNonEmptyList(List<T> elements, String elementName, Class<T> type)static voidcheckReferenceType(Element choiceElement, String elementName, String... referenceTypes)static voidcheckReferenceType(Reference reference, String elementName, String... referenceTypes)Checks that the reference contains valid resource type values.static voidcheckReferenceType(List<Reference> reference, String elementName, String... referenceTypes)static voidcheckString(String s)A sequence of Unicode charactersstatic voidcheckUri(String s)String of characters used to identify a name or a resourcestatic voidcheckValue(Integer value, int minValue)static voidcheckValue(String value, Pattern pattern)static voidcheckValueSetBinding(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 voidcheckValueSetBinding(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> TcheckValueType(T value, Class<?>... types)static voidcheckXHTMLContent(String value)static <T extends Element>
TchoiceElement(T element, String elementName, Class<?>... types)static booleanhasOnlyDataAbsentReasonExtension(Element element)static voidprohibited(Element element, String elementName)static <T extends Element>
voidprohibited(List<T> elements, String elementName)static <T extends Element>
TrequireChoiceElement(T element, String elementName, Class<?>... types)static <T> TrequireNonNull(T element, String elementName)static voidrequireValueOrChildren(Element element)static voidvalidateBase64EncodedString(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
-
requireNonNull
public static <T> T requireNonNull(T element, String elementName)- Throws:
IllegalStateException- if the passed element is null
-
checkNonEmptyList
public static <T> List<T> checkNonEmptyList(List<T> elements, String elementName, Class<T> type)
- Returns:
- the same list that was passed
- Throws:
IllegalStateException- if the passed list is empty or contains any null objects or objects of an incompatible type
-
checkList
public static <T> List<T> checkList(List<T> elements, String elementName, Class<T> type)
- Returns:
- the same list that was passed
- Throws:
IllegalStateException- if the passed list contains any null objects or objects of an incompatible type
-
requireValueOrChildren
public static void requireValueOrChildren(Element element)
- Throws:
IllegalStateException- if the passed element has no value and 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(List<Reference> reference, String elementName, String... referenceTypes)
- Throws:
IllegalStateException- if the resource type found in one or more reference values does not match the specified Reference.type value or is not one of the allowed reference types for that element
-
checkReferenceType
public static void checkReferenceType(Element choiceElement, String elementName, String... referenceTypes)
- Throws:
IllegalStateException- if the choiceElement is a Reference and the reference value does not match the specified Reference.type value or is not one of the allowed reference types for that element
-
checkReferenceType
public static void checkReferenceType(Reference reference, String elementName, String... referenceTypes)
Checks that the reference contains valid resource type values.- Parameters:
reference- the referenceelementName- the element namereferenceTypes- the valid resource types for the reference- 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)
-
-