Search in sources :

Example 1 with InMemoryLibraryLoader

use of org.opencds.cqf.cql.engine.execution.InMemoryLibraryLoader in project quality-measure-and-cohort-service by Alvearie.

the class CQLParameterTests method runTest.

public void runTest(String type, Object expectedOutput, String defaultValue) throws Exception {
    String cql = "library \"Test\" version '1.0.0'\n";
    cql += "codesystem \"DUMMY\": 'urn:mysystem'\n";
    cql += "parameter Input " + type;
    if (defaultValue != null) {
        cql += " default ";
        cql += defaultValue;
    }
    cql += "\n";
    cql += "define Output:\n\tInput\n";
    Map<String, Object> parameters = null;
    if (defaultValue == null) {
        parameters = new HashMap<>();
        parameters.put("Input", expectedOutput);
    }
    TerminologyProvider tp = new TerminologyProvider() {

        @Override
        public boolean in(Code code, ValueSetInfo valueSet) {
            return false;
        }

        @Override
        public Iterable<Code> expand(ValueSetInfo valueSet) {
            return null;
        }

        @Override
        public Code lookup(Code code, CodeSystemInfo codeSystem) {
            return code;
        }
    };
    LibraryLoader ll = new InMemoryLibraryLoader(Arrays.asList(toLibrary(cql)));
    CqlEngine engine = new CqlEngine(ll, Collections.<String, DataProvider>emptyMap(), tp);
    EvaluationResult result = engine.evaluate("Test", parameters);
    assertEquals(1, result.expressionResults.size());
    Object actual = result.forExpression("Output");
    assertEquals(expectedOutput.toString(), actual.toString());
}
Also used : CodeSystemInfo(org.opencds.cqf.cql.engine.terminology.CodeSystemInfo) TerminologyProvider(org.opencds.cqf.cql.engine.terminology.TerminologyProvider) CqlEngine(org.opencds.cqf.cql.engine.execution.CqlEngine) Code(org.opencds.cqf.cql.engine.runtime.Code) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) InMemoryLibraryLoader(org.opencds.cqf.cql.engine.execution.InMemoryLibraryLoader) InMemoryLibraryLoader(org.opencds.cqf.cql.engine.execution.InMemoryLibraryLoader) EvaluationResult(org.opencds.cqf.cql.engine.execution.EvaluationResult)

Aggregations

CqlEngine (org.opencds.cqf.cql.engine.execution.CqlEngine)1 EvaluationResult (org.opencds.cqf.cql.engine.execution.EvaluationResult)1 InMemoryLibraryLoader (org.opencds.cqf.cql.engine.execution.InMemoryLibraryLoader)1 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)1 Code (org.opencds.cqf.cql.engine.runtime.Code)1 CodeSystemInfo (org.opencds.cqf.cql.engine.terminology.CodeSystemInfo)1 TerminologyProvider (org.opencds.cqf.cql.engine.terminology.TerminologyProvider)1 ValueSetInfo (org.opencds.cqf.cql.engine.terminology.ValueSetInfo)1