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

Deduplicate the conditional and date/time operator tests #1399

Closed antvaset closed 3 months ago

antvaset commented 3 months ago

This PR deduplicates the conditional and date/time operator tests in this codebase.

Conditional operator tests

Removed engine/.../CqlConditionalOperatorsTest.cql, all tests already exist in CqlConditionalOperatorsTest.xml.

Date/time operator tests

Merged all tests from engine/.../CqlDateTimeOperatorsTest.cql into CqlDateTimeOperatorsTest.xml.

Note that: 1) I updated the DateTimeComponentFromTimezone test to expect it to raise a translation error due to the use of the timezone keyword which is no longer supported. Added the new DateTimeComponentFromTimezone2 test which uses the new timezoneoffset keyword. The CQL library was using the timezoneoffset keyword. 2) I updated the TimeDurationBetweenHourDiffPrecision test to expect it to raise a translation error due to the syntax error at Z. Added the new TimeDurationBetweenHourDiffPrecision21 test which does not haveZ, as in the CQL library. 3) TheTimeSameOrBeforeHourFalse0andTimeSameOrBeforeMillisTrue2already existed inCqlDateTimeOperatorsTest.xmlasTimeSameOrBeforeHourTrue2andTimeSameOrBeforeMillisFalse0respectively. 4) I didn't touch theIssue34A,TimeOfDayTest, andIssue34B` tests because they should remain as Java-native tests.

Note also that some of the library-based tests used the equivalence semantics when comparing the evaluation result against the expected result. E.g. for this define in the CQL library:

define DateTimeAdd5Years: DateTime(2005, 10, 10) + 5 years

the Java test case was:

var value = engine.expression(library, "DateTimeAdd5Years").value();
assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(bigDecimalZoneOffset, 2010, 10, 10)));

However the corresponding XML test case:

<test name="DateTimeAdd5Years">
    <expression>DateTime(2005, 10, 10) + 5 years</expression>
    <output>@2010-10-10T</output>
</test>

tests that this is CQL evaluates to true which uses the = operator`:

(DateTime(2005, 10, 10) + 5 years) = (@2010-10-10T)

I still consider these tests to be duplicates because the XML tests that we keep use the narrower semantics.

For all the tests that I added to the XML file that were missing, I used CVL in the output unless the test wasn't passing. For example this:

<test name="DateTimeAddThreeWeeks">
    <expression>DateTime(2018, 5, 2) + 3 weeks</expression>
    <output>@2018-05-23</output>
</test>

didn't pass but this did (both with the = and ~ operators):

<test name="DateTimeAddThreeWeeks">
    <expression>DateTime(2018, 5, 2) + 3 weeks = DateTime(2018, 5, 23)</expression>
    <output>true</output>
</test>

so I used the equality operator in the expression for these tests (also for consistency with other existing XML tests).

Also, these tests exist both in the CQL library and XML file but have different expected values:

DateTimeDurationBetweenYear
DateTimeDurationBetweenUncertainInterval
DateTimeDurationBetweenUncertainInterval2
DateTimeDurationBetweenUncertainAdd
DateTimeDurationBetweenUncertainSubtract
DateTimeDurationBetweenUncertainMultiply
DurationInDaysA
DurationInDaysAA

and the XML versions of these tests are currently skipped - something to look into in the future.

All additions to CqlDateTimeOperatorsTest.xml are mirrored in https://github.com/cqframework/cql-tests/pull/47.

github-actions[bot] commented 3 months ago

Formatting check succeeded!