Class ModelSupport


  • public final class ModelSupport
    extends Object
    • Field Detail

      • DEBUG

        public static boolean DEBUG
      • FHIR_BOOLEAN

        public static final Class<Boolean> FHIR_BOOLEAN
      • FHIR_INTEGER

        public static final Class<Integer> FHIR_INTEGER
      • FHIR_STRING

        public static final Class<String> FHIR_STRING
    • Method Detail

      • init

        public static void init()
        Calling this method allows us to load/initialize this class during startup.
      • getChoiceElementName

        public static String getChoiceElementName​(String name,
                                                  Class<?> type)
        Parameters:
        name - the name of the choice element without any type suffix
        type - the model class which represents the choice value for the choice element
        Returns:
        the serialized name of the choice element name with choice type type
      • getChoiceElementTypes

        public static Set<Class<?>> getChoiceElementTypes​(Class<?> modelClass,
                                                          String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the choice element without any type suffix
        Returns:
        the set of model classes for the allowed types of the specified choice element
      • getReferenceTargetTypes

        public static Set<String> getReferenceTargetTypes​(Class<?> modelClass,
                                                          String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the reference element
        Returns:
        a set of Strings which represent the the allowed target types for the reference
      • getClosure

        public static List<Class<?>> getClosure​(Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        A list of superclasses ordered from parent to child, including the modelClass itself
      • getConcreteType

        public static Class<?> getConcreteType​(Class<?> type)
        Parameters:
        type -
        Returns:
        the class for the concrete type of the passed type if it is a profiled type; otherwise the passed type itself
      • getConstraints

        public static Set<Constraint> getConstraints​(Class<?> modelClass)
        Returns:
        the set of constraints for the modelClass or empty if there are none
      • getElementInfo

        public static ModelSupport.ElementInfo getElementInfo​(Class<?> modelClass,
                                                              String elementName)
        Returns:
        ElementInfo for the element with the passed name on the passed modelClass or null if the modelClass does not contain an element with this name
      • getElementInfo

        public static Collection<ModelSupport.ElementInfo> getElementInfo​(Class<?> modelClass)
        Returns:
        a collection of ElementInfo for all elements of the passed modelClass or empty if the class is not a FHIR model class
      • getChoiceElementInfo

        public static ModelSupport.ElementInfo getChoiceElementInfo​(Class<?> modelClass,
                                                                    String typeSpecificElementName)
        Returns:
        ElementInfo for the choice element with the passed typeSpecificElementName of the passed modelClass or null if the modelClass does not contain a choice element that can have this typeSpecificElementName
      • getElementName

        public static String getElementName​(Field field)
        Get the actual element name from a Java field.
      • getElementName

        public static String getElementName​(String fieldName)
        Get the actual element name from a Java field name. This method reverses any encoding that was required to represent the FHIR element name in Java, such as converting class to clazz.
      • getElementNames

        public static Set<String> getElementNames​(Class<?> modelClass)
        Returns:
        the set of element names for the passed modelClass or empty if it is not a FHIR model class
      • getElementType

        public static Class<?> getElementType​(Class<?> modelClass,
                                              String elementName)
        Returns:
        the model class for the element with name elementName on the passed modelClass or null if the passed modelClass does not have an element elementName
      • getElementDeclaringType

        public static Class<?> getElementDeclaringType​(Class<?> modelClass,
                                                       String elementName)
        Get the model class which declares the elementName found on the passed modelClass.
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        Returns:
        modelClass or a superclass of modelClass, or null if the element is not found on the passed modelClass
      • isElementDeclaredBy

        public static boolean isElementDeclaredBy​(Class<?> modelClass,
                                                  String elementName,
                                                  Class<?> type)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        type - the model class to check
        Returns:
        true if the passed modelClass contains an element with name elementName and the passed type is the one that declares it; otherwise false
      • getModelClasses

        public static Set<Class<?>> getModelClasses()
        Returns:
        all model classes, including both resources and elements, concrete and abstract
      • getResourceType

        public static Class<? extends Resource> getResourceType​(String name)
        Parameters:
        name - the resource type name in titlecase to match the corresponding model class name
        Returns:
        the model class that corresponds to the passed resource type name
      • getResourceTypes

        public static Collection<Class<? extends Resource>> getResourceTypes()
        Returns:
        a collection of FHIR resource type model classes, including abstract supertypes
      • getResourceTypes

        public static Collection<Class<? extends Resource>> getResourceTypes​(boolean includeAbstractTypes)
        Returns:
        a collection of FHIR resource type model classes
      • getDataTypes

        public static Set<Class<? extends Element>> getDataTypes()
        Returns:
        the set of classes for the FHIR elements
      • getTypeName

        public static String getTypeName​(Class<?> type)
        Returns:
        the name of the FHIR data type which corresponds to the passed type
      • getTypeNames

        public static Set<String> getTypeNames​(Class<?> modelClass)
        Returns:
        the set of FHIR data type names for the passed modelClass and its supertypes
      • isBackboneElementType

        public static boolean isBackboneElementType​(Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        true if and only if modelClass is a BackboneElement
      • isChoiceElement

        public static boolean isChoiceElement​(Class<?> modelClass,
                                              String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        Returns:
        true if modelClass contains a choice element with name @{code elementName}; otherwise false
      • isChoiceElementType

        public static boolean isChoiceElementType​(Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is an allowed choice element type; otherwise false
      • isCodeSubtype

        public static boolean isCodeSubtype​(Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is subclass of com.ibm.fhir.model.type.Code; otherwise false
      • isElement

        public static boolean isElement​(Object modelObject)
        Parameters:
        modelObject - a model object which represents a FHIR resource or element
        Returns:
        true if modelObject is an element; otherwise false
      • isElementType

        public static boolean isElementType​(Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        true if modelClass is an element; otherwise false
      • isModelClass

        public static boolean isModelClass​(Class<?> type)
        Returns:
        true if type is a model class that represents a FHIR resource or element; otherwise false
      • isPrimitiveType

        public static boolean isPrimitiveType​(Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is a model class that represents a FHIR primitive type; otherwise false
        See Also:
        https://www.hl7.org/fhir/R4/datatypes.html#primitive
      • isProfiledType

        public static boolean isProfiledType​(Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is a profiled data type; otherwise false
      • isRepeatingElement

        public static boolean isRepeatingElement​(Class<?> modelClass,
                                                 String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        Returns:
        true if modelClass has an element elementName and it has max cardinality > 1; otherwise false
      • isRequiredElement

        public static boolean isRequiredElement​(Class<?> modelClass,
                                                String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        Returns:
        true if modelClass has an element elementName and it has min cardinality > 0; otherwise false
      • isResource

        public static boolean isResource​(Object modelObject)
        Parameters:
        modelObject - a model object which represents a FHIR resource or element
        Returns:
        true if modelObject represents a FHIR resource; otherwise false
      • isResourceType

        public static boolean isResourceType​(Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        true if modelClass represents a FHIR resource; otherwise false
      • isAbstract

        public static boolean isAbstract​(Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        true if modelClass is an abstract FHIR model class; otherwise false
      • isResourceType

        public static boolean isResourceType​(String name)
        Parameters:
        name - the resource type name in titlecase to match the corresponding model class name
        Returns:
        true if name is a valid FHIR resource name; otherwise false
      • isConcreteResourceType

        public static boolean isConcreteResourceType​(String name)
        Parameters:
        name - the resource type name in titlecase to match the corresponding model class name
        Returns:
        true if name is a valid FHIR resource name; otherwise false
      • isSummaryElement

        public static boolean isSummaryElement​(Class<?> modelClass,
                                               String elementName)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        elementName - the name of the element; choice element names do not include a type suffix
        Returns:
        true if modelClass has an element elementName and its marked as a summary element; otherwise false
      • truncateTime

        public static LocalTime truncateTime​(LocalTime time,
                                             ChronoUnit unit)
        Returns:
        a copy of the passed LocalTime with the time truncated to unit
      • getSystem

        public static String getSystem​(Code code)
        Returns:
        the implicit system for code if present, otherwise null
      • getDataType

        public static Class<?> getDataType​(String typeName)
        Returns:
        the data type class associated with typeName parameter if exists, otherwise null