Java Code Examples for org.cqframework.cql.cql2elm.CqlTranslator#toELM()

The following examples show how to use org.cqframework.cql.cql2elm.CqlTranslator#toELM() . 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: AggregateOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(AggregateOperatorsTest.class.getResourceAsStream("../OperatorTests/AggregateOperators.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);
        }
    }
}
 
Example 2
Source File: NullologicalOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(NullologicalOperatorsTest.class.getResourceAsStream("../OperatorTests/NullologicalOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 3
Source File: TypeOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(TypeOperatorsTest.class.getResourceAsStream("../OperatorTests/TypeOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 4
Source File: ListOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(ListOperatorsTest.class.getResourceAsStream("../OperatorTests/ListOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 5
Source File: SortingTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(QueryTest.class.getResourceAsStream("../OperatorTests/Sorting.cql"), modelManager, new LibraryManager(modelManager));
    
    // The alias test creates an error
    assertThat(translator.getErrors().size(), is(1));

    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 6
Source File: EscapeSequenceTests.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);
    CqlTranslator translator = CqlTranslator.fromStream(org.cqframework.cql.cql2elm.EscapeSequenceTests.class.getResourceAsStream("EscapeSequenceTests.cql"), modelManager, libraryManager);
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 7
Source File: CqlIntervalOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(CqlIntervalOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlIntervalOperators.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);
        }
    }
}
 
Example 8
Source File: TimeOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(TimeOperatorsTest.class.getResourceAsStream("../OperatorTests/TimeOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 9
Source File: ArithmeticOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(ArithmeticOperatorsTest.class.getResourceAsStream("../OperatorTests/ArithmeticOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 10
Source File: CqlListOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(CqlListOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlListOperators.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);
        }
    }
}
 
Example 11
Source File: CqlComparisonOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 12
Source File: AgeOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(AgeOperatorsTest.class.getResourceAsStream("../OperatorTests/AgeOperators.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);
        }
    }
}
 
Example 13
Source File: StringOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(StringOperatorsTest.class.getResourceAsStream("../OperatorTests/StringOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 14
Source File: DateTimeOperatorsTest.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    CqlTranslator translator = CqlTranslator.fromStream(DateTimeOperatorsTest.class.getResourceAsStream("../OperatorTests/DateTimeOperators.cql"), modelManager, new LibraryManager(modelManager));
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 15
Source File: EscapeSequenceWithBacktickTests.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() throws IOException {
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);
    CqlTranslator translator = CqlTranslator.fromStream(org.cqframework.cql.cql2elm.EscapeSequenceTests.class.getResourceAsStream("EscapeSequenceWithBacktickTests.cql"), modelManager, libraryManager);
    assertThat(translator.getErrors().size(), is(0));
    Library library = translator.toELM();
    defs = new HashMap<>();
    for (ExpressionDef def: library.getStatements().getDef()) {
        defs.put(def.getName(), def);
    }
}
 
Example 16
Source File: BaseTest.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
@Test
    public void testConceptConversion() throws IOException {
        CqlTranslator translator = TestUtils.runSemanticTest("fhir/r401/TestConceptConversion.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);
            }
        }

/*
         <expression localId="18" locator="15:3-16:42" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="13" locator="15:3-15:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="12" locator="15:3-15:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="17" locator="16:5-16:42" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="15" locator="16:11-16:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand xsi:type="ToConcept">
                  <operand localId="16" locator="16:20-16:42" resultTypeName="t:Code" name="ECOG performance code" xsi:type="CodeRef"/>
               </operand>
            </where>
         </expression>
 */

        ExpressionDef expressionDef = defs.get("TestCodeComparison");

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        Query query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        Equivalent equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        FunctionRef functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ToConcept.class));

        expressionDef = defs.get("TestConceptComparison");

/*
         <expression localId="26" locator="19:3-20:43" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="21" locator="19:3-19:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="20" locator="19:3-19:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="25" locator="20:5-20:43" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="23" locator="20:11-20:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand localId="24" locator="20:20-20:43" resultTypeName="t:Concept" name="ECOG performance score" xsi:type="ConceptRef"/>
            </where>
         </expression>
 */

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ConceptRef.class));
    }
 
Example 17
Source File: BaseTest.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceDateRangeOptimization() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("fhir/r401/TestChoiceDateRangeOptimization.cql", 0, CqlTranslator.Options.EnableDateRangeOptimization);
    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);
        }
    }

    /*
     <expression localId="25" locator="10:23-10:81" xsi:type="Query">
        <resultTypeSpecifier xsi:type="ListTypeSpecifier">
           <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
        </resultTypeSpecifier>
        <source localId="20" locator="10:23-10:35" alias="C">
           <resultTypeSpecifier xsi:type="ListTypeSpecifier">
              <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
           </resultTypeSpecifier>
           <expression localId="19" locator="10:23-10:33" dataType="fhir:Condition" dateProperty="recordedDate" xsi:type="Retrieve">
              <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                 <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
              </resultTypeSpecifier>
              <dateRange localId="23" locator="10:65-10:81" name="MeasurementPeriod" xsi:type="ParameterRef">
                 <resultTypeSpecifier xsi:type="IntervalTypeSpecifier">
                    <pointType name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
                 </resultTypeSpecifier>
              </dateRange>
           </expression>
        </source>
     </expression>
     */

    ExpressionDef expressionDef = defs.get("DateCondition");
    assertThat(expressionDef.getExpression(), instanceOf(Query.class));
    Query query = (Query)expressionDef.getExpression();
    assertThat(query.getSource().size(), is(1));
    assertThat(query.getSource().get(0).getExpression(), instanceOf(Retrieve.class));
    Retrieve retrieve = (Retrieve)query.getSource().get(0).getExpression();
    assertThat(retrieve.getDateProperty(), is("recordedDate"));
    assertThat(retrieve.getDateRange(), instanceOf(ParameterRef.class));

    /*
     <expression localId="35" locator="11:35-11:101" xsi:type="Query">
        <resultTypeSpecifier xsi:type="ListTypeSpecifier">
           <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
        </resultTypeSpecifier>
        <source localId="28" locator="11:35-11:47" alias="C">
           <resultTypeSpecifier xsi:type="ListTypeSpecifier">
              <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
           </resultTypeSpecifier>
           <expression localId="27" locator="11:35-11:45" dataType="fhir:Condition" dateProperty="onset" xsi:type="Retrieve">
              <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                 <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
              </resultTypeSpecifier>
              <dateRange localId="33" locator="11:85-11:101" name="MeasurementPeriod" xsi:type="ParameterRef">
                 <resultTypeSpecifier xsi:type="IntervalTypeSpecifier">
                    <pointType name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
                 </resultTypeSpecifier>
              </dateRange>
           </expression>
        </source>
     </expression>
     */

    expressionDef = defs.get("ChoiceTypePeriodCondition");
    assertThat(expressionDef.getExpression(), instanceOf(Query.class));
    query = (Query)expressionDef.getExpression();
    assertThat(query.getSource().size(), is(1));
    assertThat(query.getSource().get(0).getExpression(), instanceOf(Retrieve.class));
    retrieve = (Retrieve)query.getSource().get(0).getExpression();
    assertThat(retrieve.getDateProperty(), is("onset"));
    assertThat(retrieve.getDateRange(), instanceOf(ParameterRef.class));
}
 
Example 18
Source File: BaseTest.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
@Test
    public void testConceptConversion() throws IOException {
        CqlTranslator translator = TestUtils.runSemanticTest("fhir/r4/TestConceptConversion.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);
            }
        }

/*
         <expression localId="18" locator="15:3-16:42" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="13" locator="15:3-15:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="12" locator="15:3-15:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="17" locator="16:5-16:42" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="15" locator="16:11-16:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand xsi:type="ToConcept">
                  <operand localId="16" locator="16:20-16:42" resultTypeName="t:Code" name="ECOG performance code" xsi:type="CodeRef"/>
               </operand>
            </where>
         </expression>
 */

        ExpressionDef expressionDef = defs.get("TestCodeComparison");

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        Query query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        Equivalent equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        FunctionRef functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ToConcept.class));

        expressionDef = defs.get("TestConceptComparison");

/*
         <expression localId="26" locator="19:3-20:43" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="21" locator="19:3-19:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="20" locator="19:3-19:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="25" locator="20:5-20:43" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="23" locator="20:11-20:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand localId="24" locator="20:20-20:43" resultTypeName="t:Concept" name="ECOG performance score" xsi:type="ConceptRef"/>
            </where>
         </expression>
 */

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ConceptRef.class));
    }
 
Example 19
Source File: BaseTest.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceDateRangeOptimization() throws IOException {
    CqlTranslator translator = TestUtils.runSemanticTest("fhir/stu3/TestChoiceDateRangeOptimization.cql", 0, CqlTranslator.Options.EnableDateRangeOptimization);
    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);
        }
    }

    /*
     <expression localId="25" locator="10:23-10:81" xsi:type="Query">
        <resultTypeSpecifier xsi:type="ListTypeSpecifier">
           <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
        </resultTypeSpecifier>
        <source localId="20" locator="10:23-10:35" alias="C">
           <resultTypeSpecifier xsi:type="ListTypeSpecifier">
              <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
           </resultTypeSpecifier>
           <expression localId="19" locator="10:23-10:33" dataType="fhir:Condition" dateProperty="assertedDate" xsi:type="Retrieve">
              <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                 <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
              </resultTypeSpecifier>
              <dateRange localId="23" locator="10:65-10:81" name="MeasurementPeriod" xsi:type="ParameterRef">
                 <resultTypeSpecifier xsi:type="IntervalTypeSpecifier">
                    <pointType name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
                 </resultTypeSpecifier>
              </dateRange>
           </expression>
        </source>
     </expression>
     */

    ExpressionDef expressionDef = defs.get("DateCondition");
    assertThat(expressionDef.getExpression(), instanceOf(Query.class));
    Query query = (Query)expressionDef.getExpression();
    assertThat(query.getSource().size(), is(1));
    assertThat(query.getSource().get(0).getExpression(), instanceOf(Retrieve.class));
    Retrieve retrieve = (Retrieve)query.getSource().get(0).getExpression();
    assertThat(retrieve.getDateProperty(), is("assertedDate"));
    assertThat(retrieve.getDateRange(), instanceOf(ParameterRef.class));

    /*
     <expression localId="35" locator="11:35-11:101" xsi:type="Query">
        <resultTypeSpecifier xsi:type="ListTypeSpecifier">
           <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
        </resultTypeSpecifier>
        <source localId="28" locator="11:35-11:47" alias="C">
           <resultTypeSpecifier xsi:type="ListTypeSpecifier">
              <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
           </resultTypeSpecifier>
           <expression localId="27" locator="11:35-11:45" dataType="fhir:Condition" dateProperty="onset" xsi:type="Retrieve">
              <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                 <elementType name="fhir:Condition" xsi:type="NamedTypeSpecifier"/>
              </resultTypeSpecifier>
              <dateRange localId="33" locator="11:85-11:101" name="MeasurementPeriod" xsi:type="ParameterRef">
                 <resultTypeSpecifier xsi:type="IntervalTypeSpecifier">
                    <pointType name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
                 </resultTypeSpecifier>
              </dateRange>
           </expression>
        </source>
     </expression>
     */

    expressionDef = defs.get("ChoiceTypePeriodCondition");
    assertThat(expressionDef.getExpression(), instanceOf(Query.class));
    query = (Query)expressionDef.getExpression();
    assertThat(query.getSource().size(), is(1));
    assertThat(query.getSource().get(0).getExpression(), instanceOf(Retrieve.class));
    retrieve = (Retrieve)query.getSource().get(0).getExpression();
    assertThat(retrieve.getDateProperty(), is("onset"));
    assertThat(retrieve.getDateRange(), instanceOf(ParameterRef.class));
}
 
Example 20
Source File: BaseTest.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
@Test
    public void testConceptConversion() throws IOException {
        CqlTranslator translator = TestUtils.runSemanticTest("fhir/r4/TestConceptConversion.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);
            }
        }

/*
         <expression localId="18" locator="15:3-16:42" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="13" locator="15:3-15:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="12" locator="15:3-15:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="17" locator="16:5-16:42" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="15" locator="16:11-16:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand xsi:type="ToConcept">
                  <operand localId="16" locator="16:20-16:42" resultTypeName="t:Code" name="ECOG performance code" xsi:type="CodeRef"/>
               </operand>
            </where>
         </expression>
 */

        ExpressionDef expressionDef = defs.get("TestCodeComparison");

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        Query query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        Equivalent equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        FunctionRef functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ToConcept.class));

        expressionDef = defs.get("TestConceptComparison");

/*
         <expression localId="26" locator="19:3-20:43" xsi:type="Query">
            <resultTypeSpecifier xsi:type="ListTypeSpecifier">
               <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
            </resultTypeSpecifier>
            <source localId="21" locator="19:3-19:17" alias="O">
               <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                  <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
               </resultTypeSpecifier>
               <expression localId="20" locator="19:3-19:15" dataType="fhir:Observation" xsi:type="Retrieve">
                  <resultTypeSpecifier xsi:type="ListTypeSpecifier">
                     <elementType name="fhir:Observation" xsi:type="NamedTypeSpecifier"/>
                  </resultTypeSpecifier>
               </expression>
            </source>
            <where localId="25" locator="20:5-20:43" resultTypeName="t:Boolean" xsi:type="Equivalent">
               <operand name="ToConcept" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                  <operand localId="23" locator="20:11-20:16" resultTypeName="fhir:CodeableConcept" path="code" scope="O" xsi:type="Property"/>
               </operand>
               <operand localId="24" locator="20:20-20:43" resultTypeName="t:Concept" name="ECOG performance score" xsi:type="ConceptRef"/>
            </where>
         </expression>
 */

        assertThat(expressionDef.getExpression(), instanceOf(Query.class));
        query = (Query)expressionDef.getExpression();
        assertThat(query.getWhere(), instanceOf(Equivalent.class));
        equivalent = (Equivalent)query.getWhere();
        assertThat(equivalent.getOperand().get(0), instanceOf(FunctionRef.class));
        functionRef = (FunctionRef)equivalent.getOperand().get(0);
        assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
        assertThat(functionRef.getName(), is("ToConcept"));
        assertThat(equivalent.getOperand().get(1), instanceOf(ConceptRef.class));
    }