-
Notifications
You must be signed in to change notification settings - Fork 67
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
Address issue #184, observations not being updated when changed #185
Address issue #184, observations not being updated when changed #185
Conversation
dustinburson
commented
Apr 15, 2022
- Address issue Observations not being updated when new data arrives #184, observations not being updated when changed.
- Defect was due to using two different references to the same object for the change comparison.
- Updated CodeValueFhirTemplateProcessor.MergeObservation to perform a DeepCopy of the passed in Observation parameter. The copy is what is returned now by the function to ensure modifications are made to a new instance.
- Moved the logic to set the status of the Observation from the MergeObservation function to the R4FhirImportService.SaveObservationAsync logic. Without the move, the first time a created observation is "updated" will always result in the FHIR resource being saved even if nothing else changed because we were always setting the status to amended.
- Updated unit tests to account for new logic.
- Added extension methods for some common scenarios
- Rename FhirClientValidator to FhirClientValidatorExtensions to match other extension class names
- Rename ServiceCollectionExtrensions to FhirClientExtensions to match purpose.
- Merge content of HttpClientBuilderRegistraionExtensions into FhirClientExtensions.
- Remove registering ITelemetryLogger singleton with FhirClient. ITelemetryLogger is resolved from the service provider now. This was preventing local debugging with the Azure Function.
- Update AddAuthenticationHandler to use the registered singletons for the auth service instead of creating new instances.
- Defect was due to using two different references to the same object for the change comparison. - Updated CodeValueFhirTemplateProcessor.MergeObservation to perform a DeepCopy of the passed in Observation parameter. The copy is what is returned now by the function to ensure modifications are made to a new instance. - Moved the logic to set the status of the Observation from the MergeObservation function to the R4FhirImportService.SaveObservationAsync logic. Without the move, the first time a created observation is "updated" will always result in the FHIR resource being saved even if nothing else changed because we were always setting the status to amended. - Updated unit tests to account for new logic. - Added extension methods for some common scenarios * Rename FhirClientValidator to FhirClientValidatorExtensions to match other extension class names * Rename ServiceCollectionExtrensions to FhirClientExtensions to match purpose. * Merge content of HttpClientBuilderRegistraionExtensions into FhirClientExtensions. * Remove registering ITelemetryLogger singleton with FhirClient. ITelemetryLogger is resolved from the service provider now. This was preventing local debugging with the Azure Function. * Update AddAuthenticationHandler to use the registered singletons for the auth service instead of creating new instances.
@@ -113,8 +113,8 @@ public virtual async Task<string> SaveObservationAsync(ILookupTemplate<IFhirTemp | |||
// Merge the new data with the existing Observation. | |||
var mergedObservation = MergeObservation(config, existingObservation, observationGroup); | |||
|
|||
// Check to see if there are any changes after merging. | |||
if (mergedObservation.IsExactly(existingObservation)) | |||
// Check to see if there are any changes after merging and update the Status to ammended if changed. |
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.
Nit. Typo in amend
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.
Thanks, fixed in latest version.
/// <typeparam name="TResource">Type of resource to return.</typeparam> | ||
/// <param name="resource">Resource to copy.</param> | ||
/// <returns>New resource object with the contents of the original.</returns> | ||
public static TResource FullCopy<TResource>(this TResource resource) |
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.
I only see this referenced in unit tests. Is that intended?
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.
Covered in other comment but yes for now it is due to project compatibility issues.
@@ -128,42 +128,42 @@ protected override Observation MergeObservationImpl(CodeValueFhirTemplate templa | |||
EnsureArg.IsNotNull(grp, nameof(grp)); | |||
EnsureArg.IsNotNull(existingObservation, nameof(existingObservation)); | |||
|
|||
existingObservation.Status = ObservationStatus.Amended; | |||
var mergedObservation = existingObservation.DeepCopy() as Observation; |
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.
Should this be using the new extension method?:
var mergedObservation = existingObservation.FullCopy()
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.
Unfortunately we can't right now. This project is .NET 2.0 standard where as the Extenstions,Fhir.R4 project is .NET 6.0 and can't be downgraded due to dependencies. This project needs to stay .NET Standard till we can move our RP to .NET 6.0.
I could have introduced a completely separate project just for this method but it seemed like overkill.
Have you deployed and tested this change out in a personal cluster? |
…ameter. Update the FHIR Service UpdateResourceAsync to automatically set the ifMatchVersion if one isn't already specified and the resource being updated has a version set (i.e. not new).
Not yet in a personal cluster. I ran the Azure Function locally pointed to a remote FHIR Service using these instructions https://github.com/microsoft/iomt-fhir/blob/main/docs/Debugging.md#example-post-body testing various update and create scenarios. |