Skip to content
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

Merged
merged 3 commits into from
Apr 18, 2022

Conversation

dustinburson
Copy link
Member

  • 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.
@dustinburson dustinburson requested a review from a team as a code owner April 15, 2022 19:32
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Typo in amend

Copy link
Member Author

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)
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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()

Copy link
Member Author

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.

@rogordon01
Copy link
Contributor

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).
@dustinburson
Copy link
Member Author

Have you deployed and tested this change out in a personal cluster?

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.

@rogordon01
Copy link
Contributor

rogordon01 commented Apr 15, 2022 via email

@rogordon01 rogordon01 merged commit 27ee606 into main Apr 18, 2022
@rogordon01 rogordon01 deleted the personal/duburson/fix-observation-update-issue branch April 18, 2022 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants