Add tests for the CalculateAgeAt operators (clinical operators have none)

Open Beginner friendly
#157 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Domain
testing-qa

Research direction

Work in tests/cql/CqlClinicalOperatorsTest.xml, using the proposed XML structure and CalculateAgeAt expressions as the starting point. Compare nearby CQL test files and verify the new clinical-operators capability is accepted by the test suite. Done means the listed precision, birthday, DateTime, and null cases are represented and pass validation.

Written by the indexing model from the issue text.

Description

Gap

tests/cql has no test for any operator in Appendix B, section "Clinical Operators": there is no CalculateAge…At expression anywhere in the suite (grep -r CalculateAge tests/cql is empty at 9e92193), and none of the open pull requests adds one. The CalculateAgeAt family is one of the most used operators in real measure logic (every age-band population criterion), and it has its own edge cases (birthday not yet reached in the asOf year, null operands, the coarser-precision uncertainty the specification describes).

Proposal

A new file tests/cql/CqlClinicalOperatorsTest.xml with one group per precision. The values below are for someone born 1976-01-01 as of 2020-01-02: 44 years; 528 months; 16072 days (2296 weeks); 385728 hours, 23143680 minutes, 1388620800 seconds. Following the specification (CQL 1.5.3, Appendix B, "CalculateAgeAt": "if the given birthDate or asOf are not specified to the level of precision corresponding to the operator being invoked, the result will be an uncertainty"), the hour/minute/second cases use full DateTime literals, so their results are single values; the year/month/week/day cases use Date literals, which are precise enough for those precisions.

<?xml version="1.0" encoding="utf-8"?>
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://hl7.org/fhirpath/tests" xsi:schemaLocation="http://hl7.org/fhirpath/tests ../../testSchema/testSchema.xsd"
	name="CqlClinicalOperatorsTest" reference="https://cql.hl7.org/09-b-cqlreference.html#clinical-operators-3" version="1.0">
	<capability code="clinical-operators" />
	<group name="CalculateAgeAt" version="1.0" reference="https://cql.hl7.org/09-b-cqlreference.html#calculateageat">
		<capability code="clinical-operators" />
		<test name="CalculateAgeInYearsAtSpecExample" version="1.0">
			<!-- the specification's own example -->
			<expression>CalculateAgeInYearsAt(@2000-01-01, @2015-01-01)</expression>
			<output>15</output>
		</test>
		<test name="CalculateAgeInYearsAt" version="1.0">
			<expression>CalculateAgeInYearsAt(@1976-01-01, @2020-01-02)</expression>
			<output>44</output>
		</test>
		<test name="CalculateAgeInYearsAtDayBeforeBirthday" version="1.0">
			<!-- the birthday in the asOf year has not been reached -->
			<expression>CalculateAgeInYearsAt(@1976-01-02, @2020-01-01)</expression>
			<output>43</output>
		</test>
		<test name="CalculateAgeInYearsAtDateTime" version="1.0">
			<expression>CalculateAgeInYearsAt(@1976-01-01T00:00:00.000, @2020-01-02T00:00:00.000)</expression>
			<output>44</output>
		</test>
		<test name="CalculateAgeInYearsAtNullAsOf" version="1.0">
			<expression>CalculateAgeInYearsAt(@2000-01-01, null)</expression>
			<output>null</output>
		</test>
		<test name="CalculateAgeInYearsAtNullBirthDate" version="1.0">
			<expression>CalculateAgeInYearsAt(null, @2015-01-01)</expression>
			<output>null</output>
		</test>
		<test name="CalculateAgeInMonthsAt" version="1.0">
			<expression>CalculateAgeInMonthsAt(@1976-01-01, @2020-01-02)</expression>
			<output>528</output>
		</test>
		<test name="CalculateAgeInWeeksAt" version="1.0">
			<expression>CalculateAgeInWeeksAt(@1976-01-01, @2020-01-02)</expression>
			<output>2296</output>
		</test>
		<test name="CalculateAgeInDaysAt" version="1.0">
			<expression>CalculateAgeInDaysAt(@1976-01-01, @2020-01-02)</expression>
			<output>16072</output>
		</test>
		<test name="CalculateAgeInHoursAt" version="1.0">
			<expression>CalculateAgeInHoursAt(@1976-01-01T00:00:00.000, @2020-01-02T00:00:00.000)</expression>
			<output>385728</output>
		</test>
		<test name="CalculateAgeInMinutesAt" version="1.0">
			<expression>CalculateAgeInMinutesAt(@1976-01-01T00:00:00.000, @2020-01-02T00:00:00.000)</expression>
			<output>23143680</output>
		</test>
		<test name="CalculateAgeInSecondsAt" version="1.0">
			<expression>CalculateAgeInSecondsAt(@1976-01-01T00:00:00.000, @2020-01-02T00:00:00.000)</expression>
			<output>1388620800</output>
		</test>
	</group>
</tests>

Notes:

  • clinical-operators would be a new capability code; none of the existing codes covers this section.
  • AgeInYearsAt and the other Age… operators without a birth date need a Patient context and a data model, so they are out of reach of this expression-only format; the CalculateAge…At overloads exercise the same duration logic without that dependency.
  • A case where the birth date is 29 February and asOf is 28 February of a non-leap year would exercise the same rule as YearsBetweenLeapYearDatesEquals2; I left it out to keep this proposal independent of that test.

If the committers prefer a pull request, I can open one with this file.

Dominant language
No language data
Stars
8
Forks
9
Avg merge
4d 2h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/cql-tests

All issues in cqframework/cql-tests

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.