Skip to content

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

Merged
merged 8 commits into from
Jul 14, 2025
Merged

Conversation

LTA-Thinking
Copy link
Contributor

@LTA-Thinking LTA-Thinking commented Jun 18, 2025

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

  • 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

@LTA-Thinking LTA-Thinking requested a review from a team as a code owner June 18, 2025 14:41
Comment on lines +19 to +35
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

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.

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:

  1. Replace the foreach loop to iterate over namedChildren.Select(child => child.Value).
  2. Ensure no other parts of the code depend on the original child variable, as it will no longer be available.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.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/Resources/Delete/ReferenceRemover.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.cs
@@ -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")
EOF
@@ -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")
Copilot is powered by AI and may make mistakes. Always verify output.
@LTA-Thinking LTA-Thinking added this to the CY25Q2/2Wk06 milestone Jun 20, 2025
@LTA-Thinking LTA-Thinking added Enhancement Enhancement on existing functionality. 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 labels Jun 20, 2025
rbans96
rbans96 previously approved these changes Jul 7, 2025
@LTA-Thinking
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mikaelweave
Copy link
Contributor

Reviewed merge commit - approved on top of last approval.

@LTA-Thinking LTA-Thinking marked this pull request as draft July 11, 2025 21:15
@LTA-Thinking LTA-Thinking marked this pull request as ready for review July 11, 2025 21:15
@LTA-Thinking LTA-Thinking mentioned this pull request Jul 11, 2025
1 task
@LTA-Thinking LTA-Thinking merged commit 0d8ae43 into main Jul 14, 2025
53 checks passed
@LTA-Thinking LTA-Thinking deleted the personal/rojo/remove-references branch July 14, 2025 18:28
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 Enhancement Enhancement on existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants