Java Code Examples for org.opencds.cqf.cql.execution.Context#registerTerminologyProvider()

The following examples show how to use org.opencds.cqf.cql.execution.Context#registerTerminologyProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCodeRef.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
public void CodeRefTest1() {
    Context context = new Context(library);
    context.registerTerminologyProvider(terminologyProvider);

    Object result = context.resolveExpressionRef("CodeRef1").getExpression().evaluate(context);
    assertTrue(result != null);
}
 
Example 2
Source File: TestCodeRef.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
public void CodeRefTest2() {
    Context context = new Context(library);
    context.registerTerminologyProvider(terminologyProvider);

    Object result = context.resolveExpressionRef("CodeRef2").getExpression().evaluate(context);
    assertTrue(result != null);
}
 
Example 3
Source File: MeasureEvaluationSeed.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
public void setup(
        Measure measure, String periodStart, String periodEnd,
        String productLine, String source, String user, String pass)
{
    this.measure = measure;

    LibraryHelper.loadLibraries(measure, this.libraryLoader, this.libraryResourceProvider);

    // resolve primary library
    Library library = LibraryHelper.resolvePrimaryLibrary(measure, libraryLoader, this.libraryResourceProvider);

    // resolve execution context
    context = new Context(library);
    context.registerLibraryLoader(libraryLoader);

    List<Triple<String,String,String>> usingDefs = UsingHelper.getUsingUrlAndVersion(library.getUsings());

    if (usingDefs.size() > 1) {
        throw new IllegalArgumentException("Evaluation of Measure using multiple Models is not supported at this time.");
    }

    // If there are no Usings, there is probably not any place the Terminology
    // actually used so I think the assumption that at least one provider exists is ok.
    TerminologyProvider terminologyProvider = null;
    if (usingDefs.size() > 0) {
        // Creates a terminology provider based on the first using statement. This assumes the terminology
        // server matches the FHIR version of the CQL.
        terminologyProvider = this.providerFactory.createTerminologyProvider(
                usingDefs.get(0).getLeft(), usingDefs.get(0).getMiddle(),
                    source, user, pass);
        context.registerTerminologyProvider(terminologyProvider);
    }

    for (Triple<String,String,String> def : usingDefs)
    {
        this.dataProvider = this.providerFactory.createDataProvider(def.getLeft(), def.getMiddle(), terminologyProvider);
        context.registerDataProvider(
            def.getRight(), 
            dataProvider);
    }

    // resolve the measurement period
    measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart, true), true,
            DateHelper.resolveRequestDate(periodEnd, false), true);

    context.setParameter(null, "Measurement Period",
            new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
                    DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true));

    if (productLine != null) {
        context.setParameter(null, "Product Line", productLine);
    }

    context.setExpressionCaching(true);
}
 
Example 4
Source File: MeasureEvaluationSeed.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
public void setup(
        Measure measure, String periodStart, String periodEnd,
        String productLine, String source, String user, String pass)
{
    this.measure = measure;

    LibraryHelper.loadLibraries(measure, this.libraryLoader, this.libraryResourceProvider);

    // resolve primary library
    Library library = LibraryHelper.resolvePrimaryLibrary(measure, libraryLoader, this.libraryResourceProvider);

    // resolve execution context
    context = new Context(library);
    context.registerLibraryLoader(libraryLoader);

    List<Triple<String,String,String>> usingDefs = UsingHelper.getUsingUrlAndVersion(library.getUsings());

    if (usingDefs.size() > 1) {
        throw new IllegalArgumentException("Evaluation of Measure using multiple Models is not supported at this time.");
    }

    // If there are no Usings, there is probably not any place the Terminology
    // actually used so I think the assumption that at least one provider exists is ok.
    TerminologyProvider terminologyProvider = null;
    if (usingDefs.size() > 0) {
        // Creates a terminology provider based on the first using statement. This assumes the terminology
        // server matches the FHIR version of the CQL.
        terminologyProvider = this.providerFactory.createTerminologyProvider(
                usingDefs.get(0).getLeft(), usingDefs.get(0).getMiddle(),
                    source, user, pass);
        context.registerTerminologyProvider(terminologyProvider);
    }

    for (Triple<String,String,String> def : usingDefs)
    {
        this.dataProvider = this.providerFactory.createDataProvider(def.getLeft(), def.getMiddle(), terminologyProvider);
        context.registerDataProvider(
            def.getRight(), 
            dataProvider);
    }


    // resolve the measurement period
    measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart, true), true,
            DateHelper.resolveRequestDate(periodEnd, false), true);

    context.setParameter(null, "Measurement Period",
            new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
                    DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true));

    if (productLine != null) {
        context.setParameter(null, "Product Line", productLine);
    }

    context.setExpressionCaching(true);
}