Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Created May 1, 2023 21:20
Show Gist options
  • Save tashrifbillah/eeb9ab01d4d0fb04ca285857e1e07654 to your computer and use it in GitHub Desktop.
Save tashrifbillah/eeb9ab01d4d0fb04ca285857e1e07654 to your computer and use it in GitHub Desktop.
Count MongoDB subjects
// count good
let demographs;
let count=0;
let incl;
let csv;
let coll;
demographs=db.toc.find({"assessment":"form_sociodemographics"})
// print(demographs.length())
for (let i=0; i<demographs.length(); i++) {
d=demographs[i];
s=d['subject'];
// print(s);
coll=db[d['collection']].findOne();
if ( ! coll ){ continue; }
if (! 'chdemo_sexassigned' in coll) {
continue;
}
incl=db.toc.findOne({"assessment":"form_inclusionexclusion_criteria_review","subject":s});
if (! incl) { continue; }
csv=db[incl['collection']].findOne();
if (csv) {
if ( ('chrcrit_part' in csv) && ('included_excluded' in csv) ) {
count++;
}
}
}
print(count)
// count missing
let demographs;
let count=0;
let incl;
let csv;
let coll;
demographs=db.toc.find({"assessment":"form_sociodemographics"})
// print(demographs.length())
for (let i=0; i<demographs.length(); i++) {
d=demographs[i];
s=d['subject'];
// print(s);
coll=db[d['collection']].findOne();
if (! coll){ continue; }
if (! 'chdemo_sexassigned' in coll) {
continue;
}
incl=db.toc.findOne({"assessment":"form_inclusionexclusion_criteria_review","subject":s});
if (! incl) { continue; }
csv=db[incl['collection']].findOne();
if (csv) {
// if ( ('chrcrit_part' in csv) && ('included_excluded' in csv) ) {
if ('chrcrit_part' in csv && 'included_excluded' in csv && csv['included_excluded']==='') {
count++;
}
}
}
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment