From e2be4c836fdb5cc64b876d819342d316b0ce7f66 Mon Sep 17 00:00:00 2001 From: Paul Taladay Date: Tue, 31 Dec 2024 11:42:50 -0800 Subject: [PATCH 1/3] Fix to allow date time to be searched against a resource with a span and if included in the span that resource will be returned. --- .../Expressions/DateTimeEqualityRewriter.cs | 10 +- .../Rest/Search/DateSearchTestFixture.cs | 29 +++- .../Rest/Search/DateSearchTests.cs | 132 ++++++++++-------- 3 files changed, 106 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.Health.Fhir.Core/Features/Search/Expressions/DateTimeEqualityRewriter.cs b/src/Microsoft.Health.Fhir.Core/Features/Search/Expressions/DateTimeEqualityRewriter.cs index c91553bf26..fc32df5aed 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Search/Expressions/DateTimeEqualityRewriter.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Search/Expressions/DateTimeEqualityRewriter.cs @@ -33,12 +33,14 @@ public override Expression VisitSearchParameter(SearchParameterExpression expres public override Expression VisitMultiary(MultiaryExpression expression, object context) { expression = (MultiaryExpression)base.VisitMultiary(expression, context); + bool checkDateTimeAgainstPeriod = false; if (expression.MultiaryOperation != MultiaryOperator.And) { return expression; } List newExpressions = null; + List dateInPeriodExpression = null; int i = 0; for (; i < expression.Expressions.Count - 1; i++) { @@ -46,11 +48,13 @@ public override Expression VisitMultiary(MultiaryExpression expression, object c { case ({ } low, { } high): EnsureAllocatedAndPopulated(ref newExpressions, expression.Expressions, i); - + EnsureAllocatedAndPopulated(ref dateInPeriodExpression, expression.Expressions, i); newExpressions.Add(low); newExpressions.Add(new BinaryExpression(high.BinaryOperator, low.FieldName, high.ComponentIndex, high.Value)); newExpressions.Add(high); - + checkDateTimeAgainstPeriod = true; + dateInPeriodExpression.Add(new BinaryExpression(high.BinaryOperator, low.FieldName, low.ComponentIndex, low.Value)); + dateInPeriodExpression.Add(new BinaryExpression(low.BinaryOperator, high.FieldName, high.ComponentIndex, high.Value)); i++; break; default: @@ -65,7 +69,7 @@ public override Expression VisitMultiary(MultiaryExpression expression, object c newExpressions.Add(expression.Expressions[^1]); } - return newExpressions == null ? expression : Expression.And(newExpressions); + return newExpressions == null ? expression : checkDateTimeAgainstPeriod ? Expression.Or(Expression.And(newExpressions), Expression.And(dateInPeriodExpression)) : Expression.And(newExpressions); } private static (BinaryExpression low, BinaryExpression high) MatchPattern(Expression e1, Expression e2) diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs index 29f9bfe6fd..7923bb8294 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs @@ -33,14 +33,16 @@ protected override async Task OnInitializedAsync() }; Observations = await TestFhirClient.CreateResourcesAsync( - p => SetObservation(p, "1979-12-31"), // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999 - p => SetObservation(p, "1980"), // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999 - p => SetObservation(p, "1980-05"), // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999 - p => SetObservation(p, "1980-05-11"), // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999 - p => SetObservation(p, "1980-05-11T16:32:15"), // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999 - p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000 - p => SetObservation(p, "1981-01-01")); // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 + p => SetObservationWithPeriod(p, "1980-05-16", "1980-05-17")); // 1980-05-11T00:00:00.0000000 <-> 1980-05-12T23:59:59.9999999 + // p => SetObservation(p, "1979-12-31"), // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999 + // p => SetObservation(p, "1980"), // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999 + // p => SetObservation(p, "1980-05"), // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999 + // p => SetObservation(p, "1980-05-11"), // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999 + // p => SetObservation(p, "1980-05-11T16:32:15"), // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999 + // p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000 + // p => SetObservation(p, "1981-01-01"), // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 +/* void SetObservation(Observation observation, string date) { observation.Status = ObservationStatus.Final; @@ -52,6 +54,19 @@ void SetObservation(Observation observation, string date) }, }; observation.Effective = new FhirDateTime(date); + }*/ + + void SetObservationWithPeriod(Observation observation, string startDate, string endDate) + { + observation.Status = ObservationStatus.Final; + observation.Code = new CodeableConcept + { + Coding = new List + { + Coding, + }, + }; + observation.Effective = new Period(new FhirDateTime(startDate), new FhirDateTime(endDate)); } } } diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs index f0a6093ba0..23b50b96ff 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs @@ -36,9 +36,9 @@ public DateSearchTests(DateSearchTestFixture fixture) // sa: the range of the search value does not overlap with the range of the target value, and the range above the search value contains the range of the target value. // eb: the range of the search value does overlap not with the range of the target value, and the range below the search value contains the range of the target value. [Theory] - [InlineData("1980", 1, 2, 3, 4, 5)] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-12-31T23:59:59.9999999. + [InlineData("1980", 1, 2, 3, 4, 5, 7)] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-12-31T23:59:59.9999999. [InlineData("1980-01")] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-01-31T23:59:59.9999999. - [InlineData("1980-05", 2, 3, 4, 5)] // Any dates with start time greater than or equal to 1980-05-01T00:00:00.0000000 and end time less than or equal to 1980-05-31T23:59:59.9999999. + [InlineData("1980-05", 2, 3, 4, 5, 7)] // Any dates with start time greater than or equal to 1980-05-01T00:00:00.0000000 and end time less than or equal to 1980-05-31T23:59:59.9999999. [InlineData("1980-05-10")] // Any dates with start time greater than or equal to 1980-05-10T00:00:00.0000000 and end time less than or equal to 1980-05-10T23:59:59.9999999. [InlineData("1980-05-11", 3, 4, 5)] // Any dates with start time greater than or equal to 1980-05-11T00:00:00.0000000 and end time less than or equal to 1980-05-11T23:59:59.9999999. [InlineData("1980-05-11T16:32:15", 4, 5)] // Any dates with start time greater than or equal to 1980-05-11T16:32:15.0000000 and end time less than or equal to 1980-05-11T16:32:15.9999999. @@ -47,15 +47,15 @@ public DateSearchTests(DateSearchTestFixture fixture) [InlineData("1980-05-11T16:32:15.5000001")] // Any dates with start time greater than or equal to 1980-05-11T16:32:30.50000001 and end time less than or equal to 1980-05-11T16:32:30.50000001. [InlineData("1980-05-11T16:32:30")] // Any dates with start time greater than or equal to 1980-05-11T16:32:30.0000000 and end time less than or equal to 1980-05-11T16:32:30.9999999. [InlineData("ne1980", 0, 6)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-12-31T23:59:59.9999999. - [InlineData("ne1980-01", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-01-31T23:59:59.9999999. + [InlineData("ne1980-01", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-01-31T23:59:59.9999999. [InlineData("ne1980-05", 0, 1, 6)] // Any dates with start time less than 1980-05-01T00:00:00.0000000 or end time greater than 1980-05-31T23:59:59.9999999. - [InlineData("ne1980-05-10", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-10T00:00:00.0000000 or end time greater than 1980-05-10T23:59:59.9999999. - [InlineData("ne1980-05-11", 0, 1, 2, 6)] // Any dates with start time less than 1980-05-11T00:00:00.0000000 or end time greater than 1980-05-11T23:59:59.9999999. - [InlineData("ne1980-05-11T16:32:15", 0, 1, 2, 3, 6)] // Any dates with start time less than 1980-05-11T16:32:15.0000000 or end time greater than 1980-05-11T16:32:15.9999999. - [InlineData("ne1980-05-11T16:32:15.500", 0, 1, 2, 3, 4, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. - [InlineData("ne1980-05-11T16:32:15.5000000", 0, 1, 2, 3, 4, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. - [InlineData("ne1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000001 or end time greater than 1980-05-11T16:32:15.5000001. - [InlineData("ne1980-05-11T16:32:30", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-11T16:32:30.0000000 or end time greater than 1980-05-11T16:32:30.9999999. + [InlineData("ne1980-05-10", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-10T00:00:00.0000000 or end time greater than 1980-05-10T23:59:59.9999999. + [InlineData("ne1980-05-11", 0, 1, 2, 6, 7)] // Any dates with start time less than 1980-05-11T00:00:00.0000000 or end time greater than 1980-05-11T23:59:59.9999999. + [InlineData("ne1980-05-11T16:32:15", 0, 1, 2, 3, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.0000000 or end time greater than 1980-05-11T16:32:15.9999999. + [InlineData("ne1980-05-11T16:32:15.500", 0, 1, 2, 3, 4, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. + [InlineData("ne1980-05-11T16:32:15.5000000", 0, 1, 2, 3, 4, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. + [InlineData("ne1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000001 or end time greater than 1980-05-11T16:32:15.5000001. + [InlineData("ne1980-05-11T16:32:30", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:30.0000000 or end time greater than 1980-05-11T16:32:30.9999999. [InlineData("lt1980", 0)] // Only dates with start time earlier than 1980-01-01T00:00:00.0000000 would match. [InlineData("lt1980-04", 0, 1)] // Only dates with start time earlier than 1980-04-01T00:00:00.0000000 would match. [InlineData("lt1980-05", 0, 1)] // Only dates with start time earlier than 1980-05-01T00:00:00.0000000 would match. @@ -69,27 +69,27 @@ public DateSearchTests(DateSearchTestFixture fixture) [InlineData("lt1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-11T16:32:15.5000001 would match. [InlineData("lt1980-05-11T16:32:16", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-11T16:32:16.0000000 would match. [InlineData("lt1980-05-12", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-12T00:00:00.0000000 would match. - [InlineData("lt1980-06", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-06-01T00:00:00.0000000 would match. - [InlineData("lt1981", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000000 would match. - [InlineData("lt1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000001 would match. - [InlineData("gt1979-12-31T23:59:59.9999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1979-12-31T23:59:59.9999999 would match. + [InlineData("lt1980-06", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than 1980-06-01T00:00:00.0000000 would match. + [InlineData("lt1981", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000000 would match. + [InlineData("lt1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000001 would match. + [InlineData("gt1979-12-31T23:59:59.9999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1979-12-31T23:59:59.9999999 would match. [InlineData("gt1980", 6)] // Only dates with end time later than 1980-12-31T23:59:59.9999999 would match. - [InlineData("gt1980-04", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-04-30T23:59:59.9999999 would match. + [InlineData("gt1980-04", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-04-30T23:59:59.9999999 would match. [InlineData("gt1980-05", 1, 6)] // Only dates with end time later than 1980-05-31T23:59:59.9999999 would match. - [InlineData("gt1980-05-11", 1, 2, 6)] // Only dates with end time later than 1980-05-11T23:59:59.9999999 would match. - [InlineData("gt1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-05-11T16:32:14.9999999 would match. - [InlineData("gt1980-05-11T16:32:15", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:15.9999999 would match. - [InlineData("gt1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-05-11T16:32:15.4999999 would match. - [InlineData("gt1980-05-11T16:32:15.500", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("gt1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("gt1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000001 would match. - [InlineData("gt1980-05-11T16:32:16", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:16.9999999 would match. - [InlineData("gt1980-05-12", 1, 2, 6)] // Only dates with end time later than 1980-05-12T23:59:59.9999999 would match. + [InlineData("gt1980-05-11", 1, 2, 6, 7)] // Only dates with end time later than 1980-05-11T23:59:59.9999999 would match. + [InlineData("gt1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:14.9999999 would match. + [InlineData("gt1980-05-11T16:32:15", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.9999999 would match. + [InlineData("gt1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.4999999 would match. + [InlineData("gt1980-05-11T16:32:15.500", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("gt1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("gt1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000001 would match. + [InlineData("gt1980-05-11T16:32:16", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:16.9999999 would match. + [InlineData("gt1980-05-12", 1, 2, 6, 7)] // Only dates with end time later than 1980-05-12T23:59:59.9999999 would match. [InlineData("gt1980-06", 1, 6)] // Only dates with end time later than 1980-06-01T23:59:59.9999999 would match. [InlineData("gt1981-01-01T00:00:00.0000001", 6)] // Only dates with end time later than 1981-01-01T00:00:00.0000001 would match. - [InlineData("le1980", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-12-31T23:59:59.9999999 would match. + [InlineData("le1980", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-12-31T23:59:59.9999999 would match. [InlineData("le1980-04", 0, 1)] // Only dates with start time earlier than or equal to 1980-04-30T23:59:59.9999999 would match. - [InlineData("le1980-05", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-31T23:59:59.9999999 would match. + [InlineData("le1980-05", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-05-31T23:59:59.9999999 would match. [InlineData("le1980-05-10", 0, 1, 2)] // Only dates with start time earlier than or equal to 1980-05-10T23:59:59.9999999 would match. [InlineData("le1980-05-11", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T23:59:59.9999999 would match. [InlineData("le1980-05-11T16:32:14", 0, 1, 2, 3)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:14.9999999 would match. @@ -100,37 +100,37 @@ public DateSearchTests(DateSearchTestFixture fixture) [InlineData("le1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:15.5000001 would match. [InlineData("le1980-05-11T16:32:16", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:16.9999999 would match. [InlineData("le1980-05-12", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-12T23:59:59.9999999 would match. - [InlineData("le1980-06", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-06-30T23:59:59.9999999 would match. - [InlineData("le1981", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than or equal to 1981-12-31T23:59:59.9999999 would match. - [InlineData("le1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than or equal to 1981-01-01T00:00:00.0000001 would match. - [InlineData("ge1979-12-31T23:59:59.9999999", 0, 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1979-12-31T23:59:59.9999999 would match. - [InlineData("ge1980", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-01-01T00:00:00.0000000 would match. - [InlineData("ge1980-04", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-04-01T00:00:00.0000000 would match. - [InlineData("ge1980-05", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-01T00:00:00.0000000 would match. - [InlineData("ge1980-05-11", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T00:00:00.0000000 would match. - [InlineData("ge1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:14.0000000 would match. - [InlineData("ge1980-05-11T16:32:15", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.0000000 would match. - [InlineData("ge1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.4999999 would match. - [InlineData("ge1980-05-11T16:32:15.500", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. - [InlineData("ge1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. - [InlineData("ge1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000001 would match. - [InlineData("ge1980-05-11T16:32:16", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. - [InlineData("ge1980-05-12", 1, 2, 6)] // Only dates with end time later than or equal to 1980-05-12T00:00:00.0000000 would match. + [InlineData("le1980-06", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-06-30T23:59:59.9999999 would match. + [InlineData("le1981", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than or equal to 1981-12-31T23:59:59.9999999 would match. + [InlineData("le1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than or equal to 1981-01-01T00:00:00.0000001 would match. + [InlineData("ge1979-12-31T23:59:59.9999999", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1979-12-31T23:59:59.9999999 would match. + [InlineData("ge1980", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-01-01T00:00:00.0000000 would match. + [InlineData("ge1980-04", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-04-01T00:00:00.0000000 would match. + [InlineData("ge1980-05", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-01T00:00:00.0000000 would match. + [InlineData("ge1980-05-11", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T00:00:00.0000000 would match. + [InlineData("ge1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:14.0000000 would match. + [InlineData("ge1980-05-11T16:32:15", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.0000000 would match. + [InlineData("ge1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.4999999 would match. + [InlineData("ge1980-05-11T16:32:15.500", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. + [InlineData("ge1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. + [InlineData("ge1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000001 would match. + [InlineData("ge1980-05-11T16:32:16", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. + [InlineData("ge1980-05-12", 1, 2, 6, 7)] // Only dates with end time later than or equal to 1980-05-12T00:00:00.0000000 would match. [InlineData("ge1980-06", 1, 6)] // Only dates with end time later than or equal to 1980-06-01T00:00:00.0000000 would match. [InlineData("ge1981-01-01T00:00:00.0000001", 6)] // Only dates with end time later than or equal to 1981-01-01T00:00:00.0000001 would match. [InlineData("sa1980", 6)] // Only dates with start time later than 1981-12-31T23:59:59.9999999 would match. - [InlineData("sa1980-04", 2, 3, 4, 5, 6)] // Only dates with start time later than 1980-04-30T23:59:59.9999999 would match. + [InlineData("sa1980-04", 2, 3, 4, 5, 6, 7)] // Only dates with start time later than 1980-04-30T23:59:59.9999999 would match. [InlineData("sa1980-05", 6)] // Only dates with start time later than 1980-05-31T23:59:59.9999999 would match. - [InlineData("sa1980-05-10", 3, 4, 5, 6)] // Only dates with start time later than 1980-05-10T23:59:59.9999999 would match. - [InlineData("sa1980-05-11", 6)] // Only dates with start time later than 1980-05-11T23:59:59.9999999 would match. - [InlineData("sa1980-05-11T16:32:14", 4, 5, 6)] // Only dates with start time later than 1980-05-11T16:32:14.9999999 would match. - [InlineData("sa1980-05-11T16:32:15", 6)] // Only dates with start time later than 1980-05-11T16:32:15.9999999 would match. - [InlineData("sa1980-05-11T16:32:15.4999999", 5, 6)] // Only dates with start time later than 1980-05-11T16:32:15.49999999 would match. - [InlineData("sa1980-05-11T16:32:15.500", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("sa1980-05-11T16:32:15.5000000", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("sa1980-05-11T16:32:15.5000001", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000001 would match. - [InlineData("sa1980-05-11T16:32:16", 6)] // Only dates with start time later than 1980-05-11T16:32:16.9999999 would match. - [InlineData("sa1980-05-12", 6)] // Only dates with start time later than 1980-05-12T23:59:59.9999999 would match. + [InlineData("sa1980-05-10", 3, 4, 5, 6, 7)] // Only dates with start time later than 1980-05-10T23:59:59.9999999 would match. + [InlineData("sa1980-05-11", 6, 7)] // Only dates with start time later than 1980-05-11T23:59:59.9999999 would match. + [InlineData("sa1980-05-11T16:32:14", 4, 5, 6, 7)] // Only dates with start time later than 1980-05-11T16:32:14.9999999 would match. + [InlineData("sa1980-05-11T16:32:15", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.9999999 would match. + [InlineData("sa1980-05-11T16:32:15.4999999", 5, 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.49999999 would match. + [InlineData("sa1980-05-11T16:32:15.500", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("sa1980-05-11T16:32:15.5000000", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("sa1980-05-11T16:32:15.5000001", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000001 would match. + [InlineData("sa1980-05-11T16:32:16", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:16.9999999 would match. + [InlineData("sa1980-05-12", 6, 7)] // Only dates with start time later than 1980-05-12T23:59:59.9999999 would match. [InlineData("sa1980-06", 6)] // Only dates with start time later than 1980-06-30T23:59:59.9999999 would match. [InlineData("sa1981")] // Only dates with start time later than 1981-12-31T23:59:59.9999999 would match. [InlineData("sa1981-01-01T00:00:00.0000001")] // Only dates with start time later than 1981-01-01T00:00:00.0000001 would match. @@ -147,8 +147,8 @@ public DateSearchTests(DateSearchTestFixture fixture) [InlineData("eb1980-05-11T16:32:15.5000001", 0, 5)] // Only dates with end time earlier than 1980-05-11T16:32:15.5000001 would match. [InlineData("eb1980-05-11T16:32:16", 0, 4, 5)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. [InlineData("eb1980-05-12", 0, 3, 4, 5)] // Only dates with end time earlier than 1980-05-12T00:00:00.0000000 would match. - [InlineData("eb1980-06", 0, 2, 3, 4, 5)] // Only dates with end time earlier than 1980-06-01T00:00:00.0000000 would match. - [InlineData("eb1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5)] // Only dates with end time earlier than 1981-01-01T00:00:00.0000001 would match. + [InlineData("eb1980-06", 0, 2, 3, 4, 5, 7)] // Only dates with end time earlier than 1980-06-01T00:00:00.0000000 would match. + [InlineData("eb1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 7)] // Only dates with end time earlier than 1981-01-01T00:00:00.0000001 would match public async Task GivenADateTimeSearchParam_WhenSearched_ThenCorrectBundleShouldBeReturned(string queryValue, params int[] expectedIndices) { try @@ -214,5 +214,27 @@ public async Task GivenAnOutOfRangeDateTimeSearchParam_WhenSearched_ThenExceptio fce.StatusCode == HttpStatusCode.BadRequest, $"A '{nameof(FhirClientException)}' with '{HttpStatusCode.BadRequest}' status code was expected, but instead a '{nameof(FhirClientException)}' with '{fce.StatusCode}' status code was raised. Url: {Client.HttpClient.BaseAddress}. Activity Id: {fce.Response.GetRequestId()}. Error: {fce.Message}"); } + + [Theory] + [InlineData("1981-05-16T16:32:15.500", 7)] // This should include the observation containing a period since the date is in that effective period. + public async Task GivenADateTimeSearchParam_WhenSearchedAgainstAPeriod_ThenCorrectBundleShouldBeReturned(string queryValue, params int[] expectedIndices) + { + try + { + Bundle bundle = await Client.SearchAsync(ResourceType.Observation, $"date={queryValue}&code={Fixture.Coding.Code}"); + + Observation[] expected = expectedIndices.Select(i => Fixture.Observations[i]).ToArray(); + + ValidateBundle(bundle, expected); + } + catch (FhirClientException fce) + { + Assert.Fail($"A non-expected '{nameof(FhirClientException)}' was raised. Url: {Client.HttpClient.BaseAddress}. Activity Id: {fce.Response.GetRequestId()}. Error: {fce.Message}"); + } + catch (Exception e) + { + Assert.Fail($"A non-expected '{e.GetType()}' was raised. Url: {Client.HttpClient.BaseAddress}. No Activity Id present. Error: {e.Message}"); + } + } } } From b24089e7e24d0b90862afc3ce4b1ee82ba246bf3 Mon Sep 17 00:00:00 2001 From: Paul Taladay Date: Tue, 31 Dec 2024 13:36:31 -0800 Subject: [PATCH 2/3] Updated tests based on recent changes --- .../Search/DateTimeEqualityRewriterTests.cs | 8 +- .../Rest/Import/ImportDateSearchTests.cs | 110 +++++++++--------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Search/DateTimeEqualityRewriterTests.cs b/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Search/DateTimeEqualityRewriterTests.cs index 4294eb43cb..4632338b9e 100644 --- a/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Search/DateTimeEqualityRewriterTests.cs +++ b/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Search/DateTimeEqualityRewriterTests.cs @@ -29,7 +29,7 @@ public void GivenStartAndEndExpressions_WhenRewritten_AnUpperBoundOnStartIsAdded Expression rewrittenExpression = inputExpression.AcceptVisitor(DateTimeEqualityRewriter.Instance); Assert.Equal( - "(And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000))", + "(Or (And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000)) (And (FieldLessThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000)))", rewrittenExpression.ToString()); } @@ -57,7 +57,7 @@ public void GivenStartAndEndExpressionsInReverseOrder_WhenRewritten_AnUpperBound Expression rewrittenExpression = inputExpression.AcceptVisitor(DateTimeEqualityRewriter.Instance); Assert.Equal( - "(And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000))", + "(Or (And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000)) (And (FieldLessThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000)))", rewrittenExpression.ToString()); } @@ -72,7 +72,7 @@ public void GivenStartAndEndExclusiveExpressions_WhenRewritten_AnUpperBoundOnSta Expression rewrittenExpression = inputExpression.AcceptVisitor(DateTimeEqualityRewriter.Instance); Assert.Equal( - "(And (FieldGreaterThan DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThan DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThan DateTimeEnd 2021-01-01T23:59:59.0000000))", + "(Or (And (FieldGreaterThan DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThan DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThan DateTimeEnd 2021-01-01T23:59:59.0000000)) (And (FieldLessThan DateTimeStart 2021-01-01T00:00:00.0000000) (FieldGreaterThan DateTimeEnd 2021-01-01T23:59:59.0000000)))", rewrittenExpression.ToString()); } @@ -115,7 +115,7 @@ public void GivenStartAndEndExpressionsAndAnUnrelatedExpression_WhenRewritten_An Expression rewrittenExpression = inputExpression.AcceptVisitor(DateTimeEqualityRewriter.Instance); Assert.Equal( - "(And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000) (FieldEqual Number 1))", + "(Or (And (FieldGreaterThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldLessThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000) (FieldEqual Number 1)) (And (FieldLessThanOrEqual DateTimeStart 2021-01-01T00:00:00.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T23:59:59.0000000)))", rewrittenExpression.ToString()); } diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTests.cs index 1df6f2a48d..0b806c55ec 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTests.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTests.cs @@ -38,9 +38,9 @@ public ImportDateSearchTests(ImportDateSearchTestFixture fixture) // sa: the range of the search value does not overlap with the range of the target value, and the range above the search value contains the range of the target value. // eb: the range of the search value does overlap not with the range of the target value, and the range below the search value contains the range of the target value. [Theory] - [InlineData("1980", 1, 2, 3, 4, 5)] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-12-31T23:59:59.9999999. + [InlineData("1980", 1, 2, 3, 4, 5, 7)] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-12-31T23:59:59.9999999. [InlineData("1980-01")] // Any dates with start time greater than or equal to 1980-01-01T00:00:00.0000000 and end time less than or equal to 1980-01-31T23:59:59.9999999. - [InlineData("1980-05", 2, 3, 4, 5)] // Any dates with start time greater than or equal to 1980-05-01T00:00:00.0000000 and end time less than or equal to 1980-05-31T23:59:59.9999999. + [InlineData("1980-05", 2, 3, 4, 5, 7)] // Any dates with start time greater than or equal to 1980-05-01T00:00:00.0000000 and end time less than or equal to 1980-05-31T23:59:59.9999999. [InlineData("1980-05-10")] // Any dates with start time greater than or equal to 1980-05-10T00:00:00.0000000 and end time less than or equal to 1980-05-10T23:59:59.9999999. [InlineData("1980-05-11", 3, 4, 5)] // Any dates with start time greater than or equal to 1980-05-11T00:00:00.0000000 and end time less than or equal to 1980-05-11T23:59:59.9999999. [InlineData("1980-05-11T16:32:15", 4, 5)] // Any dates with start time greater than or equal to 1980-05-11T16:32:15.0000000 and end time less than or equal to 1980-05-11T16:32:15.9999999. @@ -49,15 +49,15 @@ public ImportDateSearchTests(ImportDateSearchTestFixture fixture) [InlineData("1980-05-11T16:32:15.5000001")] // Any dates with start time greater than or equal to 1980-05-11T16:32:30.50000001 and end time less than or equal to 1980-05-11T16:32:30.50000001. [InlineData("1980-05-11T16:32:30")] // Any dates with start time greater than or equal to 1980-05-11T16:32:30.0000000 and end time less than or equal to 1980-05-11T16:32:30.9999999. [InlineData("ne1980", 0, 6)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-12-31T23:59:59.9999999. - [InlineData("ne1980-01", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-01-31T23:59:59.9999999. + [InlineData("ne1980-01", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-01-01T00:00:00.0000000 or end time greater than 1980-01-31T23:59:59.9999999. [InlineData("ne1980-05", 0, 1, 6)] // Any dates with start time less than 1980-05-01T00:00:00.0000000 or end time greater than 1980-05-31T23:59:59.9999999. - [InlineData("ne1980-05-10", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-10T00:00:00.0000000 or end time greater than 1980-05-10T23:59:59.9999999. - [InlineData("ne1980-05-11", 0, 1, 2, 6)] // Any dates with start time less than 1980-05-11T00:00:00.0000000 or end time greater than 1980-05-11T23:59:59.9999999. - [InlineData("ne1980-05-11T16:32:15", 0, 1, 2, 3, 6)] // Any dates with start time less than 1980-05-11T16:32:15.0000000 or end time greater than 1980-05-11T16:32:15.9999999. - [InlineData("ne1980-05-11T16:32:15.500", 0, 1, 2, 3, 4, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. - [InlineData("ne1980-05-11T16:32:15.5000000", 0, 1, 2, 3, 4, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. - [InlineData("ne1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-11T16:32:15.5000001 or end time greater than 1980-05-11T16:32:15.5000001. - [InlineData("ne1980-05-11T16:32:30", 0, 1, 2, 3, 4, 5, 6)] // Any dates with start time less than 1980-05-11T16:32:30.0000000 or end time greater than 1980-05-11T16:32:30.9999999. + [InlineData("ne1980-05-10", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-10T00:00:00.0000000 or end time greater than 1980-05-10T23:59:59.9999999. + [InlineData("ne1980-05-11", 0, 1, 2, 6, 7)] // Any dates with start time less than 1980-05-11T00:00:00.0000000 or end time greater than 1980-05-11T23:59:59.9999999. + [InlineData("ne1980-05-11T16:32:15", 0, 1, 2, 3, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.0000000 or end time greater than 1980-05-11T16:32:15.9999999. + [InlineData("ne1980-05-11T16:32:15.500", 0, 1, 2, 3, 4, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. + [InlineData("ne1980-05-11T16:32:15.5000000", 0, 1, 2, 3, 4, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000000 or end time greater than 1980-05-11T16:32:15.5000000. + [InlineData("ne1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:15.5000001 or end time greater than 1980-05-11T16:32:15.5000001. + [InlineData("ne1980-05-11T16:32:30", 0, 1, 2, 3, 4, 5, 6, 7)] // Any dates with start time less than 1980-05-11T16:32:30.0000000 or end time greater than 1980-05-11T16:32:30.9999999. [InlineData("lt1980", 0)] // Only dates with start time earlier than 1980-01-01T00:00:00.0000000 would match. [InlineData("lt1980-04", 0, 1)] // Only dates with start time earlier than 1980-04-01T00:00:00.0000000 would match. [InlineData("lt1980-05", 0, 1)] // Only dates with start time earlier than 1980-05-01T00:00:00.0000000 would match. @@ -71,27 +71,27 @@ public ImportDateSearchTests(ImportDateSearchTestFixture fixture) [InlineData("lt1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-11T16:32:15.5000001 would match. [InlineData("lt1980-05-11T16:32:16", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-11T16:32:16.0000000 would match. [InlineData("lt1980-05-12", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-05-12T00:00:00.0000000 would match. - [InlineData("lt1980-06", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1980-06-01T00:00:00.0000000 would match. - [InlineData("lt1981", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000000 would match. - [InlineData("lt1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000001 would match. - [InlineData("gt1979-12-31T23:59:59.9999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1979-12-31T23:59:59.9999999 would match. + [InlineData("lt1980-06", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than 1980-06-01T00:00:00.0000000 would match. + [InlineData("lt1981", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000000 would match. + [InlineData("lt1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than 1981-01-01T00:00:00.0000001 would match. + [InlineData("gt1979-12-31T23:59:59.9999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1979-12-31T23:59:59.9999999 would match. [InlineData("gt1980", 6)] // Only dates with end time later than 1980-12-31T23:59:59.9999999 would match. - [InlineData("gt1980-04", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-04-30T23:59:59.9999999 would match. + [InlineData("gt1980-04", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-04-30T23:59:59.9999999 would match. [InlineData("gt1980-05", 1, 6)] // Only dates with end time later than 1980-05-31T23:59:59.9999999 would match. - [InlineData("gt1980-05-11", 1, 2, 6)] // Only dates with end time later than 1980-05-11T23:59:59.9999999 would match. - [InlineData("gt1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-05-11T16:32:14.9999999 would match. - [InlineData("gt1980-05-11T16:32:15", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:15.9999999 would match. - [InlineData("gt1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than 1980-05-11T16:32:15.4999999 would match. - [InlineData("gt1980-05-11T16:32:15.500", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("gt1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("gt1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6)] // Only dates with end time later than 1980-05-11T16:32:15.5000001 would match. - [InlineData("gt1980-05-11T16:32:16", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:16.9999999 would match. - [InlineData("gt1980-05-12", 1, 2, 6)] // Only dates with end time later than 1980-05-12T23:59:59.9999999 would match. + [InlineData("gt1980-05-11", 1, 2, 6, 7)] // Only dates with end time later than 1980-05-11T23:59:59.9999999 would match. + [InlineData("gt1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:14.9999999 would match. + [InlineData("gt1980-05-11T16:32:15", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.9999999 would match. + [InlineData("gt1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.4999999 would match. + [InlineData("gt1980-05-11T16:32:15.500", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("gt1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("gt1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:15.5000001 would match. + [InlineData("gt1980-05-11T16:32:16", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:16.9999999 would match. + [InlineData("gt1980-05-12", 1, 2, 6, 7)] // Only dates with end time later than 1980-05-12T23:59:59.9999999 would match. [InlineData("gt1980-06", 1, 6)] // Only dates with end time later than 1980-06-01T23:59:59.9999999 would match. [InlineData("gt1981-01-01T00:00:00.0000001", 6)] // Only dates with end time later than 1981-01-01T00:00:00.0000001 would match. - [InlineData("le1980", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-12-31T23:59:59.9999999 would match. + [InlineData("le1980", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-12-31T23:59:59.9999999 would match. [InlineData("le1980-04", 0, 1)] // Only dates with start time earlier than or equal to 1980-04-30T23:59:59.9999999 would match. - [InlineData("le1980-05", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-31T23:59:59.9999999 would match. + [InlineData("le1980-05", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-05-31T23:59:59.9999999 would match. [InlineData("le1980-05-10", 0, 1, 2)] // Only dates with start time earlier than or equal to 1980-05-10T23:59:59.9999999 would match. [InlineData("le1980-05-11", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T23:59:59.9999999 would match. [InlineData("le1980-05-11T16:32:14", 0, 1, 2, 3)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:14.9999999 would match. @@ -102,37 +102,37 @@ public ImportDateSearchTests(ImportDateSearchTestFixture fixture) [InlineData("le1980-05-11T16:32:15.5000001", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:15.5000001 would match. [InlineData("le1980-05-11T16:32:16", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-11T16:32:16.9999999 would match. [InlineData("le1980-05-12", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-05-12T23:59:59.9999999 would match. - [InlineData("le1980-06", 0, 1, 2, 3, 4, 5)] // Only dates with start time earlier than or equal to 1980-06-30T23:59:59.9999999 would match. - [InlineData("le1981", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than or equal to 1981-12-31T23:59:59.9999999 would match. - [InlineData("le1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6)] // Only dates with start time earlier than or equal to 1981-01-01T00:00:00.0000001 would match. - [InlineData("ge1979-12-31T23:59:59.9999999", 0, 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1979-12-31T23:59:59.9999999 would match. - [InlineData("ge1980", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-01-01T00:00:00.0000000 would match. - [InlineData("ge1980-04", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-04-01T00:00:00.0000000 would match. - [InlineData("ge1980-05", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-01T00:00:00.0000000 would match. - [InlineData("ge1980-05-11", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T00:00:00.0000000 would match. - [InlineData("ge1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:14.0000000 would match. - [InlineData("ge1980-05-11T16:32:15", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.0000000 would match. - [InlineData("ge1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.4999999 would match. - [InlineData("ge1980-05-11T16:32:15.500", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. - [InlineData("ge1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 5, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. - [InlineData("ge1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000001 would match. - [InlineData("ge1980-05-11T16:32:16", 1, 2, 3, 6)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. - [InlineData("ge1980-05-12", 1, 2, 6)] // Only dates with end time later than or equal to 1980-05-12T00:00:00.0000000 would match. + [InlineData("le1980-06", 0, 1, 2, 3, 4, 5, 7)] // Only dates with start time earlier than or equal to 1980-06-30T23:59:59.9999999 would match. + [InlineData("le1981", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than or equal to 1981-12-31T23:59:59.9999999 would match. + [InlineData("le1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with start time earlier than or equal to 1981-01-01T00:00:00.0000001 would match. + [InlineData("ge1979-12-31T23:59:59.9999999", 0, 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1979-12-31T23:59:59.9999999 would match. + [InlineData("ge1980", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-01-01T00:00:00.0000000 would match. + [InlineData("ge1980-04", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-04-01T00:00:00.0000000 would match. + [InlineData("ge1980-05", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-01T00:00:00.0000000 would match. + [InlineData("ge1980-05-11", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T00:00:00.0000000 would match. + [InlineData("ge1980-05-11T16:32:14", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:14.0000000 would match. + [InlineData("ge1980-05-11T16:32:15", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.0000000 would match. + [InlineData("ge1980-05-11T16:32:15.4999999", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.4999999 would match. + [InlineData("ge1980-05-11T16:32:15.500", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. + [InlineData("ge1980-05-11T16:32:15.5000000", 1, 2, 3, 4, 5, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000000 would match. + [InlineData("ge1980-05-11T16:32:15.5000001", 1, 2, 3, 4, 6, 7)] // Only dates with end time later than or equal to 1980-05-11T16:32:15.5000001 would match. + [InlineData("ge1980-05-11T16:32:16", 1, 2, 3, 6, 7)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. + [InlineData("ge1980-05-12", 1, 2, 6, 7)] // Only dates with end time later than or equal to 1980-05-12T00:00:00.0000000 would match. [InlineData("ge1980-06", 1, 6)] // Only dates with end time later than or equal to 1980-06-01T00:00:00.0000000 would match. [InlineData("ge1981-01-01T00:00:00.0000001", 6)] // Only dates with end time later than or equal to 1981-01-01T00:00:00.0000001 would match. [InlineData("sa1980", 6)] // Only dates with start time later than 1981-12-31T23:59:59.9999999 would match. - [InlineData("sa1980-04", 2, 3, 4, 5, 6)] // Only dates with start time later than 1980-04-30T23:59:59.9999999 would match. + [InlineData("sa1980-04", 2, 3, 4, 5, 6, 7)] // Only dates with start time later than 1980-04-30T23:59:59.9999999 would match. [InlineData("sa1980-05", 6)] // Only dates with start time later than 1980-05-31T23:59:59.9999999 would match. - [InlineData("sa1980-05-10", 3, 4, 5, 6)] // Only dates with start time later than 1980-05-10T23:59:59.9999999 would match. - [InlineData("sa1980-05-11", 6)] // Only dates with start time later than 1980-05-11T23:59:59.9999999 would match. - [InlineData("sa1980-05-11T16:32:14", 4, 5, 6)] // Only dates with start time later than 1980-05-11T16:32:14.9999999 would match. - [InlineData("sa1980-05-11T16:32:15", 6)] // Only dates with start time later than 1980-05-11T16:32:15.9999999 would match. - [InlineData("sa1980-05-11T16:32:15.4999999", 5, 6)] // Only dates with start time later than 1980-05-11T16:32:15.49999999 would match. - [InlineData("sa1980-05-11T16:32:15.500", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("sa1980-05-11T16:32:15.5000000", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. - [InlineData("sa1980-05-11T16:32:15.5000001", 6)] // Only dates with start time later than 1980-05-11T16:32:15.5000001 would match. - [InlineData("sa1980-05-11T16:32:16", 6)] // Only dates with start time later than 1980-05-11T16:32:16.9999999 would match. - [InlineData("sa1980-05-12", 6)] // Only dates with start time later than 1980-05-12T23:59:59.9999999 would match. + [InlineData("sa1980-05-10", 3, 4, 5, 6, 7)] // Only dates with start time later than 1980-05-10T23:59:59.9999999 would match. + [InlineData("sa1980-05-11", 6, 7)] // Only dates with start time later than 1980-05-11T23:59:59.9999999 would match. + [InlineData("sa1980-05-11T16:32:14", 4, 5, 6, 7)] // Only dates with start time later than 1980-05-11T16:32:14.9999999 would match. + [InlineData("sa1980-05-11T16:32:15", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.9999999 would match. + [InlineData("sa1980-05-11T16:32:15.4999999", 5, 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.49999999 would match. + [InlineData("sa1980-05-11T16:32:15.500", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("sa1980-05-11T16:32:15.5000000", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000000 would match. + [InlineData("sa1980-05-11T16:32:15.5000001", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:15.5000001 would match. + [InlineData("sa1980-05-11T16:32:16", 6, 7)] // Only dates with start time later than 1980-05-11T16:32:16.9999999 would match. + [InlineData("sa1980-05-12", 6, 7)] // Only dates with start time later than 1980-05-12T23:59:59.9999999 would match. [InlineData("sa1980-06", 6)] // Only dates with start time later than 1980-06-30T23:59:59.9999999 would match. [InlineData("sa1981")] // Only dates with start time later than 1981-12-31T23:59:59.9999999 would match. [InlineData("sa1981-01-01T00:00:00.0000001")] // Only dates with start time later than 1981-01-01T00:00:00.0000001 would match. @@ -149,8 +149,8 @@ public ImportDateSearchTests(ImportDateSearchTestFixture fixture) [InlineData("eb1980-05-11T16:32:15.5000001", 0, 5)] // Only dates with end time earlier than 1980-05-11T16:32:15.5000001 would match. [InlineData("eb1980-05-11T16:32:16", 0, 4, 5)] // Only dates with end time later than 1980-05-11T16:32:16.0000000 would match. [InlineData("eb1980-05-12", 0, 3, 4, 5)] // Only dates with end time earlier than 1980-05-12T00:00:00.0000000 would match. - [InlineData("eb1980-06", 0, 2, 3, 4, 5)] // Only dates with end time earlier than 1980-06-01T00:00:00.0000000 would match. - [InlineData("eb1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5)] // Only dates with end time earlier than 1981-01-01T00:00:00.0000001 would match. + [InlineData("eb1980-06", 0, 2, 3, 4, 5, 7)] // Only dates with end time earlier than 1980-06-01T00:00:00.0000000 would match. + [InlineData("eb1981-01-01T00:00:00.0000001", 0, 1, 2, 3, 4, 5, 7)] // Only dates with end time earlier than 1981-01-01T00:00:00.0000001 would match public async Task GivenADateTimeSearchParam_WhenSearched_ThenCorrectBundleShouldBeReturned(string queryValue, params int[] expectedIndices) { Bundle bundle = await _client.SearchAsync(ResourceType.Observation, $"date={queryValue}&_tag={_fixture.FixtureTag}"); From 6b1a5c5aed9a1de993d947c830d8abc7239d74b7 Mon Sep 17 00:00:00 2001 From: Paul Taladay Date: Mon, 6 Jan 2025 11:08:19 -0800 Subject: [PATCH 3/3] Updated test fixtures. Removed temporary comments. --- .../Import/ImportDateSearchTestFixture.cs | 11 ++++++++-- .../Rest/Search/DateSearchTestFixture.cs | 20 +++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTestFixture.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTestFixture.cs index 3beb7ab0c9..fa829da00d 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTestFixture.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Import/ImportDateSearchTestFixture.cs @@ -33,14 +33,21 @@ protected override async Task OnInitializedAsync() p => SetObservation(p, "1980-05-11"), // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999 p => SetObservation(p, "1980-05-11T16:32:15"), // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999 p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000 - p => SetObservation(p, "1981-01-01")); // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 - + p => SetObservation(p, "1981-01-01"), // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 + p => SetObservationWithPeriod(p, "1980-05-16", "1980-05-17")); // 1980-05-11T00:00:00.0000000 <-> 1980-05-12T23:59:59.9999999 void SetObservation(Observation observation, string date) { observation.Status = ObservationStatus.Final; observation.AddTestTag(FixtureTag); observation.Effective = new FhirDateTime(date); } + + void SetObservationWithPeriod(Observation observation, string startDate, string endDate) + { + observation.Status = ObservationStatus.Final; + observation.AddTestTag(FixtureTag); + observation.Effective = new Period(new FhirDateTime(startDate), new FhirDateTime(endDate)); + } } } } diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs index 7923bb8294..89f323bec7 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTestFixture.cs @@ -33,16 +33,14 @@ protected override async Task OnInitializedAsync() }; Observations = await TestFhirClient.CreateResourcesAsync( - p => SetObservationWithPeriod(p, "1980-05-16", "1980-05-17")); // 1980-05-11T00:00:00.0000000 <-> 1980-05-12T23:59:59.9999999 - - // p => SetObservation(p, "1979-12-31"), // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999 - // p => SetObservation(p, "1980"), // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999 - // p => SetObservation(p, "1980-05"), // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999 - // p => SetObservation(p, "1980-05-11"), // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999 - // p => SetObservation(p, "1980-05-11T16:32:15"), // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999 - // p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000 - // p => SetObservation(p, "1981-01-01"), // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 -/* + p => SetObservation(p, "1979-12-31"), // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999 + p => SetObservation(p, "1980"), // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999 + p => SetObservation(p, "1980-05"), // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999 + p => SetObservation(p, "1980-05-11"), // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999 + p => SetObservation(p, "1980-05-11T16:32:15"), // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999 + p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000 + p => SetObservation(p, "1981-01-01"), // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999 + p => SetObservationWithPeriod(p, "1980-05-16", "1980-05-17")); // 1980-05-11T00:00:00.0000000 <-> 1980-05-12T23:59:59.9999999 void SetObservation(Observation observation, string date) { observation.Status = ObservationStatus.Final; @@ -54,7 +52,7 @@ void SetObservation(Observation observation, string date) }, }; observation.Effective = new FhirDateTime(date); - }*/ + } void SetObservationWithPeriod(Observation observation, string startDate, string endDate) {