Skip to content

[Do Not Review] Fixing custom search parameter bugs. #5024

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

v-isyamauchi-gh
Copy link

Description

The change addresses issues mentioned in the bug below that are related to customer search parameters.

Related issues

Addresses [issue #117004].

Bug 117004: Custom SearchParameter with same Code Affecting Built-In Search Functionality in FHIR Service

Testing

Tested manually with a local server and also by adding UTs and E2E tests.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@v-isyamauchi-gh v-isyamauchi-gh added this to the CY25Q2/2Wk06 milestone Jun 17, 2025
@v-isyamauchi-gh v-isyamauchi-gh added Bug Bug bug bug. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Open source This change is only relevant to the OSS code or release. labels Jun 17, 2025
@v-isyamauchi-gh v-isyamauchi-gh changed the title Fixing custom search parameter bugs. [Do Not Review] Fixing custom search parameter bugs. Jun 17, 2025
@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

5 similar comments
@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

Comment on lines +409 to +413
catch (Exception ex)
{
logger.LogError(ex, "Unexpected exception during comparing search parameter expressions.");
return null;
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 4 days ago

To fix the issue, we should replace the generic catch (Exception ex) block with specific exception types that are expected during the execution of the searchParameterComparer.CompareExpression method. If there are multiple possible exceptions, each should be handled in its own catch block. Any unexpected exceptions should propagate to higher levels for proper handling.

Steps:

  1. Identify the specific exceptions that searchParameterComparer.CompareExpression might throw. For example, if it involves parsing or evaluation, exceptions like ArgumentException or InvalidOperationException might be relevant.
  2. Replace the generic catch block with specific catch blocks for these exceptions.
  3. Optionally, add a fallback catch block to rethrow unexpected exceptions if necessary.

Suggested changeset 1
src/Microsoft.Health.Fhir.Core/Features/Definition/SearchParameterDefinitionBuilder.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Core/Features/Definition/SearchParameterDefinitionBuilder.cs b/src/Microsoft.Health.Fhir.Core/Features/Definition/SearchParameterDefinitionBuilder.cs
--- a/src/Microsoft.Health.Fhir.Core/Features/Definition/SearchParameterDefinitionBuilder.cs
+++ b/src/Microsoft.Health.Fhir.Core/Features/Definition/SearchParameterDefinitionBuilder.cs
@@ -408,5 +408,10 @@
             }
-            catch (Exception ex)
+            catch (ArgumentException ex)
             {
-                logger.LogError(ex, "Unexpected exception during comparing search parameter expressions.");
+                logger.LogError(ex, "Argument exception during comparing search parameter expressions.");
+                return null;
+            }
+            catch (InvalidOperationException ex)
+            {
+                logger.LogError(ex, "Invalid operation exception during comparing search parameter expressions.");
                 return null;
EOF
@@ -408,5 +408,10 @@
}
catch (Exception ex)
catch (ArgumentException ex)
{
logger.LogError(ex, "Unexpected exception during comparing search parameter expressions.");
logger.LogError(ex, "Argument exception during comparing search parameter expressions.");
return null;
}
catch (InvalidOperationException ex)
{
logger.LogError(ex, "Invalid operation exception during comparing search parameter expressions.");
return null;
Copilot is powered by AI and may make mistakes. Always verify output.
// Note: this test ensures that the compare can parse and compare all expressiosn in search-parameters.json.
// The comparison logic is tested by other tests in this class.
var fhirCoreAssembly = Assembly.Load("Microsoft.Health.Fhir.Core");
var currentAssembly = Assembly.GetExecutingAssembly();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
currentAssembly
is useless, since its value is never read.

Copilot Autofix

AI 4 days ago

To fix the issue, the assignment to currentAssembly on line 267 should be removed entirely, as the variable is not used anywhere in the provided code. This will eliminate the unnecessary assignment and improve code clarity. No additional changes are required since the removal does not affect the program's logic or functionality.


Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
@@ -266,3 +266,3 @@
             var fhirCoreAssembly = Assembly.Load("Microsoft.Health.Fhir.Core");
-            var currentAssembly = Assembly.GetExecutingAssembly();
+// Removed the unused assignment to currentAssembly.
 
EOF
@@ -266,3 +266,3 @@
var fhirCoreAssembly = Assembly.Load("Microsoft.Health.Fhir.Core");
var currentAssembly = Assembly.GetExecutingAssembly();
// Removed the unused assignment to currentAssembly.

Copilot is powered by AI and may make mistakes. Always verify output.
var bundle = rawResource.ToITypedElement(ModelInfoProvider.Instance).ToPoco() as Bundle;
Assert.NotNull(bundle);

foreach (var entry in bundle.Entry)

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
bundle
may be null at this access because of
this
assignment.
Variable
bundle
may be null at this access because of
this
assignment.
Variable
bundle
may be null at this access because of
this
assignment.
Variable
bundle
may be null at this access because of
this
assignment.

Copilot Autofix

AI 3 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

var searchParameter = entry.Resource as SearchParameter;
Assert.NotNull(searchParameter);

if (!string.IsNullOrEmpty(searchParameter.Expression))

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
searchParameter
may be null at this access because of
this
assignment.
Variable
searchParameter
may be null at this access because of
this
assignment.
Variable
searchParameter
may be null at this access because of
this
assignment.
Variable
searchParameter
may be null at this access because of
this
assignment.

Copilot Autofix

AI 4 days ago

To fix the issue, we need to ensure that searchParameter is not null before it is dereferenced on line 297. This can be achieved by adding an explicit null check for searchParameter before calling string.IsNullOrEmpty(searchParameter.Expression). This approach ensures that the code is safe even if assertions are disabled or bypassed.


Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
@@ -296,3 +296,3 @@
 
-                    if (!string.IsNullOrEmpty(searchParameter.Expression))
+                    if (searchParameter != null && !string.IsNullOrEmpty(searchParameter.Expression))
                     {
EOF
@@ -296,3 +296,3 @@

if (!string.IsNullOrEmpty(searchParameter.Expression))
if (searchParameter != null && !string.IsNullOrEmpty(searchParameter.Expression))
{
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +305 to +308
catch (Exception ex)
{
DebugOutput($"Failed to compare an expression '{searchParameter.Expression}':{Environment.NewLine}{ex}");
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 4 days ago

To fix the issue, replace the generic catch clause with specific exception types that are relevant to the operation being performed. For example, if the _comparer.CompareExpression method can throw specific exceptions like InvalidOperationException or ArgumentException, those should be caught explicitly. Any other exceptions should be allowed to propagate. Additionally, logging can be retained for visibility into the error.

The changes will be made in the file src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs. Specifically, the catch block starting at line 305 will be updated to catch specific exceptions.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterComparerTests.cs
@@ -304,5 +304,9 @@
                         }
-                        catch (Exception ex)
+                        catch (InvalidOperationException ex)
                         {
-                            DebugOutput($"Failed to compare an expression '{searchParameter.Expression}':{Environment.NewLine}{ex}");
+                            DebugOutput($"Failed to compare an expression '{searchParameter.Expression}' due to an invalid operation:{Environment.NewLine}{ex}");
+                        }
+                        catch (ArgumentException ex)
+                        {
+                            DebugOutput($"Failed to compare an expression '{searchParameter.Expression}' due to an argument error:{Environment.NewLine}{ex}");
                         }
EOF
@@ -304,5 +304,9 @@
}
catch (Exception ex)
catch (InvalidOperationException ex)
{
DebugOutput($"Failed to compare an expression '{searchParameter.Expression}':{Environment.NewLine}{ex}");
DebugOutput($"Failed to compare an expression '{searchParameter.Expression}' due to an invalid operation:{Environment.NewLine}{ex}");
}
catch (ArgumentException ex)
{
DebugOutput($"Failed to compare an expression '{searchParameter.Expression}' due to an argument error:{Environment.NewLine}{ex}");
}
Copilot is powered by AI and may make mistakes. Always verify output.
{
if (x == null || y == null)
{
return x == y;

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type IEnumerable<(String,String)>).

Copilot Autofix

AI 4 days ago

To fix the issue, replace the reference equality check x == y with a content-based equality check. The most appropriate method for comparing two IEnumerable<T> collections is Enumerable.SequenceEqual, which checks whether two sequences have the same elements in the same order. Since the order of elements may not matter in this context, we can use SetEquals from HashSet<T> to perform an unordered comparison. This ensures that the collections are considered equal if they contain the same elements, regardless of order.

Changes to be made:

  1. Replace x == y with a content-based comparison using SetEquals.
  2. Add a null check for both x and y to handle cases where one or both are null.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
@@ -157,3 +157,10 @@
             {
-                return x == y;
+                return x == null && y == null;
+            }
+
+            var setX = new HashSet<(string definition, string expression)>(x);
+            var setY = new HashSet<(string definition, string expression)>(y);
+            if (!setX.SetEquals(setY))
+            {
+                return false;
             }
EOF
@@ -157,3 +157,10 @@
{
return x == y;
return x == null && y == null;
}

var setX = new HashSet<(string definition, string expression)>(x);
var setY = new HashSet<(string definition, string expression)>(y);
if (!setX.SetEquals(setY))
{
return false;
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +168 to +174
foreach (var cx in componetX)
{
if (!componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0)
{
return false;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.

Copilot Autofix

AI 4 days ago

To fix the issue, we will replace the foreach loop on line 168 with a LINQ Where clause to filter the elements of componetX before iterating over them. This will make the filtering logic explicit and reduce the nesting depth of the code. Specifically:

  1. Use the Where method to filter componetX based on the condition !componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0.
  2. If the condition is met, return false immediately, as the loop's purpose is to check for mismatches.

No additional imports or dependencies are required, as LINQ is already being used in the file.


Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
@@ -167,8 +167,5 @@
 
-            foreach (var cx in componetX)
+            if (componetX.Where(cx => !componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0).Any())
             {
-                if (!componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0)
-                {
-                    return false;
-                }
+                return false;
             }
EOF
@@ -167,8 +167,5 @@

foreach (var cx in componetX)
if (componetX.Where(cx => !componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0).Any())
{
if (!componetY.TryGetValue(cx.Key, out var cy) || CompareExpression(cx.Value, cy) != 0)
{
return false;
}
return false;
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +219 to +226
foreach (var expY in expsY)
{
if (Equals(expX, expY))
{
found = true;
break;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.

Copilot Autofix

AI 4 days ago

To fix the issue, we will replace the nested foreach loop that implicitly filters expsY with a LINQ Where method. This will make the filtering explicit and reduce the nesting depth of the code. Specifically:

  1. Replace the inner foreach loop (foreach (var expY in expsY)) with a LINQ query that filters expsY using the condition Equals(expX, expY).
  2. Check if the filtered sequence contains any elements using .Any().
  3. Apply similar changes to the second loop (foreach (var expX in expsX)) later in the method.

No new imports or definitions are required, as LINQ is already included via using System.Linq.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
@@ -217,11 +217,3 @@
                 {
-                    var found = false;
-                    foreach (var expY in expsY)
-                    {
-                        if (Equals(expX, expY))
-                        {
-                            found = true;
-                            break;
-                        }
-                    }
+                    var found = expsY.Where(expY => Equals(expX, expY)).Any();
 
@@ -239,11 +231,3 @@
             {
-                var found = false;
-                foreach (var expX in expsX)
-                {
-                    if (Equals(expY, expX))
-                    {
-                        found = true;
-                        break;
-                    }
-                }
+                var found = expsX.Where(expX => Equals(expY, expX)).Any();
 
EOF
@@ -217,11 +217,3 @@
{
var found = false;
foreach (var expY in expsY)
{
if (Equals(expX, expY))
{
found = true;
break;
}
}
var found = expsY.Where(expY => Equals(expX, expY)).Any();

@@ -239,11 +231,3 @@
{
var found = false;
foreach (var expX in expsX)
{
if (Equals(expY, expX))
{
found = true;
break;
}
}
var found = expsX.Where(expX => Equals(expY, expX)).Any();

Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +241 to +248
foreach (var expX in expsX)
{
if (Equals(expY, expX))
{
found = true;
break;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.

Copilot Autofix

AI 4 days ago

To fix the issue, replace the foreach loop on line 241 with a LINQ Where clause to filter expsX explicitly based on the condition Equals(expY, expX). This eliminates the need for the found flag and reduces nesting depth. The filtered sequence can then be checked directly to determine if any matching element exists.

Steps to implement the fix:

  1. Replace the foreach loop on line 241 with a LINQ Where clause.
  2. Use the Any method to check if there is at least one matching element in the filtered sequence.
  3. Remove the found flag and its associated logic.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterComparer.cs
@@ -239,13 +239,3 @@
             {
-                var found = false;
-                foreach (var expX in expsX)
-                {
-                    if (Equals(expY, expX))
-                    {
-                        found = true;
-                        break;
-                    }
-                }
-
-                if (!found)
+                if (!expsX.Any(expX => Equals(expY, expX)))
                 {
EOF
@@ -239,13 +239,3 @@
{
var found = false;
foreach (var expX in expsX)
{
if (Equals(expY, expX))
{
found = true;
break;
}
}

if (!found)
if (!expsX.Any(expX => Equals(expY, expX)))
{
Copilot is powered by AI and may make mistakes. Always verify output.
@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-isyamauchi-gh
Copy link
Author

@v-isyamauchi-gh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@microsoft-github-policy-service agree company="Microsoft"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. Open source This change is only relevant to the OSS code or release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant