Class ModelSupport


  • public final class ModelSupport
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String delimit​(java.lang.String identifier)
      Wraps the passed string identifier for use in FHIRPath
      static ModelSupport.ElementInfo getChoiceElementInfo​(java.lang.Class<?> modelClass, java.lang.String typeSpecificElementName)  
      static java.lang.String getChoiceElementName​(java.lang.String name, java.lang.Class<?> type)  
      static java.util.Set<java.lang.Class<?>> getChoiceElementTypes​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static java.util.List<java.lang.Class<?>> getClosure​(java.lang.Class<?> modelClass)  
      static java.util.Collection<java.lang.Class<?>> getCodeSubtypes()  
      static java.lang.Class<?> getConcreteType​(java.lang.Class<?> type)  
      static java.util.List<Constraint> getConstraints​(java.lang.Class<?> modelClass)  
      static java.lang.Class<?> getDataType​(java.lang.String typeName)  
      static java.util.Set<java.lang.Class<? extends Element>> getDataTypes()  
      static java.lang.Class<?> getElementDeclaringType​(java.lang.Class<?> modelClass, java.lang.String elementName)
      Get the model class which declares the elementName found on the passed modelClass.
      static java.util.Collection<ModelSupport.ElementInfo> getElementInfo​(java.lang.Class<?> modelClass)  
      static ModelSupport.ElementInfo getElementInfo​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static java.lang.String getElementName​(java.lang.reflect.Field field)
      Get the actual element name from a Java field.
      static java.lang.String getElementName​(java.lang.String fieldName)
      Get the actual element name from a Java field name.
      static java.util.Set<java.lang.String> getElementNames​(java.lang.Class<?> modelClass)  
      static java.lang.Class<?> getElementType​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static java.util.Set<java.lang.Class<?>> getModelClasses()  
      static java.util.Set<java.lang.String> getReferenceTargetTypes​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static java.lang.Class<? extends Resource> getResourceType​(java.lang.String name)  
      static java.util.Collection<java.lang.Class<? extends Resource>> getResourceTypes()  
      static java.util.Collection<java.lang.Class<? extends Resource>> getResourceTypes​(boolean includeAbstractTypes)  
      static java.lang.String getSystem​(Code code)  
      static java.lang.String getTypeName​(java.lang.Class<?> type)  
      static java.util.Set<java.lang.String> getTypeNames​(java.lang.Class<?> modelClass)  
      static void init()
      Calling this method allows us to load/initialize this class during startup.
      static boolean isAbstract​(java.lang.Class<?> modelClass)  
      static boolean isBackboneElementType​(java.lang.Class<?> modelClass)  
      static boolean isChoiceElement​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static boolean isChoiceElementType​(java.lang.Class<?> type)  
      static boolean isCodeSubtype​(java.lang.Class<?> type)  
      static boolean isCodeSubtype​(java.lang.String name)  
      static boolean isConcreteResourceType​(java.lang.String name)  
      static boolean isElement​(java.lang.Object modelObject)  
      static boolean isElementDeclaredBy​(java.lang.Class<?> modelClass, java.lang.String elementName, java.lang.Class<?> type)  
      static boolean isElementType​(java.lang.Class<?> modelClass)  
      static boolean isKeyword​(java.lang.String identifier)  
      static boolean isMetadataType​(java.lang.Class<?> type)  
      static boolean isModelClass​(java.lang.Class<?> type)  
      static boolean isPrimitiveType​(java.lang.Class<?> type)  
      static boolean isProfiledType​(java.lang.Class<?> type)  
      static boolean isRepeatingElement​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static boolean isRequiredElement​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static boolean isResource​(java.lang.Object modelObject)  
      static boolean isResourceType​(java.lang.Class<?> modelClass)  
      static boolean isResourceType​(java.lang.String name)  
      static boolean isSummaryElement​(java.lang.Class<?> modelClass, java.lang.String elementName)  
      static java.time.LocalTime truncateTime​(java.time.LocalTime time, java.time.temporal.ChronoUnit unit)  
      static java.time.temporal.TemporalAccessor truncateTime​(java.time.temporal.TemporalAccessor ta, java.time.temporal.ChronoUnit unit)  
      static java.time.ZonedDateTime truncateTime​(java.time.ZonedDateTime dateTime, java.time.temporal.ChronoUnit unit)  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FHIR_BOOLEAN

        public static final java.lang.Class<Boolean> FHIR_BOOLEAN
      • FHIR_INTEGER

        public static final java.lang.Class<Integer> FHIR_INTEGER
      • FHIR_STRING

        public static final java.lang.Class<String> FHIR_STRING
      • FHIR_DATE

        public static final java.lang.Class<Date> FHIR_DATE
      • FHIR_INSTANT

        public static final java.lang.Class<Instant> FHIR_INSTANT
    • Method Detail

      • init

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

        public static java.lang.String getChoiceElementName​(java.lang.String name,
                                                            java.lang.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 java.util.Set<java.lang.Class<?>> getChoiceElementTypes​(java.lang.Class<?> modelClass,
                                                                              java.lang.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 java.util.Set<java.lang.String> getReferenceTargetTypes​(java.lang.Class<?> modelClass,
                                                                              java.lang.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 java.util.List<java.lang.Class<?>> getClosure​(java.lang.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 java.lang.Class<?> getConcreteType​(java.lang.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 java.util.List<Constraint> getConstraints​(java.lang.Class<?> modelClass)
        Returns:
        the list of constraints for the modelClass or empty if there are none
      • getElementInfo

        public static ModelSupport.ElementInfo getElementInfo​(java.lang.Class<?> modelClass,
                                                              java.lang.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 java.util.Collection<ModelSupport.ElementInfo> getElementInfo​(java.lang.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​(java.lang.Class<?> modelClass,
                                                                    java.lang.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 java.lang.String getElementName​(java.lang.reflect.Field field)
        Get the actual element name from a Java field.
      • getElementName

        public static java.lang.String getElementName​(java.lang.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 java.util.Set<java.lang.String> getElementNames​(java.lang.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 java.lang.Class<?> getElementType​(java.lang.Class<?> modelClass,
                                                        java.lang.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 java.lang.Class<?> getElementDeclaringType​(java.lang.Class<?> modelClass,
                                                                 java.lang.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​(java.lang.Class<?> modelClass,
                                                  java.lang.String elementName,
                                                  java.lang.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 java.util.Set<java.lang.Class<?>> getModelClasses()
        Returns:
        all model classes, including both resources and elements, concrete and abstract
      • getResourceType

        public static java.lang.Class<? extends Resource> getResourceType​(java.lang.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 java.util.Collection<java.lang.Class<? extends Resource>> getResourceTypes()
        Returns:
        a collection of FHIR resource type model classes, including abstract supertypes
      • getResourceTypes

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

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

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

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

        public static boolean isBackboneElementType​(java.lang.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​(java.lang.Class<?> modelClass,
                                              java.lang.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​(java.lang.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​(java.lang.Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is subclass of org.linuxforhealth.fhir.model.type.Code; otherwise false
      • isElement

        public static boolean isElement​(java.lang.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​(java.lang.Class<?> modelClass)
        Parameters:
        modelClass - a model class which represents a FHIR resource or element
        Returns:
        true if modelClass is an element; otherwise false
      • isMetadataType

        public static boolean isMetadataType​(java.lang.Class<?> type)
        Parameters:
        type - a model class which represents a FHIR element
        Returns:
        true if type is a metadata type; otherwise false
        See Also:
        https://www.hl7.org/fhir/R4/metadatatypes.html
      • isModelClass

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

        public static boolean isPrimitiveType​(java.lang.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​(java.lang.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​(java.lang.Class<?> modelClass,
                                                 java.lang.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​(java.lang.Class<?> modelClass,
                                                java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.Class<?> modelClass,
                                               java.lang.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 java.time.ZonedDateTime truncateTime​(java.time.ZonedDateTime dateTime,
                                                           java.time.temporal.ChronoUnit unit)
        Returns:
        a copy of the passed ZonedDateTime with the time truncated to unit
      • truncateTime

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

        public static java.time.temporal.TemporalAccessor truncateTime​(java.time.temporal.TemporalAccessor ta,
                                                                       java.time.temporal.ChronoUnit unit)
        Returns:
        a copy of the passed TemporalAccessor with the time truncated to unit
      • getSystem

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

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

        public static boolean isCodeSubtype​(java.lang.String name)
      • getCodeSubtypes

        public static java.util.Collection<java.lang.Class<?>> getCodeSubtypes()