@openfn/language-dhis2 5.0.8 → 6.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.
@@ -15,26 +15,26 @@ export function execute(...operations: Operations): Operation;
15
15
  * Create a record
16
16
  * @public
17
17
  * @function
18
- * @param {string} resourceType - Type of resource to create. E.g. `trackedEntityInstances`, `programs`, `events`, ...
18
+ * @param {string} resourceType - Type of resource to create. E.g. `trackedEntities`, `programs`, `events`, ...
19
19
  * @magic resourceType $.children.resourceTypes[*]
20
20
  * @param {Dhis2Data} data - Object which defines data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.
21
21
  * @param {Object} [options] - Optional `options` to define URL parameters via params (E.g. `filter`, `dimension` and other import parameters), request config (E.g. `auth`) and the DHIS2 apiVersion.
22
22
  * @param {function} [callback] - Optional callback to handle the response
23
23
  * @returns {Operation}
24
- * @example <caption>a program</caption>
24
+ * @example <caption>Create a program</caption>
25
25
  * create('programs', {
26
26
  * name: 'name 20',
27
27
  * shortName: 'n20',
28
28
  * programType: 'WITHOUT_REGISTRATION',
29
29
  * });
30
- * @example <caption>an event</caption>
30
+ * @example <caption>Create a single event</caption>
31
31
  * create('events', {
32
32
  * program: 'eBAyeGv0exc',
33
33
  * orgUnit: 'DiszpKrYNg8',
34
34
  * status: 'COMPLETED',
35
35
  * });
36
- * @example <caption>a trackedEntityInstance</caption>
37
- * create('trackedEntityInstances', {
36
+ * @example <caption>Create a single tracker entity. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import Create tracker docs}</caption>
37
+ * create('trackedEntities', {
38
38
  * orgUnit: 'TSyzvBiovKh',
39
39
  * trackedEntityType: 'nEenWmSyUEp',
40
40
  * attributes: [
@@ -44,7 +44,7 @@ export function execute(...operations: Operations): Operation;
44
44
  * },
45
45
  * ]
46
46
  * });
47
- * @example <caption>a dataSet</caption>
47
+ * @example <caption>Create a dataSet</caption>
48
48
  * create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly' });
49
49
  * @example <caption>a dataSetNotification</caption>
50
50
  * create('dataSetNotificationTemplates', {
@@ -55,7 +55,7 @@ export function execute(...operations: Operations): Operation;
55
55
  * deliveryChannels: ['SMS'],
56
56
  * dataSets: [],
57
57
  * });
58
- * @example <caption>a dataElement</caption>
58
+ * @example <caption>Create a dataElement</caption>
59
59
  * create('dataElements', {
60
60
  * aggregationType: 'SUM',
61
61
  * domainType: 'AGGREGATE',
@@ -63,26 +63,26 @@ export function execute(...operations: Operations): Operation;
63
63
  * name: 'Paracetamol',
64
64
  * shortName: 'Para',
65
65
  * });
66
- * @example <caption>a dataElementGroup</caption>
66
+ * @example <caption>Create a dataElementGroup</caption>
67
67
  * create('dataElementGroups', {
68
68
  * name: 'Data Element Group 1',
69
69
  * dataElements: [],
70
70
  * });
71
- * @example <caption>a dataElementGroupSet</caption>
71
+ * @example <caption>Create a dataElementGroupSet</caption>
72
72
  * create('dataElementGroupSets', {
73
73
  * name: 'Data Element Group Set 4',
74
74
  * dataDimension: true,
75
75
  * shortName: 'DEGS4',
76
76
  * dataElementGroups: [],
77
77
  * });
78
- * @example <caption>a dataValueSet</caption>
78
+ * @example <caption>Create a dataValueSet</caption>
79
79
  * create('dataValueSets', {
80
80
  * dataElement: 'f7n9E0hX8qk',
81
81
  * period: '201401',
82
82
  * orgUnit: 'DiszpKrYNg8',
83
83
  * value: '12',
84
84
  * });
85
- * @example <caption>a dataValueSet with related dataValues</caption>
85
+ * @example <caption>Create a dataValueSet with related dataValues</caption>
86
86
  * create('dataValueSets', {
87
87
  * dataSet: 'pBOMPrpg1QX',
88
88
  * completeDate: '2014-02-03',
@@ -103,14 +103,38 @@ export function execute(...operations: Operations): Operation;
103
103
  * },
104
104
  * ],
105
105
  * });
106
- * @example <caption>an enrollment</caption>
106
+ * @example <caption>Create an enrollment</caption>
107
107
  * create('enrollments', {
108
- * trackedEntityInstance: 'bmshzEacgxa',
108
+ * trackedEntity: 'bmshzEacgxa',
109
109
  * orgUnit: 'TSyzvBiovKh',
110
110
  * program: 'gZBxv9Ujxg0',
111
111
  * enrollmentDate: '2013-09-17',
112
112
  * incidentDate: '2013-09-17',
113
113
  * });
114
+ * @example <caption>Create an multiple objects with the Tracker API</caption>
115
+ * create("tracker", {
116
+ * enrollments: [
117
+ * {
118
+ * trackedEntity: "bmshzEacgxa",
119
+ * orgUnit: "TSyzvBiovKh",
120
+ * program: "gZBxv9Ujxg0",
121
+ * enrollmentDate: "2013-09-17",
122
+ * incidentDate: "2013-09-17",
123
+ * },
124
+ * ],
125
+ * trackedEntities: [
126
+ * {
127
+ * orgUnit: "TSyzvBiovKh",
128
+ * trackedEntityType: "nEenWmSyUEp",
129
+ * attributes: [
130
+ * {
131
+ * attribute: "w75KJ2mc4zz",
132
+ * value: "Gigiwe",
133
+ * },
134
+ * ],
135
+ * },
136
+ * ],
137
+ * });
114
138
  */
115
139
  export function create(resourceType: string, data: Dhis2Data, options?: any, callback?: Function): Operation;
116
140
  /**
@@ -138,13 +162,12 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
138
162
  * storedBy: 'admin',
139
163
  * dataValues: [],
140
164
  * });
141
- * @example <caption>a trackedEntityInstance</caption>
142
- * update('trackedEntityInstances', 'IeQfgUtGPq2', {
143
- * created: '2015-08-06T21:12:37.256',
165
+ * @example <caption>Update a tracker entity. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import Update tracker docs}</caption>
166
+ * update('trackedEntities', '', {
167
+ * createdAt: '2015-08-06T21:12:37.256',
144
168
  * orgUnit: 'TSyzvBiovKh',
145
169
  * createdAtClient: '2015-08-06T21:12:37.256',
146
- * trackedEntityInstance: 'IeQfgUtGPq2',
147
- * lastUpdated: '2015-08-06T21:12:37.257',
170
+ * trackedEntity: 'IeQfgUtGPq2',
148
171
  * trackedEntityType: 'nEenWmSyUEp',
149
172
  * inactive: false,
150
173
  * deleted: false,
@@ -153,11 +176,9 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
153
176
  * {
154
177
  * ownerOrgUnit: 'TSyzvBiovKh',
155
178
  * program: 'IpHINAT79UW',
156
- * trackedEntityInstance: 'IeQfgUtGPq2',
179
+ * trackedEntity: 'IeQfgUtGPq2',
157
180
  * },
158
181
  * ],
159
- * enrollments: [],
160
- * relationships: [],
161
182
  * attributes: [
162
183
  * {
163
184
  * lastUpdated: '2016-01-12T00:00:00.000',
@@ -178,18 +199,18 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
178
199
  * },
179
200
  * ],
180
201
  * });
181
- * @example <caption>a dataSet</caption>
202
+ * @example <caption>Update a dataSet</caption>
182
203
  * update('dataSets', 'lyLU2wR22tC', { name: 'OpenFN Data Set', periodType: 'Weekly' });
183
204
  * @example <caption>a dataSetNotification</caption>
184
205
  * update('dataSetNotificationTemplates', 'VbQBwdm1wVP', {
185
206
  * dataSetNotificationTrigger: 'DATA_SET_COMPLETION',
186
207
  * notificationRecipient: 'ORGANISATION_UNIT_CONTACT',
187
208
  * name: 'Notification',
188
- * messageTemplate: 'Hello Updated,
209
+ * messageTemplate: 'Hello Updated',
189
210
  * deliveryChannels: ['SMS'],
190
211
  * dataSets: [],
191
212
  * });
192
- * @example <caption>a dataElement</caption>
213
+ * @example <caption>Update a dataElement</caption>
193
214
  * update('dataElements', 'FTRrcoaog83', {
194
215
  * aggregationType: 'SUM',
195
216
  * domainType: 'AGGREGATE',
@@ -197,26 +218,26 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
197
218
  * name: 'Paracetamol',
198
219
  * shortName: 'Para',
199
220
  * });
200
- * @example <caption>a dataElementGroup</caption>
221
+ * @example <caption>Update a dataElementGroup</caption>
201
222
  * update('dataElementGroups', 'QrprHT61XFk', {
202
223
  * name: 'Data Element Group 1',
203
224
  * dataElements: [],
204
225
  * });
205
- * @example <caption>a dataElementGroupSet</caption>
226
+ * @example <caption>Update a dataElementGroupSet</caption>
206
227
  * update('dataElementGroupSets', 'VxWloRvAze8', {
207
228
  * name: 'Data Element Group Set 4',
208
229
  * dataDimension: true,
209
230
  * shortName: 'DEGS4',
210
231
  * dataElementGroups: [],
211
232
  * });
212
- * @example <caption>a dataValueSet</caption>
233
+ * @example <caption>Update a dataValueSet</caption>
213
234
  * update('dataValueSets', 'AsQj6cDsUq4', {
214
235
  * dataElement: 'f7n9E0hX8qk',
215
236
  * period: '201401',
216
237
  * orgUnit: 'DiszpKrYNg8',
217
238
  * value: '12',
218
239
  * });
219
- * @example <caption>a dataValueSet with related dataValues</caption>
240
+ * @example <caption>Update a dataValueSet with related dataValues</caption>
220
241
  * update('dataValueSets', 'Ix2HsbDMLea', {
221
242
  * dataSet: 'pBOMPrpg1QX',
222
243
  * completeDate: '2014-02-03',
@@ -237,9 +258,9 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
237
258
  * },
238
259
  * ],
239
260
  * });
240
- * @example <caption>a single enrollment</caption>
261
+ * @example <caption>Update an enrollment given the provided ID</caption>
241
262
  * update('enrollments', 'CmsHzercTBa' {
242
- * trackedEntityInstance: 'bmshzEacgxa',
263
+ * trackedEntity: 'bmshzEacgxa',
243
264
  * orgUnit: 'TSyzvBiovKh',
244
265
  * program: 'gZBxv9Ujxg0',
245
266
  * enrollmentDate: '2013-10-17',
@@ -249,44 +270,72 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
249
270
  export function update(resourceType: string, path: string, data: any, options?: any, callback?: Function): Operation;
250
271
  /**
251
272
  * Get data. Generic helper method for getting data of any kind from DHIS2.
252
- * - This can be used to get `DataValueSets`,`events`,`trackedEntityInstances`,`etc.`
273
+ * - This can be used to get `DataValueSets`,`events`,`trackers`,`etc.`
253
274
  * @public
254
275
  * @function
255
- * @param {string} resourceType - The type of resource to get(use its `plural` name). E.g. `dataElements`, `trackedEntityInstances`,`organisationUnits`, etc.
276
+ * @param {string} resourceType - The type of resource to get(use its `plural` name). E.g. `dataElements`, `tracker/trackedEntities`,`organisationUnits`, etc.
256
277
  * @param {Object} query - A query object that will limit what resources are retrieved when converted into request params.
257
278
  * @param {Object} [options] - Optional `options` to define URL parameters via params beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.
258
279
  * @param {function} [callback] - Optional callback to handle the response
259
280
  * @returns {Operation} state
260
- * @example <caption>all data values for the 'pBOMPrpg1QX' dataset</caption>
281
+ * @example <caption>Get all data values for the 'pBOMPrpg1QX' dataset</caption>
261
282
  * get('dataValueSets', {
262
283
  * dataSet: 'pBOMPrpg1QX',
263
284
  * orgUnit: 'DiszpKrYNg8',
264
285
  * period: '201401',
265
286
  * fields: '*',
266
287
  * });
267
- * @example <caption>all programs for an organization unit</caption>
288
+ * @example <caption>Get all programs for an organization unit</caption>
268
289
  * get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
269
- * @example <caption>a single tracked entity instance by a unique external ID</caption>
270
- * get('trackedEntityInstances', {
271
- * ou: 'DiszpKrYNg8',
272
- * filter: ['flGbXLXCrEo:Eq:124', 'w75KJ2mc4zz:Eq:John'],
290
+ * @example <caption>Get a single tracked entity given the provided ID. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#tracked-entities-get-apitrackertrackedentities TrackedEntities docs}</caption>
291
+ * get('tracker/trackedEntities/F8yKM85NbxW');
292
+ * @example <caption>Get an enrollment given the provided ID. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#enrollments-get-apitrackerenrollments Enrollment docs}</caption>
293
+ * get('tracker/enrollments/abcd');
294
+ * @example <caption>Get all events matching given criteria. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#events-get-apitrackerevents Events docs}</caption>
295
+ * get('tracker/events');
296
+ * @example <caption>Get the relationship between two tracker entities. The only required parameters are 'trackedEntity', 'enrollment' or 'event'. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#relationships-get-apitrackerrelationships Relationships docs}</caption>
297
+ * get('tracker/relationships', {
298
+ * trackedEntity:['F8yKM85NbxW'],
273
299
  * });
274
300
  */
275
301
  export function get(resourceType: string, query: any, options?: any, callback?: Function): Operation;
302
+ /**
303
+ * Post data. Generic helper method for posting data of any kind to DHIS2.
304
+ * This can be used to create `DataValueSets`,`events`,`trackers`,etc.
305
+ * @public
306
+ * @function
307
+ * @param {string} resourceType - Type of resource to create. E.g. `trackedEntities`, `programs`, `events`, ...
308
+ * @magic resourceType $.children.resourceTypes[*]
309
+ * @param {Dhis2Data} data - Object which defines data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.
310
+ * @param {Object} [options] - Optional `options` to define URL parameters via params (E.g. `filter`, `dimension` and other import parameters), request config (E.g. `auth`) and the DHIS2 apiVersion.
311
+ * @param {function} [callback] - Optional callback to handle the response
312
+ * @returns {Operation} state
313
+ * @example <caption>Create an event</caption>
314
+ * post("tracker", {
315
+ * events: [
316
+ * {
317
+ * program: "eBAyeGv0exc",
318
+ * orgUnit: "DiszpKrYNg8",
319
+ * status: "COMPLETED",
320
+ * },
321
+ * ],
322
+ * });
323
+ */
324
+ export function post(resourceType: string, data: Dhis2Data, query: any, options?: any, callback?: Function): Operation;
276
325
  /**
277
326
  * Upsert a record. A generic helper function used to atomically either insert a row, or on the basis of the row already existing, UPDATE that existing row instead.
278
327
  * @public
279
328
  * @function
280
- * @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntityInstances`
329
+ * @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`
281
330
  * @param {Object} query - A query object that allows to uniquely identify the resource to update. If no matches found, then the resource will be created.
282
331
  * @param {Object} data - The data to use for update or create depending on the result of the query.
283
332
  * @param {{ apiVersion: object, requestConfig: object, params: object }} [options] - Optional configuration that will be applied to both the `get` and the `create` or `update` operations.
284
333
  * @param {function} [callback] - Optional callback to handle the response
285
334
  * @throws {RangeError} - Throws range error
286
335
  * @returns {Operation}
287
- * @example <caption>Example `expression.js` of upsert</caption>
288
- * upsert('trackedEntityInstances', {
289
- * ou: 'TSyzvBiovKh',
336
+ * @example <caption>Upsert a trackedEntity</caption>
337
+ * upsert('trackedEntities', {
338
+ * orgUnit: 'TSyzvBiovKh',
290
339
  * filter: ['w75KJ2mc4zz:Eq:Qassim'],
291
340
  * }, {
292
341
  * orgUnit: 'TSyzvBiovKh',
@@ -309,10 +358,10 @@ export function upsert(resourceType: string, query: any, data: any, options?: {
309
358
  * @public
310
359
  * @function
311
360
  * @param {string} httpMethod - The HTTP to inspect parameter usage for a given endpoint, e.g., `get`, `post`,`put`,`patch`,`delete`
312
- * @param {string} endpoint - The path for a given endpoint. E.g. `/trackedEntityInstances` or `/dataValueSets`
361
+ * @param {string} endpoint - The path for a given endpoint. E.g. `/trackedEntities` or `/dataValueSets`
313
362
  * @returns {Operation}
314
363
  * @example <caption>a list of parameters allowed on a given endpoint for specific http method</caption>
315
- * discover('post', '/trackedEntityInstances')
364
+ * discover('post', '/trackedEntities')
316
365
  */
317
366
  export function discover(httpMethod: string, endpoint: string): Operation;
318
367
  /**
@@ -335,14 +384,14 @@ export function patch(resourceType: string, path: string, data: any, options?: a
335
384
  * Delete a record. A generic helper function to delete an object
336
385
  * @public
337
386
  * @function
338
- * @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntityInstances`, `organisationUnits`, etc.
387
+ * @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntities`, `organisationUnits`, etc.
339
388
  * @param {string} path - Can be an `id` of an `object` or `path` to the `nested object` to `delete`.
340
389
  * @param {Object} [data] - Optional. This is useful when you want to remove multiple objects from a collection in one request. You can send `data` as, for example, `{"identifiableObjects": [{"id": "IDA"}, {"id": "IDB"}, {"id": "IDC"}]}`. See more {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#deleting-objects on DHIS2 API docs}
341
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'}`
342
391
  * @param {function} [callback] - Optional callback to handle the response
343
392
  * @returns {Operation}
344
- * @example <caption>a tracked entity instance</caption>
345
- * destroy('trackedEntityInstances', 'LcRd6Nyaq7T');
393
+ * @example <caption>a tracked entity instance. See {@link https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import Delete tracker docs}</caption>
394
+ * destroy('trackedEntities', 'LcRd6Nyaq7T');
346
395
  */
347
396
  export function destroy(resourceType: string, path: string, data?: any, options?: {
348
397
  apiVersion: number;
@@ -353,15 +402,15 @@ export function destroy(resourceType: string, path: string, data?: any, options?
353
402
  * Gets an attribute value by its case-insensitive display name
354
403
  * @public
355
404
  * @example
356
- * findAttributeValue(state.data.trackedEntityInstances[0], 'first name')
405
+ * findAttributeValue(state.data.trackedEntities[0], 'first name')
357
406
  * @function
358
- * @param {Object} trackedEntityInstance - A tracked entity instance (TEI) object
407
+ * @param {Object} trackedEntity - A tracked entity instance (TEI) object
359
408
  * @param {string} attributeDisplayName - The 'displayName' to search for in the TEI's attributes
360
409
  * @returns {string}
361
410
  */
362
- export function findAttributeValue(trackedEntityInstance: any, attributeDisplayName: string): string;
411
+ export function findAttributeValue(trackedEntity: any, attributeDisplayName: string): string;
363
412
  /**
364
- * Converts an attribute ID and value into a DSHI2 attribute object
413
+ * Converts an attribute ID and value into a DHIS2 attribute object
365
414
  * @public
366
415
  * @example
367
416
  * attr('w75KJ2mc4zz', 'Elias')
@@ -372,7 +421,7 @@ export function findAttributeValue(trackedEntityInstance: any, attributeDisplayN
372
421
  */
373
422
  export function attr(attribute: string, value: string): object;
374
423
  /**
375
- * Converts a dataElement and value into a DSHI2 dataValue object
424
+ * Converts a dataElement and value into a DHIS2 dataValue object
376
425
  * @public
377
426
  * @example
378
427
  * dv('f7n9E0hX8qk', 12)
@@ -382,4 +431,4 @@ export function attr(attribute: string, value: string): object;
382
431
  * @returns {object}
383
432
  */
384
433
  export function dv(dataElement: string, value: string): object;
385
- export { alterState, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, http, group, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
434
+ export { alterState, dataPath, dataValue, dateFns, cursor, each, field, fields, fn, fnIf, http, group, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
package/types/Utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export function shouldUseNewTracker(resourceType: any): boolean;
1
2
  export function buildUrl(urlString: any, hostUrl: any, apiVersion: any): string;
2
3
  /**
3
4
  * Determines the attribute name for a DHIS2 system ID given a resource type.
@@ -7,7 +8,9 @@ export function buildUrl(urlString: any, hostUrl: any, apiVersion: any): string;
7
8
  export function selectId(resourceType: string): string;
8
9
  export function handleResponse(result: any, state: any, callback: any): any;
9
10
  export function prettyJson(data: any): string;
10
- export function nestArray(data: any, key: any): any;
11
+ export function ensureArray(data: any, key: any): {
12
+ [x: number]: any[];
13
+ };
11
14
  export function generateUrl(configuration: any, options: any, resourceType: any, path?: any): string;
12
15
  export namespace CONTENT_TYPES {
13
16
  const xml: string;