Search in sources :

Example 1 with IBase

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);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ArrayList(java.util.ArrayList) List(java.util.List) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 2 with IBase

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();
        }
    };
}
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 3 with IBase

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;
}
Also used : IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType)

Example 4 with IBase

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);
        }
    }
}
Also used : Identifiers(gov.cms.ab2d.coverage.model.Identifiers) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 5 with IBase

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);
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) IBaseHasModifierExtensions(org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions) Iterator(java.util.Iterator) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBase(org.hl7.fhir.instance.model.api.IBase) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) Collectors(java.util.stream.Collectors) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) List(java.util.List) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition) Map(java.util.Map) BaseRuntimeElementCompositeDefinition(ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) IBaseHasModifierExtensions(org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) List(java.util.List) IBase(org.hl7.fhir.instance.model.api.IBase) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension)

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