Skip to content

Commit

Permalink
Fix: Date search doesn't match ranges properly (#4762)
Browse files Browse the repository at this point in the history
* 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.

* Updated tests based on recent changes

* Updated test fixtures. Removed temporary comments.

* Updated test results to match new expectations. Simplified logic for this particular case and addressed pr comments.

* Fixed unit test after recent changes.

* Updated more tetst based on recent changes.
  • Loading branch information
PTaladay authored Feb 5, 2025
1 parent 4455f75 commit 83759af
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))",
"(And (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T00:00:00.0000000))",
rewrittenExpression.ToString());
}

Expand Down Expand Up @@ -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))",
"(And (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T00:00:00.0000000))",
rewrittenExpression.ToString());
}

Expand All @@ -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))",
"(And (FieldLessThan DateTimeStart 2021-01-01T23:59:59.0000000) (FieldGreaterThan DateTimeEnd 2021-01-01T00:00:00.0000000))",
rewrittenExpression.ToString());
}

Expand Down Expand Up @@ -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))",
"(And (FieldLessThanOrEqual DateTimeStart 2021-01-01T23:59:59.0000000) (FieldGreaterThanOrEqual DateTimeEnd 2021-01-01T00:00:00.0000000) (FieldEqual Number 1))",
rewrittenExpression.ToString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ public override Expression VisitMultiary(MultiaryExpression expression, object c
{
case ({ } low, { } high):
EnsureAllocatedAndPopulated(ref newExpressions, expression.Expressions, i);

newExpressions.Add(low);
newExpressions.Add(new BinaryExpression(high.BinaryOperator, low.FieldName, high.ComponentIndex, high.Value));
newExpressions.Add(high);

newExpressions.Add(new BinaryExpression(high.BinaryOperator, low.FieldName, low.ComponentIndex, high.Value));
newExpressions.Add(new BinaryExpression(low.BinaryOperator, high.FieldName, high.ComponentIndex, low.Value));
i++;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-16T00:00:00.0000000 <-> 1980-05-17T23: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));
}
}
}
}
Loading

0 comments on commit 83759af

Please sign in to comment.