Search in sources :

Example 1 with ProviderBasedCqlLibrarySourceProvider

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

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;
        });
    }
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) ProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor)

Aggregations

CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)2 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)2 ProviderBasedCqlLibrarySourceProvider (com.ibm.cohort.cql.provider.ProviderBasedCqlLibrarySourceProvider)2 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)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 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