Skip to content

Commit

Permalink
Persist search indices in history documents. (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonpollett authored Oct 19, 2018
1 parent 1e6e1a0 commit 4002812
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ function upsertWithHistory(doc, matchVersionId, allowCreate, keepHistory) {
}

theDoc.isHistory = true;
theDoc.searchIndices = theDoc.searchIndices.filter(x => x.p === "_id" || x.p === "_lastUpdated");
theDoc.id = `${theDoc.resourceId}_${theDoc.version}`;

return theDoc;
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.Health.Fhir.Tests.E2E/Rest/DeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task GivenAResourceWithLargeNumberOfHistory_WhenHardDeleting_ThenSe
versionIds.Add(observation.Meta.VersionId);

// Update the observation.
for (int i = 0; i < 100; i++)
for (int i = 0; i < 50; i++)
{
response = await Client.UpdateAsync(observation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Hl7.Fhir.Model;
using Microsoft.Health.Fhir.Tests.Common;
Expand Down Expand Up @@ -134,5 +135,32 @@ public async Task GivenMoreSearchResultsThanCount_WhenSearched_ThenNextLinkUrlSh

ValidateBundle(results, patients);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenResourceWithHistory_WhenSearchedWithParams_ThenOnlyCurrentVersionShouldBeReturned()
{
// Create a coding that can be used to limit search to only the items within this test
var testCoding = new Coding("https://testSystem", Guid.NewGuid().ToString());

// Add the coding and set the observation status
var originalObservation = Samples.GetDefaultObservation();
originalObservation.Status = ObservationStatus.Preliminary;
originalObservation.Code.Coding.Add(testCoding);

// Create the original resource
var createdResource = await Client.CreateAsync(originalObservation);

// Update the status and submit the update to the server
var resourceToUpdate = createdResource.Resource;
resourceToUpdate.Status = ObservationStatus.Corrected;
var updatedResource = await Client.UpdateAsync(resourceToUpdate);

// Search for the given coding
Bundle bundle = await Client.SearchAsync($"Observation?code={testCoding.System}|{testCoding.Code}");

// The only thing returned should be the updated resource
ValidateBundle(bundle, updatedResource);
}
}
}

0 comments on commit 4002812

Please sign in to comment.