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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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
var reference = (ResourceReference)childValue;
if (reference.Reference.Contains(target, StringComparison.OrdinalIgnoreCase))
{
reference.Reference = null;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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" : ""

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 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:

  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
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.

2 participants