@openfn/language-dhis2 6.3.4 → 7.0.1
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/ast.json +129 -733
- package/dist/index.cjs +406 -360
- package/dist/index.js +405 -350
- package/package.json +4 -5
- package/types/Adaptor.d.ts +97 -184
- package/types/index.d.ts +2 -0
- package/types/tracker.d.ts +80 -0
- package/types/util.d.ts +83 -0
- package/types/Client.d.ts +0 -11
- package/types/Utils.d.ts +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-dhis2",
|
|
3
|
-
"
|
|
3
|
+
"label": "DHIS2",
|
|
4
|
+
"version": "7.0.1",
|
|
4
5
|
"description": "DHIS2 Language Pack for OpenFn",
|
|
5
6
|
"homepage": "https://docs.openfn.org",
|
|
6
7
|
"repository": {
|
|
@@ -25,19 +26,17 @@
|
|
|
25
26
|
"configuration-schema.json"
|
|
26
27
|
],
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"axios": "^1.
|
|
29
|
+
"axios": "^1.8.2",
|
|
29
30
|
"lodash": "^4.17.21",
|
|
30
31
|
"qs": "^6.11.0",
|
|
31
|
-
"@openfn/language-common": "2.
|
|
32
|
+
"@openfn/language-common": "2.5.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"assertion-error": "2.0.0",
|
|
35
36
|
"chai": "4.3.6",
|
|
36
37
|
"chai-http": "4.3.0",
|
|
37
38
|
"deep-eql": "4.1.1",
|
|
38
|
-
"esno": "^0.16.3",
|
|
39
39
|
"jsonpath": "^1.1.1",
|
|
40
|
-
"nock": "13.2.9",
|
|
41
40
|
"rimraf": "3.0.2"
|
|
42
41
|
},
|
|
43
42
|
"type": "module",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} DHIS2State
|
|
4
|
+
* @private
|
|
5
|
+
* @property data - The response body (as JSON)
|
|
6
|
+
* @property references - An array of all previous data objects used in the Job
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options object
|
|
10
|
+
* @typedef {Object} RequestOptions
|
|
11
|
+
* @property {object} query - An object of query parameters to be encoded into the URL
|
|
12
|
+
* @property {object} headers - An object of all request headers
|
|
13
|
+
* @property {string} [parseAs='json'] - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
|
|
14
|
+
* @property {string} [apiVersion=42] - The apiVersion of the request. Defaults to 42.
|
|
15
|
+
*/
|
|
1
16
|
/**
|
|
2
17
|
* Execute a sequence of operations.
|
|
3
18
|
* Wraps `language-common/execute`, and prepends initial state for DHIS2.
|
|
@@ -15,11 +30,11 @@ export function execute(...operations: Operations): Operation;
|
|
|
15
30
|
* Create a record
|
|
16
31
|
* @public
|
|
17
32
|
* @function
|
|
18
|
-
* @param {string}
|
|
19
|
-
* @magic
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @
|
|
33
|
+
* @param {string} path - Path to the resource to be created
|
|
34
|
+
* @magic path $.children.resourceTypes[*]
|
|
35
|
+
* @param {DHIS2Data} data - An object, or array of objects, to create.
|
|
36
|
+
* @param {object} params - Optional object of query parameters to include in the request
|
|
37
|
+
* @state data - The created resource as returned by DHIS2
|
|
23
38
|
* @returns {Operation}
|
|
24
39
|
* @example <caption>Create a program</caption>
|
|
25
40
|
* create('programs', {
|
|
@@ -111,42 +126,39 @@ export function execute(...operations: Operations): Operation;
|
|
|
111
126
|
* enrollmentDate: '2013-09-17',
|
|
112
127
|
* incidentDate: '2013-09-17',
|
|
113
128
|
* });
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* attribute: "w75KJ2mc4zz",
|
|
132
|
-
* value: "Gigiwe",
|
|
133
|
-
* },
|
|
134
|
-
* ],
|
|
135
|
-
* },
|
|
136
|
-
* ],
|
|
129
|
+
*/
|
|
130
|
+
export function create(path: string, data: DHIS2Data, params?: object): Operation;
|
|
131
|
+
/**
|
|
132
|
+
* Get any resource, as JSON, from DHIS2. Pass in any valid DHIS2 REST path, excluding /api and the version.
|
|
133
|
+
* For the new tracker API, see `tracker.export()`
|
|
134
|
+
* @public
|
|
135
|
+
* @function
|
|
136
|
+
* @param {string} path - Path to the resource
|
|
137
|
+
* @param {object} params - Object of query parameters to include in the request
|
|
138
|
+
* @state data - the resource returned by DHIS2
|
|
139
|
+
* @returns {Operation}
|
|
140
|
+
* @example <caption>Get all data values for the 'pBOMPrpg1QX' dataset</caption>
|
|
141
|
+
* get('dataValueSets', {
|
|
142
|
+
* dataSet: 'pBOMPrpg1QX',
|
|
143
|
+
* orgUnit: 'DiszpKrYNg8',
|
|
144
|
+
* period: '201401',
|
|
145
|
+
* fields: '*',
|
|
137
146
|
* });
|
|
147
|
+
* @example <caption>Get all programs for an organization unit</caption>
|
|
148
|
+
* get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
|
|
149
|
+
* @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>
|
|
150
|
+
* get('tracker/trackedEntities/F8yKM85NbxW');
|
|
138
151
|
*/
|
|
139
|
-
export function
|
|
152
|
+
export function get(path: string, params?: object): Operation;
|
|
140
153
|
/**
|
|
141
|
-
* Update
|
|
142
|
-
* Updating an object requires to send `all required fields` or the `full body`
|
|
154
|
+
* Update a resource object of any type. Updating an object requires all fields of the object you are updating, even if they have not been modified
|
|
143
155
|
* @public
|
|
144
156
|
* @function
|
|
145
157
|
* @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
|
|
146
158
|
* @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
|
|
147
|
-
* @param {Object} data - Data to update. It requires to send
|
|
148
|
-
* @param {
|
|
149
|
-
* @
|
|
159
|
+
* @param {Object} data - Data to update. It requires to send the full body. If you want partial updates, use patch operation.
|
|
160
|
+
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
|
|
161
|
+
* @state data - the resource returned by DHIS2
|
|
150
162
|
* @returns {Operation}
|
|
151
163
|
* @example <caption>a program</caption>
|
|
152
164
|
* update('programs', 'qAZJCrNJK8H', {
|
|
@@ -267,84 +279,21 @@ export function create(resourceType: string, data: Dhis2Data, options?: any, cal
|
|
|
267
279
|
* incidentDate: '2013-10-17',
|
|
268
280
|
* });
|
|
269
281
|
*/
|
|
270
|
-
export function update(resourceType: string, path: string, data: any, options?:
|
|
282
|
+
export function update(resourceType: string, path: string, data: any, options?: RequestOptions): Operation;
|
|
271
283
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
284
|
+
* Upsert a record. This will atomically update a record if it already exists, or otherwise create it.
|
|
285
|
+
* This function does not work with the absolute tracker path `api/tracker` but rather the new tracker paths and deprecated tracker endpoints.
|
|
274
286
|
* @public
|
|
275
287
|
* @function
|
|
276
|
-
* @param {string} resourceType - The type of resource to
|
|
277
|
-
* @param {Object} query - A query object that will limit what resources are retrieved when converted into request params.
|
|
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.
|
|
279
|
-
* @param {Object} [options.params] - The parameters for the request.
|
|
280
|
-
* @param {Object} [options.requestConfig] - The configuration for the request, including headers, etc.
|
|
281
|
-
* @param {boolean} [options.asBase64=false] - Optional flag to indicate if the response should be returned as a Base64 encoded string.
|
|
282
|
-
* @param {function} [callback] - Optional callback to handle the response
|
|
283
|
-
* @returns {Operation} state
|
|
284
|
-
* @example <caption>Get all data values for the 'pBOMPrpg1QX' dataset</caption>
|
|
285
|
-
* get('dataValueSets', {
|
|
286
|
-
* dataSet: 'pBOMPrpg1QX',
|
|
287
|
-
* orgUnit: 'DiszpKrYNg8',
|
|
288
|
-
* period: '201401',
|
|
289
|
-
* fields: '*',
|
|
290
|
-
* });
|
|
291
|
-
* @example <caption>Get all programs for an organization unit</caption>
|
|
292
|
-
* get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
|
|
293
|
-
* @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>
|
|
294
|
-
* get('tracker/trackedEntities/F8yKM85NbxW');
|
|
295
|
-
* @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>
|
|
296
|
-
* get('tracker/enrollments/abcd');
|
|
297
|
-
* @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>
|
|
298
|
-
* get('tracker/events');
|
|
299
|
-
* @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>
|
|
300
|
-
* get('tracker/relationships', {
|
|
301
|
-
* trackedEntity:['F8yKM85NbxW'],
|
|
302
|
-
* });
|
|
303
|
-
*/
|
|
304
|
-
export function get(resourceType: string, query: any, options?: {
|
|
305
|
-
params?: any;
|
|
306
|
-
requestConfig?: any;
|
|
307
|
-
asBase64?: boolean;
|
|
308
|
-
}, callback?: Function): Operation;
|
|
309
|
-
/**
|
|
310
|
-
* Post data. Generic helper method for posting data of any kind to DHIS2.
|
|
311
|
-
* This can be used to create `DataValueSets`,`events`,`trackers`,etc.
|
|
312
|
-
* @public
|
|
313
|
-
* @function
|
|
314
|
-
* @param {string} resourceType - Type of resource to create. E.g. `trackedEntities`, `programs`, `events`, ...
|
|
315
|
-
* @magic resourceType $.children.resourceTypes[*]
|
|
316
|
-
* @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.
|
|
317
|
-
* @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.
|
|
318
|
-
* @param {function} [callback] - Optional callback to handle the response
|
|
319
|
-
* @returns {Operation} state
|
|
320
|
-
* @example <caption>Create an event</caption>
|
|
321
|
-
* post("tracker", {
|
|
322
|
-
* events: [
|
|
323
|
-
* {
|
|
324
|
-
* program: "eBAyeGv0exc",
|
|
325
|
-
* orgUnit: "DiszpKrYNg8",
|
|
326
|
-
* status: "COMPLETED",
|
|
327
|
-
* },
|
|
328
|
-
* ],
|
|
329
|
-
* });
|
|
330
|
-
*/
|
|
331
|
-
export function post(resourceType: string, data: Dhis2Data, query: any, options?: any, callback?: Function): Operation;
|
|
332
|
-
/**
|
|
333
|
-
* 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.
|
|
334
|
-
* @public
|
|
335
|
-
* @function
|
|
336
|
-
* @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`
|
|
288
|
+
* @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`.
|
|
337
289
|
* @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.
|
|
338
290
|
* @param {Object} data - The data to use for update or create depending on the result of the query.
|
|
339
|
-
* @param {
|
|
340
|
-
* @param {function} [callback] - Optional callback to handle the response
|
|
291
|
+
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request
|
|
341
292
|
* @throws {RangeError} - Throws range error
|
|
293
|
+
* @state {DHIS2State}
|
|
342
294
|
* @returns {Operation}
|
|
343
295
|
* @example <caption>Upsert a trackedEntity</caption>
|
|
344
|
-
* upsert('trackedEntities', {
|
|
345
|
-
* orgUnit: 'TSyzvBiovKh',
|
|
346
|
-
* filter: ['w75KJ2mc4zz:Eq:Qassim'],
|
|
347
|
-
* }, {
|
|
296
|
+
* upsert('trackedEntities', {}, {
|
|
348
297
|
* orgUnit: 'TSyzvBiovKh',
|
|
349
298
|
* trackedEntityType: 'nEenWmSyUEp',
|
|
350
299
|
* attributes: [
|
|
@@ -354,99 +303,63 @@ export function post(resourceType: string, data: Dhis2Data, query: any, options?
|
|
|
354
303
|
* },
|
|
355
304
|
* ],
|
|
356
305
|
* });
|
|
306
|
+
* @example <caption> Upsert a dataElement </caption>
|
|
307
|
+
* upsert(
|
|
308
|
+
* 'dataElements',
|
|
309
|
+
* { filter: 'id:eq:P3jJH5Tu5VC' },
|
|
310
|
+
* {
|
|
311
|
+
* op: 'add',
|
|
312
|
+
* path: '/domainType',
|
|
313
|
+
* name: 'Acute',
|
|
314
|
+
* shortName: 'AFP follow-up',
|
|
315
|
+
* dimensionItemType: 'DATA_ELEMENT',
|
|
316
|
+
* legendSets: [],
|
|
317
|
+
* aggregationType: 'SUM',
|
|
318
|
+
* valueType: 'NUMBER',
|
|
319
|
+
* domainType: 'AGGREGATE',
|
|
320
|
+
* code: 'DE_359049',
|
|
321
|
+
* name: 'Acute Flaccid Paralysis (AFP) follow-up',
|
|
322
|
+
* }
|
|
323
|
+
* );
|
|
357
324
|
*/
|
|
358
|
-
export function upsert(resourceType: string, query: any, data: any, options?:
|
|
359
|
-
apiVersion: object;
|
|
360
|
-
requestConfig: object;
|
|
361
|
-
params: object;
|
|
362
|
-
}, callback?: Function): Operation;
|
|
363
|
-
/**
|
|
364
|
-
* Discover `DHIS2` `api` `endpoint` `query parameters` and allowed `operators` for a given resource's endpoint.
|
|
365
|
-
* @public
|
|
366
|
-
* @function
|
|
367
|
-
* @param {string} httpMethod - The HTTP to inspect parameter usage for a given endpoint, e.g., `get`, `post`,`put`,`patch`,`delete`
|
|
368
|
-
* @param {string} endpoint - The path for a given endpoint. E.g. `/trackedEntities` or `/dataValueSets`
|
|
369
|
-
* @returns {Operation}
|
|
370
|
-
* @example <caption>a list of parameters allowed on a given endpoint for specific http method</caption>
|
|
371
|
-
* discover('post', '/trackedEntities')
|
|
372
|
-
*/
|
|
373
|
-
export function discover(httpMethod: string, endpoint: string): Operation;
|
|
325
|
+
export function upsert(resourceType: string, query: any, data: any, options?: RequestOptions): Operation;
|
|
374
326
|
/**
|
|
375
|
-
*
|
|
376
|
-
* - You are not required to send the full body of object properties.
|
|
377
|
-
* - This is useful for cases where you don't want or need to update all properties on a object.
|
|
378
|
-
* @public
|
|
379
|
-
* @function
|
|
380
|
-
* @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
|
|
381
|
-
* @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
|
|
382
|
-
* @param {Object} data - Data to update. Include only the fields you want to update. E.g. `{name: "New Name"}`
|
|
383
|
-
* @param {Object} [options] - Optional configuration, including params for the update ({preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}). Defaults to `{operationName: 'patch', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
|
|
384
|
-
* @param {function} [callback] - Optional callback to handle the response
|
|
385
|
-
* @returns {Operation}
|
|
386
|
-
* @example <caption>a dataElement</caption>
|
|
387
|
-
* patch('dataElements', 'FTRrcoaog83', { name: 'New Name' });
|
|
388
|
-
*/
|
|
389
|
-
export function patch(resourceType: string, path: string, data: any, options?: any, callback?: Function): Operation;
|
|
390
|
-
/**
|
|
391
|
-
* Delete a record. A generic helper function to delete an object
|
|
327
|
+
* Delete record.
|
|
392
328
|
* @public
|
|
393
329
|
* @function
|
|
394
330
|
* @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntities`, `organisationUnits`, etc.
|
|
395
331
|
* @param {string} path - Can be an `id` of an `object` or `path` to the `nested object` to `delete`.
|
|
396
332
|
* @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}
|
|
397
|
-
* @param {
|
|
398
|
-
* @
|
|
333
|
+
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
|
|
334
|
+
* @state {DHIS2State}
|
|
399
335
|
* @returns {Operation}
|
|
400
336
|
* @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>
|
|
401
337
|
* destroy('trackedEntities', 'LcRd6Nyaq7T');
|
|
402
338
|
*/
|
|
403
|
-
export function destroy(resourceType: string, path: string, data?: any, options?:
|
|
404
|
-
apiVersion: number;
|
|
405
|
-
operationName: string;
|
|
406
|
-
resourceType: string;
|
|
407
|
-
}, callback?: Function): Operation;
|
|
339
|
+
export function destroy(resourceType: string, path: string, data?: any, options?: RequestOptions): Operation;
|
|
408
340
|
/**
|
|
409
|
-
*
|
|
410
|
-
* @public
|
|
411
|
-
* @example
|
|
412
|
-
* findAttributeValueById(state.tei, 'y1w2R6leVmh')
|
|
413
|
-
* @function
|
|
414
|
-
* @param {Object} trackedEntity - A tracked entity instance (TEI) object
|
|
415
|
-
* @param {string} attributeUid - The uid to search for in the TEI's attributes
|
|
416
|
-
* @returns {string}
|
|
341
|
+
* State object
|
|
417
342
|
*/
|
|
418
|
-
export
|
|
343
|
+
export type DHIS2State = any;
|
|
419
344
|
/**
|
|
420
|
-
*
|
|
421
|
-
* @public
|
|
422
|
-
* @example
|
|
423
|
-
* findAttributeValue(state.data.trackedEntities[0], 'first name')
|
|
424
|
-
* @function
|
|
425
|
-
* @param {Object} trackedEntity - A tracked entity instance (TEI) object
|
|
426
|
-
* @param {string} attributeDisplayName - The 'displayName' to search for in the TEI's attributes
|
|
427
|
-
* @returns {string}
|
|
428
|
-
*/
|
|
429
|
-
export function findAttributeValue(trackedEntity: any, attributeDisplayName: string): string;
|
|
430
|
-
/**
|
|
431
|
-
* Converts an attribute ID and value into a DHIS2 attribute object
|
|
432
|
-
* @public
|
|
433
|
-
* @example
|
|
434
|
-
* attr('w75KJ2mc4zz', 'Elias')
|
|
435
|
-
* @function
|
|
436
|
-
* @param {string} attribute - A tracked entity instance (TEI) attribute ID.
|
|
437
|
-
* @param {string} value - The value for that attribute.
|
|
438
|
-
* @returns {object}
|
|
439
|
-
*/
|
|
440
|
-
export function attr(attribute: string, value: string): object;
|
|
441
|
-
/**
|
|
442
|
-
* Converts a dataElement and value into a DHIS2 dataValue object
|
|
443
|
-
* @public
|
|
444
|
-
* @example
|
|
445
|
-
* dv('f7n9E0hX8qk', 12)
|
|
446
|
-
* @function
|
|
447
|
-
* @param {string} dataElement - A data element ID.
|
|
448
|
-
* @param {string} value - The value for that data element.
|
|
449
|
-
* @returns {object}
|
|
345
|
+
* Options object
|
|
450
346
|
*/
|
|
451
|
-
export
|
|
347
|
+
export type RequestOptions = {
|
|
348
|
+
/**
|
|
349
|
+
* - An object of query parameters to be encoded into the URL
|
|
350
|
+
*/
|
|
351
|
+
query: object;
|
|
352
|
+
/**
|
|
353
|
+
* - An object of all request headers
|
|
354
|
+
*/
|
|
355
|
+
headers: object;
|
|
356
|
+
/**
|
|
357
|
+
* - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
|
|
358
|
+
*/
|
|
359
|
+
parseAs?: string;
|
|
360
|
+
/**
|
|
361
|
+
* - The apiVersion of the request. Defaults to 42.
|
|
362
|
+
*/
|
|
363
|
+
apiVersion?: string;
|
|
364
|
+
};
|
|
452
365
|
export { alterState, dataPath, dataValue, dateFns, cursor, each, field, fields, fn, fnIf, http, group, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
*/
|
|
4
|
+
export type DHIS2State = any;
|
|
5
|
+
/**
|
|
6
|
+
* All options, apart from those listed here, will be appended as query parameters to the URL
|
|
7
|
+
*/
|
|
8
|
+
export type TrackerOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
|
|
11
|
+
*/
|
|
12
|
+
parseAs?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* State object
|
|
16
|
+
* @typedef {Object} DHIS2State
|
|
17
|
+
* @private
|
|
18
|
+
* @property data - The response body (as JSON)
|
|
19
|
+
* @property response - The HTTP response from the DHIS2 server (excluding the body)
|
|
20
|
+
* @property references - An array of all previous data objects used in the Job
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* All options, apart from those listed here, will be appended as query parameters to the URL
|
|
24
|
+
* @typedef {Object} TrackerOptions
|
|
25
|
+
* @property {string} [parseAs='json'] - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Import data into DHIS2 using the tracker endpoint.
|
|
29
|
+
* @alias import
|
|
30
|
+
* @public
|
|
31
|
+
* @function
|
|
32
|
+
* @param {string} strategy - The effect the import should have. Can either be CREATE, UPDATE, CREATE_AND_UPDATE and DELETE.
|
|
33
|
+
* @param {object} payload - The data to be imported.
|
|
34
|
+
* @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion, and queries for the request
|
|
35
|
+
* @state {DHIS2State}
|
|
36
|
+
* @returns {Operation}
|
|
37
|
+
* @example <caption>Import some data and pass the `atomicMode` parameter</caption>
|
|
38
|
+
* tracker.import('CREATE', $.trackerData, { atomicMode: 'ALL' })
|
|
39
|
+
* @example <caption>Import a trackedEntity resource</caption>
|
|
40
|
+
* tracker.import(
|
|
41
|
+
* 'CREATE',
|
|
42
|
+
* {
|
|
43
|
+
* trackedEntities: [
|
|
44
|
+
* {
|
|
45
|
+
* orgUnit: 'TSyzvBiovKh',
|
|
46
|
+
* trackedEntityType: 'nEenWmSyUEp',
|
|
47
|
+
* attributes: [
|
|
48
|
+
* {
|
|
49
|
+
* attribute: 'w75KJ2mc4zz',
|
|
50
|
+
* value: 'Gigiwe',
|
|
51
|
+
* },
|
|
52
|
+
* ],
|
|
53
|
+
* },
|
|
54
|
+
* ],
|
|
55
|
+
* },
|
|
56
|
+
* {
|
|
57
|
+
* atomicMode: 'ALL',
|
|
58
|
+
* }
|
|
59
|
+
* );
|
|
60
|
+
*/
|
|
61
|
+
declare function _import(strategy: string, payload: object, options?: TrackerOptions): Operation;
|
|
62
|
+
/**
|
|
63
|
+
* Export data from DHIS2.
|
|
64
|
+
* @alias export
|
|
65
|
+
* @public
|
|
66
|
+
* @function
|
|
67
|
+
* @param {string} path - Path to the resource, relative to the /tracker endpoint
|
|
68
|
+
* @param {object} query - An object of query parameters to be encoded into the URL
|
|
69
|
+
* @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion for the request
|
|
70
|
+
* @state {DHIS2State}
|
|
71
|
+
* @returns {Operation}
|
|
72
|
+
* @example <caption>Export a trackedEntity resource using the id</caption>
|
|
73
|
+
* tracker.export('trackedEntities/Gu5UKnIFnJf')
|
|
74
|
+
* @example <caption>Export all enrollment resources</caption>
|
|
75
|
+
* tracker.export('enrollments', {orgUnit: 'TSyzvBiovKh'});
|
|
76
|
+
* @example <caption>Export all events</caption>
|
|
77
|
+
* tracker.export('events')
|
|
78
|
+
*/
|
|
79
|
+
declare function _export(path: string, query: object, options?: TrackerOptions): Operation;
|
|
80
|
+
export { _import as import, _import as import, _export as export, _export as export };
|
package/types/util.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function shouldUseNewTracker(resourceType: any): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Converts an attribute ID and value into a DHIS2 attribute object
|
|
4
|
+
* @public
|
|
5
|
+
* @example
|
|
6
|
+
* fn(state => {
|
|
7
|
+
* const s = util.attr('w75KJ2mc4zz', 'Elias');
|
|
8
|
+
* console.log(s);
|
|
9
|
+
* return state;
|
|
10
|
+
* })
|
|
11
|
+
* @function
|
|
12
|
+
* @param {string} attribute - A tracked entity instance (TEI) attribute ID.
|
|
13
|
+
* @param {string} value - The value for that attribute.
|
|
14
|
+
* @returns {object}
|
|
15
|
+
*/
|
|
16
|
+
export function attr(attribute: string, value: string): object;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a dataElement and value into a DHIS2 dataValue object
|
|
19
|
+
* @public
|
|
20
|
+
* @example
|
|
21
|
+
* fn(state => {
|
|
22
|
+
* const s = util.dv('f7n9E0hX8qk', 12);
|
|
23
|
+
* console.log(s);
|
|
24
|
+
* return state
|
|
25
|
+
* })
|
|
26
|
+
* @function
|
|
27
|
+
* @param {string} dataElement - A data element ID.
|
|
28
|
+
* @param {string} value - The value for that data element.
|
|
29
|
+
* @returns {object}
|
|
30
|
+
*/
|
|
31
|
+
export function dv(dataElement: string, value: string): object;
|
|
32
|
+
/**
|
|
33
|
+
* Gets an attribute value by its case-insensitive display name
|
|
34
|
+
* @public
|
|
35
|
+
* @example
|
|
36
|
+
* fn(state => {
|
|
37
|
+
* const s = util.findAttributeValue(state.data.trackedEntities[0], 'first name');
|
|
38
|
+
* console.log(s);
|
|
39
|
+
* return state
|
|
40
|
+
* })
|
|
41
|
+
* @function
|
|
42
|
+
* @param {Object} trackedEntity - A tracked entity instance (TEI) object
|
|
43
|
+
* @param {string} attributeDisplayName - The 'displayName' to search for in the TEI's attributes
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
export function findAttributeValue(trackedEntity: any, attributeDisplayName: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Gets an attribute value by its uid
|
|
49
|
+
* @public
|
|
50
|
+
* @example
|
|
51
|
+
* fn(state =>{
|
|
52
|
+
* const s = util.findAttributeValueById(state.tei, 'y1w2R6leVmh');
|
|
53
|
+
* console.log(s);
|
|
54
|
+
* return state
|
|
55
|
+
* })
|
|
56
|
+
* @function
|
|
57
|
+
* @param {Object} trackedEntity - A tracked entity instance (TEI) object
|
|
58
|
+
* @param {string} attributeUid - The uid to search for in the TEI's attributes
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export function findAttributeValueById(trackedEntity: any, attributeUid: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Determines the attribute name for a DHIS2 system ID given a resource type.
|
|
64
|
+
* @param {string} resourceType
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
export function selectId(resourceType: string): string;
|
|
68
|
+
export function handleHttpResponse(result: any, state: any): any;
|
|
69
|
+
export function handleResponse(result: any, state: any): any;
|
|
70
|
+
export function prettyJson(data: any): string;
|
|
71
|
+
export function ensureArray(data: any, key: any): {
|
|
72
|
+
[x: number]: any[];
|
|
73
|
+
};
|
|
74
|
+
export function prefixVersionToPath(configuration: any, options: any, resourceType: any, path?: any): string;
|
|
75
|
+
export function request(configuration: any, requestData: any): Promise<any>;
|
|
76
|
+
export namespace CONTENT_TYPES {
|
|
77
|
+
const xml: string;
|
|
78
|
+
const json: string;
|
|
79
|
+
const pdf: string;
|
|
80
|
+
const csv: string;
|
|
81
|
+
const xls: string;
|
|
82
|
+
}
|
|
83
|
+
export function configureAuth(auth: any, headers?: {}): {};
|
package/types/Client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The request client takes configuration from state and an axios request object
|
|
3
|
-
* then (1) logs the method and URL, (2) applies standard headers and auth
|
|
4
|
-
* before spreading the rest of the axios configuration, and (3) executes an
|
|
5
|
-
* axios request.
|
|
6
|
-
* @function
|
|
7
|
-
* @param {object} configuration - configuration can either be a username and password OR a personal access token
|
|
8
|
-
* @param {object} axiosRequest - the axiosRequest contains valid axios params: https://axios-http.com/docs/req_config
|
|
9
|
-
* @returns {Promise} a promise that will resolve to either a response object or an error object.
|
|
10
|
-
*/
|
|
11
|
-
export function request({ username, password, pat }: object, axiosRequest: object): Promise<any>;
|
package/types/Utils.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function shouldUseNewTracker(resourceType: any): boolean;
|
|
2
|
-
export function buildUrl(urlString: any, hostUrl: any, apiVersion: any): string;
|
|
3
|
-
/**
|
|
4
|
-
* Determines the attribute name for a DHIS2 system ID given a resource type.
|
|
5
|
-
* @param {string} resourceType
|
|
6
|
-
* @returns {string}
|
|
7
|
-
*/
|
|
8
|
-
export function selectId(resourceType: string): string;
|
|
9
|
-
export function handleResponse(result: any, state: any, callback: any): any;
|
|
10
|
-
export function prettyJson(data: any): string;
|
|
11
|
-
export function ensureArray(data: any, key: any): {
|
|
12
|
-
[x: number]: any[];
|
|
13
|
-
};
|
|
14
|
-
export function generateUrl(configuration: any, options: any, resourceType: any, path?: any): string;
|
|
15
|
-
export namespace CONTENT_TYPES {
|
|
16
|
-
const xml: string;
|
|
17
|
-
const json: string;
|
|
18
|
-
const pdf: string;
|
|
19
|
-
const csv: string;
|
|
20
|
-
const xls: string;
|
|
21
|
-
}
|