Skip to content

Commit

Permalink
Fixing an IsDeleted issue on import/history. (#4473)
Browse files Browse the repository at this point in the history
* Fixing an IsDeleted issue on import/history.

* Changing the verb to PUT.

* Getting the isDeleted status from ResourceWrapper instead of caching the wrapper object.
  • Loading branch information
v-iyamauchi authored Aug 29, 2024
1 parent 43e184c commit 5552a7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public ResourceElement CreateHistoryBundle(SearchResult result)
}
#endif
if (!hasVerb && string.Equals("Import", r.Resource.Request?.Method, StringComparison.OrdinalIgnoreCase))
{
hasVerb = true;
httpVerb = resource.IsDeleted() ? Bundle.HTTPVerb.DELETE : Bundle.HTTPVerb.PUT;
}
resource.FullUrlElement = new FhirUri(_urlResolver.ResolveResourceWrapperUrl(r.Resource));
if (hasVerb)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ namespace Microsoft.Health.Fhir.Shared.Core.Features.Search
[FhirType("EntryComponent")]
public class RawBundleEntryComponent : Bundle.EntryComponent
{
private readonly bool _isDeleted;

public RawBundleEntryComponent(ResourceWrapper resourceWrapper)
{
EnsureArg.IsNotNull(resourceWrapper, nameof(resourceWrapper));

ResourceElement = new RawResourceElement(resourceWrapper);
_isDeleted = resourceWrapper.IsDeleted;
}

public RawResourceElement ResourceElement { get; set; }
Expand All @@ -33,5 +36,15 @@ public override IDeepCopyable DeepCopy()

throw new NotSupportedException();
}

/// <summary>
/// Gets a value indicating whether or not the resource has been deleted.
/// </summary>
/// <returns>True if the resource is deleted.</returns>
/// <remarks>This instance method supersedes the extension method, Bundle.EntryComponent.IsDeleted().</remarks>
public bool IsDeleted()
{
return _isDeleted;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public async Task GivenIncrementalLoad_MultipleInputVersionsWithDelete()

var history = await _client.SearchAsync($"Patient/{id}/_history");
Assert.Equal("2", history.Resource.Entry[0].Resource.VersionId);
////Assert.True(history.Resource.Entry[0].IsDeleted()); TODO: Uncomment when bug is fixed.
Assert.True(history.Resource.Entry[0].IsDeleted());
Assert.Equal("1", history.Resource.Entry[1].Resource.VersionId);
Assert.False(history.Resource.Entry[1].IsDeleted());
}
Expand Down

0 comments on commit 5552a7b

Please sign in to comment.