Search in sources :

Example 1 with CqlLibrary

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

the class TranslationCLI method runWithArgs.

public void runWithArgs(TranslationOptions options, PrintStream out) throws Exception {
    CqlLibraryProvider libraryProvider;
    if (options.directory != null && options.directory.exists()) {
        MapCqlLibraryProviderFactory libraryProviderFactory = new MapCqlLibraryProviderFactory();
        libraryProvider = libraryProviderFactory.fromDirectory(options.directory.toPath());
    } else {
        libraryProvider = new MapCqlLibraryProvider(Collections.emptyMap());
    }
    CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
    libraryProvider = new PriorityCqlLibraryProvider(libraryProvider, fhirClasspathProvider);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    if (options.modelInfoFile != null && options.modelInfoFile.exists()) {
        translator.registerModelInfo(options.modelInfoFile);
    }
    String content;
    try (InputStream is = new FileInputStream(options.cqlPath)) {
        content = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // The values in the descriptor are not relevant for the translation CLI.
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setFormat(Format.CQL).setLibraryId("TranslationCLI").setVersion("TranslationCLI");
    CqlLibrary library = new CqlLibrary().setDescriptor(descriptor).setContent(content);
    CqlTranslationResult result = translator.translate(library, new ProviderBasedCqlLibrarySourceProvider(libraryProvider));
    out.println("Translated Library: ");
    out.println(result.getMainLibrary().getContent());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MapCqlLibraryProvider(com.ibm.cohort.cql.library.MapCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) MapCqlLibraryProvider(com.ibm.cohort.cql.library.MapCqlLibraryProvider) FileInputStream(java.io.FileInputStream) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider) MapCqlLibraryProviderFactory(com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTranslationResult(com.ibm.cohort.cql.translation.CqlTranslationResult)

Example 2 with CqlLibrary

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

the class GraphWalkingElmVisitor method resolveLibrary.

protected Library resolveLibrary(VersionedIdentifier libraryIdentifier) {
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId(libraryIdentifier.getId()).setVersion(libraryIdentifier.getVersion()).setFormat(Format.ELM);
    CqlLibrary library = libraryProvider.getLibrary(descriptor);
    if (library == null) {
        throw new IllegalArgumentException("Missing library " + descriptor.toString());
    }
    LOG.trace(library.getContent());
    Library elmLibrary = JAXB.unmarshal(library.getContentAsStream(), Library.class);
    return elmLibrary;
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.hl7.elm.r1.Library) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Example 3 with CqlLibrary

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

the class CqlToElmTranslatorTest method testTranslationWithIncludes.

@Test
public void testTranslationWithIncludes() throws Exception {
    CqlLibraryProvider provider = new ClasspathCqlLibraryProvider("cql");
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("SampleLibrary").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary primaryLibrary = provider.getLibrary(descriptor);
    CqlLibrarySourceProvider sourceProvider = vid -> {
        CqlLibraryDescriptor d = new CqlLibraryDescriptor().setLibraryId(vid.getId()).setVersion(vid.getVersion()).setFormat(Format.CQL);
        return provider.getLibrary(d).getContentAsStream();
    };
    CqlToElmTranslator translator = new CqlToElmTranslator();
    try (Reader modelInfoXML = new FileReader(new File("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml"))) {
        translator.registerModelInfo(modelInfoXML);
    }
    CqlTranslationResult result = translator.translate(primaryLibrary, sourceProvider);
    assertEquals(1, result.getDependencies().size());
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) Assert.assertThrows(org.junit.Assert.assertThrows) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) Test(org.junit.Test) Reader(java.io.Reader) Format(com.ibm.cohort.cql.library.Format) File(java.io.File) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException) FileReader(java.io.FileReader) Assert.assertEquals(org.junit.Assert.assertEquals) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) Reader(java.io.Reader) FileReader(java.io.FileReader) 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) File(java.io.File) Test(org.junit.Test)

Example 4 with CqlLibrary

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

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

CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)17 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)17 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)10 Test (org.junit.Test)7 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)6 Format (com.ibm.cohort.cql.library.Format)5 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)5 HashMap (java.util.HashMap)4 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)3 CqlLibrarySourceProvider (com.ibm.cohort.cql.provider.CqlLibrarySourceProvider)3 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)3 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)3 FileReader (java.io.FileReader)3 Reader (java.io.Reader)3 Library (org.cqframework.cql.elm.execution.Library)3 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)2 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)2 MapCqlLibraryProviderFactory (com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory)2 ProviderBasedCqlLibrarySourceProvider (com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider)2 File (java.io.File)2