use of com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider 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.provider.ProviderBasedCqlLibrarySourceProvider in project quality-measure-and-cohort-service by Alvearie.
the class TranslatingCqlLibraryProvider method getLibrary.
@Override
public CqlLibrary getLibrary(CqlLibraryDescriptor libraryDescriptor) {
if (libraryDescriptor.getFormat().equals(Format.CQL)) {
return backingLibraryProvider.getLibrary(libraryDescriptor);
} else {
return translations.computeIfAbsent(libraryDescriptor, key -> {
CqlLibraryDescriptor elmDescriptor = new CqlLibraryDescriptor().setLibraryId(key.getLibraryId()).setVersion(key.getVersion()).setFormat(Format.ELM);
CqlLibrary library = backingLibraryProvider.getLibrary(elmDescriptor);
if (library == null || forceTranslation) {
CqlLibraryDescriptor cqlDescriptor = new CqlLibraryDescriptor().setLibraryId(key.getLibraryId()).setVersion(key.getVersion()).setFormat(Format.CQL);
library = backingLibraryProvider.getLibrary(cqlDescriptor);
if (library != null) {
CqlTranslationResult translationResult = translator.translate(library, new ProviderBasedCqlLibrarySourceProvider(backingLibraryProvider));
return translationResult.getMainLibrary();
}
}
return library;
});
}
}
Aggregations