@openfn/language-dhis2 7.0.1 → 7.1.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/ast.json CHANGED
@@ -15,54 +15,6 @@
15
15
  "description": null,
16
16
  "type": null
17
17
  },
18
- {
19
- "title": "function",
20
- "description": null,
21
- "name": null
22
- },
23
- {
24
- "title": "param",
25
- "description": "Path to the resource to be created",
26
- "type": {
27
- "type": "NameExpression",
28
- "name": "string"
29
- },
30
- "name": "path"
31
- },
32
- {
33
- "title": "magic",
34
- "description": "path $.children.resourceTypes[*]"
35
- },
36
- {
37
- "title": "param",
38
- "description": "An object, or array of objects, to create.",
39
- "type": {
40
- "type": "NameExpression",
41
- "name": "DHIS2Data"
42
- },
43
- "name": "data"
44
- },
45
- {
46
- "title": "param",
47
- "description": "Optional object of query parameters to include in the request",
48
- "type": {
49
- "type": "NameExpression",
50
- "name": "object"
51
- },
52
- "name": "params"
53
- },
54
- {
55
- "title": "state",
56
- "description": "data - The created resource as returned by DHIS2"
57
- },
58
- {
59
- "title": "returns",
60
- "description": null,
61
- "type": {
62
- "type": "NameExpression",
63
- "name": "Operation"
64
- }
65
- },
66
18
  {
67
19
  "title": "example",
68
20
  "description": "create('programs', {\n name: 'name 20',\n shortName: 'n20',\n programType: 'WITHOUT_REGISTRATION',\n});",
@@ -70,7 +22,7 @@
70
22
  },
71
23
  {
72
24
  "title": "example",
73
- "description": "create('events', {\n program: 'eBAyeGv0exc',\n orgUnit: 'DiszpKrYNg8',\n status: 'COMPLETED',\n});",
25
+ "description": "create('events', {\n program: 'eBAyeGv0exc',\n orgUnit: 'DiszpKrYNg8',\n occurredAt: '2025-06-19',\n status: 'COMPLETED',\n});",
74
26
  "caption": "Create a single event"
75
27
  },
76
28
  {
@@ -80,7 +32,7 @@
80
32
  },
81
33
  {
82
34
  "title": "example",
83
- "description": "create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly' });",
35
+ "description": "create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly', shortName: 'ODS' });",
84
36
  "caption": "Create a dataSet"
85
37
  },
86
38
  {
@@ -95,7 +47,7 @@
95
47
  },
96
48
  {
97
49
  "title": "example",
98
- "description": "create('dataElementGroups', {\n name: 'Data Element Group 1',\n dataElements: [],\n});",
50
+ "description": "create('dataElementGroups', {\n name: 'Data Element Group 1',\n shortName: 'DEG1',\n dataElements: [],\n});",
99
51
  "caption": "Create a dataElementGroup"
100
52
  },
101
53
  {
@@ -115,26 +67,8 @@
115
67
  },
116
68
  {
117
69
  "title": "example",
118
- "description": "create('enrollments', {\n trackedEntity: 'bmshzEacgxa',\n orgUnit: 'TSyzvBiovKh',\n program: 'gZBxv9Ujxg0',\n enrollmentDate: '2013-09-17',\n incidentDate: '2013-09-17',\n});",
70
+ "description": "create('enrollments', {\n trackedEntity: 'bmshzEacgxa',\n orgUnit: 'TSyzvBiovKh',\n program: 'ur1Edk5Oe2n',\n enrolledAt: '2013-09-17',\n enrollmentDate: '2013-09-17',\n incidentDate: '2013-09-17',\n});",
119
71
  "caption": "Create an enrollment"
120
- }
121
- ]
122
- },
123
- "valid": true
124
- },
125
- {
126
- "name": "get",
127
- "params": [
128
- "path",
129
- "params"
130
- ],
131
- "docs": {
132
- "description": "Get any resource, as JSON, from DHIS2. Pass in any valid DHIS2 REST path, excluding /api and the version.\nFor the new tracker API, see `tracker.export()`",
133
- "tags": [
134
- {
135
- "title": "public",
136
- "description": null,
137
- "type": null
138
72
  },
139
73
  {
140
74
  "title": "function",
@@ -143,16 +77,29 @@
143
77
  },
144
78
  {
145
79
  "title": "param",
146
- "description": "Path to the resource",
80
+ "description": "Path to the resource to be created",
147
81
  "type": {
148
82
  "type": "NameExpression",
149
83
  "name": "string"
150
84
  },
151
85
  "name": "path"
152
86
  },
87
+ {
88
+ "title": "magic",
89
+ "description": "path $.children.resourceTypes[*]"
90
+ },
153
91
  {
154
92
  "title": "param",
155
- "description": "Object of query parameters to include in the request",
93
+ "description": "An object, or array of objects, to create.",
94
+ "type": {
95
+ "type": "NameExpression",
96
+ "name": "DHIS2Data"
97
+ },
98
+ "name": "data"
99
+ },
100
+ {
101
+ "title": "param",
102
+ "description": "Optional object of query parameters to include in the request",
156
103
  "type": {
157
104
  "type": "NameExpression",
158
105
  "name": "object"
@@ -161,7 +108,7 @@
161
108
  },
162
109
  {
163
110
  "title": "state",
164
- "description": "data - the resource returned by DHIS2"
111
+ "description": "data - The created resource as returned by DHIS2"
165
112
  },
166
113
  {
167
114
  "title": "returns",
@@ -170,42 +117,40 @@
170
117
  "type": "NameExpression",
171
118
  "name": "Operation"
172
119
  }
173
- },
174
- {
175
- "title": "example",
176
- "description": "get('dataValueSets', {\n dataSet: 'pBOMPrpg1QX',\n orgUnit: 'DiszpKrYNg8',\n period: '201401',\n fields: '*',\n});",
177
- "caption": "Get all data values for the 'pBOMPrpg1QX' dataset"
178
- },
179
- {
180
- "title": "example",
181
- "description": "get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });",
182
- "caption": "Get all programs for an organization unit"
183
- },
184
- {
185
- "title": "example",
186
- "description": "get('tracker/trackedEntities/F8yKM85NbxW');",
187
- "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)"
188
120
  }
189
121
  ]
190
122
  },
191
123
  "valid": true
192
124
  },
193
125
  {
194
- "name": "update",
126
+ "name": "get",
195
127
  "params": [
196
- "resourceType",
197
128
  "path",
198
- "data",
199
- "options"
129
+ "params"
200
130
  ],
201
131
  "docs": {
202
- "description": "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",
132
+ "description": "Get any resource, as JSON, from DHIS2. Pass in any valid DHIS2 REST path, excluding /api and the version.\nFor the new tracker API, see `tracker.export()`",
203
133
  "tags": [
204
134
  {
205
135
  "title": "public",
206
136
  "description": null,
207
137
  "type": null
208
138
  },
139
+ {
140
+ "title": "example",
141
+ "description": "get('dataValueSets', {\n dataSet: 'pBOMPrpg1QX',\n orgUnit: 'DiszpKrYNg8',\n period: '201401',\n fields: '*',\n});",
142
+ "caption": "Get all data values for the 'pBOMPrpg1QX' dataset"
143
+ },
144
+ {
145
+ "title": "example",
146
+ "description": "get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });",
147
+ "caption": "Get all programs for an organization unit"
148
+ },
149
+ {
150
+ "title": "example",
151
+ "description": "get('tracker/trackedEntities/F8yKM85NbxW');",
152
+ "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)"
153
+ },
209
154
  {
210
155
  "title": "function",
211
156
  "description": null,
@@ -213,16 +158,7 @@
213
158
  },
214
159
  {
215
160
  "title": "param",
216
- "description": "The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.",
217
- "type": {
218
- "type": "NameExpression",
219
- "name": "string"
220
- },
221
- "name": "resourceType"
222
- },
223
- {
224
- "title": "param",
225
- "description": "The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`",
161
+ "description": "Path to the resource",
226
162
  "type": {
227
163
  "type": "NameExpression",
228
164
  "name": "string"
@@ -231,24 +167,12 @@
231
167
  },
232
168
  {
233
169
  "title": "param",
234
- "description": "Data to update. It requires to send the full body. If you want partial updates, use patch operation.",
170
+ "description": "Object of query parameters to include in the request",
235
171
  "type": {
236
172
  "type": "NameExpression",
237
- "name": "Object"
238
- },
239
- "name": "data"
240
- },
241
- {
242
- "title": "param",
243
- "description": "An optional object containing query, parseAs,and headers for the request.",
244
- "type": {
245
- "type": "OptionalType",
246
- "expression": {
247
- "type": "NameExpression",
248
- "name": "RequestOptions"
249
- }
173
+ "name": "object"
250
174
  },
251
- "name": "options"
175
+ "name": "params"
252
176
  },
253
177
  {
254
178
  "title": "state",
@@ -261,6 +185,26 @@
261
185
  "type": "NameExpression",
262
186
  "name": "Operation"
263
187
  }
188
+ }
189
+ ]
190
+ },
191
+ "valid": true
192
+ },
193
+ {
194
+ "name": "update",
195
+ "params": [
196
+ "resourceType",
197
+ "path",
198
+ "data",
199
+ "options"
200
+ ],
201
+ "docs": {
202
+ "description": "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",
203
+ "tags": [
204
+ {
205
+ "title": "public",
206
+ "description": null,
207
+ "type": null
264
208
  },
265
209
  {
266
210
  "title": "example",
@@ -316,6 +260,62 @@
316
260
  "title": "example",
317
261
  "description": "update('enrollments', 'CmsHzercTBa' {\n trackedEntity: 'bmshzEacgxa',\n orgUnit: 'TSyzvBiovKh',\n program: 'gZBxv9Ujxg0',\n enrollmentDate: '2013-10-17',\n incidentDate: '2013-10-17',\n});",
318
262
  "caption": "Update an enrollment given the provided ID"
263
+ },
264
+ {
265
+ "title": "function",
266
+ "description": null,
267
+ "name": null
268
+ },
269
+ {
270
+ "title": "param",
271
+ "description": "The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.",
272
+ "type": {
273
+ "type": "NameExpression",
274
+ "name": "string"
275
+ },
276
+ "name": "resourceType"
277
+ },
278
+ {
279
+ "title": "param",
280
+ "description": "The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`",
281
+ "type": {
282
+ "type": "NameExpression",
283
+ "name": "string"
284
+ },
285
+ "name": "path"
286
+ },
287
+ {
288
+ "title": "param",
289
+ "description": "Data to update. It requires to send the full body. If you want partial updates, use patch operation.",
290
+ "type": {
291
+ "type": "NameExpression",
292
+ "name": "Object"
293
+ },
294
+ "name": "data"
295
+ },
296
+ {
297
+ "title": "param",
298
+ "description": "An optional object containing query, parseAs,and headers for the request.",
299
+ "type": {
300
+ "type": "OptionalType",
301
+ "expression": {
302
+ "type": "NameExpression",
303
+ "name": "RequestOptions"
304
+ }
305
+ },
306
+ "name": "options"
307
+ },
308
+ {
309
+ "title": "state",
310
+ "description": "data - the resource returned by DHIS2"
311
+ },
312
+ {
313
+ "title": "returns",
314
+ "description": null,
315
+ "type": {
316
+ "type": "NameExpression",
317
+ "name": "Operation"
318
+ }
319
319
  }
320
320
  ]
321
321
  },
@@ -337,6 +337,16 @@
337
337
  "description": null,
338
338
  "type": null
339
339
  },
340
+ {
341
+ "title": "example",
342
+ "description": "upsert('trackedEntities', {}, {\n orgUnit: 'TSyzvBiovKh',\n trackedEntityType: 'nEenWmSyUEp',\n attributes: [\n {\n attribute: 'w75KJ2mc4zz',\n value: 'Qassim',\n },\n ],\n});",
343
+ "caption": "Upsert a trackedEntity"
344
+ },
345
+ {
346
+ "title": "example",
347
+ "description": "upsert(\n 'dataElements',\n { filter: 'id:eq:P3jJH5Tu5VC' },\n {\n op: 'add',\n path: '/domainType',\n name: 'Acute',\n shortName: 'AFP follow-up',\n dimensionItemType: 'DATA_ELEMENT',\n legendSets: [],\n aggregationType: 'SUM',\n valueType: 'NUMBER',\n domainType: 'AGGREGATE',\n code: 'DE_359049',\n name: 'Acute Flaccid Paralysis (AFP) follow-up',\n }\n );",
348
+ "caption": "Upsert a dataElement"
349
+ },
340
350
  {
341
351
  "title": "function",
342
352
  "description": null,
@@ -400,16 +410,6 @@
400
410
  "type": "NameExpression",
401
411
  "name": "Operation"
402
412
  }
403
- },
404
- {
405
- "title": "example",
406
- "description": "upsert('trackedEntities', {}, {\n orgUnit: 'TSyzvBiovKh',\n trackedEntityType: 'nEenWmSyUEp',\n attributes: [\n {\n attribute: 'w75KJ2mc4zz',\n value: 'Qassim',\n },\n ],\n});",
407
- "caption": "Upsert a trackedEntity"
408
- },
409
- {
410
- "title": "example",
411
- "description": "upsert(\n 'dataElements',\n { filter: 'id:eq:P3jJH5Tu5VC' },\n {\n op: 'add',\n path: '/domainType',\n name: 'Acute',\n shortName: 'AFP follow-up',\n dimensionItemType: 'DATA_ELEMENT',\n legendSets: [],\n aggregationType: 'SUM',\n valueType: 'NUMBER',\n domainType: 'AGGREGATE',\n code: 'DE_359049',\n name: 'Acute Flaccid Paralysis (AFP) follow-up',\n }\n );",
412
- "caption": "Upsert a dataElement"
413
413
  }
414
414
  ]
415
415
  },
@@ -436,6 +436,11 @@
436
436
  "description": null,
437
437
  "name": null
438
438
  },
439
+ {
440
+ "title": "example",
441
+ "description": "destroy('trackedEntities', 'LcRd6Nyaq7T');",
442
+ "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)"
443
+ },
439
444
  {
440
445
  "title": "param",
441
446
  "description": "The type of resource to be deleted. E.g. `trackedEntities`, `organisationUnits`, etc.",
@@ -489,11 +494,6 @@
489
494
  "type": "NameExpression",
490
495
  "name": "Operation"
491
496
  }
492
- },
493
- {
494
- "title": "example",
495
- "description": "destroy('trackedEntities', 'LcRd6Nyaq7T');",
496
- "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)"
497
497
  }
498
498
  ]
499
499
  },
@@ -1150,6 +1150,125 @@
1150
1150
  ]
1151
1151
  },
1152
1152
  "valid": false
1153
+ },
1154
+ {
1155
+ "name": "as",
1156
+ "params": [
1157
+ "key",
1158
+ "operation"
1159
+ ],
1160
+ "docs": {
1161
+ "description": "Run an operation and save the result to a custom key in state instead of overwriting state.data.",
1162
+ "tags": [
1163
+ {
1164
+ "title": "public",
1165
+ "description": null,
1166
+ "type": null
1167
+ },
1168
+ {
1169
+ "title": "function",
1170
+ "description": null,
1171
+ "name": null
1172
+ },
1173
+ {
1174
+ "title": "example",
1175
+ "description": "as('cceData', collections.get('cce-data-dhis2', { key: `*:*:${$.syncedAt}*` }));",
1176
+ "caption": "Fetch cce-data from collections and store them under state.cceData"
1177
+ },
1178
+ {
1179
+ "title": "param",
1180
+ "description": "The state key to assign the result of the operation to.",
1181
+ "type": {
1182
+ "type": "NameExpression",
1183
+ "name": "string"
1184
+ },
1185
+ "name": "key"
1186
+ },
1187
+ {
1188
+ "title": "param",
1189
+ "description": " An operation that returns a new state object with a `data` property",
1190
+ "type": {
1191
+ "type": "NameExpression",
1192
+ "name": "function"
1193
+ },
1194
+ "name": "operation"
1195
+ },
1196
+ {
1197
+ "title": "returns",
1198
+ "description": null,
1199
+ "type": {
1200
+ "type": "NameExpression",
1201
+ "name": "Operation"
1202
+ }
1203
+ }
1204
+ ]
1205
+ },
1206
+ "valid": true
1207
+ },
1208
+ {
1209
+ "name": "map",
1210
+ "params": {},
1211
+ "docs": {
1212
+ "description": "Iterates over a collection of items and returns a new array of mapped values,\nlike Javascript's `Array.map()` function.\n\nEach item in the source array will be passed into the callback function. The returned value\nwill be added to the new array. The callback is passed the original item, the current index\nin the source array (ie, the nth item number), and the state object.\n\nWrites a new array to `state.data` with transformed values.c array.",
1213
+ "tags": [
1214
+ {
1215
+ "title": "public",
1216
+ "description": null,
1217
+ "type": null
1218
+ },
1219
+ {
1220
+ "title": "function",
1221
+ "description": null,
1222
+ "name": null
1223
+ },
1224
+ {
1225
+ "title": "example",
1226
+ "description": "map($.items', (data, index, state) => {\n return {\n id: index + 1,\n name: data.name,\n createdAt: state.cursor,\n };\n});",
1227
+ "caption": "Transform an array of items in state"
1228
+ },
1229
+ {
1230
+ "title": "example",
1231
+ "description": "map($.items, async (data, index, state) => {\n const userInfo = await fetchUserInfo(data.userId);\n return {\n id: index + 1,\n name: data.name,\n extra: userInfo,\n };\n});",
1232
+ "caption": "Map items asynchronously (e.g. fetch extra info)"
1233
+ },
1234
+ {
1235
+ "title": "param",
1236
+ "description": "An array of items or a a JSONPath string which points to an array of items.",
1237
+ "type": {
1238
+ "type": "UnionType",
1239
+ "elements": [
1240
+ {
1241
+ "type": "NameExpression",
1242
+ "name": "string"
1243
+ },
1244
+ {
1245
+ "type": "NameExpression",
1246
+ "name": "Array"
1247
+ }
1248
+ ]
1249
+ },
1250
+ "name": "path"
1251
+ },
1252
+ {
1253
+ "title": "param",
1254
+ "description": "The mapping function, invoked with `(data, index, state)` for each item in the array.",
1255
+ "type": {
1256
+ "type": "NameExpression",
1257
+ "name": "function"
1258
+ },
1259
+ "name": "callback"
1260
+ },
1261
+ {
1262
+ "title": "returns",
1263
+ "description": null,
1264
+ "type": {
1265
+ "type": "NameExpression",
1266
+ "name": "State"
1267
+ }
1268
+ }
1269
+ ]
1270
+ },
1271
+ "valid": false
1153
1272
  }
1154
1273
  ]
1155
1274
  }
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
26
26
  var src_exports = {};
27
27
  __export(src_exports, {
28
28
  alterState: () => import_language_common3.alterState,
29
+ as: () => import_language_common3.as,
29
30
  create: () => create,
30
31
  cursor: () => import_language_common3.cursor,
31
32
  dataPath: () => import_language_common3.dataPath,
@@ -43,6 +44,7 @@ __export(src_exports, {
43
44
  group: () => import_language_common3.group,
44
45
  http: () => http_exports,
45
46
  lastReferenceValue: () => import_language_common3.lastReferenceValue,
47
+ map: () => import_language_common3.map,
46
48
  merge: () => import_language_common3.merge,
47
49
  metadata: () => metadata_default,
48
50
  sourceValue: () => import_language_common3.sourceValue,
@@ -285,6 +287,7 @@ var metadata_default = metadata;
285
287
  var Adaptor_exports = {};
286
288
  __export(Adaptor_exports, {
287
289
  alterState: () => import_language_common3.alterState,
290
+ as: () => import_language_common3.as,
288
291
  create: () => create,
289
292
  cursor: () => import_language_common3.cursor,
290
293
  dataPath: () => import_language_common3.dataPath,
@@ -301,6 +304,7 @@ __export(Adaptor_exports, {
301
304
  group: () => import_language_common3.group,
302
305
  http: () => import_language_common3.http,
303
306
  lastReferenceValue: () => import_language_common3.lastReferenceValue,
307
+ map: () => import_language_common3.map,
304
308
  merge: () => import_language_common3.merge,
305
309
  sourceValue: () => import_language_common3.sourceValue,
306
310
  update: () => update,
@@ -341,7 +345,6 @@ function configMigrationHelper(state) {
341
345
  }
342
346
  function create(path, data, params = {}) {
343
347
  return async (state) => {
344
- var _a;
345
348
  if (path === "tracker") {
346
349
  throw new Error("Invalid resourceType. Use `tracker.import()` instead.");
347
350
  }
@@ -373,15 +376,11 @@ function create(path, data, params = {}) {
373
376
  data: resolvedData
374
377
  });
375
378
  }
376
- const details = `with response ${JSON.stringify(
377
- (_a = response.body) == null ? void 0 : _a.message,
378
- null,
379
- 2
380
- )}`;
381
- console.log(`Created ${resolvedPath} ${details}`);
379
+ console.log(`Created ${resolvedPath}`);
382
380
  const { location } = response.headers;
383
- if (location)
381
+ if (location) {
384
382
  console.log(`Record available @ ${location}`);
383
+ }
385
384
  return handleResponse(response, state);
386
385
  };
387
386
  }
@@ -724,6 +723,7 @@ var src_default = Adaptor_exports;
724
723
  // Annotate the CommonJS export names for ESM import in node:
725
724
  0 && (module.exports = {
726
725
  alterState,
726
+ as,
727
727
  create,
728
728
  cursor,
729
729
  dataPath,
@@ -740,6 +740,7 @@ var src_default = Adaptor_exports;
740
740
  group,
741
741
  http,
742
742
  lastReferenceValue,
743
+ map,
743
744
  merge,
744
745
  metadata,
745
746
  sourceValue,
package/dist/index.js CHANGED
@@ -240,6 +240,7 @@ var metadata_default = metadata;
240
240
  var Adaptor_exports = {};
241
241
  __export(Adaptor_exports, {
242
242
  alterState: () => alterState,
243
+ as: () => as,
243
244
  create: () => create,
244
245
  cursor: () => cursor,
245
246
  dataPath: () => dataPath,
@@ -256,6 +257,7 @@ __export(Adaptor_exports, {
256
257
  group: () => group,
257
258
  http: () => http,
258
259
  lastReferenceValue: () => lastReferenceValue,
260
+ map: () => map,
259
261
  merge: () => merge,
260
262
  sourceValue: () => sourceValue,
261
263
  update: () => update,
@@ -265,18 +267,20 @@ import { execute as commonExecute } from "@openfn/language-common";
265
267
  import { expandReferences, throwError } from "@openfn/language-common/util";
266
268
  import {
267
269
  alterState,
270
+ as,
271
+ cursor,
268
272
  dataPath,
269
273
  dataValue,
270
274
  dateFns,
271
- cursor,
272
275
  each,
273
276
  field,
274
277
  fields,
275
278
  fn,
276
279
  fnIf,
277
- http,
278
280
  group,
281
+ http,
279
282
  lastReferenceValue,
283
+ map,
280
284
  merge,
281
285
  sourceValue
282
286
  } from "@openfn/language-common";
@@ -312,7 +316,6 @@ function configMigrationHelper(state) {
312
316
  }
313
317
  function create(path, data, params = {}) {
314
318
  return async (state) => {
315
- var _a;
316
319
  if (path === "tracker") {
317
320
  throw new Error("Invalid resourceType. Use `tracker.import()` instead.");
318
321
  }
@@ -344,15 +347,11 @@ function create(path, data, params = {}) {
344
347
  data: resolvedData
345
348
  });
346
349
  }
347
- const details = `with response ${JSON.stringify(
348
- (_a = response.body) == null ? void 0 : _a.message,
349
- null,
350
- 2
351
- )}`;
352
- console.log(`Created ${resolvedPath} ${details}`);
350
+ console.log(`Created ${resolvedPath}`);
353
351
  const { location } = response.headers;
354
- if (location)
352
+ if (location) {
355
353
  console.log(`Record available @ ${location}`);
354
+ }
356
355
  return handleResponse(response, state);
357
356
  };
358
357
  }
@@ -694,6 +693,7 @@ function _export(path, query, options = {}) {
694
693
  var src_default = Adaptor_exports;
695
694
  export {
696
695
  alterState,
696
+ as,
697
697
  create,
698
698
  cursor,
699
699
  dataPath,
@@ -711,6 +711,7 @@ export {
711
711
  group,
712
712
  http_exports as http,
713
713
  lastReferenceValue,
714
+ map,
714
715
  merge,
715
716
  metadata_default as metadata,
716
717
  sourceValue,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-dhis2",
3
3
  "label": "DHIS2",
4
- "version": "7.0.1",
4
+ "version": "7.1.0",
5
5
  "description": "DHIS2 Language Pack for OpenFn",
6
6
  "homepage": "https://docs.openfn.org",
7
7
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "axios": "^1.8.2",
30
30
  "lodash": "^4.17.21",
31
31
  "qs": "^6.11.0",
32
- "@openfn/language-common": "2.5.0"
32
+ "@openfn/language-common": "3.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "assertion-error": "2.0.0",
@@ -29,13 +29,6 @@ export function execute(...operations: Operations): Operation;
29
29
  /**
30
30
  * Create a record
31
31
  * @public
32
- * @function
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
38
- * @returns {Operation}
39
32
  * @example <caption>Create a program</caption>
40
33
  * create('programs', {
41
34
  * name: 'name 20',
@@ -46,6 +39,7 @@ export function execute(...operations: Operations): Operation;
46
39
  * create('events', {
47
40
  * program: 'eBAyeGv0exc',
48
41
  * orgUnit: 'DiszpKrYNg8',
42
+ * occurredAt: '2025-06-19',
49
43
  * status: 'COMPLETED',
50
44
  * });
51
45
  * @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>
@@ -60,7 +54,7 @@ export function execute(...operations: Operations): Operation;
60
54
  * ]
61
55
  * });
62
56
  * @example <caption>Create a dataSet</caption>
63
- * create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly' });
57
+ * create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly', shortName: 'ODS' });
64
58
  * @example <caption>a dataSetNotification</caption>
65
59
  * create('dataSetNotificationTemplates', {
66
60
  * dataSetNotificationTrigger: 'DATA_SET_COMPLETION',
@@ -81,6 +75,7 @@ export function execute(...operations: Operations): Operation;
81
75
  * @example <caption>Create a dataElementGroup</caption>
82
76
  * create('dataElementGroups', {
83
77
  * name: 'Data Element Group 1',
78
+ * shortName: 'DEG1',
84
79
  * dataElements: [],
85
80
  * });
86
81
  * @example <caption>Create a dataElementGroupSet</caption>
@@ -122,21 +117,24 @@ export function execute(...operations: Operations): Operation;
122
117
  * create('enrollments', {
123
118
  * trackedEntity: 'bmshzEacgxa',
124
119
  * orgUnit: 'TSyzvBiovKh',
125
- * program: 'gZBxv9Ujxg0',
120
+ * program: 'ur1Edk5Oe2n',
121
+ * enrolledAt: '2013-09-17',
126
122
  * enrollmentDate: '2013-09-17',
127
123
  * incidentDate: '2013-09-17',
128
124
  * });
125
+ * @function
126
+ * @param {string} path - Path to the resource to be created
127
+ * @magic path $.children.resourceTypes[*]
128
+ * @param {DHIS2Data} data - An object, or array of objects, to create.
129
+ * @param {object} params - Optional object of query parameters to include in the request
130
+ * @state data - The created resource as returned by DHIS2
131
+ * @returns {Operation}
129
132
  */
130
133
  export function create(path: string, data: DHIS2Data, params?: object): Operation;
131
134
  /**
132
135
  * Get any resource, as JSON, from DHIS2. Pass in any valid DHIS2 REST path, excluding /api and the version.
133
136
  * For the new tracker API, see `tracker.export()`
134
137
  * @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
138
  * @example <caption>Get all data values for the 'pBOMPrpg1QX' dataset</caption>
141
139
  * get('dataValueSets', {
142
140
  * dataSet: 'pBOMPrpg1QX',
@@ -148,18 +146,16 @@ export function create(path: string, data: DHIS2Data, params?: object): Operatio
148
146
  * get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
149
147
  * @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
148
  * get('tracker/trackedEntities/F8yKM85NbxW');
149
+ * @function
150
+ * @param {string} path - Path to the resource
151
+ * @param {object} params - Object of query parameters to include in the request
152
+ * @state data - the resource returned by DHIS2
153
+ * @returns {Operation}
151
154
  */
152
155
  export function get(path: string, params?: object): Operation;
153
156
  /**
154
157
  * 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
155
158
  * @public
156
- * @function
157
- * @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
158
- * @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
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
162
- * @returns {Operation}
163
159
  * @example <caption>a program</caption>
164
160
  * update('programs', 'qAZJCrNJK8H', {
165
161
  * name: '14e1aa02c3f0a31618e096f2c6d03bed',
@@ -278,20 +274,19 @@ export function get(path: string, params?: object): Operation;
278
274
  * enrollmentDate: '2013-10-17',
279
275
  * incidentDate: '2013-10-17',
280
276
  * });
277
+ * @function
278
+ * @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
279
+ * @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
280
+ * @param {Object} data - Data to update. It requires to send the full body. If you want partial updates, use patch operation.
281
+ * @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
282
+ * @state data - the resource returned by DHIS2
283
+ * @returns {Operation}
281
284
  */
282
285
  export function update(resourceType: string, path: string, data: any, options?: RequestOptions): Operation;
283
286
  /**
284
287
  * Upsert a record. This will atomically update a record if it already exists, or otherwise create it.
285
288
  * This function does not work with the absolute tracker path `api/tracker` but rather the new tracker paths and deprecated tracker endpoints.
286
289
  * @public
287
- * @function
288
- * @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`.
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.
290
- * @param {Object} data - The data to use for update or create depending on the result of the query.
291
- * @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request
292
- * @throws {RangeError} - Throws range error
293
- * @state {DHIS2State}
294
- * @returns {Operation}
295
290
  * @example <caption>Upsert a trackedEntity</caption>
296
291
  * upsert('trackedEntities', {}, {
297
292
  * orgUnit: 'TSyzvBiovKh',
@@ -321,20 +316,28 @@ export function update(resourceType: string, path: string, data: any, options?:
321
316
  * name: 'Acute Flaccid Paralysis (AFP) follow-up',
322
317
  * }
323
318
  * );
319
+ * @function
320
+ * @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`.
321
+ * @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.
322
+ * @param {Object} data - The data to use for update or create depending on the result of the query.
323
+ * @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request
324
+ * @throws {RangeError} - Throws range error
325
+ * @state {DHIS2State}
326
+ * @returns {Operation}
324
327
  */
325
328
  export function upsert(resourceType: string, query: any, data: any, options?: RequestOptions): Operation;
326
329
  /**
327
330
  * Delete record.
328
331
  * @public
329
332
  * @function
333
+ * @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>
334
+ * destroy('trackedEntities', 'LcRd6Nyaq7T');
330
335
  * @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntities`, `organisationUnits`, etc.
331
336
  * @param {string} path - Can be an `id` of an `object` or `path` to the `nested object` to `delete`.
332
337
  * @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}
333
338
  * @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
334
339
  * @state {DHIS2State}
335
340
  * @returns {Operation}
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>
337
- * destroy('trackedEntities', 'LcRd6Nyaq7T');
338
341
  */
339
342
  export function destroy(resourceType: string, path: string, data?: any, options?: RequestOptions): Operation;
340
343
  /**
@@ -362,4 +365,4 @@ export type RequestOptions = {
362
365
  */
363
366
  apiVersion?: string;
364
367
  };
365
- export { alterState, dataPath, dataValue, dateFns, cursor, each, field, fields, fn, fnIf, http, group, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
368
+ export { alterState, as, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, group, http, lastReferenceValue, map, merge, sourceValue } from "@openfn/language-common";
@@ -28,12 +28,6 @@ export type TrackerOptions = {
28
28
  * Import data into DHIS2 using the tracker endpoint.
29
29
  * @alias import
30
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
31
  * @example <caption>Import some data and pass the `atomicMode` parameter</caption>
38
32
  * tracker.import('CREATE', $.trackerData, { atomicMode: 'ALL' })
39
33
  * @example <caption>Import a trackedEntity resource</caption>
@@ -57,24 +51,30 @@ export type TrackerOptions = {
57
51
  * atomicMode: 'ALL',
58
52
  * }
59
53
  * );
54
+ * @function
55
+ * @param {string} strategy - The effect the import should have. Can either be CREATE, UPDATE, CREATE_AND_UPDATE and DELETE.
56
+ * @param {object} payload - The data to be imported.
57
+ * @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion, and queries for the request
58
+ * @state {DHIS2State}
59
+ * @returns {Operation}
60
60
  */
61
61
  declare function _import(strategy: string, payload: object, options?: TrackerOptions): Operation;
62
62
  /**
63
63
  * Export data from DHIS2.
64
64
  * @alias export
65
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
66
  * @example <caption>Export a trackedEntity resource using the id</caption>
73
67
  * tracker.export('trackedEntities/Gu5UKnIFnJf')
74
68
  * @example <caption>Export all enrollment resources</caption>
75
69
  * tracker.export('enrollments', {orgUnit: 'TSyzvBiovKh'});
76
70
  * @example <caption>Export all events</caption>
77
71
  * tracker.export('events')
72
+ * @function
73
+ * @param {string} path - Path to the resource, relative to the /tracker endpoint
74
+ * @param {object} query - An object of query parameters to be encoded into the URL
75
+ * @param {TrackerOptions} [options] - An optional object containing parseAs, and apiVersion for the request
76
+ * @state {DHIS2State}
77
+ * @returns {Operation}
78
78
  */
79
79
  declare function _export(path: string, query: object, options?: TrackerOptions): Operation;
80
80
  export { _import as import, _import as import, _export as export, _export as export };