cqframework / clinical_quality_language

Clinical Quality Language (CQL) is an HL7 specification for the expression of clinical knowledge that can be used within both the Clinical Decision Support (CDS) and Clinical Quality Measurement (CQM) domains. This repository contains complementary tooling in support of that specification.
https://confluence.hl7.org/display/CDS/Clinical+Quality+Language
Apache License 2.0
267 stars 123 forks source link

Merge CQL library-based comparison operator tests into XML-based tests #1398

Closed antvaset closed 2 months ago

antvaset commented 3 months ago

I copied all the tests from the engine's CqlComparisonOperatorsTest.all_comparison_operators_tests (CQL library-based) to CqlComparisonOperatorsTest.xml (unless the same or equivalent tests were there already) and removed the library-based tests that test the same functionality as the XML tests.

The CqlComparisonOperatorsTest.all_comparison_operators_tests method uses the engine/.../CqlComparisonOperatorsTest.cql library. Note that there are also similar define's in cql-to-elm/.../CqlComparisonOperators.cql and cql-to-elm/.../ComparisonOperators.cql. I went through all three and added the new tests to CqlComparisonOperatorsTest.xml.

Note also:

1) I renamed these tests:

define TupleEqDateTimeNull: Tuple { dateId: 12, Date: DateTime(2012, 1, 1) } = Tuple { dateId: 12, Date: DateTime(2012, 1, 1) }

define DateTimeEqNull2: DateTime(2001, 1, 1, null) = DateTime(2001, 1, 1, null, null)

to TupleEqDateTimeTrue2 and DateTimeEqTrue respectively because they both evaluate to true. They come from cql-to-elm/.../CqlComparisonOperators.cql which is only used in cql2elm tests that check translatability and not compare the results of the tests.

2) These were already in CqlListOperatorsTest.xml:

define ListEqEmptyEmpty : {} = {}

define EquivListEmptyEmpty          : {} ~ {}
define EquivListABCABC              : { 'a', 'b', 'c' } ~ { 'a', 'b', 'c' }
define EquivListABCAB               : { 'a', 'b', 'c' } ~ { 'a', 'b' }
define EquivListABC123              : { 'a', 'b', 'c' } ~ { 1, 2, 3 }
define EquivList123ABC              : { 1, 2, 3 } ~ { 'a', 'b', 'c' }
define EquivList123String123        : { 1, 2, 3 } ~  { '1', '2', '3' }

define ListNotEqEmptyEmpty : {} != {}
define ListNotEqABCABC : { 'a', 'b', 'c' } != { 'a', 'b', 'c' }
define ListNotEqABCAB : { 'a', 'b', 'c' } != { 'a', 'b' }
define ListNotEqABC123: { 'a', 'b', 'c' } != { 1, 2, 3 }
define ListNotEq123ABC: { 1, 2, 3 } != { 'a', 'b', 'c' }
define ListNotEq123String123:  { 1, 2, 3 } != { '1', '2', '3' }

3) These were missing from CqlListOperatorsTest.xml:

define ListEqABCABC : { 'a', 'b', 'c' } = { 'a', 'b', 'c' }
define ListEqABCAB : { 'a', 'b', 'c' } = { 'a', 'b' }
define ListEqABC123: { 'a', 'b', 'c' } = { 1, 2, 3 }
define ListEq123ABC: { 1, 2, 3 } = { 'a', 'b', 'c' }
define ListEq123String123:  { 1, 2, 3 } = { '1', '2', '3' }

3) These or equivalent were already in CqlIntervalOperatorsTest.xml:

define IntervalEq1To101To10: Interval[1, 10] = Interval[1, 10]
define IntervalEq1To101To5: Interval[1, 10] = Interval[1, 5]

define EquivInterval1To101To10      : Interval[1, 10] ~ Interval[1, 10]
define EquivInterval1To101To5       : Interval[1, 10] ~ Interval[1, 5]

define IntervalNotEq1To101To10: Interval[1, 10] != Interval[1, 10]
define IntervalNotEq1To101To5: Interval[1, 10] != Interval[1, 5]

4) These tests were skipped in CqlComparisonOperatorsTest.all_comparison_operators_tests:

define TupleEqJohnJohnFalse: Tuple { Id : 1, Name : 'John', Position: 'Shift Manager' } = Tuple { Id : 1, Name : 'John' }
define TupleEqJohnJohnFalse2: Tuple { Id : 1, Name : 'John' } = Tuple { Id : 1, Name : 'John', Position: 'Shift Manager' }
define EquivTupleJohnJohnFalse            : Tuple { Id : 1, Name : 'John', Position: 'Shift Manager' } ~ Tuple { Id : 1, Name : 'John' }
define EquivTupleJohnJohnFalse2           : Tuple { Id : 1, Name : 'John' } ~ Tuple { Id : 1, Name : 'John', Position: 'Shift Manager' }

but they work as expected (throw a translation error), so I added them to CqlComparisonOperatorsTest.xml.

Now that everything is synced into CqlComparisonOperatorsTest.xml, I could remove engine/.../CqlComparisonOperatorsTest.cql which was only used by the engine's CqlComparisonOperatorsTest. I also removed the cql_comparison_test_suite_compiles test from that class which made sure that the CQL library compiled with no errors. The test used the default options without DisableListDemotion and DisableListPromotion. The same compiler options are used when the XML tests are run (with the addition of EnableDateRangeOptimization which should not affect the translatability of the comparison operator tests in question), so they also test the same translation functionality.

At this stage, we have to keep the other two CQL files because they are currently used in other tests (some cql2elm and cql-formatter tests). In the future, we can generate those CQL files dynamically from the XML content when we run the tests and not have to maintain the files separately?

There are corresponding PRs in the cql-tests repo: https://github.com/cqframework/cql-tests/pull/45 and https://github.com/cqframework/cql-tests/pull/46.

github-actions[bot] commented 3 months ago

Formatting check succeeded!

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 63.73%. Comparing base (dd98ccc) to head (e905da9). Report is 3 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1398 +/- ## ========================================= Coverage 63.73% 63.73% Complexity 2666 2666 ========================================= Files 494 494 Lines 27836 27829 -7 Branches 5528 5528 ========================================= - Hits 17741 17737 -4 + Misses 7852 7848 -4 - Partials 2243 2244 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.