-
Notifications
You must be signed in to change notification settings - Fork 574
Feature/firely 6 update #5199
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?
Feature/firely 6 update #5199
Conversation
Directory.Packages.props
Outdated
| <PackageVersion Include="Hl7.Fhir.Specification.R4" Version="$(Hl7FhirVersion)" /> | ||
| <PackageVersion Include="Hl7.Fhir.Specification.R4B" Version="$(Hl7FhirVersion)" /> | ||
| <PackageVersion Include="Hl7.Fhir.Specification.R5" Version="$(Hl7FhirVersion)" /> | ||
| <PackageVersion Include="IdentityServer4" Version="4.1.2" /> |
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.
bad things happened to this merge 😞
a499f9a to
41108f4
Compare
| ResourceWrapperOperation resourceWrapper = await BundleTestsCommonFunctions.GetResourceWrapperOperationAsync( | ||
| resource, | ||
| new BundleResourceContext(Bundle.BundleType.Batch, BundleProcessingLogic.Parallel, GetHttpVerb(i), persistedId: null, operation.Id)); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb((int)i), string.Empty, operation.Id)); |
Check warning
Code scanning / CodeQL
Cast to same type Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the issue, simply remove the redundant cast (int)i and use i directly as the argument to GetHttpVerb. This means editing the one line within the method GivenABatchOperation_WhenAppendedMultipleResourcesInParallelWaitForAllToBeAppended_ThenCompleteWithSuccess so that GetHttpVerb((int)i) becomes GetHttpVerb(i). No imports, methods, or additional definitions are required.
-
Copy modified line R95
| @@ -92,7 +92,7 @@ | ||
| Parallel.For(0, numberOfResources, (i, task) => | ||
| { | ||
| DomainResource resource = BundleTestsCommonFunctions.GetSamplePatient(Guid.NewGuid()); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb((int)i), string.Empty, operation.Id)); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb(i), string.Empty, operation.Id)); | ||
|
|
||
| Task<UpsertOutcome> appendedResourceTask = operation.AppendResourceAsync(resourceWrapper, dataStore, cts.Token); | ||
| tasksWaitingForMergeAsync.Add(appendedResourceTask); |
| ResourceWrapperOperation resourceWrapper = await BundleTestsCommonFunctions.GetResourceWrapperOperationAsync( | ||
| resource, | ||
| new BundleResourceContext(Bundle.BundleType.Batch, BundleProcessingLogic.Parallel, GetHttpVerb(i), persistedId: null, operation.Id)); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb((int)i), string.Empty, operation.Id)); |
Check warning
Code scanning / CodeQL
Cast to same type Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
The best way to fix the problem is to remove the redundant cast (int)i on line 220. Instead, pass i directly to the GetHttpVerb function. No changes are needed to any imports, method signatures, or additional code outside of removing the unnecessary cast. Only a single edit to line 220 in the file is required.
-
Copy modified line R220
| @@ -217,7 +217,7 @@ | ||
| else | ||
| { | ||
| DomainResource resource = BundleTestsCommonFunctions.GetSamplePatient(Guid.NewGuid()); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb((int)i), string.Empty, operation.Id)); | ||
| ResourceWrapperOperation resourceWrapper = BundleTestsCommonFunctions.GetResourceWrapperOperation(resource, new BundleResourceContext(null, BundleProcessingLogic.Parallel, GetHttpVerb(i), string.Empty, operation.Id)); | ||
|
|
||
| appendTask = operation.AppendResourceAsync(resourceWrapper, dataStore, cts.Token); | ||
| } |
| RegexOptions.Compiled); | ||
|
|
||
| private FhirJsonParser _parser; | ||
| private FhirJsonDeserializer _parser; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix this issue, add the readonly modifier to the field _parser. This ensures that _parser can only be set during the field's declaration or within the class's constructor, preventing unintended assignment elsewhere. Specifically, locate the declaration private FhirJsonDeserializer _parser; (line 23) in the file ImportResourceParser.cs and change it to private readonly FhirJsonDeserializer _parser;. No other code or imports need to be changed, as assignment occurs appropriately in the constructor.
-
Copy modified line R23
| @@ -20,7 +20,7 @@ | ||
| { | ||
| public class ImportResourceParser : IImportResourceParser | ||
| { | ||
| private FhirJsonDeserializer _parser; | ||
| private readonly FhirJsonDeserializer _parser; | ||
| private IResourceWrapperFactory _resourceFactory; | ||
|
|
||
| public ImportResourceParser(FhirJsonDeserializer parser, IResourceWrapperFactory resourceFactory) |
| if (resource is ResourceReference reference) | ||
| { | ||
| var childValue = child.Value; | ||
| if (childValue.TypeName == "Reference") | ||
| if (reference.Reference != null && reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| var reference = (ResourceReference)childValue; | ||
| if (reference.Reference != null && reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| reference.Reference = null; | ||
| reference.Display = "Referenced resource deleted"; | ||
| } | ||
| reference.Reference = null; | ||
| reference.Display = "Referenced resource deleted"; | ||
| } | ||
| else if (childValue.Children.Any()) | ||
| } |
Check notice
Code scanning / CodeQL
Nested 'if' statements can be combined Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the issue, combine the two if statements at lines 30 and 32 into a single conditional by combining their conditions with &&. Use proper parentheses to ensure correct operator precedence and take care that the inline variable (reference) declared by the pattern-matching is expression is only used if the type match succeeds. In recent C# versions, this is permitted directly in the conditional. Replace:
if (resource is ResourceReference reference)
{
if (reference.Reference != null && reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase))
{
// ...
}
}with:
if (resource is ResourceReference reference
&& reference.Reference != null
&& reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase))
{
// ...
}Only lines within the method RemoveReferenceRecursive in file src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Delete/ReferenceRemover.cs need updating.
No additional imports, methods, or definitions are required.
-
Copy modified lines R30-R32 -
Copy modified lines R34-R35
| @@ -27,13 +27,12 @@ | ||
| } | ||
|
|
||
| // Check if this is a ResourceReference | ||
| if (resource is ResourceReference reference) | ||
| if (resource is ResourceReference reference | ||
| && reference.Reference != null | ||
| && reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| if (reference.Reference != null && reference.Reference.Equals(target, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| reference.Reference = null; | ||
| reference.Display = "Referenced resource deleted"; | ||
| } | ||
| reference.Reference = null; | ||
| reference.Display = "Referenced resource deleted"; | ||
| } | ||
|
|
||
| // Recursively process all properties |
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs
Fixed
Show fixed
Hide fixed
| } | ||
|
|
||
| var fhirJsonSerializer = new FhirJsonSerializer(new SerializerSettings() { AppendNewLine = false, Pretty = false }); | ||
| var fhirJsonSerializer = new FhirJsonSerializer(); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning test
fhirJsonSerializer
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix this problem, simply remove the unused assignment var fhirJsonSerializer = new FhirJsonSerializer(); from line 329 in the method. This does not affect the program logic, since the instantiated object is never used, nor does its construction have any necessary, visible side-effect in this context. No other changes are needed elsewhere, and no imports or definitions need to be modified or added.
| @@ -326,7 +326,6 @@ | ||
| } | ||
| } | ||
|
|
||
| var fhirJsonSerializer = new FhirJsonSerializer(); | ||
| using var sw = new StringWriter(sb); | ||
| sb.AppendLine("Actual collection as below -"); | ||
| foreach (var element in actualResources) |
| parameters.Parameter.Add(new Parameters.ParameterComponent() { Name = "profile", Value = new FhirString(profile) }); | ||
|
|
||
| var parser = new FhirJsonParser(); | ||
| var parser = new FhirJsonDeserializer(); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning test
parser
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix a "useless assignment to local variable" you either (a) remove the unused variable and its assignment if they are truly unnecessary, or (b) start using the variable where it was intended to be used, if the code is incomplete. Here, the parser variable is created but never used, and the test already performs JSON conversion via parameters.ToJson(), so the parser is clearly redundant.
The best fix without changing functionality is to delete the declaration/assignment line var parser = new FhirJsonDeserializer(); in GivenInvalidProfile_WhenValidateCalled_ThenBadRequestReturned in test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/ValidateTests.cs. No other code in the method needs to be updated, and no new imports or helper methods are required. This change simply removes dead code and does not affect the test’s behavior.
| @@ -210,7 +210,6 @@ | ||
| Parameters parameters = new Parameters(); | ||
| parameters.Parameter.Add(new Parameters.ParameterComponent() { Name = "profile", Value = new FhirString(profile) }); | ||
|
|
||
| var parser = new FhirJsonDeserializer(); | ||
| parameters.Parameter.Add(new Parameters.ParameterComponent() { Name = "resource", Resource = Samples.GetDefaultPatient().ToPoco<Patient>() }); | ||
|
|
||
| exception = await Assert.ThrowsAsync<FhirClientException>(async () => await _client.ValidateAsync("Patient/$validate", parameters.ToJson())); |
| { | ||
| private ResourceWrapperFactory _resourceWrapperFactory; | ||
| private FhirJsonParser _fhirJsonParser; | ||
| private FhirJsonDeserializer _fhirJsonDeserializer; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix the problem, the _fhirJsonDeserializer field should be marked readonly so it cannot be reassigned after the object is constructed. For consistency and the same reasoning, the other similar dependency fields (_resourceWrapperFactory, _fhirJsonSerializer, _modelInfoProvider) should also be made readonly, provided they are initialized in the constructor and not reassigned elsewhere. This change does not alter runtime behavior as long as there are no later assignments; it only enforces the existing usage pattern at compile time.
Concretely, in tools/Microsoft.Health.Fhir.R4.ResourceParser/ResourceWrapperParser.cs, update the field declarations near the top of the ResourceWrapperParser class (lines 27–30) by adding the readonly modifier to each of these four private fields:
private ResourceWrapperFactory _resourceWrapperFactory;private FhirJsonDeserializer _fhirJsonDeserializer;private FhirJsonSerializer _fhirJsonSerializer;private IModelInfoProvider _modelInfoProvider;
No additional methods, imports, or definitions are required; this is a modifier-only change.
-
Copy modified lines R27-R30
| @@ -24,10 +24,10 @@ | ||
| { | ||
| public class ResourceWrapperParser | ||
| { | ||
| private ResourceWrapperFactory _resourceWrapperFactory; | ||
| private FhirJsonDeserializer _fhirJsonDeserializer; | ||
| private FhirJsonSerializer _fhirJsonSerializer; | ||
| private IModelInfoProvider _modelInfoProvider; | ||
| private readonly ResourceWrapperFactory _resourceWrapperFactory; | ||
| private readonly FhirJsonDeserializer _fhirJsonDeserializer; | ||
| private readonly FhirJsonSerializer _fhirJsonSerializer; | ||
| private readonly IModelInfoProvider _modelInfoProvider; | ||
|
|
||
| public ResourceWrapperParser() | ||
| { |
41108f4 to
2809f6c
Compare
| Base element2 = null; | ||
|
|
||
| // Act | ||
| var result = element1.EqualValues(element2); |
Check failure
Code scanning / CodeQL
Dereferenced variable is always null Error
element1
Copilot Autofix
AI 1 day ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
| if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild) | ||
| { | ||
| if (!sourceChild.EqualValues(sourceElement.Key, otherChild, otherElement.Key)) | ||
| { | ||
| return false; | ||
| } | ||
| } |
Check notice
Code scanning / CodeQL
Nested 'if' statements can be combined Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix this kind of issue you merge nested if statements that both guard the same block of logic and have no else parts into a single if whose condition is the logical && of the original conditions. This keeps behavior identical but avoids unnecessary nesting and makes intent clearer.
In this specific case in src/Microsoft.Health.Fhir.Core/Extensions/BaseExtensions.cs, within the for (int j = 0; j < sourceList.Count; j++) loop, there is an outer if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild) and then an inner if (!sourceChild.EqualValues(...)). CodeQL, however, is flagging the pattern at line 85 as nested ifs that can be combined. The actual nested-if pattern exists one level deeper: currently the code is:
for (int j = 0; j < sourceList.Count; j++)
{
if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild)
{
if (!sourceChild.EqualValues(sourceElement.Key, otherChild, otherElement.Key))
{
return false;
}
}
}We can combine the two if statements into one by moving the EqualValues check into the combined condition. The resulting code:
for (int j = 0; j < sourceList.Count; j++)
{
if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild &&
!sourceChild.EqualValues(sourceElement.Key, otherChild, otherElement.Key))
{
return false;
}
}preserves the logic: EqualValues is only evaluated when both list entries are Base instances, and return false is executed when they are both Base and not equal. No new imports or helper methods are required; this is a local change inside EqualValues(Base source, string sourceName, Base other, string otherName).
-
Copy modified lines R85-R86 -
Copy modified line R88
| @@ -82,12 +82,10 @@ | ||
|
|
||
| for (int j = 0; j < sourceList.Count; j++) | ||
| { | ||
| if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild) | ||
| if (sourceList[j] is Base sourceChild && otherList[j] is Base otherChild && | ||
| !sourceChild.EqualValues(sourceElement.Key, otherChild, otherElement.Key)) | ||
| { | ||
| if (!sourceChild.EqualValues(sourceElement.Key, otherChild, otherElement.Key)) | ||
| { | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } |
Description
This pull request introduces significant changes to how FHIR resources are represented and processed within the codebase, moving from the use of
ITypedElementtoPocoNodefor resource elements. This update impacts a wide range of files, refactoring interfaces, implementations, and test code to align with the new model. Additionally, there are several dependency version updates and some package version downgrades.The most important changes are:
Core Model Refactoring
ResourceElementand related APIs to usePocoNodeinstead ofITypedElement, affecting constructors, properties, and internal logic inResourceElement,ResourceTypeExtensions, and all related usages. This change improves consistency and interoperability with the FHIR .NET library. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]IReferenceToElementResolverinterface and its implementation to returnPocoNodeinstead ofITypedElement. [1] [2] [3]IModelInfoProvider.GetEvaluationContextsignature to accept a resolver function returningPocoNode. [1] [2]Dependency and Package Version Updates
Directory.Packages.props, includingHealthcareSharedPackageVersion,DotNetSdkPackageVersion,Azure.Identity,Microsoft.Data.SqlClient, andNewtonsoft.Json. Also, updatedHl7FhirVersionandOpenIddictpackages to newer versions. [1] [2] [3] [4]IdentityServer4and updatedMicrosoft.EntityFrameworkCore.InMemoryto a newer version. [1] [2]Test Adjustments
PocoNode-based APIs and adjusted mock setups and test logic accordingly. [1] [2] [3] [4] [5] [6]Minor Logic Changes
PocoNodeinstances, ensuring correct FHIRPath context and evaluation. [1] [2] [3]CreateBulkUpdateHandlerto correctly extract the operation value from FHIR parameters, handlingFhirStringspecifically.These changes collectively modernize the resource handling pipeline and align the codebase with the latest FHIR .NET best practices.
Related issues
Addresses [issue #].
Testing
Describe how this change was tested.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)