Skip to content

Conversation

@anagperal
Copy link
Contributor

@anagperal anagperal commented Jul 24, 2025

📌 References

📝 Implementation

  • Add all the options in /analytics/enrollments/query endpoint accordinng to documentation

📹 Screenshots/Screen capture

🔥 Notes to the tester

For example: to get total pages

curl -u admin:district 'https://play.im.dhis2.org/stable-2-41-4-2/api/41/analytics/enrollments/query/IpHINAT79UW?dimension=cejWyOfXge6,lZGmxYbs97q,ou%3AUSER_ORGUNIT,w75KJ2mc4zz,zDhUuAYrxNC&headers=ouname,w75KJ2mc4zz,cejWyOfXge6,zDhUuAYrxNC,lZGmxYbs97q&totalPages=true&rowContext=true&displayProperty=NAME&pageSize=100&page=1&includeMetadataDetails=true&outputType=ENROLLMENT' -sS | jq

For example: to filter by program status

curl -u admin:district 'https://play.im.dhis2.org/stable-2-41-4-2/api/41/analytics/enrollments/query/IpHINAT79UW?dimension=cejWyOfXge6,lZGmxYbs97q,ou%3AUSER_ORGUNIT,w75KJ2mc4zz,zDhUuAYrxNC&headers=ouname,w75KJ2mc4zz,cejWyOfXge6,zDhUuAYrxNC,lZGmxYbs97q&totalPages=false&rowContext=true&programStatus=ACTIVE&displayProperty=NAME&pageSize=100&page=1&includeMetadataDetails=true&outputType=ENROLLMENT' -sS | jq

For example: to get order by ouname asc

curl -u admin:district 'https://play.im.dhis2.org/stable-2-41-4-2/api/41/analytics/enrollments/query/IpHINAT79UW?dimension=cejWyOfXge6,lZGmxYbs97q,ou%3AUSER_ORGUNIT,w75KJ2mc4zz,zDhUuAYrxNC&headers=ouname,w75KJ2mc4zz,cejWyOfXge6,zDhUuAYrxNC,lZGmxYbs97q&totalPages=false&rowContext=true&programStatus=ACTIVE&displayProperty=NAME&pageSize=100&page=1&includeMetadataDetails=true&outputType=ENROLLMENT&asc=ouname'  -sS  | jq

@bundlemon
Copy link

bundlemon bot commented Jul 24, 2025

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
135.58KB (+1.07KB +0.8%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@anagperal anagperal requested review from adrianq and tokland July 24, 2025 11:11
Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

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

In-line comments:

page: number;
pageSize: number;
paging: boolean;
};
Copy link
Contributor

@tokland tokland Jul 28, 2025

Choose a reason for hiding this comment

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

Cool, so now we get .metaData.pager object, but we don't have types for the response, right? Is that something we want to implement at this point? (we would use conditional types, let me know if you have no experience with them)

asc?: AscDescParameter;
desc?: AscDescParameter;
coordinatesOnly?: boolean;
headers?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

string types are too unspecific. Docs "One or more headers name separated by comma". At the worst case, we can create an alias: "type HeadersSeparatedByCommas = string". Question: Are these headers known? (dx, dxname, pe, ...)

return this.d2Api.get<AnalyticsResponse>(
`/analytics/enrollments/query/${programId}`,
options as AnalyticsOptions
options as Omit<GetEnrollmentsQueryOptions, "programId">
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a bit confused as to why we needed to cast the options object, it seemed compatible with the type. Apparently, it comes from the early unpacking that extracts programId. So let's keep it simple: options: GetEnrollmentsQueryOptions and now the cast can be removed.

@anagperal anagperal requested a review from tokland August 25, 2025 05:42
auth: { type: "basic", username: "admin", password: "district" },
});

export async function test() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically we don't have unused functions in the code as usage demos, but it won't hurt. Hopefully one day we can add proper specs and move this there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my bad, these were the tests I used to check if the conditional was working properly, and I should not have uploaded them.

enrollmentDate: "LAST_12_MONTHS,THIS_MONTH",
paging: true,
totalPages: true,
skipData: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't the conditional conditional for skipMeta, right? no problem, it should not be a typical use case.

Copy link
Contributor Author

@anagperal anagperal Aug 25, 2025

Choose a reason for hiding this comment

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

I was going to do it, but since it didn't do anything if you set skipMeta to true or false, I haven't implemented it because I don't know if it affects any other fields appart from removing metaData (which would be logical, but just in case)

@adrianq adrianq merged commit b31d9de into development Sep 15, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants