Skip to content

Commit

Permalink
Add IsDeleted check in search queries (#3925)
Browse files Browse the repository at this point in the history
Add IsDeleted check in search queries to avoid returned deleted resources in :not queries

Refs #3920 AB#121553
  • Loading branch information
feordin authored Jun 17, 2024
1 parent e5c679d commit 3324d72
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,7 @@ public override object VisitSqlRoot(SqlRootExpression expression, SearchOptions

AppendHistoryClause(delimitedClause, context.ResourceVersionTypes); // This does not hurt today, but will be neded with resource history separation

if (expression.SearchParamTableExpressions.Count == 0)
{
AppendDeletedClause(delimitedClause, context.ResourceVersionTypes);
}
AppendDeletedClause(delimitedClause, context.ResourceVersionTypes);
}

if (!searchOptions.CountOnly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ItemGroup>
<EmbeddedResource Include="TestFiles\Normative\Bundle-BatchWithDuplicatedItems.json" />
<EmbeddedResource Include="TestFiles\Normative\Bundle-BatchWithConditionalUpdateByIdentifier.json" />
<EmbeddedResource Include="TestFiles\Normative\Flag.json" />
<EmbeddedResource Include="TestFiles\Normative\Import-Observation.ndjson" />
<EmbeddedResource Include="TestFiles\Normative\LegacyRawReindexJobRecord.json" />
<EmbeddedResource Include="DefinitionFiles\R5\SearchParameters.json" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"resourceType": "Flag",
"id": "example",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Large Dog warning for Peter Patient</div>"
},
"identifier": [
{
"value": "12345"
}
],
"status": "inactive",
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/flag-category",
"code": "safety",
"display": "Safety"
}
],
"text": "Safety"
}
],
"code": {
"coding": [
{
"system": "http://example.org/local",
"code": "bigdog",
"display": "Big dog"
}
],
"text": "Patient has a big dog at his home. Always always wear a suit of armor or take other active counter-measures"
},
"subject": {
"reference": "Patient/example",
"display": "Peter Patient"
},
"period": {
"start": "2015-01-17",
"end": "2016-12-01"
},
"author": {
"reference": "Practitioner/example",
"display": "Nancy Nurse"
}
}
13 changes: 13 additions & 0 deletions test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/DeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ async Task<FhirClientException> ExecuteAndValidateGoneStatus(Func<Task> action)
}
}

[Fact]
public async Task GivenADeletedResource_WhenSearchWithNotModifier_ThenDeletedResourcesShouldNotBeReturned()
{
FhirResponse<Flag> response = await _client.CreateAsync(Samples.GetJsonSample("Flag").ToPoco<Flag>());

// Delete all Flag resources
await _client.DeleteAllResources(ResourceType.Flag, null);

var searchResults = await _client.SearchAsync("Flag?identifier:not=123");

Assert.True(searchResults.Resource.Entry == null || searchResults.Resource.Entry.Count == 0);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenHardDeleting_ThenServerShouldDeleteAllRelatedResourcesSuccessfully()
Expand Down

0 comments on commit 3324d72

Please sign in to comment.