Search in sources :

Example 1 with CompiledLibrary

use of org.cqframework.cql.cql2elm.model.CompiledLibrary in project clinical_quality_language by cqframework.

the class LibraryManager method tryCompiledLibraryElm.

private CompiledLibrary tryCompiledLibraryElm(VersionedIdentifier libraryIdentifier, CqlTranslatorOptions options) {
    CompiledLibrary result = null;
    InputStream librarySource = null;
    if (librarySourceLoader instanceof LibrarySourceLoaderExt) {
        LibrarySourceLoaderExt sourceLoaderExt = (LibrarySourceLoaderExt) librarySourceLoader;
        Set<LibraryContentType> supportedTypes = sourceLoaderExt.getSupportedContentTypes();
        for (LibraryContentType type : supportedTypes) {
            if (type != LibraryContentType.CQL) {
                try {
                    librarySource = sourceLoaderExt.getLibrarySource(libraryIdentifier, type);
                    if (librarySource == null) {
                        continue;
                    }
                    result = generateCompiledLibraryFromElm(libraryIdentifier, librarySource, type, options);
                    if (result != null) {
                        break;
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
    }
    return result;
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) InputStream(java.io.InputStream) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 2 with CompiledLibrary

use of org.cqframework.cql.cql2elm.model.CompiledLibrary in project clinical_quality_language by cqframework.

the class ElmRequirementsContext method reportExpressionRef.

public ElmRequirement reportExpressionRef(ExpressionRef expressionRef) {
    CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), expressionRef.getLibraryName());
    try {
        ExpressionDef ed = targetLibrary.resolveExpressionRef(expressionRef.getName());
        if (!visited.contains(ed)) {
            visitor.visitElement(ed, this);
        }
        ElmRequirement inferredRequirements = getInferredRequirements(ed);
        // Report data requirements for this expression def to the current context (that are not already part of the inferred requirements
        ElmRequirements reportedRequirements = getReportedRequirements(ed);
        if (reportedRequirements != null) {
            reportRequirements(reportedRequirements, inferredRequirements);
        }
        // Return the inferred requirements for the expression def
        return inferredRequirements;
    } finally {
        unprepareLibraryVisit(expressionRef.getLibraryName());
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary)

Example 3 with CompiledLibrary

use of org.cqframework.cql.cql2elm.model.CompiledLibrary in project clinical_quality_language by cqframework.

the class BaseTest method testRetrieveWithConcept.

@Test
public void testRetrieveWithConcept() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("fhir/dstu2/TestRetrieveWithConcept.cql", 0);
    CompiledLibrary library = translator.getTranslatedLibrary();
    ExpressionDef expressionDef = library.resolveExpressionRef("Test Tobacco Smoking Status");
    assertThat(expressionDef.getExpression(), instanceOf(Retrieve.class));
    Retrieve retrieve = (Retrieve) expressionDef.getExpression();
    assertThat(retrieve.getCodes(), instanceOf(ToList.class));
    ToList toList = (ToList) retrieve.getCodes();
    assertThat(toList.getOperand(), instanceOf(CodeRef.class));
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) Test(org.testng.annotations.Test)

Example 4 with CompiledLibrary

use of org.cqframework.cql.cql2elm.model.CompiledLibrary in project clinical_quality_language by cqframework.

the class BaseTest method testEqualityWithConversions.

@Test
public void testEqualityWithConversions() throws IOException {
    CompiledLibrary library = visitFileLibrary("fhir/r4/EqualityWithConversions.cql");
    ExpressionDef getGender = library.resolveExpressionRef("GetGender");
    assertThat(getGender.getExpression(), instanceOf(Equal.class));
    Equal equal = (Equal) getGender.getExpression();
    assertThat(equal.getOperand().get(0), instanceOf(FunctionRef.class));
    FunctionRef functionRef = (FunctionRef) equal.getOperand().get(0);
    assertThat(functionRef.getName(), is("ToString"));
    assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) Test(org.testng.annotations.Test)

Example 5 with CompiledLibrary

use of org.cqframework.cql.cql2elm.model.CompiledLibrary in project clinical_quality_language by cqframework.

the class BaseTest method testEqualityWithConversions.

@Test
public void testEqualityWithConversions() throws IOException {
    CompiledLibrary library = visitFileLibrary("fhir/r401/EqualityWithConversions.cql");
    ExpressionDef getGender = library.resolveExpressionRef("GetGender");
    assertThat(getGender.getExpression(), instanceOf(Equal.class));
    Equal equal = (Equal) getGender.getExpression();
    assertThat(equal.getOperand().get(0), instanceOf(FunctionRef.class));
    FunctionRef functionRef = (FunctionRef) equal.getOperand().get(0);
    assertThat(functionRef.getName(), is("ToString"));
    assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) Test(org.testng.annotations.Test)

Aggregations

CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)35 Test (org.testng.annotations.Test)25 CqlTranslator (org.cqframework.cql.cql2elm.CqlTranslator)16 IOException (java.io.IOException)5 JAXBException (javax.xml.bind.JAXBException)4 InputStream (java.io.InputStream)3 NamespaceInfo (org.cqframework.cql.cql2elm.NamespaceInfo)3 DataType (org.hl7.cql.model.DataType)2 ExpressionDef (org.hl7.elm.r1.ExpressionDef)2 InputStreamReader (java.io.InputStreamReader)1 QuickDataType.quickDataType (org.cqframework.cql.cql2elm.matchers.QuickDataType.quickDataType)1 ChoiceType (org.hl7.cql.model.ChoiceType)1 Annotation (org.hl7.cql_annotations.r1.Annotation)1 Tag (org.hl7.cql_annotations.r1.Tag)1 CodeDef (org.hl7.elm.r1.CodeDef)1 CodeSystemDef (org.hl7.elm.r1.CodeSystemDef)1 ConceptDef (org.hl7.elm.r1.ConceptDef)1 FunctionDef (org.hl7.elm.r1.FunctionDef)1 IncludeDef (org.hl7.elm.r1.IncludeDef)1 Library (org.hl7.elm.r1.Library)1