Search in sources :

Example 1 with DebugMap

use of org.opencds.cqf.cql.engine.debug.DebugMap in project quality-measure-and-cohort-service by Alvearie.

the class CqlContextFactory method createContext.

/**
 * Initialize a CQL Engine Context object with the provided settings.
 *
 * @param libraryProvider           Provider for CQL library resources
 * @param topLevelLibraryIdentifier Identifier for the top level library
 * @param terminologyProvider       Provider for CQL terminology resources
 * @param dataProvider              Provider for data that underlies the evaluation
 * @param evaluationDateTime        Date and time that will be considered "now" during
 *                                  CQL evaluation. If null, then ZonedDateTime.now()
 *                                  will be used each time a context object is
 *                                  initialized.
 * @param contextData               Name-Value pair of context name + context value
 *                                  corresponding to the unique ID of an individual
 *                                  context that is being evaluated. In a Patient
 *                                  context, this would be the Patient ID, etc.
 * @param parameters                Optional input parameters for the CQL evaluation
 * @param debug                     Debug configuration.
 * @return initialized Context object
 * @throws CqlLibraryDeserializationException if the specified library cannot be
 *                                            loaded
 */
public Context createContext(CqlLibraryProvider libraryProvider, CqlVersionedIdentifier topLevelLibraryIdentifier, CqlTerminologyProvider terminologyProvider, CqlDataProvider dataProvider, ZonedDateTime evaluationDateTime, Pair<String, String> contextData, Map<String, Parameter> parameters, CqlDebug debug) throws CqlLibraryDeserializationException {
    ContextCacheKey key = new ContextCacheKey(libraryProvider, topLevelLibraryIdentifier, terminologyProvider, this.externalFunctionProvider, evaluationDateTime, parameters);
    Context cqlContext;
    if (cacheContexts) {
        cqlContext = CONTEXT_CACHE.computeIfAbsent(key, this::createContext);
    } else {
        cqlContext = createContext(key);
    }
    // The following data elements need to be reset on every evaluation...
    Set<String> uris = getModelUrisForLibrary(cqlContext.getCurrentLibrary());
    for (String modelUri : uris) {
        cqlContext.registerDataProvider(modelUri, dataProvider);
    }
    resetContextValues(cqlContext);
    cqlContext.clearExpressions();
    if (contextData != null) {
        cqlContext.setContextValue(contextData.getKey(), contextData.getValue());
    }
    DebugMap debugMap = createDebugMap(debug);
    cqlContext.setDebugMap(debugMap);
    cqlContext.setExpressionCaching(this.cacheExpressions);
    cqlContext.clearEvaluatedResources();
    return cqlContext;
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) DebugMap(org.opencds.cqf.cql.engine.debug.DebugMap)

Example 2 with DebugMap

use of org.opencds.cqf.cql.engine.debug.DebugMap in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationSeeder method createContext.

protected Context createContext(org.cqframework.cql.elm.execution.Library library, String modelUri, DataProvider dataProvider, String productLine, LibraryLoader libraryLoader) {
    Context context = createDefaultContext(library);
    context.registerLibraryLoader(libraryLoader);
    context.registerTerminologyProvider(terminologyProvider);
    context.registerDataProvider(modelUri, dataProvider);
    if (productLine != null) {
        context.setParameter(null, "Product Line", productLine);
    }
    if (enableExpressionCaching) {
        context.setExpressionCaching(true);
    }
    if (debugMode) {
        DebugMap debugMap = new DebugMap();
        debugMap.setIsLoggingEnabled(true);
        context.setDebugMap(debugMap);
    }
    return context;
}
Also used : CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Context(org.opencds.cqf.cql.engine.execution.Context) DebugMap(org.opencds.cqf.cql.engine.debug.DebugMap)

Aggregations

DebugMap (org.opencds.cqf.cql.engine.debug.DebugMap)2 Context (org.opencds.cqf.cql.engine.execution.Context)2 CDMContext (com.ibm.cohort.engine.cqfruler.CDMContext)1