Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
fix: use Fhir Http client to hard delete patients (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
liammoat authored Apr 17, 2024
1 parent 6174243 commit 3cfc3fe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/Integration.Tests/Core/Pds/PdsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public class PdsServiceTests : IDisposable
{
private readonly ApiWebApplicationFactory _webApplicationFactory;
private readonly IPdsService _sut;
private readonly HttpClient _fhirHttpClient;
private readonly IDataHubFhirClientWrapper _dataHubFhirClientWrapper;

public PdsServiceTests()
{
_webApplicationFactory = new ApiWebApplicationFactory();
_dataHubFhirClientWrapper = _webApplicationFactory.Services.GetService<IDataHubFhirClientWrapper>()!;
_fhirHttpClient = _webApplicationFactory.Services
.GetRequiredService<IHttpClientFactory>()
.CreateClient("DataHubFhirClient");
_sut = _webApplicationFactory.Services.GetService<IPdsService>()
?? throw new Exception("Failed to resolve IPdsService from the service provider");
}
Expand Down Expand Up @@ -227,14 +231,15 @@ private static MeshClient GetMeshClient()

private async Task CleanFhirStore()
{
var searchResult =
await _dataHubFhirClientWrapper.SearchResourceByParams<Patient>(
new SearchParams().LimitTo(Globals.FhirServerMaxPageSize));
var searchParams = new SearchParams().LimitTo(Globals.FhirServerMaxPageSize);
var searchResult = await _dataHubFhirClientWrapper.SearchResourceByParams<Patient>(searchParams);

while (searchResult != null)
{
foreach (var patient in searchResult.Entry)
await _dataHubFhirClientWrapper.DeleteAsync($"{patient.Resource.TypeName}/{patient.Resource.Id}");
{
await _fhirHttpClient.DeleteAsync($"Patient/{patient.Resource.Id}?hardDelete=true");
}

searchResult = await _dataHubFhirClientWrapper.ContinueAsync(searchResult!);

Expand Down

0 comments on commit 3cfc3fe

Please sign in to comment.