-
Notifications
You must be signed in to change notification settings - Fork 569
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 about 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 about 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 about 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 about 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 |
| reindexParameters.Add("targetResourcetype", new FhirString("Specimen")); | ||
| (reindexJobResult, reindexJobUri) = await RunReindexToCompletion(reindexParameters); | ||
|
|
||
| Parameters.ParameterComponent searchParamListParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.SearchParams); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning test
reindexJobUri
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix this problem, we should replace the assignment of the unused variable reindexJobUri in the tuple assignment with a discard (_). This makes it clear that the second value returned from RunReindexToCompletion is intentionally not used.
Specifically, in test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs, within the method shown, replace:
(reindexJobResult, reindexJobUri) = await RunReindexToCompletion(reindexParameters);with:
(reindexJobResult, _) = await RunReindexToCompletion(reindexParameters);This eliminates the unnecessary assignment to reindexJobUri and avoids keeping unused local variables.
No changes to imports, methods, or other logic are required.
-
Copy modified line R292
| @@ -284,13 +284,12 @@ | ||
| searchParamPosted = await Client.CreateAsync(searchParam); | ||
| _output.WriteLine($"{nameof(searchParamPosted)} Response.StatusCode is {searchParamPosted.Response.StatusCode} and posted Url is {searchParam.Url}"); | ||
|
|
||
| Uri reindexJobUri; | ||
| FhirResponse<Parameters> reindexJobResult; | ||
|
|
||
| // Start a reindex job | ||
| var reindexParameters = new Parameters(); | ||
| reindexParameters.Add("targetResourcetype", new FhirString("Specimen")); | ||
| (reindexJobResult, reindexJobUri) = await RunReindexToCompletion(reindexParameters); | ||
| (reindexJobResult, _) = await RunReindexToCompletion(reindexParameters); | ||
|
|
||
| Parameters.ParameterComponent searchParamListParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.SearchParams); | ||
| Parameters.ParameterComponent targetResourcesParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.TargetResourceTypes); |
|
|
||
| Parameters.ParameterComponent searchParamListParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.SearchParams); | ||
| Parameters.ParameterComponent targetResourcesParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.TargetResourceTypes); | ||
| Parameters.ParameterComponent resourcesParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.Resources); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning test
reindexJobUri
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix this issue, replace the assignment to the unused local variable reindexJobUri (which is never read) with a discard variable (_). This clarifies intent for anyone reading the code and avoids unnecessary local variable declarations. Locate the tuple assignment on line 408 in test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs where (reindexJobResult, reindexJobUri) = ... and change to (reindexJobResult, _) = .... Also, remove the declaration of reindexJobUri on line 402 since it is no longer needed. No additional imports or methods are needed; all required functionality is already present.
-
Copy modified line R407
| @@ -399,13 +399,12 @@ | ||
| searchParamPosted = await Client.CreateAsync(searchParam); | ||
| _output.WriteLine($"{nameof(searchParamPosted)} Response.StatusCode is {searchParamPosted.Response.StatusCode} and posted Url is {searchParam.Url}"); | ||
|
|
||
| Uri reindexJobUri; | ||
| FhirResponse<Parameters> reindexJobResult; | ||
|
|
||
| // Start a reindex job | ||
| var reindexParameters = new Parameters(); | ||
| reindexParameters.Add("targetResourceTypes", new FhirString("Specimen,Immunization")); | ||
| (reindexJobResult, reindexJobUri) = await RunReindexToCompletion(reindexParameters); | ||
| (reindexJobResult, _) = await RunReindexToCompletion(reindexParameters); | ||
|
|
||
| Parameters.ParameterComponent searchParamListParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.SearchParams); | ||
| Parameters.ParameterComponent targetResourcesParam = reindexJobResult.Resource.Parameter.FirstOrDefault(p => p.Name == JobRecordProperties.TargetResourceTypes); |
| _output.WriteLine(error); | ||
| success = false; | ||
| await Task.Delay(TimeSpan.FromSeconds(10)); | ||
| } | ||
| } | ||
| while (!success && retryCount < MaxRetryCount); | ||
|
|
||
| Assert.True(success, $"There are bundle validation failures. {retryCount} attempts reached. Check test logs."); |
Check notice
Code scanning / CodeQL
Generic catch clause Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix this issue, the catch clause in the retry loop should be restricted to only catch specific exceptions that might realistically occur during validation and that are appropriate to handle with a retry. For this scenario, since the method being called interacts with a FHIR client and presumably does not expect programming errors, it should catch at minimum FhirClientException, and possibly exceptions like HttpRequestException. Unrecoverable exceptions (such as NullReferenceException, OutOfMemoryException, etc.) should not be caught or retried, as they represent serious bugs that should fail the test outright. The change should be in the file test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/CustomSearchParamTests.cs, specifically replacing catch (Exception ex) on line 437 with more specific exception types. No new methods or definitions are required, and no new imports (the relevant exception types are already available in the context).
-
Copy modified line R437 -
Copy modified lines R445-R452
| @@ -434,7 +434,7 @@ | ||
|
|
||
| _output.WriteLine($"Success on attempt {retryCount} of {MaxRetryCount}"); | ||
| } | ||
| catch (Exception ex) | ||
| catch (FhirClientException ex) | ||
| { | ||
| string error = $"Attempt {retryCount} of {MaxRetryCount}: Failed to validate bundle: {ex}"; | ||
|
|
||
| @@ -442,6 +442,14 @@ | ||
| success = false; | ||
| await Task.Delay(TimeSpan.FromSeconds(10)); | ||
| } | ||
| catch (System.Net.Http.HttpRequestException ex) | ||
| { | ||
| string error = $"Attempt {retryCount} of {MaxRetryCount}: HTTP request failed during bundle validation: {ex}"; | ||
|
|
||
| _output.WriteLine(error); | ||
| success = false; | ||
| await Task.Delay(TimeSpan.FromSeconds(10)); | ||
| } | ||
| } | ||
| while (!success && retryCount < MaxRetryCount); | ||
|
|
| } | ||
|
|
||
| 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 about 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 about 2 months ago
To fix this issue, simply delete the line assigning parser = new FhirJsonDeserializer() on line 213. Since parser is not used elsewhere in the method, its declaration and instantiation are unnecessary. This change is contained within the file test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/ValidateTests.cs, specifically within the method GivenInvalidProfile_WhenValidateCalled_ThenBadRequestReturned. No additional imports or method changes are needed.
| @@ -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 about 2 months ago
The best way to fix the problem is to add the readonly modifier to the _fhirJsonDeserializer field declaration in ResourceWrapperParser.cs. This change clarifies the intent that this field cannot be reassigned after construction, aligns with best practices for immutability, and does not affect existing functionality since all assignments occur in the constructor. Specifically, change line 28 of the file to declare _fhirJsonDeserializer as private readonly FhirJsonDeserializer _fhirJsonDeserializer;. No new methods, imports, or other changes are required.
-
Copy modified line R28
| @@ -25,7 +25,7 @@ | ||
| public class ResourceWrapperParser | ||
| { | ||
| private ResourceWrapperFactory _resourceWrapperFactory; | ||
| private FhirJsonDeserializer _fhirJsonDeserializer; | ||
| private readonly FhirJsonDeserializer _fhirJsonDeserializer; | ||
| private FhirJsonSerializer _fhirJsonSerializer; | ||
| private IModelInfoProvider _modelInfoProvider; | ||
|
|
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)