Search in sources :

Example 1 with Library

use of org.cqframework.cql.elm.execution.Library 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 Library

use of org.cqframework.cql.elm.execution.Library in project quality-measure-and-cohort-service by Alvearie.

the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipWithSearchPathsSuccess.

@Test
public void testLibraryFoundInZipWithSearchPathsSuccess() throws Exception {
    MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip-structured/col_colorectal_cancer_screening_v1_0_0.zip"), "CDSexport");
    CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
    provider = new PriorityCqlLibraryProvider(provider, fhirClasspathProvider);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    provider = new TranslatingCqlLibraryProvider(provider, translator, false);
    LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(provider);
    VersionedIdentifier id = new VersionedIdentifier().withId("COL_InitialPop").withVersion("1.0.0");
    Library library = libraryLoader.load(id);
    Assert.assertEquals("COL_InitialPop", library.getIdentifier().getId());
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) Library(org.cqframework.cql.elm.execution.Library) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) Test(org.junit.Test)

Example 3 with Library

use of org.cqframework.cql.elm.execution.Library in project CRD by HL7-DaVinci.

the class CqlExecutionContextBuilder method getExecutionContext.

public static Context getExecutionContext(CqlRule cqlRule, HashMap<String, Resource> cqlParams, String baseUrl) {
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);
    libraryManager.getLibrarySourceLoader().clearProviders();
    Library library = null;
    LibraryLoader libraryLoader = null;
    if (cqlRule.isPrecompiled()) {
    // todo
    } else {
        libraryManager.getLibrarySourceLoader().registerProvider(cqlRule.getRawCqlLibrarySourceProvider(CQL_VERSION));
        libraryLoader = new LocalLibraryLoader(libraryManager);
        try {
            library = CqlExecution.translate(cqlRule.getRawMainCqlLibrary(CQL_VERSION), libraryManager, modelManager);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    FhirContext fhirContext = FhirContext.forR4();
    Context context = new Context(library);
    context.registerLibraryLoader(libraryLoader);
    context.setExpressionCaching(true);
    R4FhirModelResolver modelResolver = new R4FhirModelResolver();
    RestFhirRetrieveProvider retrieveProvider = new RestFhirRetrieveProvider(new SearchParameterResolver(fhirContext), fhirContext.newRestfulGenericClient("http://fhirtest.uhn.ca/baseR4"));
    CompositeDataProvider provider = new CompositeDataProvider(modelResolver, retrieveProvider);
    context.registerDataProvider("http://hl7.org/fhir", provider);
    for (Map.Entry<String, org.hl7.fhir.r4.model.Resource> entry : cqlParams.entrySet()) {
        context.setParameter(null, entry.getKey(), entry.getValue());
    }
    context.setParameter(null, "base_url", baseUrl);
    return context;
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) FhirContext(ca.uhn.fhir.context.FhirContext) FhirContext(ca.uhn.fhir.context.FhirContext) Resource(org.hl7.fhir.r4.model.Resource) ModelManager(org.cqframework.cql.cql2elm.ModelManager) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) LocalLibraryLoader(org.hl7.davinci.endpoint.cql.LocalLibraryLoader) R4FhirModelResolver(org.opencds.cqf.cql.engine.fhir.model.R4FhirModelResolver) SearchParameterResolver(org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver) LocalLibraryLoader(org.hl7.davinci.endpoint.cql.LocalLibraryLoader) RestFhirRetrieveProvider(org.opencds.cqf.cql.engine.fhir.retrieve.RestFhirRetrieveProvider) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager) CompositeDataProvider(org.opencds.cqf.cql.engine.data.CompositeDataProvider) Library(org.cqframework.cql.elm.execution.Library) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Library

use of org.cqframework.cql.elm.execution.Library 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;
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) CDMContext(com.ibm.cohort.engine.cqfruler.CDMContext) Library(org.cqframework.cql.elm.execution.Library) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 5 with Library

use of org.cqframework.cql.elm.execution.Library in project quality-measure-and-cohort-service by Alvearie.

the class R4TranslatingLibraryLoader method translateLibrary.

private String translateLibrary(String content, VersionedIdentifier libraryIdentifier) {
    LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResolutionProvider = new ResolverLibraryResolutionProvider<>(resolver);
    LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment> librarySourceProvider = new LibrarySourceProvider<>(libraryResolutionProvider, org.hl7.fhir.r4.model.Library::getContent, Attachment::getContentType, Attachment::getData);
    CqlLibrarySourceProvider cqlLibrarySourceProvider = new SourceProviderBasedCqlLibrarySourceProvider(librarySourceProvider);
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setFormat(Format.CQL).setLibraryId(libraryIdentifier.getId()).setVersion(libraryIdentifier.getVersion());
    CqlLibrary library = new CqlLibrary().setDescriptor(descriptor).setContent(content);
    return translator.translate(library, cqlLibrarySourceProvider).getMainLibrary().getContent();
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) LibrarySourceProvider(org.opencds.cqf.common.providers.LibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) Attachment(org.hl7.fhir.r4.model.Attachment) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) ResolverLibraryResolutionProvider(com.ibm.cohort.cql.hapi.provider.ResolverLibraryResolutionProvider)

Aggregations

Library (org.cqframework.cql.elm.execution.Library)14 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)6 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)5 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)3 JAXBException (javax.xml.bind.JAXBException)3 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)2 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)2 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)2 ProviderBasedLibraryLoader (com.ibm.cohort.cql.library.ProviderBasedLibraryLoader)2 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2