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

History returns items in the wrong order #2689

Closed
rmeoc opened this issue Jul 6, 2022 · 3 comments
Closed

History returns items in the wrong order #2689

rmeoc opened this issue Jul 6, 2022 · 3 comments
Labels
Bug Bug bug bug. Specification An issue referring or related to the FHIR Specification

Comments

@rmeoc
Copy link

rmeoc commented Jul 6, 2022

Describe the bug
The versions returned when retrieving history are sorted from old to new, while they should be from new to old. See the following section of the FHIR Specification (from http://hl7.org/fhir/http.html#history):

The return content is a Bundle with type set to history containing the specified version history, sorted with oldest versions last, and including deleted resources.

FHIR Version?
Stu3

Data provider?
I don't know. I have encountered the bug with the Azure Health Data Services FHIR service. I don't know what Data provider is used by that service.

To Reproduce
Steps to reproduce the behavior:

  1. Invoke the history interaction, e.g. GET [base]/[type]/[id]/_history

Expected behavior
A bundle is returned containing the version history sorted with oldest versions last.

Actual behavior
A bundle is returned containing the version history sorted with oldest versions first.

AB#93193

@rmeoc rmeoc added the Bug Bug bug bug. label Jul 6, 2022
@brendankowitz
Copy link
Member

Hi @rmeoc, thanks for reporting this, we'll investigate

@brendankowitz
Copy link
Member

brendankowitz commented Jul 14, 2022

Cosmos sorts correctly with _lastUpdated DESC:

_queryBuilder
.Append("ORDER BY ")
#pragma warning disable CA1834 // Consider using 'StringBuilder.Append(char)' when applicable
.Append(SearchValueConstants.RootAliasName).Append('.').Append(KnownResourceWrapperProperties.LastModified)
#pragma warning restore CA1834 // Consider using 'StringBuilder.Append(char)' when applicable
.AppendLine(" DESC");

The SQL Provider looks to be sorting incorrectly with:

newSearchOptions.Sort = new (SearchParameterInfo searchParameterInfo, SortOrder sortOrder)[]
{
(_fakeLastUpdate, SortOrder.Ascending),
};

History tests should be updated to check ordering:

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenNoType_WhenGettingSystemHistory_TheServerShouldReturnTheAppropriateBundleSuccessfully()
{
using FhirResponse<Bundle> readResponse = await _client.SearchAsync("_history");
Assert.NotEmpty(readResponse.Resource.Entry);
}

@brendankowitz brendankowitz added the Specification An issue referring or related to the FHIR Specification label Jul 14, 2022
@EXPEkesheth
Copy link
Contributor

@rmeoc Thanks for reporting the issue. The issue is fixed.
Reach out for any additional questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug bug bug. Specification An issue referring or related to the FHIR Specification
Projects
None yet
Development

No branches or pull requests

3 participants