All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.fhir.cql.translator.impl.InJVMCqlTranslationProvider Maven / Gradle / Ivy

The newest version!
/*
 * (C) Copyright IBM Corp. 2021
 *
 * SPDX-License-Identifier: Apache-2.0
 */
package com.ibm.fhir.cql.translator.impl;

import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.cqframework.cql.cql2elm.CqlTranslator;
import org.cqframework.cql.cql2elm.CqlTranslator.Options;
import org.cqframework.cql.cql2elm.CqlTranslatorException;
import org.cqframework.cql.cql2elm.FhirLibrarySourceProvider;
import org.cqframework.cql.cql2elm.LibraryBuilder;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.cqframework.cql.cql2elm.ModelManager;
import org.cqframework.cql.elm.execution.Library;
import org.cqframework.cql.elm.tracking.TrackBack;
import org.fhir.ucum.UcumService;
import org.opencds.cqf.cql.engine.execution.CqlLibraryReader;

import com.ibm.fhir.cql.translator.CqlTranslationException;

/**
 * Provide an implementation of the CqlTranslationProvider interface that uses
 * the CQL translator directly inside the JVM. 
 */
public class InJVMCqlTranslationProvider extends BaseCqlTranslationProvider {

    private static final Logger LOG = Logger.getLogger(InJVMCqlTranslationProvider.class.getName());
    
    private ModelManager modelManager;
    private LibraryManager libraryManager;
    
    public InJVMCqlTranslationProvider() {
        this.modelManager = new ModelManager();
        this.libraryManager = new LibraryManager(modelManager);
        addLibrarySourceProvider(new FhirLibrarySourceProvider());
    }

    public InJVMCqlTranslationProvider(LibraryManager libraryManager, ModelManager modelManager) {
        this.modelManager = modelManager;
        this.libraryManager = libraryManager;
    }

    public InJVMCqlTranslationProvider(LibrarySourceProvider provider) {
        this();
        addLibrarySourceProvider(provider);
    }

    public InJVMCqlTranslationProvider addLibrarySourceProvider(LibrarySourceProvider provider) {
        libraryManager.getLibrarySourceLoader().registerProvider(provider);
        return this;
    }

    @Override
    public List translate(InputStream cql, List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy