/**
* State object
* @typedef {Object} DHIS2State
* @private
* @property data - The response body (as JSON)
* @property references - An array of all previous data objects used in the Job
*/
/**
* Options object
* @typedef {Object} RequestOptions
* @property {object} query - An object of query parameters to be encoded into the URL
* @property {object} headers - An object of all request headers
* @property {string} [parseAs='json'] - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
* @property {string} [apiVersion=42] - The apiVersion of the request. Defaults to 42.
*/
/**
* Execute a sequence of operations.
* Wraps `language-common/execute`, and prepends initial state for DHIS2.
* @example
* execute(
* create('foo'),
* delete('bar')
* )(state)
* @private
* @param {Operations} operations - Operations to be performed.
* @returns {Operation}
*/
export function execute(...operations: Operations): Operation;
/**
* Create a record
* @public
* @example
Create a program
* create('programs', {
* name: 'name 20',
* shortName: 'n20',
* programType: 'WITHOUT_REGISTRATION',
* });
* @example Create a single event
* create('events', {
* program: 'eBAyeGv0exc',
* orgUnit: 'DiszpKrYNg8',
* occurredAt: '2025-06-19',
* status: 'COMPLETED',
* });
* @example 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)
* create('trackedEntities', {
* orgUnit: 'TSyzvBiovKh',
* trackedEntityType: 'nEenWmSyUEp',
* attributes: [
* {
* attribute: 'w75KJ2mc4zz',
* value: 'Gigiwe',
* },
* ]
* });
* @example Create a dataSet
* create('dataSets', { name: 'OpenFn Data Set', periodType: 'Monthly', shortName: 'ODS' });
* @example a dataSetNotification
* create('dataSetNotificationTemplates', {
* dataSetNotificationTrigger: 'DATA_SET_COMPLETION',
* notificationRecipient: 'ORGANISATION_UNIT_CONTACT',
* name: 'Notification',
* messageTemplate: 'Hello',
* deliveryChannels: ['SMS'],
* dataSets: [],
* });
* @example Create a dataElement
* create('dataElements', {
* aggregationType: 'SUM',
* domainType: 'AGGREGATE',
* valueType: 'NUMBER',
* name: 'Paracetamol',
* shortName: 'Para',
* });
* @example Create a dataElementGroup
* create('dataElementGroups', {
* name: 'Data Element Group 1',
* shortName: 'DEG1',
* dataElements: [],
* });
* @example Create a dataElementGroupSet
* create('dataElementGroupSets', {
* name: 'Data Element Group Set 4',
* dataDimension: true,
* shortName: 'DEGS4',
* dataElementGroups: [],
* });
* @example Create a dataValueSet
* create('dataValueSets', {
* dataElement: 'f7n9E0hX8qk',
* period: '201401',
* orgUnit: 'DiszpKrYNg8',
* value: '12',
* });
* @example Create a dataValueSet with related dataValues
* create('dataValueSets', {
* dataSet: 'pBOMPrpg1QX',
* completeDate: '2014-02-03',
* period: '201401',
* orgUnit: 'DiszpKrYNg8',
* dataValues: [
* {
* dataElement: 'f7n9E0hX8qk',
* value: '1',
* },
* {
* dataElement: 'Ix2HsbDMLea',
* value: '2',
* },
* {
* dataElement: 'eY5ehpbEsB7',
* value: '3',
* },
* ],
* });
* @example Create an enrollment
* create('enrollments', {
* trackedEntity: 'bmshzEacgxa',
* orgUnit: 'TSyzvBiovKh',
* program: 'ur1Edk5Oe2n',
* enrolledAt: '2013-09-17',
* enrollmentDate: '2013-09-17',
* incidentDate: '2013-09-17',
* });
* @function
* @param {string} path - Path to the resource to be created
* @magic path $.children.resourceTypes[*]
* @param {DHIS2Data} data - An object, or array of objects, to create.
* @param {object} params - Optional object of query parameters to include in the request
* @state data - The created resource as returned by DHIS2
* @returns {Operation}
*/
export function create(path: string, data: DHIS2Data, params?: object): Operation;
/**
* Get any resource, as JSON, from DHIS2. Pass in any valid DHIS2 REST path, excluding /api and the version.
* For the new tracker API, see `tracker.export()`
* @public
* @example Get all data values for the 'pBOMPrpg1QX' dataset
* get('dataValueSets', {
* dataSet: 'pBOMPrpg1QX',
* orgUnit: 'DiszpKrYNg8',
* period: '201401',
* fields: '*',
* });
* @example Get all programs for an organization unit
* get('programs', { orgUnit: 'TSyzvBiovKh', fields: '*' });
* @example 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)
* get('tracker/trackedEntities/F8yKM85NbxW');
* @function
* @param {string} path - Path to the resource
* @param {object} params - Object of query parameters to include in the request
* @state data - the resource returned by DHIS2
* @returns {Operation}
*/
export function get(path: string, params?: object): Operation;
/**
* 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
* @public
* @example a program
* update('programs', 'qAZJCrNJK8H', {
* name: '14e1aa02c3f0a31618e096f2c6d03bed',
* shortName: '14e1aa02',
* programType: 'WITHOUT_REGISTRATION',
* });
* @example an event
* update('events', 'PVqUD2hvU4E', {
* program: 'eBAyeGv0exc',
* orgUnit: 'Ngelehun CHC',
* status: 'COMPLETED',
* storedBy: 'admin',
* dataValues: [],
* });
* @example Update a tracker entity. See [Update tracker docs](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-241/tracker.html#webapi_nti_import)
* update('trackedEntities', '', {
* createdAt: '2015-08-06T21:12:37.256',
* orgUnit: 'TSyzvBiovKh',
* createdAtClient: '2015-08-06T21:12:37.256',
* trackedEntity: 'IeQfgUtGPq2',
* trackedEntityType: 'nEenWmSyUEp',
* inactive: false,
* deleted: false,
* featureType: 'NONE',
* programOwners: [
* {
* ownerOrgUnit: 'TSyzvBiovKh',
* program: 'IpHINAT79UW',
* trackedEntity: 'IeQfgUtGPq2',
* },
* ],
* attributes: [
* {
* lastUpdated: '2016-01-12T00:00:00.000',
* displayName: 'Last name',
* created: '2016-01-12T00:00:00.000',
* valueType: 'TEXT',
* attribute: 'zDhUuAYrxNC',
* value: 'Russell',
* },
* {
* lastUpdated: '2016-01-12T00:00:00.000',
* code: 'MMD_PER_NAM',
* displayName: 'First name',
* created: '2016-01-12T00:00:00.000',
* valueType: 'TEXT',
* attribute: 'w75KJ2mc4zz',
* value: 'Catherine',
* },
* ],
* });
* @example Update a dataSet
* update('dataSets', 'lyLU2wR22tC', { name: 'OpenFN Data Set', periodType: 'Weekly' });
* @example a dataSetNotification
* update('dataSetNotificationTemplates', 'VbQBwdm1wVP', {
* dataSetNotificationTrigger: 'DATA_SET_COMPLETION',
* notificationRecipient: 'ORGANISATION_UNIT_CONTACT',
* name: 'Notification',
* messageTemplate: 'Hello Updated',
* deliveryChannels: ['SMS'],
* dataSets: [],
* });
* @example Update a dataElement
* update('dataElements', 'FTRrcoaog83', {
* aggregationType: 'SUM',
* domainType: 'AGGREGATE',
* valueType: 'NUMBER',
* name: 'Paracetamol',
* shortName: 'Para',
* });
* @example Update a dataElementGroup
* update('dataElementGroups', 'QrprHT61XFk', {
* name: 'Data Element Group 1',
* dataElements: [],
* });
* @example Update a dataElementGroupSet
* update('dataElementGroupSets', 'VxWloRvAze8', {
* name: 'Data Element Group Set 4',
* dataDimension: true,
* shortName: 'DEGS4',
* dataElementGroups: [],
* });
* @example Update a dataValueSet
* update('dataValueSets', 'AsQj6cDsUq4', {
* dataElement: 'f7n9E0hX8qk',
* period: '201401',
* orgUnit: 'DiszpKrYNg8',
* value: '12',
* });
* @example Update a dataValueSet with related dataValues
* update('dataValueSets', 'Ix2HsbDMLea', {
* dataSet: 'pBOMPrpg1QX',
* completeDate: '2014-02-03',
* period: '201401',
* orgUnit: 'DiszpKrYNg8',
* dataValues: [
* {
* dataElement: 'f7n9E0hX8qk',
* value: '1',
* },
* {
* dataElement: 'Ix2HsbDMLea',
* value: '2',
* },
* {
* dataElement: 'eY5ehpbEsB7',
* value: '3',
* },
* ],
* });
* @example Update an enrollment given the provided ID
* update('enrollments', 'CmsHzercTBa' {
* trackedEntity: 'bmshzEacgxa',
* orgUnit: 'TSyzvBiovKh',
* program: 'gZBxv9Ujxg0',
* enrollmentDate: '2013-10-17',
* incidentDate: '2013-10-17',
* });
* @function
* @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
* @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
* @param {Object} data - Data to update. It requires to send the full body. If you want partial updates, use patch operation.
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
* @state data - the resource returned by DHIS2
* @returns {Operation}
*/
export function update(resourceType: string, path: string, data: any, options?: RequestOptions): Operation;
/**
* Upsert a record. This will atomically update a record if it already exists, or otherwise create it.
* This function does not work with the absolute tracker path `api/tracker` but rather the new tracker paths and deprecated tracker endpoints.
* @public
* @example Upsert a trackedEntity
* upsert('trackedEntities', {}, {
* orgUnit: 'TSyzvBiovKh',
* trackedEntityType: 'nEenWmSyUEp',
* attributes: [
* {
* attribute: 'w75KJ2mc4zz',
* value: 'Qassim',
* },
* ],
* });
* @example Upsert a dataElement
* upsert(
* 'dataElements',
* { filter: 'id:eq:P3jJH5Tu5VC' },
* {
* op: 'add',
* path: '/domainType',
* name: 'Acute',
* shortName: 'AFP follow-up',
* dimensionItemType: 'DATA_ELEMENT',
* legendSets: [],
* aggregationType: 'SUM',
* valueType: 'NUMBER',
* domainType: 'AGGREGATE',
* code: 'DE_359049',
* name: 'Acute Flaccid Paralysis (AFP) follow-up',
* }
* );
* @function
* @param {string} resourceType - The type of a resource to `upsert`. E.g. `trackedEntities`.
* @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.
* @param {Object} data - The data to use for update or create depending on the result of the query.
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request
* @throws {RangeError} - Throws range error
* @state {DHIS2State}
* @returns {Operation}
*/
export function upsert(resourceType: string, query: any, data: any, options?: RequestOptions): Operation;
/**
* Delete record.
* @public
* @function
* @example 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)
* destroy('trackedEntities', 'LcRd6Nyaq7T');
* @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntities`, `organisationUnits`, etc.
* @param {string} path - Can be an `id` of an `object` or `path` to the `nested object` to `delete`.
* @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}
* @param {RequestOptions} [options] - An optional object containing query, parseAs,and headers for the request.
* @state {DHIS2State}
* @returns {Operation}
*/
export function destroy(resourceType: string, path: string, data?: any, options?: RequestOptions): Operation;
/**
* State object
*/
export type DHIS2State = any;
/**
* Options object
*/
export type RequestOptions = {
/**
* - An object of query parameters to be encoded into the URL
*/
query: object;
/**
* - An object of all request headers
*/
headers: object;
/**
* - The response format to parse (e.g., 'json', 'text', 'stream', or 'base64'. Defaults to `json`
*/
parseAs?: string;
/**
* - The apiVersion of the request. Defaults to 42.
*/
apiVersion?: string;
};
export { alterState, as, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, group, lastReferenceValue, map, merge, sourceValue } from "@openfn/language-common";