Search in sources :

Example 6 with CqlLibraryProvider

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

the class CqlTranslationIntegrationTest method multipleFilesInFolder__translatedSuccessfully.

@Test
public void multipleFilesInFolder__translatedSuccessfully() throws Exception {
    Path rootDirectory = Paths.get("src/test/resources/cql/multiple-files");
    MapCqlLibraryProviderFactory providerFactory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider backingLibraryProvider = providerFactory.fromDirectory(rootDirectory);
    runMultipleFilesTest(backingLibraryProvider);
}
Also used : Path(java.nio.file.Path) MapCqlLibraryProviderFactory(com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Test(org.junit.Test)

Example 7 with CqlLibraryProvider

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

the class CqlTranslationIntegrationTest method runMultipleFilesTest.

private void runMultipleFilesTest(CqlLibraryProvider backingLibraryProvider) {
    Path modelInfo = Paths.get("src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml");
    CqlToElmTranslator translator = new CqlToElmTranslator();
    translator.registerModelInfo(modelInfo.toFile());
    CqlLibraryProvider libraryProvider = new TranslatingCqlLibraryProvider(backingLibraryProvider, translator, true);
    List<String> libraryNames = Arrays.asList("BreastCancerScreening", "Test", "TestDateQuery");
    for (String libraryName : libraryNames) {
        CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId(libraryName).setVersion("1.0.0").setFormat(Format.ELM);
        CqlLibrary library = libraryProvider.getLibrary(descriptor);
        Assert.assertFalse(library.getContent().isEmpty());
    }
}
Also used : Path(java.nio.file.Path) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Example 8 with CqlLibraryProvider

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

the class CqlTranslationIntegrationTest method exceptionCausedByNotIncludingFHIRHelpers.

@Test
public void exceptionCausedByNotIncludingFHIRHelpers() {
    CqlLibraryProvider backingLibraryProvider = new ClasspathCqlLibraryProvider("cql.failure");
    CqlToElmTranslator translator = new CqlToElmTranslator();
    CqlLibraryProvider translatingLibraryProvider = new TranslatingCqlLibraryProvider(backingLibraryProvider, translator, true);
    boolean failed = false;
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("MissingFhirHelpers").setVersion("1.0.0").setFormat(Format.ELM);
    try {
        translatingLibraryProvider.getLibrary(descriptor);
    } catch (Exception e) {
        failed = true;
        Assert.assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().startsWith("There were exceptions during cql translation:"));
    }
    if (!failed) {
        Assert.fail("Did not fail translation");
    }
}
Also used : ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 9 with CqlLibraryProvider

use of com.ibm.cohort.cql.library.CqlLibraryProvider 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 10 with CqlLibraryProvider

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

the class TranslatingCqlLibraryProviderTest method testLoadWithTranslation.

@Test
public void testLoadWithTranslation() throws Exception {
    CqlToElmTranslator translator = new CqlToElmTranslator();
    try (Reader modelInfoXML = new FileReader("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml")) {
        translator.registerModelInfo(modelInfoXML);
    }
    CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("cql");
    CqlLibraryProvider provider = new TranslatingCqlLibraryProvider(backingProvider, translator);
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("CohortHelpers").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary library = provider.getLibrary(descriptor);
    assertEquals(Format.CQL, library.getDescriptor().getFormat());
    assertTrue(library.getContent().startsWith("library"));
    descriptor.setFormat(Format.ELM);
    library = provider.getLibrary(descriptor);
    assertEquals(Format.ELM, library.getDescriptor().getFormat());
    assertTrue(library.getContent().startsWith("<?xml"));
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Aggregations

CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)27 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)23 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)18 Test (org.junit.Test)15 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)13 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)11 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)10 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)10 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)9 HashMap (java.util.HashMap)9 Path (java.nio.file.Path)8 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)7 MapCqlLibraryProviderFactory (com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory)7 File (java.io.File)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)3 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)3 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)3 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)3