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();
}
};
}
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;
}
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());
}
Aggregations