Search in sources :

Example 6 with ExpressionDef

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

the class BaseTest method testQICore.

@Test
public void testQICore() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("qicore/v410/TestQICore.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("TestAdverseEvent");
    assertThat(def.getExpression(), instanceOf(Retrieve.class));
    Retrieve retrieve = (Retrieve) def.getExpression();
    assertThat(retrieve.getTemplateId(), is("http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-adverseevent"));
}
Also used : Retrieve(org.hl7.elm.r1.Retrieve) 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 7 with ExpressionDef

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

the class BaseTest method testEXM124.

@Test
public void testEXM124() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("qicore/v410/EXM124_QICore4-8.2.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 8 with ExpressionDef

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

the class CqlComparisonOperatorsTest method setup.

@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(CqlComparisonOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlComparisonOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    if (library.getStatements() != null) {
        for (ExpressionDef def : library.getStatements().getDef()) {
            defs.put(def.getName(), def);
        }
    }
}
Also used : ExpressionDef(org.hl7.elm.r1.ExpressionDef) CqlTranslator(org.cqframework.cql.cql2elm.CqlTranslator) LibraryManager(org.cqframework.cql.cql2elm.LibraryManager) Library(org.hl7.elm.r1.Library) ModelManager(org.cqframework.cql.cql2elm.ModelManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with ExpressionDef

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

the class NullologicalOperatorsTest method testCoalesce.

@Test
public void testCoalesce() {
    ExpressionDef def = defs.get("CoalesceList");
    assertThat(def, hasTypeAndResult(Coalesce.class, "System.Integer"));
    Coalesce coalesce = (Coalesce) def.getExpression();
    assertThat(coalesce.getOperand(), hasSize(1));
    assertThat(coalesce.getOperand().get(0), instanceOf(org.hl7.elm.r1.List.class));
    org.hl7.elm.r1.List args = (org.hl7.elm.r1.List) coalesce.getOperand().get(0);
    assertThat(args.getElement(), hasSize(5));
    int i = 1;
    for (Expression arg : args.getElement()) {
        assertThat(arg, literalFor(i++));
    }
    def = defs.get("CoalesceTwoArgument");
    assertThat(def, hasTypeAndResult(Coalesce.class, "System.Integer"));
    assertIntegerArgs((Coalesce) def.getExpression(), 1, 2);
    def = defs.get("CoalesceThreeArgument");
    assertThat(def, hasTypeAndResult(Coalesce.class, "System.Integer"));
    assertIntegerArgs((Coalesce) def.getExpression(), 1, 2, 3);
    def = defs.get("CoalesceFourArgument");
    assertThat(def, hasTypeAndResult(Coalesce.class, "System.Integer"));
    assertIntegerArgs((Coalesce) def.getExpression(), 1, 2, 3, 4);
    def = defs.get("CoalesceFiveArgument");
    assertThat(def, hasTypeAndResult(Coalesce.class, "System.Integer"));
    assertIntegerArgs((Coalesce) def.getExpression(), 1, 2, 3, 4, 5);
}
Also used : ExpressionDef(org.hl7.elm.r1.ExpressionDef) Expression(org.hl7.elm.r1.Expression) Coalesce(org.hl7.elm.r1.Coalesce) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with ExpressionDef

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

the class DataRequirementsProcessor method extractParameters.

private List<ParameterDefinition> extractParameters(ElmRequirementsContext context, ElmRequirements requirements, VersionedIdentifier libraryIdentifier, Iterable<ExpressionDef> expressionDefs) {
    List<ParameterDefinition> result = new ArrayList<>();
    // TODO: Support library qualified parameters
    // Until then, name clashes should result in a warning
    Map<String, ParameterDefinition> pds = new HashMap<String, ParameterDefinition>();
    for (ElmRequirement def : requirements.getParameterDefs()) {
        ParameterDefinition pd = toParameterDefinition(def.getLibraryIdentifier(), (ParameterDef) def.getElement());
        if (pds.containsKey(pd.getName())) {
            ParameterDefinition existingPd = pds.get(pd.getName());
            if (!isEquivalentDefinition(existingPd, pd)) {
                // Issue a warning that the parameter has a duplicate name but an incompatible type
                validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", String.format("Parameter declaration %s.%s is already defined in a different library with a different type. Parameter binding may result in errors during evaluation.", def.getLibraryIdentifier().getId(), pd.getName()), ValidationMessage.IssueSeverity.WARNING));
            }
        } else {
            pds.put(pd.getName(), pd);
            result.add(pd);
        }
    }
    for (ExpressionDef def : expressionDefs) {
        if (def != null && !(def instanceof FunctionDef) && (def.getAccessLevel() == null || def.getAccessLevel() == AccessModifier.PUBLIC)) {
            result.add(toOutputParameterDefinition(libraryIdentifier, def));
        }
    }
    return result;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ElmRequirement(org.cqframework.cql.elm.requirements.ElmRequirement)

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