Skip to content

Previous link url is always the first page when using offset-based pagination in facade #4468

Open
@ydaniju

Description

@ydaniju

Describe the bug
We are using hapi fhir as a facade. Pagination of search endpoints is performed by using SimpleBundleProvider which generated the right links for the current and next pages. However, once we get to page 3 (and above), the previous link always points to page 1 instead of page 2 (currentPage - 1).

To Reproduce
Steps to reproduce the behavior:

  1. Create a Resource Provider search endpoint eg PatientResourceProvider
// List<IBaseResource> resourceList -> could be empty for reproducing this issue
SimpleBundleProvider bundleProvider = new SimpleBundleProvider(resourceList);

/**
* meta is a DTO for the backend service providing search data
* Offset and counterPerPage are from @Count and @Offset respectively
* Could be hardcoded to reproduce this issue
* /

bundleProvider.setCurrentPageOffset(meta.getOffset());
bundleProvider.setCurrentPageSize(meta.getCountPerPage());
bundleProvider.setSize(meta.getTotalCount()); // you can use a fixed size of 10

return bundleProvider;
  1. Set currentPageSize = 1, currentPageOffset = 3, totalCount (ie size) = 10 corresponding to ...?_count=1&_offset=3
  2. Make a request to the search endpoint of the resource provider
  3. You will get
  "link": [
    {
      "relation": "self",
      "url": "...?_count=1&_offset=3" // correct
    },
    {
      "relation": "next",
      "url": "...?_count=1&_offset=4" // correct
    },
    {
      "relation": "previous",
      "url": "...?_count=1&_offset=0" // wrong
    }

Expected behavior
The previous link url should look like "url": "...?_count=1&_offset=2" ie _offset should be current page offset minus count per page
Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • HAPI FHIR Version: 6.2.5
  • OS: N/A
  • Browser: N/A

Additional context
If this is a bug, we could raise a fix for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions