Search in sources :

Example 1 with IPrimitiveType

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

the class Reflections method getPrimitiveFunction.

/**
 * 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> Function<BaseType, ReturnType> getPrimitiveFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
    checkNotNull(theBaseTypeClass);
    checkNotNull(theChildName);
    IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
    return r -> {
        Optional<IBase> value = accessor.getFirstValueOrNull(r);
        if (!value.isPresent()) {
            return null;
        } else {
            return ((IPrimitiveType<ReturnType>) value.get()).getValue();
        }
    };
}
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) Optional(java.util.Optional) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)

Example 2 with IPrimitiveType

use of org.hl7.fhir.instance.model.api.IPrimitiveType in project bunsen by cerner.

the class StringToHapiSetter method toHapi.

@Override
public IBase toHapi(Object sparkObject) {
    IPrimitiveType element = (IPrimitiveType) elementDefinition.newInstance();
    element.setValueAsString((String) sparkObject);
    return element;
}
Also used : IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType)

Example 3 with IPrimitiveType

use of org.hl7.fhir.instance.model.api.IPrimitiveType 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

IPrimitiveType (org.hl7.fhir.instance.model.api.IPrimitiveType)3 IAccessor (ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)2 IBase (org.hl7.fhir.instance.model.api.IBase)2 BaseRuntimeElementDefinition (ca.uhn.fhir.context.BaseRuntimeElementDefinition)1 FhirContext (ca.uhn.fhir.context.FhirContext)1 RuntimeResourceDefinition (ca.uhn.fhir.context.RuntimeResourceDefinition)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Library (org.hl7.fhir.dstu3.model.Library)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Test (org.junit.jupiter.api.Test)1