Search in sources :

Example 1 with CDMContext

use of com.ibm.cohort.engine.cqfruler.CDMContext in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testDefinesOnMeasureReport.

@Test
public void testDefinesOnMeasureReport() {
    MeasureReport report = new MeasureReport();
    Map<VersionedIdentifier, Map<String, Object>> expectedResults = setupTestExpectedResultsContext();
    CDMContext defineContext = setupTestDefineContext(expectedResults);
    CDMMeasureEvaluation.addDefineEvaluationToReport(report, defineContext, DefineReturnOptions.ALL);
    assertEquals(5, report.getExtension().size());
    int index = 0;
    for (Entry<VersionedIdentifier, Map<String, Object>> expectedLibraryResults : expectedResults.entrySet()) {
        for (Entry<String, Object> defineResult : expectedLibraryResults.getValue().entrySet()) {
            Extension extension = report.getExtension().get(index++);
            assertEquals(MeasureEvidenceHelper.createEvidenceKey(expectedLibraryResults.getKey(), defineResult.getKey()), extension.getExtensionByUrl(CDMConstants.EVIDENCE_TEXT_URL).getValue().primitiveValue());
            // hack because Type does not return equals for 2 identical objects :(
            Type returnType = extension.getExtensionByUrl(CDMConstants.EVIDENCE_VALUE_URL).getValue();
            if (defineResult.getValue() instanceof Boolean) {
                assertTrue(returnType.isBooleanPrimitive());
                assertEquals(defineResult.getValue(), ((BooleanType) returnType).booleanValue());
            } else if (defineResult.getValue() instanceof String) {
                assertTrue(returnType.isPrimitive());
                assertEquals(defineResult.getValue(), returnType.primitiveValue());
            } else if (defineResult.getValue() instanceof DomainResource) {
                assertTrue(returnType instanceof Reference);
            }
        }
    }
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) Reference(org.hl7.fhir.r4.model.Reference) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Extension(org.hl7.fhir.r4.model.Extension) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Type(org.hl7.fhir.r4.model.Type) BooleanType(org.hl7.fhir.r4.model.BooleanType) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) Test(org.junit.Test)

Example 2 with CDMContext

use of com.ibm.cohort.engine.cqfruler.CDMContext 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)

Example 3 with CDMContext

use of com.ibm.cohort.engine.cqfruler.CDMContext in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method setupTestDefineContext.

private CDMContext setupTestDefineContext(Map<VersionedIdentifier, Map<String, Object>> expectedResults) {
    Library library = new Library();
    CDMContext defineContext = new CDMContext(library);
    for (Entry<VersionedIdentifier, Map<String, Object>> expectedLibraryResults : expectedResults.entrySet()) {
        for (Entry<String, Object> defineResult : expectedLibraryResults.getValue().entrySet()) {
            defineContext.addExpressionToCache(expectedLibraryResults.getKey(), defineResult.getKey(), defineResult.getValue());
        }
    }
    return defineContext;
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Library(org.cqframework.cql.elm.execution.Library) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 4 with CDMContext

use of com.ibm.cohort.engine.cqfruler.CDMContext in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testBooleanDefinesOnMeasureReport.

@Test
public void testBooleanDefinesOnMeasureReport() {
    MeasureReport report = new MeasureReport();
    CDMContext defineContext = setupTestDefineContext(setupTestExpectedResultsContext());
    CDMMeasureEvaluation.addDefineEvaluationToReport(report, defineContext, DefineReturnOptions.BOOLEAN);
    assertEquals(3, report.getExtension().size());
    for (Extension extension : report.getExtension()) {
        Type returnType = extension.getExtensionByUrl(CDMConstants.EVIDENCE_VALUE_URL).getValue();
        assertTrue(returnType instanceof BooleanType);
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Type(org.hl7.fhir.r4.model.Type) BooleanType(org.hl7.fhir.r4.model.BooleanType) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) BooleanType(org.hl7.fhir.r4.model.BooleanType) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Aggregations

CDMContext (com.ibm.cohort.engine.cqfruler.CDMContext)4 Extension (org.hl7.fhir.r4.model.Extension)3 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)3 AbstractMap (java.util.AbstractMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)2 BooleanType (org.hl7.fhir.r4.model.BooleanType)2 Type (org.hl7.fhir.r4.model.Type)2 Test (org.junit.Test)2 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)1 DefineReturnOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions)1 Library (org.cqframework.cql.elm.execution.Library)1 DomainResource (org.hl7.fhir.r4.model.DomainResource)1 Measure (org.hl7.fhir.r4.model.Measure)1 Reference (org.hl7.fhir.r4.model.Reference)1 MeasureScoring (org.hl7.fhir.r4.model.codesystems.MeasureScoring)1