Skip to content

Commit

Permalink
Merge pull request #633 from OpenFn/feat/970-kobo-examples
Browse files Browse the repository at this point in the history
kobotoolbox: add job examples
  • Loading branch information
josephjclark authored Feb 14, 2025
2 parents 557f81b + a316e3a commit 706f688
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions adaptors/library/jobs/kobotoolbox-get-submissions.js
Original file line number Diff line number Diff line change
@@ -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}"}}`,
})
);
13 changes: 13 additions & 0 deletions adaptors/library/jobs/kobotoolbox-get-suspected-patients.js
Original file line number Diff line number Diff line change
@@ -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 };
});
10 changes: 10 additions & 0 deletions adaptors/library/staticExamples.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
"cytoscape": "3.28.1"
},
"packageManager": "[email protected]"
}
}

0 comments on commit 706f688

Please sign in to comment.