Search in sources :

Example 1 with DefineReturnOptions

use of com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluation method evaluatePatientMeasure.

/**
 * Evaluate a CDM Patient Quality Measure
 *
 * @param measure   CDM Patient Quality Measure
 * @param context   CQL Engine Execution Context pre-configured for use in
 *                  measure evaluation
 * @param patientIds Patient ID(s) of the patient to evaluate (first element when generating INDIVIDUAL type report)
 * @param evidenceOptions MeasureEvidenceOptions to indicate whether or not to return evaluated resources and define level results
 * @param parameterMap Map of parameter names to Parameter objects
 * @param type  Type of report to be generated
 * @return MeasureReport with population components filled out.
 */
public MeasureReport evaluatePatientMeasure(Measure measure, Context context, List<String> patientIds, MeasureEvidenceOptions evidenceOptions, Map<String, Parameter> parameterMap, MeasureReport.MeasureReportType type) {
    context.setExpressionCaching(true);
    boolean includeEvaluatedResources = (evidenceOptions != null) ? evidenceOptions.isIncludeEvaluatedResources() : false;
    MeasureReport report;
    switch(type) {
        case INDIVIDUAL:
            report = evaluation.evaluatePatientMeasure(measure, context, patientIds.get(0), includeEvaluatedResources);
            break;
        case SUBJECTLIST:
            report = evaluation.evaluatePatientListMeasure(measure, context, patientIds, includeEvaluatedResources);
            break;
        default:
            throw new IllegalStateException("Unsupported measure report type requested: " + type);
    }
    setReportMeasureToMeasureId(report, measure);
    MeasureScoring scoring = MeasureScoring.fromCode(measure.getScoring().getCodingFirstRep().getCode());
    switch(scoring) {
        case PROPORTION:
        case RATIO:
            // implement custom logic for CDM care-gaps
            Iterator<Measure.MeasureGroupComponent> it = measure.getGroup().iterator();
            for (int i = 0; it.hasNext(); i++) {
                Measure.MeasureGroupComponent group = it.next();
                MeasureReport.MeasureReportGroupComponent reportGroup = report.getGroup().get(i);
                boolean evaluateCareGaps = isEligibleForCareGapEvaluation(reportGroup);
                for (Measure.MeasureGroupPopulationComponent pop : group.getPopulation()) {
                    if (pop.getCode().hasCoding(CDMConstants.CDM_CODE_SYSTEM_MEASURE_POPULATION_TYPE, CDMConstants.CARE_GAP)) {
                        Boolean result = Boolean.FALSE;
                        if (evaluateCareGaps) {
                            result = evaluateCriteria(context, pop.getCriteria().getExpression());
                        }
                        MeasureReport.MeasureReportGroupPopulationComponent output = new MeasureReport.MeasureReportGroupPopulationComponent();
                        // need this to differentiate between multiple instances of care-gap
                        output.setId(pop.getId());
                        output.setCode(pop.getCode());
                        output.setCount(result ? 1 : 0);
                        reportGroup.addPopulation(output);
                    }
                }
            }
            break;
        default:
    }
    if (context instanceof CDMContext) {
        CDMContext defineContext = (CDMContext) context;
        // Grab the define results from the expression cache
        MeasureEvidenceOptions.DefineReturnOptions defineReturnOptions = (evidenceOptions != null) ? evidenceOptions.getDefineReturnOption() : MeasureEvidenceOptions.DefineReturnOptions.NONE;
        addDefineEvaluationToReport(report, defineContext, defineReturnOptions);
    }
    List<Extension> parameterExtensions = getParameterExtensions(measure, context, parameterMap);
    parameterExtensions.forEach(report::addExtension);
    return report;
}
Also used : MeasureReport(org.hl7.fhir.r4.model.MeasureReport) MeasureScoring(org.hl7.fhir.r4.model.codesystems.MeasureScoring) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) Extension(org.hl7.fhir.r4.model.Extension) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) Measure(org.hl7.fhir.r4.model.Measure)

Aggregations

CDMContext (com.ibm.cohort.engine.cqfruler.CDMContext)1 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)1 DefineReturnOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions)1 Extension (org.hl7.fhir.r4.model.Extension)1 Measure (org.hl7.fhir.r4.model.Measure)1 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)1 MeasureScoring (org.hl7.fhir.r4.model.codesystems.MeasureScoring)1