Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
99c6347
add support for PAT tokens
eperedo Jun 11, 2025
34a44db
update version
eperedo Jun 11, 2025
409975b
add PAT support for axios, update readme file
eperedo Jun 11, 2025
5506e2e
Minor refactors
tokland Jun 12, 2025
55eb88c
fix version number
tokland Jun 12, 2025
23e6266
Pass extra options to yarn publish
tokland Jun 12, 2025
13cc6a1
Added patch mehtod
idelcano Jun 13, 2025
7fd01b7
fix type for users and userGroups in sharing schema
eperedo Jun 16, 2025
31e90b5
Add all the options in /analytics/enrollments/query/ endpoint accordi…
anagperal Jul 24, 2025
0f4db44
Use cross-fetch for node 18
tokland Jul 28, 2025
b6a00fe
Remove formData.getHeaders(), not implemented in browser
tokland Jul 29, 2025
558fae7
Use wrapper to support fetch in browser
tokland Jul 29, 2025
02fd00f
add agent support for fetch backend
eperedo Aug 1, 2025
f59ce6a
update package version
eperedo Aug 1, 2025
2ff1b40
Merge pull request #171 from EyeSeeTea/feature/add_patch_method
ifoche Aug 6, 2025
92845ab
Use post body on email notification message
tokland Aug 13, 2025
6a7c2da
Add PATCH request method to D2ApiGeneric and to Model. Change patch m…
anagperal Aug 13, 2025
10f15f3
Remove unused PATCH_HEADERS
anagperal Aug 13, 2025
9f9b5b9
Add info for PATCH, improve README and use only one type of response …
anagperal Aug 19, 2025
c530992
Merge pull request #169 from EyeSeeTea/feature/add-pat-token-support-…
adrianq Aug 19, 2025
795d478
Merge branch 'development' into fix/sharing-type-users-groups-8698pp7br
adrianq Aug 19, 2025
493ceb3
Merge pull request #170 from EyeSeeTea/fix/sharing-type-users-groups-…
adrianq Aug 19, 2025
a9a5f21
Merge pull request #173 from EyeSeeTea/feature/support-node-fetch-18
adrianq Aug 19, 2025
279f8a9
Merge remote-tracking branch 'origin/development' into feature/fetch-…
tokland Aug 19, 2025
4e4774d
Merge pull request #174 from EyeSeeTea/feature/fetch-proxy-agent-8698…
adrianq Aug 19, 2025
7ac528b
Merge pull request #175 from EyeSeeTea/feature/send-email-on-post-body
adrianq Aug 19, 2025
d5f0e5e
Merge pull request #176 from EyeSeeTea/feature/add-patch-d2Api-and-model
adrianq Aug 19, 2025
c130047
Merge branch 'development' into enhancement/analytics-enrollments-que…
anagperal Aug 24, 2025
0de03fa
Add descriptions and add conditionals with pagination
anagperal Aug 25, 2025
3bd2a0a
Delete test
anagperal Aug 25, 2025
5a835bb
Generate 2.41 schemas
anagperal Sep 2, 2025
088e9e2
feat: To keep schema types stable, sort properties and unions
tokland Sep 2, 2025
b31d9de
Merge pull request #172 from EyeSeeTea/enhancement/analytics-enrollme…
adrianq Sep 15, 2025
557cf74
Merge pull request #178 from EyeSeeTea/feature/api-schema-v41
adrianq Sep 15, 2025
df82d5f
bump version
adrianq Sep 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 119 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ $ yarn publish [--tag beta] [--patch | --minor | --major]
```ts
import { D2Api } from "d2-api/2.36";

// Basic access authentication
const api = new D2Api({
baseUrl: "https://play.im.dhis2.org/dev",
auth: { username: "admin", password: "district" },
auth: { type: "basic", username: "admin", password: "district" },
});

// Personal Access Token (PAT) authentication
const api = new D2Api({
baseUrl: "https://play.im.dhis2.org/dev",
auth: { type: "personalToken", token: "token_here" },
});
```

Learn more about [PAT authentication here](https://docs.dhis2.org/en/full/develop/dhis-core-version-240/developer-manual.html#webapi_pat_authentication)

### Metadata models

#### GET single (by ID)
Expand Down Expand Up @@ -118,6 +127,84 @@ const response = await api.models.dataSets
.getData();
```

#### PATCH (JSON Patch operations)

The patch method supports the following operations according to [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) and DHIS2 extensions. The `path` field uses [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) syntax:

- **`add`**: Adds a value to an object or array
- **`remove`**: Removes a value from an object or array
- **`replace`**: Replaces a value in an object or array
- **`remove-by-id`**: DHIS2-specific operation to remove an item by ID from an array

```ts
// Examples of different patch operations
const patchOperations = [
// Add a new property
{ op: "add", path: "/description", value: "New Description" },

// Add to end of array (using -)
{ op: "add", path: "/users/-", value: { id: "FVsLhslRbTK" } },

// Add to specific array index (0 is the array index)
{ op: "add", path: "/users/0", value: { id: "FVsLhslRbTK" } },

// Replace existing property
{ op: "replace", path: "/name", value: "Updated Name" },

// Remove property
{ op: "remove", path: "/description" },

// Remove array item by index (1 is the array index)
{ op: "remove", path: "/users/1" },

// DHIS2-specific: Remove array item by ID
{ op: "remove-by-id", path: "/users", id: "FVsLhslRbTK" },
];
```

```ts
// Patch dataSets
const response = await api.models.dataSets
.patch("BfMAe6Itzgt", [
{ op: "replace", path: "/name", value: "Updated Child Health" },
{ op: "add", path: "/code", value: "DS_359711_NEW" },
{ op: "remove", path: "/description" },
{ op: "add", path: "/dataSetElements/-", value: { id: "x3Do5e7g4Qo" } },
{ op: "remove-by-id", path: "/organisationUnits", id: "TGRCfJEnXJr" },
])
.getData();

// Patch users
const userResponse = await api.models.users
.patch("gEnZri18JsV", [
{ op: "replace", path: "/name", value: "Ali new" },
{ op: "add", path: "/email", value: "ali.dummy@dhis2.org" },
{ op: "replace", path: "/disabled", value: true },
])
.getData();

// Patch data elements
const elementResponse = await api.models.dataElements
.patch("fbfJHSPpUQD", [
{ op: "replace", path: "/name", value: "ANC first visit" },
{ op: "replace", path: "/valueType", value: "INTEGER" },
{ op: "add", path: "/domainType", value: "TRACKER" },
{ op: "add", path: "/dataElementGroups/-", value: { id: "k1M0nuodfhN" } },
{ op: "remove-by-id", path: "/dataElementGroups", id: "k1M0nuodfhN" },
])
.getData();

// Patch organisation units
const orgUnitResponse = await api.models.organisationUnits
.patch("bL4ooGhyHRQ", [
{ op: "replace", path: "/name", value: "New Pujehun Name" },
{ op: "add", path: "/code", value: "OU_260377_NEW" },
{ op: "remove-by-id", path: "/children", id: "RzKeCma9qb1" },
{ op: "add", path: "/children/-", value: { id: "RzKeCma9qb1" } },
])
.getData();
```

### Metadata

#### GET
Expand Down Expand Up @@ -184,9 +271,37 @@ const analyticsData = await api.analytics

```ts
const analyticsData = await api.analytics
.getEnrollmentsQuery("IpHINAT79UW", {
dimension: ["GxdhnY5wmHq", "ou:ImspTQPwCqd"],
enrollmentDate: "LAST_12_MONTHS,THIS_MONTH",
.getEnrollmentsQuery({
programId: "IpHINAT79UW",
dimension: ["cejWyOfXge6", "lZGmxYbs97q", "ou:USER_ORGUNIT", "w75KJ2mc4zz", "zDhUuAYrxNC"],
programStatus: "ACTIVE",
})
.getData();
```

Disable pagination:

```ts
const analyticsData = await api.analytics
.getEnrollmentsQuery({
programId: "IpHINAT79UW",
dimension: ["cejWyOfXge6", "lZGmxYbs97q", "ou:USER_ORGUNIT", "w75KJ2mc4zz", "zDhUuAYrxNC"],
programStatus: "ACTIVE",
paging: false,
})
.getData();
```

Get pagination and total pages:

```ts
const analyticsData = await api.analytics
.getEnrollmentsQuery({
programId: "IpHINAT79UW",
dimension: ["cejWyOfXge6", "lZGmxYbs97q", "ou:USER_ORGUNIT", "w75KJ2mc4zz", "zDhUuAYrxNC"],
programStatus: "ACTIVE",
paging: true,
totalPages: true,
})
.getData();
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eyeseetea/d2-api",
"description": "Typed wrapper over DHIS2 API",
"version": "1.19.1",
"version": "1.20.0",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_opts=$(if echo "$version" | grep -q beta; then echo "--tag beta"; fi)

yarn clean
yarn build
yarn publish $publish_opts --new-version "$version" build/
yarn publish $publish_opts --new-version "$version" "$@" build/

git tag "v$version" -f -m "Bump version"
git push --tags
Loading
Loading