-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Date search doesn't match ranges properly #4762
base: main
Are you sure you want to change the base?
Conversation
…and if included in the span that resource will be returned.
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs
Dismissed
Show dismissed
Hide dismissed
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For clarity, I think we shouldn't nest ternary operators :)
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test shouldn't pass. The search is for 1981 but the data is in 1980.
|
||
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified by having it be:
newExpressions.Add(new BinaryExpression(high.BinaryOperator, low.FieldName, low.ComponentIndex, high.Value));
newExpressions.Add(new BinaryExpression(low.BinaryOperator, high.FieldName, high.ComponentIndex, low.Value));
You could then remove the dateInPeriodExpression variable, the old newExpressions assignments on lines 52-54, and the Or Expression on line 72.
The current generated SQL is
(StartDateTime >= '2022-05-01T00:00:00.0000000Z' AND StartDateTime <= '2022-05-01T23:59:59.9999999Z' AND EndDateTime <= '2022-05-01T23:59:59.9999999Z' )
OR
(StartDateTime <= '2022-05-01T00:00:00.0000000Z' AND EndDateTime >= '2022-05-01T23:59:59.9999999Z' )
and this would change it to be
StartDateTime <= '2022-05-01T23:59:59.9999999Z' AND EndDateTime >= '2022-05-01T00:00:00.0000000Z'
Description
Updates the logic to check if the date time is within the range on a given resource and if so will return that resource.
Related issues
Addresses [issue AB#131564].
Testing
Added additional unit test for validation and ran existing test to verify no new issues introduced.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)