Skip to content

dhis2: Add pagination to get()#1567

Open
hunterachieng wants to merge 2 commits intomainfrom
feature/1546-dhis2-pagination
Open

dhis2: Add pagination to get()#1567
hunterachieng wants to merge 2 commits intomainfrom
feature/1546-dhis2-pagination

Conversation

@hunterachieng
Copy link
Contributor

@hunterachieng hunterachieng commented Feb 25, 2026

Summary

Implemented pagination capabilities in the get() function.

Use limit for the exact number of items to be returned; default is 10000
Use offset for the page number to start with; default is 1

Fixes #1546

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to
know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • If this is a new adaptor, added the adaptor on marketing website ?
  • If this PR includes breaking changes, do we need to update any jobs in
    production? Is it safe to release?
  • Are there any unit tests?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.
  • Have you ticked a box under AI Usage?

Signed-off-by: Hunter Achieng <achienghunter@gmail.com>
Signed-off-by: Hunter Achieng <achienghunter@gmail.com>
Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started a review but I need to put this down today as it sounds like you're not blocked on this.

I don't think the pagination rules are right though - so we need to take a real close look at that.

I also wonder if we need to add a callback like onPageDownloaded, and trigger that callback every time we finish a page. That makes it a lot easier for you to process data in batches, rather than downloading everything in one huge hit (this is a problem that affects a lot of our pagination APIs, but maybe this is an opportunity to start a new design pattern)

* @function
* @param {string} path - Path to the resource
* @param {object} params - Object of query parameters to include in the request
* @options {number} [options.limit] - Optional limit to the number of records returned. By default, this is 10,000.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. These docs are a little strange because they sort of imply that limit and offset are the only options. But you can put in any dhis2 query parameter here right?

I'll come back to this later and decide what to do

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also offset is a page number, not an item offset? So it's saying "get me page 1000" not "get me items from item 1000"?


export const getWithPagination = async (configuration, path, options = {}) => {
const { limit, offset = 1, ...requestOptions } = options;
const maxResults = requestOptions.query?.pageSize ?? limit ?? Infinity;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max results != page size!

The two things are very different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

dhis2: add pagination support

2 participants