Search in sources :

Example 11 with ExpressionDef

use of org.hl7.elm.r1.ExpressionDef in project clinical_quality_language by cqframework.

the class BaseTest method testEXM165.

@Test
public void testEXM165() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("qicore/v410/EXM165_QICore4-8.5.000.cql", 0);
    Library library = translator.toELM();
    Map<String, ExpressionDef> defs = new HashMap<>();
    if (library.getStatements() != null) {
        for (ExpressionDef def : library.getStatements().getDef()) {
            defs.put(def.getName(), def);
        }
    }
    ExpressionDef def = defs.get("Initial Population");
}
Also used : ExpressionDef(org.hl7.elm.r1.ExpressionDef) HashMap(java.util.HashMap) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) Library(org.hl7.elm.r1.Library) Test(org.testng.annotations.Test)

Example 12 with ExpressionDef

use of org.hl7.elm.r1.ExpressionDef in project clinical_quality_language by cqframework.

the class BaseTest method testFHIRHelpers.

@Test
public void testFHIRHelpers() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("fhir/r401/TestFHIRHelpers.cql", 0);
    CompiledLibrary translatedLibrary = translator.getTranslatedLibrary();
    assertResultType(translatedLibrary, "TestExtensions", "FHIR", "Extension");
    assertResultType(translatedLibrary, "TestElementExtensions", "FHIR", "Extension");
    assertResultType(translatedLibrary, "TestModifierExtensions", "FHIR", "Extension");
    assertResultType(translatedLibrary, "TestElementModifierExtensions", "FHIR", "Extension");
    ExpressionDef ed = translatedLibrary.resolveExpressionRef("TestChoiceConverts");
    DataType resultType = ed.getExpression().getResultType();
    assertThat(resultType, instanceOf(ChoiceType.class));
    assertThat(resultType.toString(), equalTo("choice<System.String,System.Boolean,System.Date,System.DateTime,System.Decimal,System.Integer,System.Time,System.Quantity,System.Concept,System.Code,interval<System.Quantity>,interval<System.DateTime>,System.Ratio,FHIR.Address,FHIR.Annotation,FHIR.Attachment,FHIR.ContactPoint,FHIR.HumanName,FHIR.Identifier,FHIR.Money,FHIR.Reference,FHIR.SampledData,FHIR.Signature,FHIR.Timing,FHIR.ContactDetail,FHIR.Contributor,FHIR.DataRequirement,FHIR.Expression,FHIR.ParameterDefinition,FHIR.RelatedArtifact,FHIR.TriggerDefinition,FHIR.UsageContext,FHIR.Dosage,FHIR.Meta>"));
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) ChoiceType(org.hl7.cql.model.ChoiceType) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) QuickDataType.quickDataType(org.cqframework.cql.cql2elm.matchers.QuickDataType.quickDataType) DataType(org.hl7.cql.model.DataType) Test(org.testng.annotations.Test)

Example 13 with ExpressionDef

use of org.hl7.elm.r1.ExpressionDef in project clinical_quality_language by cqframework.

the class BaseTest method assertResultType.

private void assertResultType(CompiledLibrary translatedLibrary, String expressionName, String namespace, String name) {
    ExpressionDef ed = translatedLibrary.resolveExpressionRef(expressionName);
    DataType resultType = ed.getExpression().getResultType();
    assertThat(resultType, instanceOf(ClassType.class));
    ClassType resultClassType = (ClassType) resultType;
    assertThat(resultClassType.getNamespace(), equalTo(namespace));
    assertThat(resultClassType.getSimpleName(), equalTo(name));
}
Also used : QuickDataType.quickDataType(org.cqframework.cql.cql2elm.matchers.QuickDataType.quickDataType) DataType(org.hl7.cql.model.DataType) ClassType(org.hl7.cql.model.ClassType)

Example 14 with ExpressionDef

use of org.hl7.elm.r1.ExpressionDef in project clinical_quality_language by cqframework.

the class SemanticTests method testTypeOperators.

@Test
public void testTypeOperators() throws IOException {
    CqlTranslator translator = runSemanticTest("OperatorTests/TypeOperators.cql");
    org.hl7.elm.r1.Library library = translator.toELM();
    Map<String, ExpressionDef> defs = new HashMap<>();
    if (library.getStatements() != null) {
        for (ExpressionDef def : library.getStatements().getDef()) {
            defs.put(def.getName(), def);
        }
    }
    ExpressionDef def = defs.get("TestIf");
    assertThat(def.getResultType(), instanceOf(ChoiceType.class));
    ChoiceType choiceType = (ChoiceType) def.getResultType();
    DataType type = null;
    for (DataType dt : choiceType.getTypes()) {
        if (type == null) {
            type = dt;
            assertThat(dt, instanceOf(NamedType.class));
            assertThat(((NamedType) dt).getName(), equalTo("System.String"));
        } else {
            assertThat(dt, instanceOf(NamedType.class));
            assertThat(((NamedType) dt).getName(), equalTo("System.Boolean"));
        }
    }
    def = defs.get("TestCase");
    assertThat(def.getResultType(), instanceOf(ChoiceType.class));
    choiceType = (ChoiceType) def.getResultType();
    type = null;
    for (DataType dt : choiceType.getTypes()) {
        if (type == null) {
            type = dt;
            assertThat(dt, instanceOf(NamedType.class));
            assertThat(((NamedType) dt).getName(), equalTo("System.String"));
        } else {
            assertThat(dt, instanceOf(NamedType.class));
            assertThat(((NamedType) dt).getName(), equalTo("System.Boolean"));
        }
    }
}
Also used : HashMap(java.util.HashMap) ChoiceType(org.hl7.cql.model.ChoiceType) NamedType(org.hl7.cql.model.NamedType) DataType(org.hl7.cql.model.DataType) org.hl7.elm.r1(org.hl7.elm.r1) Test(org.testng.annotations.Test)

Example 15 with ExpressionDef

use of org.hl7.elm.r1.ExpressionDef in project clinical_quality_language by cqframework.

the class NullologicalOperatorsTest method testIsNull.

@Test
public void testIsNull() {
    ExpressionDef def = defs.get("IsNullExpression");
    assertThat(def, hasTypeAndResult(IsNull.class, "System.Boolean"));
    IsNull isNull = (IsNull) def.getExpression();
    assertThat(isNull.getOperand(), literalFor(1));
}
Also used : ExpressionDef(org.hl7.elm.r1.ExpressionDef) IsNull(org.hl7.elm.r1.IsNull) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ExpressionDef (org.hl7.elm.r1.ExpressionDef)11 Test (org.testng.annotations.Test)9 Library (org.hl7.elm.r1.Library)7 HashMap (java.util.HashMap)6 CqlTranslator (org.cqframework.cql.cql2elm.CqlTranslator)6 CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)4 Element (org.hl7.elm.r1.Element)4 BeforeTest (org.testng.annotations.BeforeTest)4 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 ModelManager (org.cqframework.cql.cql2elm.ModelManager)3 DataType (org.hl7.cql.model.DataType)3 Annotation (org.hl7.cql_annotations.r1.Annotation)3 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)2 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)2 Format (com.ibm.cohort.cql.library.Format)2 IOException (java.io.IOException)2 QuickDataType.quickDataType (org.cqframework.cql.cql2elm.matchers.QuickDataType.quickDataType)2