Skip to content

Conversation

@paorodma-ms
Copy link
Contributor

@paorodma-ms paorodma-ms commented Mar 31, 2025

Description

Merging latest from #4731 to this feature branch.

Related issues

Addresses [issue #].
https://microsofthealth.visualstudio.com/Health/_workitems/edit/149048

Testing

Describe how this change was tested.

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)

brendankowitz and others added 30 commits January 24, 2025 20:31
* Added additional error handling to CosmosHealthchecks

* Added tests

* fix code scanning error in tests

* make code easier to review

* add test descriptions back to code

* removed unnecessary exception logging

* Moved logging of CosmosDiagnostic to the property bag

* fix code scanning error
* Fix to allow date time to be searched against a resource with a span and if included in the span that resource will be returned.

* Updated tests based on recent changes

* Updated test fixtures. Removed temporary comments.

* Updated test results to match new expectations. Simplified logic for this particular case and addressed pr comments.

* Fixed unit test after recent changes.

* Updated more tetst based on recent changes.
Update FhirService to use Firely 5.11.3 SDK

Refs AB#135366
* add cosmos direct code configuration options

* keep existing behavior for Cosmos Direct rediscovery

* Delete docs/rest/pers-env.http

* Delete docs/rest/export-test.http
* Catch shutdown cancellation exceptions for conformance provider

* reenable disposing semaphores

* Simplify disposal code

* undo semaphore slim disposal changes
Remove resource id from hash

Refs AB#135263
)

* Reviving schema upgrade test for local

* Revive schema comparison test and make SQL normalization generic

* usings

* fixed var check

* return
* Remove LegacyExportJobWorker #4750

* Remove UseQueueClientJobs configuration since it is the default now, no other possibility. Remove unused variables from CosmosFhirOperationDataStore

* Remove classes and stored procedures from Cosmos DB related to LegacyExportJob. Modified unit test in CosmosDBInitializationTests to appropriately check for all incoming list of sp's

* Readded necessary legacy code to be able to query a legacy export job.

* Remove commented code from test

* Add schema version 86, removing unused table ExportJob
dependabot bot and others added 11 commits March 21, 2025 22:27
Bumps [AngleSharp](https://github.com/AngleSharp/AngleSharp) from 1.1.2 to 1.2.0.
- [Release notes](https://github.com/AngleSharp/AngleSharp/releases)
- [Changelog](https://github.com/AngleSharp/AngleSharp/blob/devel/CHANGELOG.md)
- [Commits](AngleSharp/AngleSharp@1.1.2...1.2.0)

---
updated-dependencies:
- dependency-name: AngleSharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
updated-dependencies:
- dependency-name: xunit.runner.visualstudio
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [Hl7.Fhir.STU3](https://github.com/FirelyTeam/firely-net-sdk) from 5.11.3 to 5.11.4.
- [Release notes](https://github.com/FirelyTeam/firely-net-sdk/releases)
- [Changelog](https://github.com/FirelyTeam/firely-net-sdk/blob/develop/release-notes.md)
- [Commits](FirelyTeam/firely-net-sdk@v5.11.3...v5.11.4)

---
updated-dependencies:
- dependency-name: Hl7.Fhir.STU3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [Microsoft.Azure.Cosmos](https://github.com/Azure/azure-cosmos-dotnet-v3) and [System.Text.Encodings.Web](https://github.com/dotnet/runtime). These dependencies needed to be updated together.

Updates `Microsoft.Azure.Cosmos` from 3.45.2 to 3.47.2
- [Release notes](https://github.com/Azure/azure-cosmos-dotnet-v3/releases)
- [Changelog](https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/changelog.md)
- [Commits](Azure/azure-cosmos-dotnet-v3@3.45.2...3.47.2)

Updates `System.Text.Encodings.Web` from 9.0.2 to 6.0.0
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](dotnet/runtime@v9.0.2...v6.0.0)

---
updated-dependencies:
- dependency-name: Microsoft.Azure.Cosmos
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: System.Text.Encodings.Web
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Add deleted status check (#4883)

Refs AB#140720
@paorodma-ms paorodma-ms requested a review from a team as a code owner March 31, 2025 19:54
@paorodma-ms paorodma-ms self-assigned this Mar 31, 2025
@paorodma-ms paorodma-ms changed the title Users/paolaro/update raw resource feature branch Update raw resource feature branch Mar 31, 2025
@paorodma-ms paorodma-ms added this to the 2Wk13 milestone Mar 31, 2025
@paorodma-ms paorodma-ms added Build Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Schema Version unchanged labels Mar 31, 2025
if (inputResource is not Parameters)
{
throw new RequestNotValidException(string.Format(Resources.UnsupportedResourceType, inputResource.GetType().ToString()));
throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, inputResource.GetType().ToString()));

Check notice

Code scanning / CodeQL

Redundant ToString() call Note

Redundant call to 'ToString' on a String object.

Copilot Autofix

AI 8 months ago

To fix the problem, we need to remove the redundant ToString call on the Type object. Specifically, we should modify the line where inputResource.GetType().ToString() is used within the string.Format method. Instead of calling ToString explicitly, we can pass the Type object directly to string.Format, which will implicitly call ToString.

Suggested changeset 1
src/Microsoft.Health.Fhir.Api/Features/Filters/ValidateParametersResourceAttribute.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.Api/Features/Filters/ValidateParametersResourceAttribute.cs b/src/Microsoft.Health.Fhir.Api/Features/Filters/ValidateParametersResourceAttribute.cs
--- a/src/Microsoft.Health.Fhir.Api/Features/Filters/ValidateParametersResourceAttribute.cs
+++ b/src/Microsoft.Health.Fhir.Api/Features/Filters/ValidateParametersResourceAttribute.cs
@@ -32,3 +32,3 @@
             {
-                throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, inputResource.GetType().ToString()));
+                throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, inputResource.GetType()));
             }
EOF
@@ -32,3 +32,3 @@
{
throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, inputResource.GetType().ToString()));
throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, inputResource.GetType()));
}
Copilot is powered by AI and may make mistakes. Always verify output.
_contextAccessor.RequestContext = fhirRequestContext;
var result = new BulkDeleteResult();
long numDeleted;
IDictionary<string, long> resourcesDeleted = new Dictionary<string, long>();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

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

Copilot Autofix

AI 8 months ago

To fix the problem, we should remove the redundant assignment to resourcesDeleted on line 76. This will clean up the code and remove the unnecessary assignment without changing the existing functionality.

Suggested changeset 1
src/Microsoft.Health.Fhir.Core/Features/Operations/BulkDelete/BulkDeleteProcessingJob.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/Operations/BulkDelete/BulkDeleteProcessingJob.cs b/src/Microsoft.Health.Fhir.Core/Features/Operations/BulkDelete/BulkDeleteProcessingJob.cs
--- a/src/Microsoft.Health.Fhir.Core/Features/Operations/BulkDelete/BulkDeleteProcessingJob.cs
+++ b/src/Microsoft.Health.Fhir.Core/Features/Operations/BulkDelete/BulkDeleteProcessingJob.cs
@@ -75,3 +75,3 @@
                 var result = new BulkDeleteResult();
-                IDictionary<string, long> resourcesDeleted = new Dictionary<string, long>();
+                IDictionary<string, long> resourcesDeleted;
                 using IScoped<IDeletionService> deleter = _deleterFactory.Invoke();
EOF
@@ -75,3 +75,3 @@
var result = new BulkDeleteResult();
IDictionary<string, long> resourcesDeleted = new Dictionary<string, long>();
IDictionary<string, long> resourcesDeleted;
using IScoped<IDeletionService> deleter = _deleterFactory.Invoke();
Copilot is powered by AI and may make mistakes. Always verify output.
var resourceKey = new ResourceKey(request.Resource.InstanceType, request.Resource.Id, request.Resource.VersionId);
ResourceWrapper prevSearchParamResource = await _fhirDataStore.GetAsync(resourceKey, cancellationToken);
if (prevSearchParamResource != null)
if (prevSearchParamResource != null && prevSearchParamResource.IsDeleted == false)

Check notice

Code scanning / CodeQL

Unnecessarily complex Boolean expression Note

The expression 'A == false' can be simplified to '!A'.

Copilot Autofix

AI 8 months ago

To fix the problem, we need to simplify the Boolean expression prevSearchParamResource.IsDeleted == false to !prevSearchParamResource.IsDeleted. This change will make the code more readable and maintainable without altering its functionality.

  • Locate the file src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs.
  • Find the line containing prevSearchParamResource.IsDeleted == false.
  • Replace it with !prevSearchParamResource.IsDeleted.
Suggested changeset 1
src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.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/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs
--- a/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs
+++ b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/CreateOrUpdateSearchParameterBehavior.cs
@@ -54,3 +54,3 @@
                 ResourceWrapper prevSearchParamResource = await _fhirDataStore.GetAsync(resourceKey, cancellationToken);
-                if (prevSearchParamResource != null && prevSearchParamResource.IsDeleted == false)
+                if (prevSearchParamResource != null && !prevSearchParamResource.IsDeleted)
                 {
EOF
@@ -54,3 +54,3 @@
ResourceWrapper prevSearchParamResource = await _fhirDataStore.GetAsync(resourceKey, cancellationToken);
if (prevSearchParamResource != null && prevSearchParamResource.IsDeleted == false)
if (prevSearchParamResource != null && !prevSearchParamResource.IsDeleted)
{
Copilot is powered by AI and may make mistakes. Always verify output.
EnsureArg.IsNotNull(coreFeaturesConfiguration?.Value, nameof(coreFeaturesConfiguration));

_mediator = mediator;
_coreFeaturesConfiguration = coreFeaturesConfiguration.Value;

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
coreFeaturesConfiguration
may be null at this access as suggested by
this
null check.

Copilot Autofix

AI 8 months ago

To fix the problem, we need to ensure that coreFeaturesConfiguration is not null before it is dereferenced. This can be done by adding an explicit null check for coreFeaturesConfiguration in the constructor. This way, we can be certain that coreFeaturesConfiguration is not null when it is assigned to _coreFeaturesConfiguration.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Api/Controllers/IncludesController.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.Api/Controllers/IncludesController.cs b/src/Microsoft.Health.Fhir.Shared.Api/Controllers/IncludesController.cs
--- a/src/Microsoft.Health.Fhir.Shared.Api/Controllers/IncludesController.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Api/Controllers/IncludesController.cs
@@ -37,2 +37,3 @@
             EnsureArg.IsNotNull(mediator, nameof(mediator));
+            EnsureArg.IsNotNull(coreFeaturesConfiguration, nameof(coreFeaturesConfiguration));
             EnsureArg.IsNotNull(coreFeaturesConfiguration?.Value, nameof(coreFeaturesConfiguration));
EOF
@@ -37,2 +37,3 @@
EnsureArg.IsNotNull(mediator, nameof(mediator));
EnsureArg.IsNotNull(coreFeaturesConfiguration, nameof(coreFeaturesConfiguration));
EnsureArg.IsNotNull(coreFeaturesConfiguration?.Value, nameof(coreFeaturesConfiguration));
Copilot is powered by AI and may make mistakes. Always verify output.

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

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

Copilot Autofix

AI 8 months ago

To fix the problem, we need to remove the assignment to the reindexJobId variable since it is not used in the method. This can be done by modifying the tuple deconstruction to only include the activeReindexJobs variable, which is the only variable needed for the method's logic.

Suggested changeset 1
src/Microsoft.Health.Fhir.Shared.Core/Features/Operations/SearchParameterState/SearchParameterStateUpdateHandler.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/Operations/SearchParameterState/SearchParameterStateUpdateHandler.cs b/src/Microsoft.Health.Fhir.Shared.Core/Features/Operations/SearchParameterState/SearchParameterStateUpdateHandler.cs
--- a/src/Microsoft.Health.Fhir.Shared.Core/Features/Operations/SearchParameterState/SearchParameterStateUpdateHandler.cs
+++ b/src/Microsoft.Health.Fhir.Shared.Core/Features/Operations/SearchParameterState/SearchParameterStateUpdateHandler.cs
@@ -239,3 +239,3 @@
             {
-                (var activeReindexJobs, var reindexJobId) = await fhirOperationDataStore.Value.CheckActiveReindexJobsAsync(cancellationToken);
+                var (activeReindexJobs, _) = await fhirOperationDataStore.Value.CheckActiveReindexJobsAsync(cancellationToken);
                 if (activeReindexJobs)
EOF
@@ -239,3 +239,3 @@
{
(var activeReindexJobs, var reindexJobId) = await fhirOperationDataStore.Value.CheckActiveReindexJobsAsync(cancellationToken);
var (activeReindexJobs, _) = await fhirOperationDataStore.Value.CheckActiveReindexJobsAsync(cancellationToken);
if (activeReindexJobs)
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +1498 to +1500
.AcceptVisitor(DateTimeEqualityRewriter.Instance)
.AcceptVisitor(FlatteningRewriter.Instance)
.AcceptVisitor(UntypedReferenceRewriter.Instance)

Check warning

Code scanning / CodeQL

Useless upcast Warning

There is no need to upcast from
null
to
SqlExpressionRewriterWithInitialContext - the conversion can be done implicitly.

Copilot Autofix

AI 8 months ago

To fix the problem, we need to remove the redundant cast from StringOverflowRewriter.Instance or LegacyStringOverflowRewriter.Instance to SqlExpressionRewriterWithInitialContext<object>. This can be done by simply removing the cast and keeping the rest of the code unchanged.

  • Remove the explicit cast on line 1512.
  • Ensure that the functionality remains the same by keeping the rest of the code intact.
Suggested changeset 1
src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.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.SqlServer/Features/Search/SqlServerSearchService.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs
--- a/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs
+++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs
@@ -1511,5 +1511,5 @@
                 .AcceptVisitor(
-                    (SqlExpressionRewriterWithInitialContext<object>)(_schemaInformation.Current >= SchemaVersionConstants.PartitionedTables
+                    _schemaInformation.Current >= SchemaVersionConstants.PartitionedTables
                         ? StringOverflowRewriter.Instance
-                        : LegacyStringOverflowRewriter.Instance))
+                        : LegacyStringOverflowRewriter.Instance)
                 .AcceptVisitor(NumericRangeRewriter.Instance)
EOF
@@ -1511,5 +1511,5 @@
.AcceptVisitor(
(SqlExpressionRewriterWithInitialContext<object>)(_schemaInformation.Current >= SchemaVersionConstants.PartitionedTables
_schemaInformation.Current >= SchemaVersionConstants.PartitionedTables
? StringOverflowRewriter.Instance
: LegacyStringOverflowRewriter.Instance))
: LegacyStringOverflowRewriter.Instance)
.AcceptVisitor(NumericRangeRewriter.Instance)
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +154 to +194
foreach (var resourceType in relatedResourceTypes)
{
if (!relatedResources.TryGetValue(resourceType, out _) && _relatedResourcesByResourceType.TryGetValue(resourceType, out var relatedResourcesByResourceType))
{
var resources = relatedResourcesByResourceType.Where(
x =>
{
switch (x.TypeName)
{
case KnownResourceTypes.DiagnosticReport:
return patientReferences.Contains(((DiagnosticReport)x).Subject?.Reference);

case KnownResourceTypes.Group:
return ((Group)x).Member.Any(y => patientReferences.Contains(y.Entity?.Reference));

case KnownResourceTypes.MedicationDispense:
return patientReferences.Contains(((MedicationDispense)x).Subject?.Reference);

case KnownResourceTypes.MedicationRequest:
return patientReferences.Contains(((MedicationRequest)x).Subject?.Reference);

case KnownResourceTypes.Observation:
return patientReferences.Contains(((Observation)x).Subject?.Reference);

case KnownResourceTypes.Organization:
return patientResources.Any(y => ((Patient)y).ManagingOrganization?.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false);

case KnownResourceTypes.Practitioner:
return patientResources.Any(y => ((Patient)y).GeneralPractitioner.Any(z => z.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false));

default:
throw new InvalidOperationException($"Unsupported resource type: {resourceType}");
}
});

if (resources.Any())
{
relatedResources.Add(resourceType, new List<Resource>(resources));
}
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note test

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

Copilot Autofix

AI 8 months ago

To fix the problem, we will refactor the foreach loop on line 154 to use the Where method from LINQ. This will make the filtering condition explicit and improve the readability of the code. Specifically, we will apply the Where method to relatedResourceTypes to filter out the elements that do not meet the condition before iterating over them.

Suggested changeset 1
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/IncludesOperationTestFixture.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/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/IncludesOperationTestFixture.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/IncludesOperationTestFixture.cs
--- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/IncludesOperationTestFixture.cs
+++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/IncludesOperationTestFixture.cs
@@ -153,41 +153,39 @@
             var relatedResources = new Dictionary<string, IList<Resource>>(StringComparer.OrdinalIgnoreCase);
-            foreach (var resourceType in relatedResourceTypes)
+            foreach (var resourceType in relatedResourceTypes.Where(resourceType => !relatedResources.TryGetValue(resourceType, out _) && _relatedResourcesByResourceType.TryGetValue(resourceType, out var relatedResourcesByResourceType)))
             {
-                if (!relatedResources.TryGetValue(resourceType, out _) && _relatedResourcesByResourceType.TryGetValue(resourceType, out var relatedResourcesByResourceType))
-                {
-                    var resources = relatedResourcesByResourceType.Where(
-                        x =>
+                var relatedResourcesByResourceType = _relatedResourcesByResourceType[resourceType];
+                var resources = relatedResourcesByResourceType.Where(
+                    x =>
+                    {
+                        switch (x.TypeName)
                         {
-                            switch (x.TypeName)
-                            {
-                                case KnownResourceTypes.DiagnosticReport:
-                                    return patientReferences.Contains(((DiagnosticReport)x).Subject?.Reference);
+                            case KnownResourceTypes.DiagnosticReport:
+                                return patientReferences.Contains(((DiagnosticReport)x).Subject?.Reference);
 
-                                case KnownResourceTypes.Group:
-                                    return ((Group)x).Member.Any(y => patientReferences.Contains(y.Entity?.Reference));
+                            case KnownResourceTypes.Group:
+                                return ((Group)x).Member.Any(y => patientReferences.Contains(y.Entity?.Reference));
 
-                                case KnownResourceTypes.MedicationDispense:
-                                    return patientReferences.Contains(((MedicationDispense)x).Subject?.Reference);
+                            case KnownResourceTypes.MedicationDispense:
+                                return patientReferences.Contains(((MedicationDispense)x).Subject?.Reference);
 
-                                case KnownResourceTypes.MedicationRequest:
-                                    return patientReferences.Contains(((MedicationRequest)x).Subject?.Reference);
+                            case KnownResourceTypes.MedicationRequest:
+                                return patientReferences.Contains(((MedicationRequest)x).Subject?.Reference);
 
-                                case KnownResourceTypes.Observation:
-                                    return patientReferences.Contains(((Observation)x).Subject?.Reference);
+                            case KnownResourceTypes.Observation:
+                                return patientReferences.Contains(((Observation)x).Subject?.Reference);
 
-                                case KnownResourceTypes.Organization:
-                                    return patientResources.Any(y => ((Patient)y).ManagingOrganization?.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false);
+                            case KnownResourceTypes.Organization:
+                                return patientResources.Any(y => ((Patient)y).ManagingOrganization?.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false);
 
-                                case KnownResourceTypes.Practitioner:
-                                    return patientResources.Any(y => ((Patient)y).GeneralPractitioner.Any(z => z.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false));
+                            case KnownResourceTypes.Practitioner:
+                                return patientResources.Any(y => ((Patient)y).GeneralPractitioner.Any(z => z.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false));
 
-                                default:
-                                    throw new InvalidOperationException($"Unsupported resource type: {resourceType}");
-                            }
-                        });
+                            default:
+                                throw new InvalidOperationException($"Unsupported resource type: {resourceType}");
+                        }
+                    });
 
-                    if (resources.Any())
-                    {
-                        relatedResources.Add(resourceType, new List<Resource>(resources));
-                    }
+                if (resources.Any())
+                {
+                    relatedResources.Add(resourceType, new List<Resource>(resources));
                 }
EOF
@@ -153,41 +153,39 @@
var relatedResources = new Dictionary<string, IList<Resource>>(StringComparer.OrdinalIgnoreCase);
foreach (var resourceType in relatedResourceTypes)
foreach (var resourceType in relatedResourceTypes.Where(resourceType => !relatedResources.TryGetValue(resourceType, out _) && _relatedResourcesByResourceType.TryGetValue(resourceType, out var relatedResourcesByResourceType)))
{
if (!relatedResources.TryGetValue(resourceType, out _) && _relatedResourcesByResourceType.TryGetValue(resourceType, out var relatedResourcesByResourceType))
{
var resources = relatedResourcesByResourceType.Where(
x =>
var relatedResourcesByResourceType = _relatedResourcesByResourceType[resourceType];
var resources = relatedResourcesByResourceType.Where(
x =>
{
switch (x.TypeName)
{
switch (x.TypeName)
{
case KnownResourceTypes.DiagnosticReport:
return patientReferences.Contains(((DiagnosticReport)x).Subject?.Reference);
case KnownResourceTypes.DiagnosticReport:
return patientReferences.Contains(((DiagnosticReport)x).Subject?.Reference);

case KnownResourceTypes.Group:
return ((Group)x).Member.Any(y => patientReferences.Contains(y.Entity?.Reference));
case KnownResourceTypes.Group:
return ((Group)x).Member.Any(y => patientReferences.Contains(y.Entity?.Reference));

case KnownResourceTypes.MedicationDispense:
return patientReferences.Contains(((MedicationDispense)x).Subject?.Reference);
case KnownResourceTypes.MedicationDispense:
return patientReferences.Contains(((MedicationDispense)x).Subject?.Reference);

case KnownResourceTypes.MedicationRequest:
return patientReferences.Contains(((MedicationRequest)x).Subject?.Reference);
case KnownResourceTypes.MedicationRequest:
return patientReferences.Contains(((MedicationRequest)x).Subject?.Reference);

case KnownResourceTypes.Observation:
return patientReferences.Contains(((Observation)x).Subject?.Reference);
case KnownResourceTypes.Observation:
return patientReferences.Contains(((Observation)x).Subject?.Reference);

case KnownResourceTypes.Organization:
return patientResources.Any(y => ((Patient)y).ManagingOrganization?.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false);
case KnownResourceTypes.Organization:
return patientResources.Any(y => ((Patient)y).ManagingOrganization?.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false);

case KnownResourceTypes.Practitioner:
return patientResources.Any(y => ((Patient)y).GeneralPractitioner.Any(z => z.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false));
case KnownResourceTypes.Practitioner:
return patientResources.Any(y => ((Patient)y).GeneralPractitioner.Any(z => z.Reference?.Equals($"{x.TypeName}/{x.Id}") ?? false));

default:
throw new InvalidOperationException($"Unsupported resource type: {resourceType}");
}
});
default:
throw new InvalidOperationException($"Unsupported resource type: {resourceType}");
}
});

if (resources.Any())
{
relatedResources.Add(resourceType, new List<Resource>(resources));
}
if (resources.Any())
{
relatedResources.Add(resourceType, new List<Resource>(resources));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +298 to +304
foreach (var jsonInt in lineItem.Item2)
{
var json = jsonInt;
var (resourceType, resourceId) = ParseJson(ref json, Guid.NewGuid().ToString());
var entry = GetEntry(json, resourceType, resourceId);
entries.Add(entry);
}

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 8 months ago

To fix the problem, we should replace the foreach loop with a LINQ Select method to transform the elements of lineItem.Item2 before iterating over them. This will make the code more readable by explicitly showing the transformation applied to each element.

  • Replace the foreach loop that iterates over lineItem.Item2 with a Select method that transforms each element.
  • Update the loop to iterate over the transformed sequence returned by Select.
Suggested changeset 1
tools/PerfTester/Program.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/tools/PerfTester/Program.cs b/tools/PerfTester/Program.cs
--- a/tools/PerfTester/Program.cs
+++ b/tools/PerfTester/Program.cs
@@ -296,4 +296,3 @@
 
-                var entries = new List<string>();
-                foreach (var jsonInt in lineItem.Item2)
+                var entries = lineItem.Item2.Select(jsonInt =>
                 {
@@ -301,5 +300,4 @@
                     var (resourceType, resourceId) = ParseJson(ref json, Guid.NewGuid().ToString());
-                    var entry = GetEntry(json, resourceType, resourceId);
-                    entries.Add(entry);
-                }
+                    return GetEntry(json, resourceType, resourceId);
+                }).ToList();
 
EOF
@@ -296,4 +296,3 @@

var entries = new List<string>();
foreach (var jsonInt in lineItem.Item2)
var entries = lineItem.Item2.Select(jsonInt =>
{
@@ -301,5 +300,4 @@
var (resourceType, resourceId) = ParseJson(ref json, Guid.NewGuid().ToString());
var entry = GetEntry(json, resourceType, resourceId);
entries.Add(entry);
}
return GetEntry(json, resourceType, resourceId);
}).ToList();

Copilot is powered by AI and may make mistakes. Always verify output.
@paorodma-ms
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paorodma-ms
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@brendankowitz brendankowitz requested a review from Copilot April 1, 2025 21:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR merges the latest upstream changes into the raw resource feature branch, updating several Architecture Decision Records (ADRs), documentation, and build pipeline scripts. Key changes include:

  • Adding new ADR documents that describe the $includes operation, _include support in delete requests, resource ID integer mapping, and resource table refactoring.
  • Updating build and CI/CD pipelines to include Linux-based jobs and streamline Docker build parameters.
  • Enhancing documentation by adding instructions for connecting to a SQL database and updating the project README and PR template.

Reviewed Changes

Copilot reviewed 236 out of 241 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/arch/adr-2503-Bundle-include-operation.md New ADR for implementing the $includes operation.
docs/arch/Readme.md Added ADR documentation guidelines.
docs/arch/Proposals/adr-2502-_include-on-delete.md New ADR for supporting the _include parameter in delete requests.
docs/arch/Proposals/adr-2502-ResourceIdIntMap.md New ADR for introducing integer-based resource mapping.
docs/arch/Proposals/adr-2502-Resource-table-refactor.md New ADR detailing resource table refactoring and index optimization.
docs/HowToConnectSQLDatabase.md New documentation on connecting to a SQL database.
build/pr-pipeline.yml Updated to include a Linux_dotnet8 job and corresponding pool configuration.
build/jobs/provision-deploy.yml Added registryName variable in deployment job.
build/jobs/docker-build-push.yml Updated Docker build script with enhanced multi-platform support and removed the multiplePlatforms parameter.
build/jobs/docker-build-all.yml Removed the multiplePlatforms parameter from composite builds.
build/ci-pipeline.yml Adjusted CI pipeline job to use a Linux agent.
build/ci-deploy.yml Removed the multiplePlatforms parameter from the deploy pipeline.
build/build-image.yml Removed the multiplePlatforms parameter.
README.md Updated to include a link for connecting to a SQL Database.
.github/pull_request_template.md Minor template updates regarding ADR and squash-merge requirements.
Files not reviewed (5)
  • Directory.Packages.props: Language not supported
  • build/docker/Dockerfile: Language not supported
  • build/dotnet8-compat/global.json: Language not supported
  • global.json: Language not supported
  • samples/templates/default-azuredeploy-docker.json: Language not supported

Comment on lines +7 to +8
In order to support splitting the table, we move the raw binary of the resource to it's own table, so that the binary will not have be to be moved when resource meta data moves from the current to the history table.

Copy link

Copilot AI Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a grammatical error on this line: consider replacing "it's" with "its" and removing the extraneous "be" (i.e., '...will not have to be moved...').

Suggested change
In order to support splitting the table, we move the raw binary of the resource to it's own table, so that the binary will not have be to be moved when resource meta data moves from the current to the history table.
In order to support splitting the table, we move the raw binary of the resource to its own table, so that the binary will not have to be moved when resource meta data moves from the current to the history table.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +46
The above schema diagrams shows to overall reduction of one index in the new tables.

Copy link

Copilot AI Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The sentence is awkwardly worded; consider rephrasing it to 'The above schema diagrams show the overall reduction of one index in the new tables.'

Suggested change
The above schema diagrams shows to overall reduction of one index in the new tables.
The above schema diagrams show the overall reduction of one index in the new tables.

Copilot uses AI. Check for mistakes.
@paorodma-ms paorodma-ms merged commit a9ab0ca into feature-branch/raw-resource-split Apr 2, 2025
46 checks passed
@paorodma-ms paorodma-ms deleted the users/paolaro/update-raw-resource-feature-branch branch April 2, 2025 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Build Schema Version unchanged

Projects

None yet

Development

Successfully merging this pull request may close these issues.