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());
}
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;
}
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());
}
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());
}
}
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"));
}
Aggregations