Search in sources :

Example 1 with ProviderBasedLibraryLoader

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

the class CqlTranslationIntegrationTest method singleFile_withOptions__translatedSuccessfully.

@Test
public void singleFile_withOptions__translatedSuccessfully() {
    CqlLibraryProvider backingLibraryProvider = new ClasspathCqlLibraryProvider("cql.basic");
    CqlToElmTranslator translator = new CqlToElmTranslator();
    Path modelInfo = Paths.get("src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml");
    translator.registerModelInfo(modelInfo.toFile());
    CqlLibraryProvider translatingLibraryProvider = new TranslatingCqlLibraryProvider(backingLibraryProvider, translator, true);
    LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(translatingLibraryProvider);
    VersionedIdentifier identifier = new VersionedIdentifier().withId("Test").withVersion("1.0.0");
    Library library = libraryLoader.load(identifier);
    Assert.assertEquals(identifier, library.getIdentifier());
    Assert.assertEquals(2, library.getAnnotation().size());
    Assert.assertEquals(4, library.getStatements().getDef().size());
}
Also used : Path(java.nio.file.Path) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) Test(org.junit.Test)

Example 2 with ProviderBasedLibraryLoader

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

the class CqlContextFactory method createContext.

/**
 * Initialize a CQL context from the values associated with the provided
 * CQL Context Key. This encapsulates the set of initializations that are
 * static from run to run.
 *
 * @param contextKey container for stable context settings
 * @return initialized CQL Context object
 * @throws CqlLibraryDeserializationException if the specified library cannot be loaded
 */
protected Context createContext(ContextCacheKey contextKey) throws CqlLibraryDeserializationException {
    LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(contextKey.libraryProvider);
    VersionedIdentifier vid = new VersionedIdentifier().withId(contextKey.topLevelLibraryIdentifier.getId()).withVersion(contextKey.topLevelLibraryIdentifier.getVersion());
    Library entryPoint = libraryLoader.load(vid);
    Context cqlContext;
    if (contextKey.evaluationDateTime != null) {
        cqlContext = new Context(entryPoint, contextKey.evaluationDateTime, new CqlSystemDataProvider());
    } else {
        cqlContext = new Context(entryPoint, new CqlSystemDataProvider());
    }
    cqlContext.registerExternalFunctionProvider(vid, this.externalFunctionProvider);
    registerExternalIncludes(cqlContext, cqlContext.getCurrentLibrary());
    cqlContext.registerLibraryLoader(libraryLoader);
    cqlContext.registerTerminologyProvider(contextKey.terminologyProvider);
    if (contextKey.parameters != null) {
        Library library = cqlContext.getCurrentLibrary();
        for (Map.Entry<String, Parameter> entry : contextKey.parameters.entrySet()) {
            Object cqlValue = entry.getValue().toCqlType();
            cqlContext.setParameter(library.getLocalId(), entry.getKey(), cqlValue);
        }
        if (library.getIncludes() != null && library.getIncludes().getDef() != null) {
            for (IncludeDef def : library.getIncludes().getDef()) {
                String name = def.getLocalIdentifier();
                for (Map.Entry<String, Parameter> parameterValue : contextKey.parameters.entrySet()) {
                    Object cqlValue = parameterValue.getValue().toCqlType();
                    cqlContext.setParameter(name, parameterValue.getKey(), cqlValue);
                }
            }
        }
    }
    return cqlContext;
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) IncludeDef(org.cqframework.cql.elm.execution.IncludeDef) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) Library(org.cqframework.cql.elm.execution.Library) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) DebugMap(org.opencds.cqf.cql.engine.debug.DebugMap) CqlSystemDataProvider(com.ibm.cohort.cql.data.CqlSystemDataProvider)

Aggregations

ProviderBasedLibraryLoader (com.ibm.cohort.cql.library.ProviderBasedLibraryLoader)2 Library (org.cqframework.cql.elm.execution.Library)2 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)2 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)2 CqlSystemDataProvider (com.ibm.cohort.cql.data.CqlSystemDataProvider)1 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)1 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)1 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)1 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)1 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IncludeDef (org.cqframework.cql.elm.execution.IncludeDef)1 Test (org.junit.Test)1 DebugMap (org.opencds.cqf.cql.engine.debug.DebugMap)1 Context (org.opencds.cqf.cql.engine.execution.Context)1