Search in sources :

Example 16 with MeasureEvidenceOptions

use of com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions 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 17 with MeasureEvidenceOptions

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

the class MeasureEvaluatorTest method measure_default_invalid_type.

@Test(expected = InvalidOperatorArgument.class)
public void measure_default_invalid_type() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("TestAdultMales", DEFAULT_VERSION, "cql/fhir-measure/test-parameter-defaults.cql");
    expressionsByPopulationType.clear();
    expressionsByPopulationType.put(MeasurePopulationType.INITIALPOPULATION, INITIAL_POPULATION);
    expressionsByPopulationType.put(MeasurePopulationType.DENOMINATOR, DENOMINATOR);
    expressionsByPopulationType.put(MeasurePopulationType.NUMERATOR, NUMERATOR);
    Measure measure = getProportionMeasure("ProportionMeasureName", library, expressionsByPopulationType);
    measure.addExtension(createMeasureParameter("SomeAge", new StringType("invalid")));
    mockFhirResourceRetrieval(measure);
    evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions());
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) Test(org.junit.Test)

Example 18 with MeasureEvidenceOptions

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

the class MeasureEvaluatorTest method in_populations_evaluated_resources_returned.

@Test
public void in_populations_evaluated_resources_returned() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = setupDefineReturnLibrary();
    expressionsByPopulationType.clear();
    expressionsByPopulationType.put(MeasurePopulationType.INITIALPOPULATION, INITIAL_POPULATION);
    expressionsByPopulationType.put(MeasurePopulationType.DENOMINATOR, DENOMINATOR);
    expressionsByPopulationType.put(MeasurePopulationType.NUMERATOR, NUMERATOR);
    Measure measure = getProportionMeasure("ProportionMeasureName", library, expressionsByPopulationType);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions(true, DefineReturnOptions.NONE));
    assertNotNull(report);
    assertFalse(report.getEvaluatedResource().isEmpty());
    assertEquals(null, report.getExtensionByUrl(CDMConstants.EVIDENCE_URL));
}
Also used : CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Library(org.hl7.fhir.r4.model.Library) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) Test(org.junit.Test)

Aggregations

MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)18 Measure (org.hl7.fhir.r4.model.Measure)15 Test (org.junit.Test)15 Library (org.hl7.fhir.r4.model.Library)14 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)11 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)10 Patient (org.hl7.fhir.r4.model.Patient)10 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)6 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)6 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)6 MeasureContext (com.ibm.cohort.engine.measure.MeasureContext)6 HashMap (java.util.HashMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 IParser (ca.uhn.fhir.parser.IParser)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 PatientListMeasureEvaluation (com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation)3 Coding (org.hl7.fhir.r4.model.Coding)3 MeasureEvaluation (com.ibm.cohort.engine.api.service.model.MeasureEvaluation)2 Headers (com.jayway.restassured.response.Headers)2 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)2