diff --git a/adaptors/library/jobs/kobotoolbox-get-submissions.js b/adaptors/library/jobs/kobotoolbox-get-submissions.js new file mode 100644 index 000000000000..777d609699a6 --- /dev/null +++ b/adaptors/library/jobs/kobotoolbox-get-submissions.js @@ -0,0 +1,12 @@ +//Get all Kobo forms/projects, and then get form submissions +//that were submitted after a specific time +cursor($.cursor, { defaultValue: 'today' }); + +getForms(); + +each( + $.data, + getSubmissions($.data.uid, { + query: `{"_submission_time":{"$gte":"${$.cursor}"}}`, + }) +); 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..489168832751 --- /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 +getSubmissions('aDReHdA7UuNBYsiCXQBr43'); + +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 }; +}); diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 6b3c2f65f040..93569137c2b4 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-get-suspected-patients", + "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 +}