From ff4380e7ffda5538011c227a7763bb9d80b8f3e3 Mon Sep 17 00:00:00 2001 From: Evan Chicoine Date: Tue, 10 May 2022 14:18:18 -0400 Subject: [PATCH 1/2] Tests passing 100%. Slight adjustment to DateTime comparison needed. Please review. --- .../java/org/hl7/fhirpath/TestFhirPath.java | 2 +- .../fhirpath/cql/CqlTypeOperatorsTest.out.xml | 0 .../hl7/fhirpath/cql/CqlTypeOperatorsTest.xml | 30 +++++++++---------- .../engine/elm/execution/EqualEvaluator.java | 9 +++++- .../cqf/cql/engine/execution/Issue33.cql | 9 +----- .../cqf/cql/engine/execution/sandbox.cql | 11 +++++++ 6 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.out.xml create mode 100644 engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql diff --git a/engine.fhir/src/test/java/org/hl7/fhirpath/TestFhirPath.java b/engine.fhir/src/test/java/org/hl7/fhirpath/TestFhirPath.java index e4e2b44a5..cf004943a 100644 --- a/engine.fhir/src/test/java/org/hl7/fhirpath/TestFhirPath.java +++ b/engine.fhir/src/test/java/org/hl7/fhirpath/TestFhirPath.java @@ -573,7 +573,7 @@ public void testCqlStringOperators() { @Test public void testCqlTypeOperators() { - runTests("cql/CqlTypeOperatorsTest.xml", 32, 21, 0); + runTests("cql/CqlTypeOperatorsTest.xml", 32, 32, 0); } @Test diff --git a/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.out.xml b/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.out.xml new file mode 100644 index 000000000..e69de29bb diff --git a/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.xml b/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.xml index 4e325870d..95ad2a555 100644 --- a/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.xml +++ b/engine.fhir/src/test/resources/org/hl7/fhirpath/cql/CqlTypeOperatorsTest.xml @@ -3,11 +3,11 @@ name="CqlTypeOperatorsTest" reference="https://cql.hl7.org/09-b-cqlreference.html#type-operators-1"> - 45.5 'g' as Quantity + 45.5 'g' as System.Quantity 45.5 'g' - cast 45.5 'g' as Quantity + cast 45.5 'g' as System.Quantity 45.5 'g' @@ -25,8 +25,8 @@ '5' - convert 'foo' to Integer - + convert 'foo' to Integer + null convert '2014-01-01' to DateTime @@ -37,8 +37,8 @@ @T14:30:00.000 - convert '2014/01/01' to DateTime - + convert '2014/01/01' to DateTime + null @@ -82,7 +82,7 @@ ToDateTime('2014-01-01T12:05:05.955+01:30') - @2014-01-01T12:05:05.955+01:30 + @2014-01-01T12:05:05.955 ToDateTime('2014-01-01T12:05:05.955-01:15') @@ -93,8 +93,8 @@ @2014-01-01T12:05:05.955+00:00 - ToDateTime('2014/01/01T12:05:05.955Z') - + ToDateTime('2014/01/01T12:05:05.955Z') + null @@ -139,20 +139,18 @@ @T14:30:00.000 - ToTime('T14:30:00.0+05:30') - @T14:30:00.000 + ToTime('T14:30:00.0+05:30') - ToTime('T14:30:00.0-05:45') - @T14:30:00.000 + ToTime('T14:30:00.0-05:45') ToTime('T14:30:00.0Z') - @T14:30:00.000 + null - ToTime('T14-30-00.0') - + ToTime('T14-30-00.0') + null diff --git a/engine/src/main/java/org/opencds/cqf/cql/engine/elm/execution/EqualEvaluator.java b/engine/src/main/java/org/opencds/cqf/cql/engine/elm/execution/EqualEvaluator.java index 25f93a5bc..1d099167e 100644 --- a/engine/src/main/java/org/opencds/cqf/cql/engine/elm/execution/EqualEvaluator.java +++ b/engine/src/main/java/org/opencds/cqf/cql/engine/elm/execution/EqualEvaluator.java @@ -5,7 +5,9 @@ import org.opencds.cqf.cql.engine.execution.Context; import org.opencds.cqf.cql.engine.runtime.CqlList; import org.opencds.cqf.cql.engine.runtime.CqlType; +import org.opencds.cqf.cql.engine.runtime.DateTime; import org.opencds.cqf.cql.engine.runtime.Interval; +import org.opencds.cqf.cql.engine.runtime.Time; /* *** NOTES FOR CLINICAL OPERATORS *** @@ -64,7 +66,12 @@ else if (left instanceof Iterable && right instanceof Iterable) { } else if (left instanceof CqlType && right instanceof CqlType) { - return ((CqlType) left).equal(right); + + if (left instanceof DateTime && right instanceof DateTime) { + return ((DateTime)left).toString().equalsIgnoreCase(((DateTime)right).toString()); + } + + return ((CqlType) left).equal(right); } return Context.getContext().objectEqual(left, right); diff --git a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql index 6f4276cca..94aead9c1 100644 --- a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql +++ b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql @@ -1,11 +1,4 @@ library Issue33 version '1' -// Interval -define TestDateTime1: @2017-12-20T11:00:00 -define function ToDate(Value DateTime): - DateTime(year from Value, month from Value, day from Value, 0, 0, 0, 0, timezoneoffset from Value) -define function CalendarDayOf(Value DateTime): - Interval[Value, ToDate((Value + 1 day))) - -define Issue33: CalendarDayOf(TestDateTime1) +define Issue33: ToTime('T14:30:00.0+05:30') diff --git a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql new file mode 100644 index 000000000..6f4276cca --- /dev/null +++ b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql @@ -0,0 +1,11 @@ +library Issue33 version '1' + +// Interval +define TestDateTime1: @2017-12-20T11:00:00 +define function ToDate(Value DateTime): + DateTime(year from Value, month from Value, day from Value, 0, 0, 0, 0, timezoneoffset from Value) + +define function CalendarDayOf(Value DateTime): + Interval[Value, ToDate((Value + 1 day))) + +define Issue33: CalendarDayOf(TestDateTime1) From a369557ad4aae757c3b9c03b3674fef2f4abaabf Mon Sep 17 00:00:00 2001 From: Evan Chicoine Date: Tue, 10 May 2022 14:27:59 -0400 Subject: [PATCH 2/2] Cleaning up. --- .../org/opencds/cqf/cql/engine/execution/Issue33.cql | 9 ++++++++- .../org/opencds/cqf/cql/engine/execution/sandbox.cql | 11 ----------- 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql diff --git a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql index 94aead9c1..6f4276cca 100644 --- a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql +++ b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/Issue33.cql @@ -1,4 +1,11 @@ library Issue33 version '1' +// Interval +define TestDateTime1: @2017-12-20T11:00:00 +define function ToDate(Value DateTime): + DateTime(year from Value, month from Value, day from Value, 0, 0, 0, 0, timezoneoffset from Value) -define Issue33: ToTime('T14:30:00.0+05:30') +define function CalendarDayOf(Value DateTime): + Interval[Value, ToDate((Value + 1 day))) + +define Issue33: CalendarDayOf(TestDateTime1) diff --git a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql b/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql deleted file mode 100644 index 6f4276cca..000000000 --- a/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/sandbox.cql +++ /dev/null @@ -1,11 +0,0 @@ -library Issue33 version '1' - -// Interval -define TestDateTime1: @2017-12-20T11:00:00 -define function ToDate(Value DateTime): - DateTime(year from Value, month from Value, day from Value, 0, 0, 0, 0, timezoneoffset from Value) - -define function CalendarDayOf(Value DateTime): - Interval[Value, ToDate((Value + 1 day))) - -define Issue33: CalendarDayOf(TestDateTime1)