Search in sources :

Example 1 with CqlTranslationResult

use of com.ibm.cohort.cql.translation.CqlTranslationResult 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)

Aggregations

ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)1 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)1 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)1 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)1 MapCqlLibraryProvider (com.ibm.cohort.cql.library.MapCqlLibraryProvider)1 MapCqlLibraryProviderFactory (com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory)1 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)1 ProviderBasedCqlLibrarySourceProvider (com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider)1 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)1 CqlTranslationResult (com.ibm.cohort.cql.translation.CqlTranslationResult)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1