Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tests/cql/CqlAggregateFunctionsTest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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="CqlAggregateFunctionsTest" reference="https://cql.hl7.org/09-b-cqlreference.html#aggregate-functions" version="1.5">
<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="CqlAggregateFunctionsTest" reference="https://cql.hl7.org/09-b-cqlreference.html#aggregate-functions" version="1.5">
<!-- Suite-level capability (applies to all groups/tests unless overridden) -->
<capability code="aggregate-functions"/>
<group name="AllTrue" version="1.5">
<test name="AllTrueAllTrue" version="1.5">
<expression>AllTrue({true,true})</expression>
Expand Down Expand Up @@ -85,6 +86,8 @@
</group>
<group name="Product" version="1.5">
<test name="ProductLong" version="1.5">
<!-- Requires Long arithmetic support -->
<capability code="system.long"/>
<expression>Product({5L, 4L, 5L})</expression>
<output>100L</output>
</test>
Expand All @@ -95,10 +98,13 @@
<output>4</output>
</test>
<test name="CountTestDateTime" version="1.5">
<!-- Counting DateTimes implies date/time handling & comparisons -->
<capability code="date-and-time-operators"/>
<expression>Count({ DateTime(2014), DateTime(2001), DateTime(2010) })</expression>
<output>3</output>
</test>
<test name="CountTestTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Count({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 })</expression>
<output>3</output>
</test>
Expand All @@ -113,6 +119,7 @@
<output>90</output>
</test>
<test name="MaxTestLong" version="1.5">
<capability code="system.long"/>
<expression>Max({ 5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L })</expression>
<output>90L</output>
</test>
Expand All @@ -121,10 +128,12 @@
<output>'zebra'</output>
</test>
<test name="MaxTestDateTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Max({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6) })</expression>
<output>@2012-10-06T</output>
</test>
<test name="MaxTestTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Max({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 })</expression>
<output>@T20:59:59.999</output>
</test>
Expand All @@ -141,6 +150,7 @@
<output>0</output>
</test>
<test name="MinTestLong" version="1.5">
<capability code="system.long"/>
<expression>Min({5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L})</expression>
<output>0L</output>
</test>
Expand All @@ -149,10 +159,12 @@
<output>'bye'</output>
</test>
<test name="MinTestDateTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Min({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6) })</expression>
<output>@2012-09-05T</output>
</test>
<test name="MinTestTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Min({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 })</expression>
<output>@T05:59:59.999</output>
</test>
Expand All @@ -163,14 +175,17 @@
<output>9</output>
</test>
<test name="ModeTestDateTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Mode({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) })</expression>
<output>@2012-09-05T</output>
</test>
<test name="ModeTestDateTime2" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Mode({ DateTime(2012, 10, 5), DateTime(2012, 10, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) })</expression>
<output>@2012-10-05T</output>
</test>
<test name="ModeTestTime" version="1.5">
<capability code="date-and-time-operators"/>
<expression>Mode({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999, @T05:59:59.999 })</expression>
<output>@T05:59:59.999</output>
</test>
Expand Down Expand Up @@ -213,10 +228,13 @@
<output>20.0</output>
</test>
<test name="SumTestLong" version="1.5">
<capability code="system.long"/>
<expression>Sum({ 6L, 2L, 3L, 4L, 5L })</expression>
<output>20L</output>
</test>
<test name="SumTestQuantity" version="1.5">
<!-- Quantity arithmetic (with potential for unit conversions) -->
<capability code="unit-conversion-support"/>
<expression>Sum({1 'ml',2 'ml',3 'ml',4 'ml',5 'ml'})</expression>
<output>15 'ml'</output>
</test>
Expand Down
72 changes: 51 additions & 21 deletions tests/cql/CqlAggregateTest.xml
Original file line number Diff line number Diff line change
@@ -1,85 +1,115 @@
<?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="CqlAggregateTest" reference="http://build.fhir.org/ig/HL7/cql/03-developersguide.html#aggregate-queries" version="1.5">
<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="CqlAggregateTest" reference="http://build.fhir.org/ig/HL7/cql/03-developersguide.html#aggregate-queries" version="1.5">
<!-- Suite-level capability (applies to all groups/tests unless overridden) -->
<capability code="aggregate-clause-query"/>
<group name="AggregateTests" version="1.5">
<!-- Group-level capability (applies to all tests in this group) -->
<capability code="aggregate-clause-query"/>
<test name="FactorialOfFive" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>({ 1, 2, 3, 4, 5 }) Num aggregate Result starting 1: Result * Num</expression>
<output>120</output>
</test>
<test name="RolledOutIntervals" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
({
Interval[@2012-01-01, @2012-02-28],
Interval[@2012-02-01, @2012-03-31],
Interval[@2012-03-01, @2012-04-30]
Interval[@2012-01-01, @2012-02-28],
Interval[@2012-02-01, @2012-03-31],
Interval[@2012-03-01, @2012-04-30]
}) M
aggregate R starting (null as List&lt;Interval&lt;DateTime>>): R union ({
M X
let S: Max({ end of Last(R) + 1 day, start of X }),
E: S + duration in days of X
return Interval[S, E]
})
aggregate R starting (null as List&lt;Interval&lt;DateTime>>): R union ({
M X
let S: Max({ end of Last(R) + 1 day, start of X }),
E: S + duration in days of X
return Interval[S, E]
})
</expression>
<output>
{
Interval[@2012-01-01, @2012-02-28],
Interval[@2012-02-29, @2012-04-28],
Interval[@2012-04-29, @2012-06-28]
Interval[@2012-01-01, @2012-02-28],
Interval[@2012-02-29, @2012-04-28],
Interval[@2012-04-29, @2012-06-28]
}
</output>
<!-- Execution Error: Invalid precision: 1. -->
</test>
<test name="AggregateSumWithStart" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
({ 1, 2, 3, 4, 5 }) Num
aggregate Result starting 1: Result + Num
aggregate Result starting 1: Result + Num
</expression>
<output>16</output>
<!-- 15 + 1 (the initial value) -->
</test>
<test name="AggregateSumWithNull" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
({ 1, 2, 3, 4, 5 }) Num
aggregate Result: Coalesce(Result, 0) + Num
aggregate Result: Coalesce(Result, 0) + Num
</expression>
<output>15</output>
<!-- 15 + 0 (the initial value from null) -->
</test>
<test name="AggregateSumAll" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num
aggregate all Result: Coalesce(Result, 0) + Num
aggregate all Result: Coalesce(Result, 0) + Num
</expression>
<output>24</output>
<!-- 24 + 0 -->
</test>
<test name="AggregateSumDistinct" version="1.5">
<!-- Single-source aggregate -->
<capability code="single-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num
aggregate distinct Result: Coalesce(Result, 0) + Num
aggregate distinct Result: Coalesce(Result, 0) + Num
</expression>
<output>15</output>
<!-- 15 + 0 (the initial value) -->
</test>
<test name="Multi" version="1.5">
<!-- Multi-source aggregate -->
<capability code="multi-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
from ({1}) X, ({2}) Y, ({3}) Z
aggregate Agg: Coalesce(Agg, 0) + X + Y + Z
aggregate Agg: Coalesce(Agg, 0) + X + Y + Z
</expression>
<output>6</output>
</test>
<test name="MegaMulti" version="1.5">
<!-- Multi-source aggregate -->
<capability code="multi-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
from ({1, 2}) X, ({1, 2}) Y, ({1, 2}) Z
aggregate Agg starting 0: Agg + X + Y + Z
aggregate Agg starting 0: Agg + X + Y + Z
</expression>
<output>36</output>
<!-- (1+1+1)+(1+1+2)+(1+2+1)+(1+2+2)+(2+1+1)+(2+1+2)+(2+2+1)+(2+2+2) -->
</test>
<test name="MegaMultiDistinct" version="1.5">
<!-- Multi-source aggregate -->
<capability code="multi-source-query"/>
<capability code="aggregate-clause-query"/>
<expression>
from ({1, 2, 2, 1}) X, ({1, 2, 1, 2}) Y, ({2, 1, 2, 1}) Z
aggregate distinct Agg starting 1: Agg + X + Y + Z
aggregate distinct Agg starting 1: Agg + X + Y + Z
</expression>
<output>37</output>
<!-- 1 + (1+1+1)+(1+1+2)+(1+2+1)+(1+2+2)+(2+1+1)+(2+1+2)+(2+2+1)+(2+2+2) -->
Expand Down
Loading
Loading