medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
439 stars 207 forks source link

Add functionality of getting people with pagination in cht-datasource #9237

Closed sugat009 closed 1 week ago

sugat009 commented 2 months ago

Is your feature request related to a problem? Please describe.

This feature is part of the bigger feature of the creation of API endpoints for getting contacts by type. (#9193) The target of this feature is to have the functionality of getting people using cht-datasource with the option of pagination.

Describe the solution you'd like

Person.v1.getAll(limit, skip);

As mentioned in the parent ticket:

Describe alternatives you've considered

Additional context

jkuester commented 1 month ago

@sugat009 Thinking some more about API naming here (along with the iterator function, I propose these function signatures:

const getPage = (limit = 100, skip = 0) => Promise<Person.v1.Person[]>

const getAll = () => AsyncGenerator<Person.v1.Person, void>

Under the hood, getAll can call getPage. The main thing here is that I would like to encourage use of the getAll instead of getPage, so we do not have consumers trying to manually page through results unless it is necessary. For this issue, I think all this means is that you would need to change your function name from getAll to getPage. Let me know if this seems reasonable. Happy to discuss more!

sugat009 commented 1 month ago

@jkuester Of course, that sounds good.

jkuester commented 1 week ago

I am removing this from the 4.11 milestone since it is covered already by https://github.com/medic/cht-core/issues/9241.