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
435 stars 204 forks source link

API Endpoints for getting contacts by type #9193

Open jkuester opened 2 weeks ago

jkuester commented 2 weeks ago

Is your feature request related to a problem? Please describe. As noted in https://github.com/medic/cht-core/issues/8889, getting the contacts of a specific type is needed for cht-user-managment.

Describe the solution you'd like

HTTP GET api/v1/person

HTTP GET api/v1/place?type=clinic

Endpoints should also accept the following query parameters to allow for paging through the data:

When it comes to the cht-datasource api, things will be a bit interesting. On one hand, most consumers of the lib will not want to manually deal with paging, but instead we should return something like an async Iterable so the paging it completely abstracted away. However, the api code will need to be able to make a targeted request for a specific limit/skip since that is what it will be receiving as a request and for best performance we will need to be able to pass those though directly to the Couch view query... Perhaps we just provide both functions in cht-datasource:

Describe alternatives you've considered Other ways to structure the API include:

However, these do not seem any more clear than just using a query parameter and are definitely less flexible.

sugat009 commented 4 days ago

After a bit of assessment, I've decided to break this task down into smaller tasks in the following way.

  1. Add functionality of getting people with pagination in the cht-datasource. (#9237)
  2. Add functionality of getting people as an iterator in the cht-datasource. (#9238)
  3. Add functionality of getting places with pagination in the cht-datasource. (#9239)
  4. Add functionality of getting places as an iterator in the cht-datasource. (#9240)
  5. Add API api/v1/person. (#9241)
  6. Add API api/v1/place?type=clinic (#9242)
sugat009 commented 4 days ago

I will be pushing each sub-task changes to this branch 9193-api-endpoints-for-getting-contacts-by-type.