Missing orderby clause in TrackedEntityInstance Ids query

Hi DHIS team,

We are hitting the below API to fetch TrackedEntityInstance(TEI) Ids

http:///api/25/trackedEntityInstances?eventEndDate=2018-06-03&eventStartDate=2018-03-18&fields=trackedEntityInstance&ou=a2620f76786&ouMode=DESCENDANTS&page=1&pageSize=1000&totalPages=true

The above API call will give first 1000 TEI ids because the call is paginated with pagesize=1000. Like that we are making calls for other pages to fetch all the TEI Ids.

DHIS is using the below query to get the TEI ids

select distinct tei from TrackedEntityInstance tei left join tei.trackedEntityAttributeValues where ( tei.organisationUnit.path LIKE ‘/a2cf79e8g34/a1c343a3w24%’) and tei.deleted is false;

In this query we couldn’t find any order by clause. Is there any chance that few of the TEI ids which are returned in some page are going to be repeated in another page also.

Is this query going to be executed every time for each paginated API call?

···

Rajeswari Gottipati
Sr Consultant
Email
rajeswag@thoughtworks.com
Telephone
+91 9949292931
ThoughtWorks

Hi

Postgres should return the results in row-order if no order by clause is specified, so it should be OK. You can always specify additional ordering if you need it.

···

On Thu, Jun 7, 2018 at 8:54 AM, Rajeswari Gottipati rajeswag@thoughtworks.com wrote:

Hi DHIS team,

We are hitting the below API to fetch TrackedEntityInstance(TEI) Ids

http:///api/25/trackedEntityInstances?eventEndDate=2018-06-03&eventStartDate=2018-03-18&fields=trackedEntityInstance&ou=a2620f76786&ouMode=DESCENDANTS&page=1&pageSize=1000&totalPages=true

The above API call will give first 1000 TEI ids because the call is paginated with pagesize=1000. Like that we are making calls for other pages to fetch all the TEI Ids.

DHIS is using the below query to get the TEI ids

select distinct tei from TrackedEntityInstance tei left join tei.trackedEntityAttributeValues where ( tei.organisationUnit.path LIKE ‘/a2cf79e8g34/a1c343a3w24%’) and tei.deleted is false;

In this query we couldn’t find any order by clause. Is there any chance that few of the TEI ids which are returned in some page are going to be repeated in another page also.

Is this query going to be executed every time for each paginated API call?

Rajeswari Gottipati
Sr Consultant
Email
rajeswag@thoughtworks.com
Telephone
+91 9949292931
ThoughtWorks


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

Hi Morten,

Thanks for your inputs. Can you help us understanding how paginated API calls are going to be handled in DHIS side. For example,

If we make an API call to get first 1000 results i.e page1 – DHIS will hit the DB with some query and gives the results (please correct me if I am wrong here). Will it store the DB query results in-memory?

Subsequently if we make the same API call but for second 1000 i.e page2 – How DHIS returns the data this time. Will it hit the database again to get the data or will it get from in-memory?

If we want to add an additional “orderby” clause, is there any parameter in API to perform sorting or we have to add “orderby” clause in DHIS query.

Thanks,

Rajeswari.

···

On Thu, Jun 7, 2018 at 12:50 PM, Morten Olav Hansen morten@dhis2.org wrote:

Hi

Postgres should return the results in row-order if no order by clause is specified, so it should be OK. You can always specify additional ordering if you need it.


Rajeswari Gottipati
Sr Consultant
Email
rajeswag@thoughtworks.com
Telephone
+91 9949292931
ThoughtWorks

Morten Olav Hansen

Senior Engineer, DHIS 2

University of Oslo

http://www.dhis2.org

On Thu, Jun 7, 2018 at 8:54 AM, Rajeswari Gottipati rajeswag@thoughtworks.com wrote:

Hi DHIS team,

We are hitting the below API to fetch TrackedEntityInstance(TEI) Ids

http:///api/25/trackedEntityInstances?eventEndDate=2018-06-03&eventStartDate=2018-03-18&fields=trackedEntityInstance&ou=a2620f76786&ouMode=DESCENDANTS&page=1&pageSize=1000&totalPages=true

The above API call will give first 1000 TEI ids because the call is paginated with pagesize=1000. Like that we are making calls for other pages to fetch all the TEI Ids.

DHIS is using the below query to get the TEI ids

select distinct tei from TrackedEntityInstance tei left join tei.trackedEntityAttributeValues where ( tei.organisationUnit.path LIKE ‘/a2cf79e8g34/a1c343a3w24%’) and tei.deleted is false;

In this query we couldn’t find any order by clause. Is there any chance that few of the TEI ids which are returned in some page are going to be repeated in another page also.

Is this query going to be executed every time for each paginated API call?

Rajeswari Gottipati
Sr Consultant
Email
rajeswag@thoughtworks.com
Telephone
+91 9949292931
ThoughtWorks


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp