-
Notifications
You must be signed in to change notification settings - Fork 548
Bulk Delete: Remove references #5027
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
Conversation
src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.cs
Show resolved
Hide resolved
foreach (var child in namedChildren) | ||
{ | ||
var childValue = child.Value; | ||
if (childValue.TypeName == "Reference") | ||
{ | ||
var reference = (ResourceReference)childValue; | ||
if (reference.Reference.Contains(target, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
reference.Reference = null; | ||
reference.Display = "Referenced resource deleted"; | ||
} | ||
} | ||
else if (childValue.Children.Any()) | ||
{ | ||
RemoveReference(childValue, target); | ||
} | ||
} |
Check notice
Code scanning / CodeQL
Missed opportunity to use Select Note
maps its iteration variable to another variable
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the issue, we will replace the foreach
loop on line 19 with a LINQ Select
transformation. This will map namedChildren
to a sequence of child.Value
objects, which can then be iterated over directly. The rest of the loop logic remains unchanged. This approach improves readability by explicitly separating the transformation step from the iteration logic.
Changes required:
- Replace the
foreach
loop to iterate overnamedChildren.Select(child => child.Value)
. - Ensure no other parts of the code depend on the original
child
variable, as it will no longer be available.
-
Copy modified line R19
@@ -18,5 +18,4 @@ | ||
var namedChildren = resource.NamedChildren; | ||
foreach (var child in namedChildren) | ||
foreach (var childValue in namedChildren.Select(child => child.Value)) | ||
{ | ||
var childValue = child.Value; | ||
if (childValue.TypeName == "Reference") |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Reviewed merge commit - approved on top of last approval. |
Description
Adds a parameter to bulk-delete to allow for the removal of references to deleted resources.
Related issues
Addresses User Story 139078
Testing
New and existing tests
FHIR Team Checklist
Semver Change (docs)
Patch