-
Notifications
You must be signed in to change notification settings - Fork 536
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
base: main
Are you sure you want to change the base?
Conversation
var reference = (ResourceReference)childValue; | ||
if (reference.Reference.Contains(target, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
reference.Reference = null; |
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.
Just double checking that a null value as the reference is valid. Can we have an empty value for the reference property?
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.
Yes, reference just requires that one of the fields reference, identifier, or display has a 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.
Yes, agreed, the reference property is optional. By setting it to null will the property no longer be included in the serialized json? I think it could be an issue if we end up with something like "reference" : ""
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 20 hours 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") |
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