Search in sources :

Example 1 with R4TranslatingLibraryLoader

use of com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeeder method create.

public IMeasureEvaluationSeed create(Measure measure, String periodStart, String periodEnd, String productLine, Map<String, Parameter> parameters) {
    // Gather the primary library and all of its dependencies
    List<Library> fhirLibraries = libraryDependencyGatherer.gatherForMeasure(measure);
    if (CollectionUtils.isEmpty(fhirLibraries)) {
        throw new IllegalArgumentException(String.format("No libraries were able to be loaded for %s", measure.getId()));
    }
    // the "primary" library is always the first library loaded for the measure
    Library primaryFhirLibrary = fhirLibraries.get(0);
    VersionedIdentifier libraryIdentifier = new VersionedIdentifier().withId(primaryFhirLibrary.getName()).withVersion(primaryFhirLibrary.getVersion());
    LibraryLoader libraryLoader = new R4TranslatingLibraryLoader(libraryResolver, new CqlToElmTranslator());
    org.cqframework.cql.elm.execution.Library primaryLibrary = libraryLoader.load(libraryIdentifier);
    List<Triple<String, String, String>> usingDefs = UsingHelper.getUsingUrlAndVersion(primaryLibrary.getUsings());
    if (usingDefs.size() > 1) {
        throw new IllegalArgumentException("Evaluation of Measure using multiple Models is not supported at this time.");
    }
    // Per the above condition, we should only have one model per measure
    String lastModelUri = usingDefs.get(usingDefs.size() - 1).getRight();
    DataProvider dataProvider = dataProviders.get(lastModelUri);
    Context context = createContext(primaryLibrary, lastModelUri, dataProvider, productLine, libraryLoader);
    // fhir path: Measure.extension[measureParameter][].valueParameterDefinition.extension[defaultValue]
    measure.getExtension().stream().filter(MeasureEvaluationSeeder::isMeasureParameter).map(parameter -> dataProvider.resolvePath(parameter, "valueParameterDefinition")).map(ParameterDefinition.class::cast).forEach(parameterDefinition -> setDefaultValue(context, parameterDefinition));
    if (parameters != null) {
        parameters.entrySet().stream().forEach(e -> context.setParameter(null, e.getKey(), e.getValue().toCqlType()));
    }
    // Set measurement period last to make sure we respect periodStart
    // and periodEnd date boundaries for an execution.
    Interval measurementPeriod = createMeasurePeriod(periodStart, periodEnd);
    context.setParameter(null, MEASUREMENT_PERIOD, measurementPeriod);
    return new CustomMeasureEvaluationSeed(measure, context, measurementPeriod, dataProvider);
}
Also used : CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Context(org.opencds.cqf.cql.engine.execution.Context) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) R4TranslatingLibraryLoader(com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) Triple(org.apache.commons.lang3.tuple.Triple) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) DataProvider(org.opencds.cqf.cql.engine.data.DataProvider) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) R4TranslatingLibraryLoader(com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader) Interval(org.opencds.cqf.cql.engine.runtime.Interval)

Aggregations

CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)1 R4TranslatingLibraryLoader (com.ibm.cohort.cql.hapi.R4TranslatingLibraryLoader)1 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)1 CDMContext (com.ibm.cohort.engine.cqfruler.CDMContext)1 Triple (org.apache.commons.lang3.tuple.Triple)1 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)1 Library (org.hl7.fhir.r4.model.Library)1 DataProvider (org.opencds.cqf.cql.engine.data.DataProvider)1 Context (org.opencds.cqf.cql.engine.execution.Context)1 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)1 Interval (org.opencds.cqf.cql.engine.runtime.Interval)1