From 7ffbde98bfee8945e55a8cc6b29a857162b32fb2 Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Mon, 9 Dec 2024 21:49:08 +0300 Subject: [PATCH 1/3] add generate-library --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 46fd827deaf..63d8248ff64 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "generate-library": "docusaurus generate-library", "generate-adaptors": "docusaurus generate-adaptors", "start": "docusaurus generate-adaptors & docusaurus start", - "start:dev": "docusaurus generate-adaptors -m && docusaurus start", + "start:dev": "docusaurus generate-adaptors -m && docusaurus generate-library && docusaurus start", "start-offline": "docusaurus start", "build": "docusaurus build", "swizzle": "docusaurus swizzle", @@ -62,4 +62,4 @@ "cytoscape": "3.28.1" }, "packageManager": "yarn@3.2.3" -} +} \ No newline at end of file From 23466eee405058e9ce7025e2c4deb2d2b7618418 Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Mon, 9 Dec 2024 21:49:34 +0300 Subject: [PATCH 2/3] update dhis2 examples --- adaptors/library/jobs/DHIS2-DataValues-API.js | 45 +++++++++------ adaptors/library/jobs/DHIS2-Events-API.js | 55 ++++++++++++------- adaptors/library/staticExamples.json | 4 +- 3 files changed, 65 insertions(+), 39 deletions(-) diff --git a/adaptors/library/jobs/DHIS2-DataValues-API.js b/adaptors/library/jobs/DHIS2-DataValues-API.js index b305cd97743..84b6b03fdce 100644 --- a/adaptors/library/jobs/DHIS2-DataValues-API.js +++ b/adaptors/library/jobs/DHIS2-DataValues-API.js @@ -1,20 +1,33 @@ // ---- // Add data to data value sets in DHIS2 using a generic JSON message, submitted -// by Taylor Downs @ OpenFn. +// by Taylor Downs @ OpenFn. Co-authored by @mtuchi // --- -dataValueSet( - fields( - field('dataSet', 'pBOMPrpg1QX'), - field('orgUnit', 'DiszpKrYNg8'), - field('period', '201401'), - field('completeData', dataValue('form.date')), - field('dataValues', function (state) { - return [ - dataElement('qrur9Dvnyt5', dataValue('form.prop_a')(state)), - dataElement('oZg33kd9taw', dataValue('form.prop_b')(state)), - dataElement('msodh3rEMJa', dataValue('form.prop_c')(state)), - ]; - }) - ) -); +fn(state => { + const { form } = state.data; + // Create a data value set mapping + state.dataValueSetMap = { + dataSet: 'pBOMPrpg1QX', + completeDate: form.date, + period: '201401', + orgUnit: 'DiszpKrYNg8', + dataValues: [ + { + dataElement: 'f7n9E0hX8qk', + value: form.prop_a, + }, + { + dataElement: 'Ix2HsbDMLea', + value: form.prop_b, + }, + { + dataElement: 'eY5ehpbEsB7', + value: form.prop_c, + }, + ], + }; + return state; +}); + +// Create dataValueSets +create('dataValueSets', state => state.dataValueSetMap); diff --git a/adaptors/library/jobs/DHIS2-Events-API.js b/adaptors/library/jobs/DHIS2-Events-API.js index e1b02e6b837..422ac0bdd09 100644 --- a/adaptors/library/jobs/DHIS2-Events-API.js +++ b/adaptors/library/jobs/DHIS2-Events-API.js @@ -1,25 +1,38 @@ // ---- // Create new events in DHIS2 using a generic JSON message, submitted by -// Taylor Downs @ OpenFn for demonstration porpoises. +// Taylor Downs @ OpenFn, Co-authored by @mtuchi // --- -event( - fields( - field('program', 'eBAyeGv0exc'), - field('orgUnit', 'DiszpKrYNg8'), - field('eventDate', dataValue('meta.date')), - field('status', 'COMPLETED'), - field('storedBy', 'admin'), - field('coordinate', { - latitude: '59.8', - longitude: '10.9', - }), - field('dataValues', function (state) { - return [ - dataElement('qrur9Dvnyt5', dataValue('form.prop_a')(state)), - dataElement('oZg33kd9taw', dataValue('form.prop_b')(state)), - dataElement('msodh3rEMJa', dataValue('form.prop_c')(state)), - ]; - }) - ) -); +fn(state => { + const { meta, form } = state.data; + + state.events = { + program: 'eBAyeGv0exc', + orgUnit: 'DiszpKrYNg8', + occurredAt: meta.date, + status: 'COMPLETED', + storedBy: 'admin', + geometry: { + type: 'POINT', + coordinates: [59.8, 10.9], + }, + dataValues: [ + { + dataElement: 'qrur9Dvnyt5', + value: form.prop_a, + }, + { + dataElement: 'oZg33kd9taw', + value: form.prop_b, + }, + { + dataElement: 'msodh3rEMJa', + value: form.prop_c, + }, + ], + }; + + return state; +}); + +create('events', state => state.events); diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 02cd577b75e..6b3c2f65f04 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -59,12 +59,12 @@ { "expressionPath": "jobs/DHIS2-DataValues-API", "adaptor": "dhis2", - "name": "Add data values" + "name": "Create data values" }, { "expressionPath": "jobs/DHIS2-Events-API", "adaptor": "dhis2", - "name": "Add events" + "name": "Create new events" }, { "expressionPath": "jobs/ODK-Create-Many-Records-Moving-In-And-Out-Of-Repeat-Blocks", From 94a27f280252465980911eb4643ecf93868bb01d Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Tue, 10 Dec 2024 15:46:48 +0300 Subject: [PATCH 3/3] remove fn block --- adaptors/library/jobs/DHIS2-DataValues-API.js | 46 +++++++--------- adaptors/library/jobs/DHIS2-Events-API.js | 54 ++++++++----------- 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/adaptors/library/jobs/DHIS2-DataValues-API.js b/adaptors/library/jobs/DHIS2-DataValues-API.js index 84b6b03fdce..ef582f0a7c0 100644 --- a/adaptors/library/jobs/DHIS2-DataValues-API.js +++ b/adaptors/library/jobs/DHIS2-DataValues-API.js @@ -3,31 +3,23 @@ // by Taylor Downs @ OpenFn. Co-authored by @mtuchi // --- -fn(state => { - const { form } = state.data; - // Create a data value set mapping - state.dataValueSetMap = { - dataSet: 'pBOMPrpg1QX', - completeDate: form.date, - period: '201401', - orgUnit: 'DiszpKrYNg8', - dataValues: [ - { - dataElement: 'f7n9E0hX8qk', - value: form.prop_a, - }, - { - dataElement: 'Ix2HsbDMLea', - value: form.prop_b, - }, - { - dataElement: 'eY5ehpbEsB7', - value: form.prop_c, - }, - ], - }; - return state; +create('dataValueSets', { + dataSet: 'pBOMPrpg1QX', + completeDate: $.form.date, + period: '201401', + orgUnit: 'DiszpKrYNg8', + dataValues: [ + { + dataElement: 'f7n9E0hX8qk', + value: $.form.prop_a, + }, + { + dataElement: 'Ix2HsbDMLea', + value: $.form.prop_b, + }, + { + dataElement: 'eY5ehpbEsB7', + value: $.form.prop_c, + }, + ], }); - -// Create dataValueSets -create('dataValueSets', state => state.dataValueSetMap); diff --git a/adaptors/library/jobs/DHIS2-Events-API.js b/adaptors/library/jobs/DHIS2-Events-API.js index 422ac0bdd09..ff5175fdddc 100644 --- a/adaptors/library/jobs/DHIS2-Events-API.js +++ b/adaptors/library/jobs/DHIS2-Events-API.js @@ -3,36 +3,28 @@ // Taylor Downs @ OpenFn, Co-authored by @mtuchi // --- -fn(state => { - const { meta, form } = state.data; - - state.events = { - program: 'eBAyeGv0exc', - orgUnit: 'DiszpKrYNg8', - occurredAt: meta.date, - status: 'COMPLETED', - storedBy: 'admin', - geometry: { - type: 'POINT', - coordinates: [59.8, 10.9], +create('events', { + program: 'eBAyeGv0exc', + orgUnit: 'DiszpKrYNg8', + occurredAt: $.meta.date, + status: 'COMPLETED', + storedBy: 'admin', + geometry: { + type: 'POINT', + coordinates: [59.8, 10.9], + }, + dataValues: [ + { + dataElement: 'qrur9Dvnyt5', + value: $.form.prop_a, }, - dataValues: [ - { - dataElement: 'qrur9Dvnyt5', - value: form.prop_a, - }, - { - dataElement: 'oZg33kd9taw', - value: form.prop_b, - }, - { - dataElement: 'msodh3rEMJa', - value: form.prop_c, - }, - ], - }; - - return state; + { + dataElement: 'oZg33kd9taw', + value: $.form.prop_b, + }, + { + dataElement: 'msodh3rEMJa', + value: $.form.prop_c, + }, + ], }); - -create('events', state => state.events);