Search in sources :

Example 6 with IAnyResource

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

the class ReportProvider method patientReport.

private Parameters.ParametersParameterComponent patientReport(Patient thePatient, Period thePeriod, String serverBase) {
    String patientId = thePatient.getIdElement().getIdPart();
    final Map<IIdType, IAnyResource> bundleEntries = new HashMap<>();
    bundleEntries.put(thePatient.getIdElement(), thePatient);
    ReferenceParam subjectParam = new ReferenceParam(patientId);
    search(MeasureReport.class, Searches.byParam("subject", subjectParam)).getAllResourcesTyped().forEach(measureReport -> {
        if (measureReport.getPeriod().getEnd().before(thePeriod.getStart()) || measureReport.getPeriod().getStart().after(thePeriod.getEnd())) {
            return;
        }
        bundleEntries.putIfAbsent(measureReport.getIdElement(), measureReport);
        getEvaluatedResources(measureReport).values().forEach(resource -> bundleEntries.putIfAbsent(resource.getIdElement(), resource));
    });
    Bundle patientReportBundle = new Bundle();
    patientReportBundle.setMeta(new Meta().addProfile(PATIENT_REPORT_PROFILE_URL));
    patientReportBundle.setType(Bundle.BundleType.COLLECTION);
    patientReportBundle.setTimestamp(new Date());
    patientReportBundle.setId(patientId + "-report");
    patientReportBundle.setIdentifier(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString()));
    bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource.getValue()).setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), resource.getValue().getIdElement().getIdPart()))));
    Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent();
    patientParameter.setResource(patientReportBundle);
    patientParameter.setId(thePatient.getIdElement().getIdPart() + "-report");
    patientParameter.setName("return");
    return patientParameter;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Parameters(org.hl7.fhir.r4.model.Parameters) HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) Resource(org.hl7.fhir.r4.model.Resource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Date(java.util.Date) Identifier(org.hl7.fhir.r4.model.Identifier) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 7 with IAnyResource

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

Example 8 with IAnyResource

use of org.hl7.fhir.instance.model.api.IAnyResource in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method createAdjudicationWithReason.

/**
 * @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link
 *     AdjudicationComponent} will be contained in
 * @param ccwVariable the {@link CcwCodebookInterface} being coded
 * @param reasonCode the value to use for the {@link AdjudicationComponent#getReason()}'s {@link
 *     Coding#getCode()} for the resulting {@link Coding}
 * @return the output {@link AdjudicationComponent} for the specified input values
 */
static AdjudicationComponent createAdjudicationWithReason(IAnyResource rootResource, CcwCodebookInterface ccwVariable, Object reasonCode) {
    // Cheating here, since they use the same URL.
    String categoryConceptCode = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
    CodeableConcept category = createCodeableConcept(TransformerConstants.CODING_CCW_ADJUDICATION_CATEGORY, categoryConceptCode);
    category.getCodingFirstRep().setDisplay(ccwVariable.getVariable().getLabel());
    AdjudicationComponent adjudication = new AdjudicationComponent(category);
    adjudication.setReason(createCodeableConcept(rootResource, ccwVariable, reasonCode));
    return adjudication;
}
Also used : AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 9 with IAnyResource

use of org.hl7.fhir.instance.model.api.IAnyResource in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method createCodeableConceptForFieldId.

/**
 * Unlike {@link #createCodeableConcept(IAnyResource, CcwCodebookVariable, Optional)}, this method
 * creates a {@link CodeableConcept} that's intended for use as a field ID/discriminator: the
 * {@link Variable#getId()} will be used for the {@link Coding#getCode()}, rather than the {@link
 * Coding#getSystem()}.
 *
 * @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link
 *     CodeableConcept} will be contained in
 * @param codingSystem the {@link Coding#getSystem()} to use
 * @param ccwVariable the {@link CcwCodebookInterface} being coded
 * @return the output {@link CodeableConcept} for the specified input values
 */
private static CodeableConcept createCodeableConceptForFieldId(IAnyResource rootResource, String codingSystem, CcwCodebookInterface ccwVariable) {
    String code = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
    Coding coding = new Coding(codingSystem, code, ccwVariable.getVariable().getLabel());
    return new CodeableConcept().addCoding(coding);
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 10 with IAnyResource

use of org.hl7.fhir.instance.model.api.IAnyResource in project beneficiary-fhir-data by CMSgov.

the class TransformerUtilsV2 method createExtensionCoding.

/**
 * @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link Extension}
 *     will be contained in
 * @param ccwVariable the {@link CcwCodebookInterface} being coded
 * @param code the value to use for {@link Coding#getCode()} for the resulting {@link Coding}
 * @return the output {@link Extension}, with {@link Extension#getValue()} set to a new {@link
 *     Coding} to represent the specified input values
 */
static Extension createExtensionCoding(IAnyResource rootResource, CcwCodebookInterface ccwVariable, Optional<?> code) {
    if (!code.isPresent()) {
        throw new IllegalArgumentException();
    }
    Coding coding = createCoding(rootResource, ccwVariable, code.get());
    String extensionUrl = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
    Extension extension = new Extension(extensionUrl, coding);
    return extension;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding)

Aggregations

Coding (org.hl7.fhir.dstu3.model.Coding)4 Coding (org.hl7.fhir.r4.model.Coding)4 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)3 IAnyResource (org.hl7.fhir.instance.model.api.IAnyResource)3 IBaseExtension (org.hl7.fhir.instance.model.api.IBaseExtension)3 Extension (org.hl7.fhir.dstu3.model.Extension)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 Extension (org.hl7.fhir.r4.model.Extension)2 BaseRuntimeChildDefinition (ca.uhn.fhir.context.BaseRuntimeChildDefinition)1 BaseRuntimeElementCompositeDefinition (ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition)1 BaseRuntimeElementDefinition (ca.uhn.fhir.context.BaseRuntimeElementDefinition)1 RuntimeElemContainedResourceList (ca.uhn.fhir.context.RuntimeElemContainedResourceList)1 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1