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);
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations