@openfn/language-dhis2 3.0.0-0 → 3.0.0

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 CHANGED
@@ -1,13 +1,28 @@
1
- # Language DHIS2 [![Build Status](https://travis-ci.org/OpenFn/language-dhis2.svg?branch=main)](https://travis-ci.org/OpenFn/language-dhis2)
1
+ # Language DHIS2 [<img src="https://avatars2.githubusercontent.com/u/9555108?s=200&v=4)" alt="alt text" height="20">](https://www.openfn.org) [![CircleCI](https://circleci.com/gh/OpenFn/language-dhis2.svg?style=svg)](https://circleci.com/gh/OpenFn/language-dhis2)
2
2
 
3
- Language Pack for building expressions and operations for working with the
3
+ An OpenFn language Pack for building expressions and operations for working with
4
+ the
4
5
  [DHIS2 API](http://dhis2.github.io/dhis2-docs/master/en/developer/html/dhis2_developer_manual.html).
6
+ Used most commonly via OpenFn.org or by hand with
7
+ [OpenFn/core](https://github.com/OpenFn/core) from the root of this repo:
8
+
9
+ ```sh
10
+ core execute \
11
+ -l ../language-dhis2 \
12
+ -e ./tmp/myExpressions.js \
13
+ -s ./tmp/state.json \
14
+ -o ./tmp/output.json
15
+ ```
5
16
 
6
17
  ## Documentation
7
18
 
8
19
  View the [docs site](https://openfn.github.io/language-dhis2/) for full
9
- technical documentation. Below, find a samples of the most commonly used helper
10
- functions.
20
+ technical documentation.
21
+
22
+ There are lots of **examples** for how to use the various helper functions on
23
+ the main
24
+ [Adaptor docs](https://openfn.github.io/language-dhis2/module-Adaptor.html)
25
+ page.
11
26
 
12
27
  ## Sample State
13
28
 
@@ -16,165 +31,25 @@ functions.
16
31
  "configuration": {
17
32
  "username": "admin",
18
33
  "password": "district",
19
- "hostUrl": "https://play.dhis2.org/2.35.1"
34
+ "hostUrl": "https://play.dhis2.org/2.36.6"
20
35
  },
21
- "data": {
22
- "a": 1,
23
- "b": 2
24
- }
36
+ "data": { "a": 1, "b": 2 }
25
37
  }
26
38
  ```
27
39
 
28
- ## Analytics API
29
-
30
- #### Fetch analytics data for PMTCT data over last 6 months.
31
-
32
- ```js
33
- fetchAnalytics({
34
- query: {
35
- dimension: ['dx:CYI5LEmm3cG;GDVU1o5rTNF', 'pe:LAST_6_MONTHS'],
36
- filter: 'ou:GHlyx9Pg9mn',
37
- displayProperty: 'NAME',
38
- outputIdScheme: 'UID',
39
- },
40
- });
41
- ```
42
-
43
- ## Tracked Entity API
44
-
45
- #### Create a new tracked entity instance and enroll them from a CommCare form submission.
46
-
47
- ```js
48
- createTEI({
49
- trackedEntityType: 'nEenWmSyUEp',
50
- orgUnit: 'g8upMTyEZGZ',
51
- attributes: [
52
- {
53
- attribute: 'w75KJ2mc4zz',
54
- value: dataValue('form.first_name')(state),
55
- },
56
- {
57
- attribute: 'zDhUuAYrxNC',
58
- value: dataValue('form.last_name')(state),
59
- },
60
- ],
61
- enrollments: [
62
- {
63
- orgUnit: 'g8upMTyEZGZ',
64
- program: 'IpHINAT79UW',
65
- enrollmentDate: '2019-04-08',
66
- incidentDate: '2019-04-08',
67
- },
68
- ],
69
- });
70
- ```
71
-
72
- #### Upsert a tracked entity instance from a CommCare form submission.
73
-
74
- ```js
75
- upsertTEI(
76
- 'w75KJ2mc4zz', // match on 'patientID', a custom external ID in dhis2
77
- {
78
- trackedEntityType: 'nEenWmSyUEp',
79
- orgUnit: 'g8upMTyEZGZ',
80
- attributes: [
81
- {
82
- attribute: 'w75KJ2mc4zz',
83
- value: dataValue('form.first_name')(state),
84
- },
85
- {
86
- attribute: 'zDhUuAYrxNC',
87
- value: dataValue('form.last_name')(state),
88
- },
89
- ],
90
- }
91
- );
92
- ```
93
-
94
- ## Events API
95
-
96
- #### `Events API` expression
97
-
98
- ```js
99
- event(
100
- fields(
101
- field("program", "eBAyeGv0exc"),
102
- field("orgUnit", "DiszpKrYNg8"),
103
- field("eventDate", dataValue("date")),
104
- field("status", "COMPLETED"),
105
- field("storedBy", "admin"),
106
- field("coordinate", {
107
- "latitude": "59.8",
108
- "longitude": "10.9"
109
- }),
110
- field("dataValues", function(state) {
111
- return [
112
- dataElement("qrur9Dvnyt5", dataValue("prop_a"))(state)
113
- dataElement("oZg33kd9taw", dataValue("prop_b"))(state)
114
- dataElement("msodh3rEMJa", dataValue("prop_c"))(state)
115
- ]
116
- })
117
- )
118
- )
119
- ```
120
-
121
- #### Current `fetchEvents API` expression (Optional `postUrl` for a complete fetch)
122
-
123
- ```js
124
- fetchEvents({
125
- fields: {
126
- orgUnit: 'DiszpKrYNg8',
127
- program: 'eBAyeGv0exc',
128
- endDate: '2016-01-01',
129
- },
130
- postUrl: 'https://www.openfn.org/inbox/123',
131
- });
132
- ```
133
-
134
- #### Reference on how to query and read events https://docs.dhis2.org/2.22/en/developer/html/ch01s15.html#d5e1994
135
-
136
- ## Data Values / Data Value Sets API
137
-
138
- #### Current `DataValueSets API` expression
139
-
140
- ```js
141
- dataValueSet({
142
- dataSet: dataValue('set'),
143
- orgUnit: 'DiszpKrYNg8',
144
- period: '201402',
145
- completeData: '2014-03-03',
146
- dataValues: [
147
- dataElement('f7n9E0hX8qk', dataValue('data[0].site_school_number')),
148
- dataElement('Ix2HsbDMLea', dataValue('age')),
149
- dataElement('eY5ehpbEsB7', 30),
150
- ],
151
- });
152
- ```
153
-
154
- #### Current `fetchData API` expression (Optional `postUrl` for a complete fetch)
155
-
156
- ```js
157
- fetchData({
158
- fields: {
159
- dataSet: 'pBOMPrpg1QX',
160
- orgUnit: 'DiszpKrYNg8',
161
- period: '201711',
162
- },
163
- postUrl: 'https://www.openfn.org/inbox/123',
164
- });
165
- ```
166
-
167
- #### Reference on how to read data values https://docs.dhis2.org/2.22/en/developer/html/ch01s13.html#d5e1642
168
-
169
- [Docs](docs/index)
170
-
171
40
  ## Development
172
41
 
173
- Clone the repo, run `npm install`.
42
+ Clone the repo and run `npm install`.
43
+
44
+ Run tests using `npm run test` or `npm run test:watch`. (NB: that this repo also
45
+ contain integration tests which can be run with `npm run integration-test`.)
174
46
 
175
- Run tests using `npm run test` or `npm run test:watch`
47
+ ⚠️ NB: Make changes to the files in `src/` and then use `npm run build` to
48
+ generate output files in `lib/`.
176
49
 
177
- NB: There are two types of tests: unit tests and integration tests.
50
+ The documentation is autogenerated, so please **rebuild the docs** after making
51
+ changes by running
52
+ `./node_modules/.bin/jsdoc --readme ./README.md ./lib -d docs`
178
53
 
179
54
  ### Unit Tests
180
55
 
@@ -191,22 +66,56 @@ needs to be added.
191
66
 
192
67
  ### End-to-end integration tests
193
68
 
194
- Integration tests allow us to test the end-to-end behavior of the helper functions
195
- and also to test the examples we provide via inline documentation.
69
+ Integration tests allow us to test the end-to-end behavior of the helper
70
+ functions and also to test the examples we provide via inline documentation.
196
71
 
197
72
  For example with integration tests we answer the following question:
198
73
 
199
74
  > Does `create('events', eventPayload)` actually create a new event in a live
200
75
  > DHIS2 system?
201
76
 
202
- To run integration tests, execute `npm run integration-test`. These
203
- tests use network I/O and a public connection to a DHIS2 "play" server so their
204
- timing and performance is unpredictable. Consider adding an increased timeout,
205
- and modifying the orgUnit, program, etc., IDs set in `globalState`.
206
-
207
- Anytime a new example is added in the documentation of a helper function, a new
208
- integration test should be done.
77
+ To run integration tests, execute `npm run integration-test`. These tests use
78
+ network I/O and a public connection to a DHIS2 "play" server so their timing and
79
+ performance is unpredictable. Consider adding an increased timeout, and
80
+ modifying the orgUnit, program, etc., IDs set in `globalState`.
81
+
82
+ #### Troubleshooting the tests
83
+
84
+ - Depending on your internet strength please consider changing the **global
85
+ timeout** in the `test/mocha.opts` file to avoid faillures related to network
86
+ timeouts.
87
+
88
+ - The behavior of the tests in `test/integration.js` is very unpredictable; they
89
+ depend on the **configuration of a target DHIS2 instance**. Currently you need
90
+ to have at least one organisation unit with one program, one
91
+ trackedEntityInstance and one programStage in it. These components need to be
92
+ well configured for the integration tests to work. For example: the
93
+ trackedEntityInstance need to be enrolled to the program, which should be
94
+ created in that organisation unit and contains at least that programStage. If
95
+ the tests fail, you must adjust these attributes in the
96
+ [before hook](test/integration.js):
97
+
98
+ ```javascript
99
+ before(done => {
100
+ fixture.initialState = {
101
+ configuration: {
102
+ username: 'admin',
103
+ password: 'district',
104
+ hostUrl: 'https://play.dhis2.org/2.36.6',
105
+ },
106
+ program: 'IpHINAT79UW',
107
+ orgUnit: 'DiszpKrYNg8',
108
+ trackedEntityInstance: 'uhubxsfLanV',
109
+ programStage: 'eaDHS084uMp',
110
+ };
111
+ done();
112
+ });
113
+ ```
209
114
 
210
- ### Build
115
+ - Make sure the `update` and `upsert` integration tests don't affect those
116
+ initial organisation units, programs, programStage and trackedEntityInstance
117
+ required. Otherwise the create integration tests would be broken again; and
118
+ that's an endless faillure loop :(
211
119
 
212
- Build the project using `npm run build`.
120
+ Anytime a new example is added in the documentation of a helper function, a new
121
+ integration test should be built.