use of org.hl7.fhir.instance.model.api.IBase in project cqf-ruler by DBCG.
the class Libraries method getFunctions.
static LibraryFunctions getFunctions(FhirVersionEnum fhirVersionEnum) {
FhirContext fhirContext = FhirContext.forCached(fhirVersionEnum);
Class<? extends IBaseResource> libraryClass = fhirContext.getResourceDefinition(LIBRARY_RESOURCE_TYPE).getImplementingClass();
Function<IBase, List<IBase>> attachments = Reflections.getFunction(libraryClass, "content");
Function<IBase, String> contentType = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "contentType");
Function<IBase, byte[]> content = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "data");
Function<IBase, String> version = Reflections.getVersionFunction(libraryClass);
return new LibraryFunctions(attachments, contentType, content, version);
}
use of org.hl7.fhir.instance.model.api.IBase 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.IBase 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.IBase in project ab2d by CMSgov.
the class FhirUtils method addMbiIdsToEobs.
public static void addMbiIdsToEobs(IBaseResource eob, CoverageSummary patient, FhirVersion version) {
if (eob == null) {
return;
}
// Add extesions only if beneficiary id is present and known to memberships
Long benId = EobUtils.getPatientId(eob);
if (benId != null && patient != null) {
Identifiers identifiers = patient.getIdentifiers();
// Add each mbi to each eob
if (identifiers.getCurrentMbi() != null) {
IBase currentMbiExtension = ExtensionUtils.createMbiExtension(identifiers.getCurrentMbi(), true, version);
ExtensionUtils.addExtension(eob, currentMbiExtension, version);
}
for (String mbi : identifiers.getHistoricMbis()) {
IBase mbiExtension = ExtensionUtils.createMbiExtension(mbi, false, version);
ExtensionUtils.addExtension(eob, mbiExtension, version);
}
}
}
use of org.hl7.fhir.instance.model.api.IBase in project bunsen by cerner.
the class HapiCompositeConverter method fromHapi.
@Override
public Object fromHapi(Object input) {
IBase composite = (IBase) input;
Object[] values = new Object[children.size()];
int valueIndex = 0;
Iterator<StructureField<HapiConverter<T>>> schemaIterator = children.iterator();
if (composite instanceof IAnyResource) {
// Id element
StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
values[0] = schemaEntry.result().fromHapi(((IAnyResource) composite).getIdElement());
valueIndex++;
// Meta element
schemaEntry = schemaIterator.next();
values[valueIndex] = schemaEntry.result().fromHapi(((IAnyResource) composite).getMeta());
valueIndex++;
}
Map<String, List> properties = fhirSupport.compositeValues(composite);
// Co-iterate with an index so we place the correct values into the corresponding locations.
for (; valueIndex < children.size(); ++valueIndex) {
StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
String propertyName = schemaEntry.propertyName();
// Append the [x] suffix for choice properties.
if (schemaEntry.isChoice()) {
propertyName = propertyName + "[x]";
}
HapiConverter<T> converter = schemaEntry.result();
List propertyValues = properties.get(propertyName);
if (propertyValues != null && !propertyValues.isEmpty()) {
if (isMultiValued(converter.getDataType())) {
values[valueIndex] = schemaEntry.result().fromHapi(propertyValues);
} else {
values[valueIndex] = schemaEntry.result().fromHapi(propertyValues.get(0));
}
} else if (converter.extensionUrl() != null) {
// No corresponding property for the name, so see if it is an Extension or ModifierExtention
List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
for (IBaseExtension extension : extensions) {
if (extension.getUrl().equals(converter.extensionUrl())) {
values[valueIndex] = schemaEntry.result().fromHapi(extension);
}
}
} else if (converter instanceof MultiValueConverter && ((MultiValueConverter) converter).getElementConverter().extensionUrl() != null) {
final String extensionUrl = ((MultiValueConverter) converter).getElementConverter().extensionUrl();
List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
final List<? extends IBaseExtension> extensionList = extensions.stream().filter(extension -> extension.getUrl().equals(extensionUrl)).collect(Collectors.toList());
if (extensionList.size() > 0) {
values[valueIndex] = schemaEntry.result().fromHapi(extensionList);
}
}
}
return createComposite(values);
}
Aggregations