Skip to content

Add warning to search response when pages have shifted #3590

@lmsurpre

Description

@lmsurpre

Is your feature request related to a problem? Please describe.
Many FHIR Server implementations hold search session state to provide stable paging. That hurts performance/scalability but may be more appropriate for certain use cases.

Describe the solution you'd like
In cases where we cannot provide stable paging, we can at least detect that the pages have shifted and provide a warning.

  1. add the "changeId" of the first result to the 'next' link with a param name like 'prevChangeId'
  2. add the "changeId" of the last result to the 'prev' link with a param name like 'nextChangeId'
  3. when we get a search request with a 'prevChangeId' value, fetch an extra resource just before the page and confirm that its id matches the expected value
  4. when we get a search request with a 'nextChangeId' value, fetch an extra resource just after the page and confirm that its id matches the expected value

For 3 and 4, if the id doesn't match the expected value then add an OperationOutcome to the response bundle with a warning like:

"Pages have shifted; check prior pages for changed results"

Worked example:

GET [base]/Patient?_count=3

Bundle
links:
* next: /Patient?_page=2&_count=3&prevChangeId=3
entry:
* id=1
* id=2
* id=3
GET [base]/Patient?_page=2&_count=3&prevChangeId=3

Bundle
links:
* prev: /Patient?page=1&_count=3&nextChangeId=4
* next: /Patient?page=3&_count=3&prevChangeId=6
entry:
* id=4
* id=5
* id=6

Describe alternatives you've considered
Fetch full pages on either side of the current page and hash those, then use that hash.
This would cover cases where there was an insert and a delete on either side...so the page looks stable but there is some changed content.

Acceptance Criteria

  1. GIVEN a search with multiple pages of results
    AND a user has requested a page (e.g. page 1)
    WHEN a resource from that page (or prior) is deleted
    AND the user then follows the provided (now-stale) "next" link (e.g. to page 2)
    THEN the response bundle contains an entry with mode=outcome and an OperationOutcome resource that includes an appropriate warning

  2. GIVEN a search with multiple pages of results
    AND a user has requested a page (e.g. page 2)
    WHEN a resource that would land on that page (or prior) is added
    AND the user then follows the provided (now-stale) "prev" link (e.g. to page 1)
    THEN the response bundle contains an entry with mode=outcome and an OperationOutcome resource that includes an appropriate warning

  3. GIVEN a search with multiple pages of results
    AND a user has requested a page (e.g. page 1)
    WHEN no resource from that page (or prior) is deleted (either no deletes or a delete of a resource on a latter page)
    AND the user then follows the provided "next" link (e.g. to page 2)
    THEN the response bundle does not contain an entry with mode=outcome and an OperationOutcome resource about shifted pages

  4. GIVEN a search with multiple pages of results
    AND a user has requested a page (e.g. page 2)
    WHEN no resource that would land on that page (or prior) is added
    AND the user then follows the provided "prev" link (e.g. to page 1)
    THEN the response bundle does not contain an entry with mode=outcome and an OperationOutcome resource about shifted pages

Additional context
If we do it with #3476 I think we could provide more stable paging when _sort=none (e.g. instead of issuing a warning when pages shift, we could potentially just start the next page at the most appropriate place)

Metadata

Metadata

Labels

P2Priority 2 - Should HaveenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions