Search in sources :

Example 6 with IBase

use of org.hl7.fhir.instance.model.api.IBase in project cqf-ruler by DBCG.

the class Reflections method getFunction.

/**
 * Generates a function to access a primitive property of the given
 * BaseType.
 *
 * @param <BaseType>       an IBase type
 * @param <ReturnType>     a return type for the Functions
 * @param theBaseTypeClass the class of a the IBase type
 * @param theChildName     to create a function for
 * @return a function for accessing the "theChildName" property of the
 *         BaseType
 */
@SuppressWarnings("unchecked")
public static <BaseType extends IBase, ReturnType extends List<? extends IBase>> Function<BaseType, ReturnType> getFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
    checkNotNull(theBaseTypeClass);
    checkNotNull(theChildName);
    IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
    return r -> {
        return (ReturnType) accessor.getValues(r);
    };
}
Also used : List(java.util.List) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor) FhirContext(ca.uhn.fhir.context.FhirContext) IBase(org.hl7.fhir.instance.model.api.IBase) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) Optional(java.util.Optional) RuntimeResourceDefinition(ca.uhn.fhir.context.RuntimeResourceDefinition) Function(java.util.function.Function) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)

Example 7 with IBase

use of org.hl7.fhir.instance.model.api.IBase in project cqf-ruler by DBCG.

the class ReflectionsTest method testAccessor.

@Test
public void testAccessor() {
    Library library = new Library().setName("test");
    IAccessor accessor = Reflections.getAccessor(library.getClass(), "name");
    Optional<IBase> opt = accessor.getFirstValueOrNull(library);
    @SuppressWarnings("unchecked") IPrimitiveType<String> value = (IPrimitiveType<String>) opt.get();
    assertEquals("test", value.getValue());
}
Also used : IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) Library(org.hl7.fhir.dstu3.model.Library) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor) IBase(org.hl7.fhir.instance.model.api.IBase) Test(org.junit.jupiter.api.Test)

Aggregations

IBase (org.hl7.fhir.instance.model.api.IBase)6 List (java.util.List)4 IPrimitiveType (org.hl7.fhir.instance.model.api.IPrimitiveType)4 IAccessor (ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)3 BaseRuntimeElementDefinition (ca.uhn.fhir.context.BaseRuntimeElementDefinition)3 FhirContext (ca.uhn.fhir.context.FhirContext)3 RuntimeResourceDefinition (ca.uhn.fhir.context.RuntimeResourceDefinition)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)2 BaseRuntimeChildDefinition (ca.uhn.fhir.context.BaseRuntimeChildDefinition)1 BaseRuntimeElementCompositeDefinition (ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition)1 RuntimeElemContainedResourceList (ca.uhn.fhir.context.RuntimeElemContainedResourceList)1 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Library (org.hl7.fhir.dstu3.model.Library)1