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

Remove duplicate tests for aggregate functions, aggregate queries, and arithmetic functions #1396

Closed antvaset closed 4 months ago

antvaset commented 4 months ago

This PR removes CQL library-based tests for CQL expressions in favour of XML-based tests. All library tests that are not present in XML are moved to XML.

This is a continuation of https://github.com/cqframework/clinical_quality_language/pull/1383 and addresses https://github.com/cqframework/clinical_quality_language/issues/1376.

The following library tests needed to be modified when moved to XML: 1) CqlArithmeticFunctionsTest/Exp/Exp1Long - changed the expression from Exp(1L) to Round(Exp(1L), 8) (also changed the name to Exp1L). Fixing the precision makes the test more robust and consistent with CqlArithmeticFunctionsTest/Exp/Exp1. 2) CqlArithmeticFunctionsTest/Negate/NegateMaxLong - set the expected result to -9223372036854775807L (-(2^63 - 1)).

This PR addresses the tests for aggregate functions, aggregate queries, and arithmetic functions, to make it easier to review and merge early. The rest will be covered in subsequent PRs.


I used this TS script to compare the test files:

const cqlContent = '<content of CQL file e.g. CqlAggregateFunctionsTest.cql>';
const xmlContent = '<content of XML file e.g. CqlAggregateFunctionsTest.xml>';

const cqlTests = cqlContent.split('\ndefine ').slice(1).map(_ => ({
    name: _.split(':')[0].trim(),
    expression: _.split(':').slice(1).join(':').split('\n').map((line) => line.split('//')[0]).join('\n').trim(),
}))
const xmlTests = Array.from(new JSDOM(xmlContent, { contentType: 'text/xml' }).window.document.documentElement.querySelectorAll('test')).map(_ => ({
    name: _.getAttribute('name'),
    expression: _.querySelector('expression').textContent,
}))

for (const cqlTest of cqlTests) {
    const xmlTest = xmlTests.find(_ => _.name === cqlTest.name);
    if (!xmlTest) {
        console.log(`Test ${cqlTest.name} not found in XML`);
        continue;
    }
    if (cqlTest.expression !== xmlTest.expression) {
        console.log(`Test ${cqlTest.name} has different expressions in CQL and XML`);
    }
}
github-actions[bot] commented 4 months ago

Formatting check succeeded!

codecov[bot] commented 4 months ago

Codecov Report

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

Project coverage is 63.73%. Comparing base (7e91478) to head (67cf75d).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1396 +/- ## ============================================ - Coverage 63.73% 63.73% -0.01% - Complexity 2665 2666 +1 ============================================ Files 493 493 Lines 27774 27774 Branches 5521 5521 ============================================ - Hits 17703 17702 -1 Misses 7830 7830 - Partials 2241 2242 +1 ```

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