From 9a7c30a6bbc7af49c24621939e65b1a5f221258d Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Thu, 6 Feb 2025 12:54:19 +0300 Subject: [PATCH 1/8] feat: add examples to kobotoolbox Signed-off-by: Hunter Achieng --- adaptors/library/jobs/kobotoolbox-create-asset.js | 4 ++++ adaptors/library/jobs/kobotoolbox-get-submissions.js | 6 ++++++ adaptors/library/staticExamples.json | 10 ++++++++++ package.json | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 adaptors/library/jobs/kobotoolbox-create-asset.js create mode 100644 adaptors/library/jobs/kobotoolbox-get-submissions.js diff --git a/adaptors/library/jobs/kobotoolbox-create-asset.js b/adaptors/library/jobs/kobotoolbox-create-asset.js new file mode 100644 index 000000000000..f82d2c22973c --- /dev/null +++ b/adaptors/library/jobs/kobotoolbox-create-asset.js @@ -0,0 +1,4 @@ +http.post('/assets/', { + name: 'Feedback Survey Test', + asset_type: 'survey', +}); diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js new file mode 100644 index 000000000000..a59697f0ef2d --- /dev/null +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -0,0 +1,6 @@ +fn(state => { + state.formId = state.data.formId; + return state; +}); + +getSubmissions($.formId); diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 6b3c2f65f040..f391cea805b4 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -105,5 +105,15 @@ "expressionPath": "jobs/async-findValue", "adaptor": "postgresql", "name": "Using findValue with an array of data" + }, + { + "expressionPath": "jobs/kobotoolbox-create-asset", + "adaptor": "kobotoolbox", + "name": "Create an asset in KoboToolbox" + }, + { + "expressionPath": "jobs/kobotoolbox-get-submissions", + "adaptor": "kobotoolbox", + "name": "Extract submissions from KoboToolbox" } ] \ No newline at end of file diff --git a/package.json b/package.json index 63d8248ff648..d29573d7d89c 100644 --- a/package.json +++ b/package.json @@ -62,4 +62,4 @@ "cytoscape": "3.28.1" }, "packageManager": "yarn@3.2.3" -} \ No newline at end of file +} From 51702b4219f913e39ee05566591010d82b4f1924 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Thu, 6 Feb 2025 18:50:38 +0300 Subject: [PATCH 2/8] fix: update kobo example Signed-off-by: Hunter Achieng --- adaptors/library/jobs/kobotoolbox-create-asset.js | 4 ---- .../jobs/kobotoolbox-get-suspected-patients.js | 13 +++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 adaptors/library/jobs/kobotoolbox-create-asset.js create mode 100644 adaptors/library/jobs/kobotoolbox-get-suspected-patients.js diff --git a/adaptors/library/jobs/kobotoolbox-create-asset.js b/adaptors/library/jobs/kobotoolbox-create-asset.js deleted file mode 100644 index f82d2c22973c..000000000000 --- a/adaptors/library/jobs/kobotoolbox-create-asset.js +++ /dev/null @@ -1,4 +0,0 @@ -http.post('/assets/', { - name: 'Feedback Survey Test', - asset_type: 'survey', -}); diff --git a/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js b/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js new file mode 100644 index 000000000000..54b490906a64 --- /dev/null +++ b/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js @@ -0,0 +1,13 @@ +// Get all submissions of a specific form/asset and get the percentage of patients suspected of having covid-19 +http.get('/assets/aDReHdA7UuNBYsiCXQBr43/data/'); + +fn(state => { + const results = state.data?.results; + + const suspectedPatients = results.filter( + item => item['Please_select_sample_type'] === 'suspected_covid_19' + ); + const suspectedCovidPatientsPercentage = + (suspectedPatients.length / results.length) * 100; + return { ...state, suspectedCovidPatientsPercentage }; +}); From 45a9373782984bfec6a0cbde50c59365ca056bfa Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Thu, 6 Feb 2025 18:58:26 +0300 Subject: [PATCH 3/8] update example function Signed-off-by: Hunter Achieng --- adaptors/library/jobs/kobotoolbox-get-suspected-patients.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js b/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js index 54b490906a64..489168832751 100644 --- a/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js +++ b/adaptors/library/jobs/kobotoolbox-get-suspected-patients.js @@ -1,5 +1,5 @@ // Get all submissions of a specific form/asset and get the percentage of patients suspected of having covid-19 -http.get('/assets/aDReHdA7UuNBYsiCXQBr43/data/'); +getSubmissions('aDReHdA7UuNBYsiCXQBr43'); fn(state => { const results = state.data?.results; From 49e8c9a839e0d3d79c5182e719956f5c0ccd5c5d Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Thu, 6 Feb 2025 19:11:33 +0300 Subject: [PATCH 4/8] update static examples Signed-off-by: Hunter Achieng --- adaptors/library/staticExamples.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index f391cea805b4..93569137c2b4 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -107,7 +107,7 @@ "name": "Using findValue with an array of data" }, { - "expressionPath": "jobs/kobotoolbox-create-asset", + "expressionPath": "jobs/kobotoolbox-get-suspected-patients", "adaptor": "kobotoolbox", "name": "Create an asset in KoboToolbox" }, From f4f192e691d69b0e7abb7045bdebba1adea868b3 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Fri, 7 Feb 2025 13:19:18 +0300 Subject: [PATCH 5/8] fix get submission example Signed-off-by: Hunter Achieng --- adaptors/library/jobs/kobotoolbox-get-submissions.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js index a59697f0ef2d..85ec2eab41d4 100644 --- a/adaptors/library/jobs/kobotoolbox-get-submissions.js +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -1,6 +1,11 @@ +//Get all submissions of a specific form/asset that were submitted after a specific time fn(state => { state.formId = state.data.formId; return state; }); -getSubmissions($.formId); +http.get(`/assets/${$.formId}/data/`, { + query: { + query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, + }, +}); From a42f383f74bd86294fef769eeaa581fd74985d17 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Fri, 7 Feb 2025 18:10:44 +0300 Subject: [PATCH 6/8] update submission example Signed-off-by: Hunter Achieng --- adaptors/library/jobs/kobotoolbox-get-submissions.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js index 85ec2eab41d4..b35f59a2aa8d 100644 --- a/adaptors/library/jobs/kobotoolbox-get-submissions.js +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -4,8 +4,6 @@ fn(state => { return state; }); -http.get(`/assets/${$.formId}/data/`, { - query: { - query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, - }, +getSubmissions($.formId, { + query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, }); From db1bf7d8688e998f63094ade2811ad7a98baff5b Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Fri, 7 Feb 2025 18:38:39 +0300 Subject: [PATCH 7/8] add cursor to example Signed-off-by: Hunter Achieng --- .../library/jobs/kobotoolbox-get-submissions.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js index b35f59a2aa8d..007ee1e4fd2b 100644 --- a/adaptors/library/jobs/kobotoolbox-get-submissions.js +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -1,9 +1,11 @@ //Get all submissions of a specific form/asset that were submitted after a specific time -fn(state => { - state.formId = state.data.formId; - return state; -}); +cursor($.cursor, { defaultValue: 'today' }); -getSubmissions($.formId, { - query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, -}); +getForms(); + +each( + $.data, + getSubmissions($.data.uid, { + query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, + }) +); From a316e3a4d23a7eece73308167382cde9e2704912 Mon Sep 17 00:00:00 2001 From: Aleksa Krolls Date: Sun, 9 Feb 2025 17:36:54 +0100 Subject: [PATCH 8/8] modified comment explanation --- adaptors/library/jobs/kobotoolbox-get-submissions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js index 007ee1e4fd2b..777d609699a6 100644 --- a/adaptors/library/jobs/kobotoolbox-get-submissions.js +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -1,4 +1,5 @@ -//Get all submissions of a specific form/asset that were submitted after a specific time +//Get all Kobo forms/projects, and then get form submissions +//that were submitted after a specific time cursor($.cursor, { defaultValue: 'today' }); getForms();