Package com.ibm.fhir.model.util
Class ModelSupport
- java.lang.Object
-
- com.ibm.fhir.model.util.ModelSupport
-
public final class ModelSupport extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ModelSupport.ElementInfo
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEBUG
static Class<Boolean>
FHIR_BOOLEAN
static Class<Integer>
FHIR_INTEGER
static Class<String>
FHIR_STRING
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
delimit(String identifier)
Wraps the passed string identifier for use in FHIRPathstatic ModelSupport.ElementInfo
getChoiceElementInfo(Class<?> modelClass, String typeSpecificElementName)
static String
getChoiceElementName(String name, Class<?> type)
static Set<Class<?>>
getChoiceElementTypes(Class<?> modelClass, String elementName)
static List<Class<?>>
getClosure(Class<?> modelClass)
static Class<?>
getConcreteType(Class<?> type)
static Set<Constraint>
getConstraints(Class<?> modelClass)
static Class<?>
getDataType(String typeName)
static Set<Class<? extends Element>>
getDataTypes()
static Class<?>
getElementDeclaringType(Class<?> modelClass, String elementName)
Get the model class which declares the elementName found on the passed modelClass.static Collection<ModelSupport.ElementInfo>
getElementInfo(Class<?> modelClass)
static ModelSupport.ElementInfo
getElementInfo(Class<?> modelClass, String elementName)
static String
getElementName(Field field)
Get the actual element name from a Java field.static String
getElementName(String fieldName)
Get the actual element name from a Java field name.static Set<String>
getElementNames(Class<?> modelClass)
static Class<?>
getElementType(Class<?> modelClass, String elementName)
static Set<Class<?>>
getModelClasses()
static Set<String>
getReferenceTargetTypes(Class<?> modelClass, String elementName)
static Class<? extends Resource>
getResourceType(String name)
static Collection<Class<? extends Resource>>
getResourceTypes()
static Collection<Class<? extends Resource>>
getResourceTypes(boolean includeAbstractTypes)
static String
getSystem(Code code)
static String
getTypeName(Class<?> type)
static Set<String>
getTypeNames(Class<?> modelClass)
static void
init()
Calling this method allows us to load/initialize this class during startup.static boolean
isAbstract(Class<?> modelClass)
static boolean
isBackboneElementType(Class<?> modelClass)
static boolean
isChoiceElement(Class<?> modelClass, String elementName)
static boolean
isChoiceElementType(Class<?> type)
static boolean
isCodeSubtype(Class<?> type)
static boolean
isConcreteResourceType(String name)
static boolean
isElement(Object modelObject)
static boolean
isElementDeclaredBy(Class<?> modelClass, String elementName, Class<?> type)
static boolean
isElementType(Class<?> modelClass)
static boolean
isKeyword(String identifier)
static boolean
isMetadataType(Class<?> type)
static boolean
isModelClass(Class<?> type)
static boolean
isPrimitiveType(Class<?> type)
static boolean
isProfiledType(Class<?> type)
static boolean
isRepeatingElement(Class<?> modelClass, String elementName)
static boolean
isRequiredElement(Class<?> modelClass, String elementName)
static boolean
isResource(Object modelObject)
static boolean
isResourceType(Class<?> modelClass)
static boolean
isResourceType(String name)
static boolean
isSummaryElement(Class<?> modelClass, String elementName)
static LocalTime
truncateTime(LocalTime time, ChronoUnit unit)
static TemporalAccessor
truncateTime(TemporalAccessor ta, ChronoUnit unit)
static ZonedDateTime
truncateTime(ZonedDateTime dateTime, ChronoUnit unit)
-
-
-
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 suffixtype
- the model class which represents the choice value for the choice element- Returns:
- the serialized name of the choice element
name
with choice typetype
-
getChoiceElementTypes
public static Set<Class<?>> getChoiceElementTypes(Class<?> modelClass, String elementName)
- Parameters:
modelClass
- a model class which represents a FHIR resource or elementelementName
- 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 elementelementName
- 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 elementelementName
- 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 elementelementName
- the name of the element; choice element names do not include a type suffixtype
- 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 elementelementName
- 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
-
isMetadataType
public static boolean isMetadataType(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(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 elementelementName
- the name of the element; choice element names do not include a type suffix- Returns:
- true if
modelClass
has an elementelementName
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 elementelementName
- the name of the element; choice element names do not include a type suffix- Returns:
- true if
modelClass
has an elementelementName
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 elementelementName
- the name of the element; choice element names do not include a type suffix- Returns:
- true if
modelClass
has an elementelementName
and its marked as a summary element; otherwise false
-
truncateTime
public static ZonedDateTime truncateTime(ZonedDateTime dateTime, ChronoUnit unit)
- Returns:
- a copy of the passed ZonedDateTime with the time truncated to
unit
-
truncateTime
public static LocalTime truncateTime(LocalTime time, ChronoUnit unit)
- Returns:
- a copy of the passed LocalTime with the time truncated to
unit
-
truncateTime
public static TemporalAccessor truncateTime(TemporalAccessor ta, ChronoUnit unit)
- Returns:
- a copy of the passed TemporalAccessor with the time truncated to
unit
-
isKeyword
public static boolean isKeyword(String identifier)
- Returns:
- true if
identifier
is a reserved keyword in FHIRPath version N1 - See Also:
- http://hl7.org/fhirpath/2018Sep/index.html#keywords
-
delimit
public static String delimit(String identifier)
Wraps the passed string identifier for use in FHIRPath
-
getSystem
public static String getSystem(Code code)
- Returns:
- the implicit system for
code
if present, otherwise null
-
-