@openfn/language-dhis2 6.0.0 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -73
- package/ast.json +7 -7
- package/package.json +2 -2
- package/types/Adaptor.d.ts +7 -7
package/README.md
CHANGED
|
@@ -1,98 +1,107 @@
|
|
|
1
1
|
# Language DHIS2
|
|
2
2
|
|
|
3
|
-
An OpenFn language
|
|
4
|
-
|
|
5
|
-
[
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
An OpenFn language pack for building expressions and operations to work with the
|
|
4
|
+
[DHIS2 API](https://docs.dhis2.org/en/home.html). Commonly used via
|
|
5
|
+
[OpenFn.org](https://app.openfn.org) or manually with
|
|
6
|
+
[OpenFn CLI](https://github.com/OpenFn/kit).
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
1. [Getting Started](#getting-started)
|
|
11
|
+
2. [Important Note](#important-note)
|
|
12
|
+
3. [Configuration](#configuration)
|
|
13
|
+
4. [Helper Functions](#helper-functions)
|
|
14
|
+
5. [Development](#development)
|
|
15
|
+
- [Running Tests](#running-tests)
|
|
16
|
+
- [Unit Tests](#unit-tests)
|
|
17
|
+
- [Integration Tests](#integration-tests)
|
|
18
|
+
- [Troubleshooting Tests](#troubleshooting-tests)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Getting Started
|
|
23
|
+
|
|
24
|
+
To use this package, execute commands via OpenFn/core from the root of the
|
|
25
|
+
repository:
|
|
8
26
|
|
|
9
27
|
```sh
|
|
10
|
-
|
|
11
|
-
-l ../language-dhis2 \
|
|
12
|
-
-e ./tmp/expression.js \
|
|
13
|
-
-s ./tmp/state.json \
|
|
14
|
-
-o ./tmp/output.json
|
|
28
|
+
openfn job.js -a dhis2 -s tmp/state.json
|
|
15
29
|
```
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
> API versions before 42 (2.42). For later API versions and the new tracker, use
|
|
20
|
-
> adaptor 6.0+. See
|
|
21
|
-
> [DHIS2 documentation](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/tracker.html)
|
|
22
|
-
> for more information.
|
|
31
|
+
For installation and usage, see the
|
|
32
|
+
[docs site](https://docs.openfn.org/adaptors/packages/dhis2-docs).
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
---
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
full technical documentation.
|
|
36
|
+
## Important Note
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
the
|
|
31
|
-
[
|
|
32
|
-
|
|
38
|
+
- For DHIS2 API versions 2.42+ and the **new tracker**, use **adaptor 6.0+**.
|
|
39
|
+
Refer to the
|
|
40
|
+
[DHIS2 API documentation](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/tracker.html)
|
|
41
|
+
for details.
|
|
42
|
+
- For **old tracker versions** and DHIS2 API versions **prior to 2.42**, use
|
|
43
|
+
**adaptor 5.0+**. But we highly recommend upgrading to the latest version.
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
---
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
official
|
|
38
|
-
[configuration-schema](https://docs.openfn.org/adaptors/packages/dhis2-configuration-schema/)
|
|
39
|
-
definition.
|
|
47
|
+
## Configuration
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
All required and optional properties for `state.configuration` are defined in
|
|
50
|
+
the official
|
|
51
|
+
[configuration-schema](https://docs.openfn.org/adaptors/packages/dhis2-configuration-schema/).
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
also contain integration tests which can be run with
|
|
45
|
-
`pnpm run integration-test`.)
|
|
53
|
+
Ensure you configure:
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
- **Username**: DHIS2 admin username
|
|
56
|
+
- **Password**: Corresponding DHIS2 admin password
|
|
57
|
+
- **Host URL**: URL of the DHIS2 instance
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
changes by running `pnpm build docs`
|
|
59
|
+
Example configuration:
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"username": "admin",
|
|
64
|
+
"password": "district",
|
|
65
|
+
"hostUrl": "https://play.dhis2.org/2.36.6"
|
|
66
|
+
}
|
|
67
|
+
```
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
such as:
|
|
69
|
+
---
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
> API?
|
|
71
|
+
## Helper Functions
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
Helper functions simplify common DHIS2 operations. View the
|
|
74
|
+
[complete function documentation](https://docs.openfn.org/adaptors/packages/dhis2-docs).
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
### Running Tests
|
|
79
|
+
|
|
80
|
+
To run unit and integration tests, use the following commands:
|
|
81
|
+
|
|
82
|
+
- **Unit Tests**: `pnpm test`
|
|
83
|
+
- **Integration Tests**: `pnpm test:integration`
|
|
65
84
|
|
|
66
|
-
|
|
85
|
+
_Note: Integration tests depend on a live DHIS2 instance._
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
### Unit Tests
|
|
88
|
+
|
|
89
|
+
Unit tests validate helper functions independently. For example:
|
|
70
90
|
|
|
71
|
-
|
|
91
|
+
- Does `create('events', payload)` perform a correct POST request?
|
|
72
92
|
|
|
73
|
-
|
|
74
|
-
> DHIS2 system?
|
|
93
|
+
Add new unit tests whenever helper functions are updated.
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
network I/O and a public connection to a DHIS2 "play" server so their timing and
|
|
78
|
-
performance is unpredictable. Consider adding an increased timeout, and
|
|
79
|
-
modifying the orgUnit, program, etc., IDs set in `globalState`.
|
|
95
|
+
### Integration Tests
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
Integration tests validate end-to-end behavior with a live DHIS2 instance.
|
|
98
|
+
Ensure your test environment includes:
|
|
82
99
|
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
- At least one **organisation unit**.
|
|
101
|
+
- One **program** and a corresponding **program stage**.
|
|
102
|
+
- A **tracked entity instance** enrolled in the program.
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
depend on the **configuration of a target DHIS2 instance**. Currently you need
|
|
89
|
-
to have at least one organisation unit with one program, one
|
|
90
|
-
trackedEntityInstance and one programStage in it. These components need to be
|
|
91
|
-
well configured for the integration tests to work. For example: the
|
|
92
|
-
trackedEntityInstance need to be enrolled to the program, which should be
|
|
93
|
-
created in that organisation unit and contains at least that programStage. If
|
|
94
|
-
the tests fail, you must adjust these attributes in the
|
|
95
|
-
[before hook](https://github.com/OpenFn/adaptors/tree/main/packages/dhis2/test/integration.js):
|
|
104
|
+
Modify `globalState` in `test/integration.js` as needed:
|
|
96
105
|
|
|
97
106
|
```javascript
|
|
98
107
|
before(done => {
|
|
@@ -111,10 +120,14 @@ before(done => {
|
|
|
111
120
|
});
|
|
112
121
|
```
|
|
113
122
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
### Troubleshooting Tests
|
|
124
|
+
|
|
125
|
+
- **Timeout Errors**: Increase the global timeout in `test/mocha.opts`.
|
|
126
|
+
- **Environment Issues**: Ensure DHIS2 components (programs, org units, etc.)
|
|
127
|
+
are correctly configured.
|
|
128
|
+
|
|
129
|
+
---
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
For further technical details, see the
|
|
132
|
+
[documentation](https://docs.openfn.org/adaptors/packages/dhis2-docs) or contact
|
|
133
|
+
the [OpenFn community](https://community.openfn.org).
|
package/ast.json
CHANGED
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
{
|
|
89
89
|
"title": "example",
|
|
90
90
|
"description": "create('trackedEntities', {\n orgUnit: 'TSyzvBiovKh',\n trackedEntityType: 'nEenWmSyUEp',\n attributes: [\n {\n attribute: 'w75KJ2mc4zz',\n value: 'Gigiwe',\n },\n ]\n});",
|
|
91
|
-
"caption": "Create a single tracker entity. See
|
|
91
|
+
"caption": "Create a single tracker entity. See [Create tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)"
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
"title": "example",
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
{
|
|
234
234
|
"title": "example",
|
|
235
235
|
"description": "update('trackedEntities', '', {\n createdAt: '2015-08-06T21:12:37.256',\n orgUnit: 'TSyzvBiovKh',\n createdAtClient: '2015-08-06T21:12:37.256',\n trackedEntity: 'IeQfgUtGPq2',\n trackedEntityType: 'nEenWmSyUEp',\n inactive: false,\n deleted: false,\n featureType: 'NONE',\n programOwners: [\n {\n ownerOrgUnit: 'TSyzvBiovKh',\n program: 'IpHINAT79UW',\n trackedEntity: 'IeQfgUtGPq2',\n },\n ],\n attributes: [\n {\n lastUpdated: '2016-01-12T00:00:00.000',\n displayName: 'Last name',\n created: '2016-01-12T00:00:00.000',\n valueType: 'TEXT',\n attribute: 'zDhUuAYrxNC',\n value: 'Russell',\n },\n {\n lastUpdated: '2016-01-12T00:00:00.000',\n code: 'MMD_PER_NAM',\n displayName: 'First name',\n created: '2016-01-12T00:00:00.000',\n valueType: 'TEXT',\n attribute: 'w75KJ2mc4zz',\n value: 'Catherine',\n },\n ],\n});",
|
|
236
|
-
"caption": "Update a tracker entity. See
|
|
236
|
+
"caption": "Update a tracker entity. See [Update tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)"
|
|
237
237
|
},
|
|
238
238
|
{
|
|
239
239
|
"title": "example",
|
|
@@ -363,22 +363,22 @@
|
|
|
363
363
|
{
|
|
364
364
|
"title": "example",
|
|
365
365
|
"description": "get('tracker/trackedEntities/F8yKM85NbxW');",
|
|
366
|
-
"caption": "Get a single tracked entity given the provided ID. See
|
|
366
|
+
"caption": "Get a single tracked entity given the provided ID. See [TrackedEntities docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#tracked-entities-get-apitrackertrackedentities)"
|
|
367
367
|
},
|
|
368
368
|
{
|
|
369
369
|
"title": "example",
|
|
370
370
|
"description": "get('tracker/enrollments/abcd');",
|
|
371
|
-
"caption": "Get an enrollment given the provided ID. See
|
|
371
|
+
"caption": "Get an enrollment given the provided ID. See [Enrollment docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#enrollments-get-apitrackerenrollments)"
|
|
372
372
|
},
|
|
373
373
|
{
|
|
374
374
|
"title": "example",
|
|
375
375
|
"description": "get('tracker/events');",
|
|
376
|
-
"caption": "Get all events matching given criteria. See
|
|
376
|
+
"caption": "Get all events matching given criteria. See [Events docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#events-get-apitrackerevents)"
|
|
377
377
|
},
|
|
378
378
|
{
|
|
379
379
|
"title": "example",
|
|
380
380
|
"description": "get('tracker/relationships', {\n trackedEntity:['F8yKM85NbxW'],\n});",
|
|
381
|
-
"caption": "Get the relationship between two tracker entities. The only required parameters are 'trackedEntity', 'enrollment' or 'event'. See
|
|
381
|
+
"caption": "Get the relationship between two tracker entities. The only required parameters are 'trackedEntity', 'enrollment' or 'event'. See [Relationships docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#relationships-get-apitrackerrelationships)"
|
|
382
382
|
}
|
|
383
383
|
]
|
|
384
384
|
},
|
|
@@ -848,7 +848,7 @@
|
|
|
848
848
|
{
|
|
849
849
|
"title": "example",
|
|
850
850
|
"description": "destroy('trackedEntities', 'LcRd6Nyaq7T');",
|
|
851
|
-
"caption": "a tracked entity instance. See
|
|
851
|
+
"caption": "a tracked entity instance. See [Delete tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)"
|
|
852
852
|
}
|
|
853
853
|
]
|
|
854
854
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-dhis2",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "DHIS2 Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"axios": "^1.7.7",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"qs": "^6.11.0",
|
|
31
|
-
"@openfn/language-common": "2.
|
|
31
|
+
"@openfn/language-common": "2.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"assertion-error": "2.0.0",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function execute(...operations: Operations): Operation;
|
|
|
33
33
|
* orgUnit: 'DiszpKrYNg8',
|
|
34
34
|
* status: 'COMPLETED',
|
|
35
35
|
* });
|
|
36
|
-
* @example <caption>Create a single tracker entity. See
|
|
36
|
+
* @example <caption>Create a single tracker entity. See [Create tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)</caption>
|
|
37
37
|
* create('trackedEntities', {
|
|
38
38
|
* orgUnit: 'TSyzvBiovKh',
|
|
39
39
|
* trackedEntityType: 'nEenWmSyUEp',
|
|
@@ -162,7 +162,7 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
|
|
|
162
162
|
* storedBy: 'admin',
|
|
163
163
|
* dataValues: [],
|
|
164
164
|
* });
|
|
165
|
-
* @example <caption>Update a tracker entity. See
|
|
165
|
+
* @example <caption>Update a tracker entity. See [Update tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)</caption>
|
|
166
166
|
* update('trackedEntities', '', {
|
|
167
167
|
* createdAt: '2015-08-06T21:12:37.256',
|
|
168
168
|
* orgUnit: 'TSyzvBiovKh',
|
|
@@ -287,13 +287,13 @@ export function update(resourceType: string, path: string, data: any, options?:
|
|
|
287
287
|
* });
|
|
288
288
|
* @example <caption>Get all programs for an organization unit</caption>
|
|
289
289
|
* get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
|
|
290
|
-
* @example <caption>Get a single tracked entity given the provided ID. See
|
|
290
|
+
* @example <caption>Get a single tracked entity given the provided ID. See [TrackedEntities docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#tracked-entities-get-apitrackertrackedentities)</caption>
|
|
291
291
|
* get('tracker/trackedEntities/F8yKM85NbxW');
|
|
292
|
-
* @example <caption>Get an enrollment given the provided ID. See
|
|
292
|
+
* @example <caption>Get an enrollment given the provided ID. See [Enrollment docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#enrollments-get-apitrackerenrollments)</caption>
|
|
293
293
|
* get('tracker/enrollments/abcd');
|
|
294
|
-
* @example <caption>Get all events matching given criteria. See
|
|
294
|
+
* @example <caption>Get all events matching given criteria. See [Events docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#events-get-apitrackerevents)</caption>
|
|
295
295
|
* get('tracker/events');
|
|
296
|
-
* @example <caption>Get the relationship between two tracker entities. The only required parameters are 'trackedEntity', 'enrollment' or 'event'. See
|
|
296
|
+
* @example <caption>Get the relationship between two tracker entities. The only required parameters are 'trackedEntity', 'enrollment' or 'event'. See [Relationships docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#relationships-get-apitrackerrelationships)</caption>
|
|
297
297
|
* get('tracker/relationships', {
|
|
298
298
|
* trackedEntity:['F8yKM85NbxW'],
|
|
299
299
|
* });
|
|
@@ -390,7 +390,7 @@ export function patch(resourceType: string, path: string, data: any, options?: a
|
|
|
390
390
|
* @param {{apiVersion: number,operationName: string,resourceType: string}} [options] - Optional `options` for `del` operation including params e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}. Defaults to `{operationName: 'delete', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
|
|
391
391
|
* @param {function} [callback] - Optional callback to handle the response
|
|
392
392
|
* @returns {Operation}
|
|
393
|
-
* @example <caption>a tracked entity instance. See
|
|
393
|
+
* @example <caption>a tracked entity instance. See [Delete tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)</caption>
|
|
394
394
|
* destroy('trackedEntities', 'LcRd6Nyaq7T');
|
|
395
395
|
*/
|
|
396
396
|
export function destroy(resourceType: string, path: string, data?: any, options?: {
|