This repository was archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagProportionPerCollection.js
More file actions
109 lines (89 loc) · 3.76 KB
/
tagProportionPerCollection.js
File metadata and controls
109 lines (89 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* MongoDB script that returns the proportion of MongoDB objects from a specific collection
* that contain a specific tag.
To run:
For default collection (MR), tag (AngioFlag), start year (2010) and end year (2018):
mongo tagPropPerColl.js > prop.txt
For custom collection:
mongo --eval "var coll='image_CT';" tagPropPerColl.js > prop.txt
For custom tag:
mongo --eval "var tagArg='FlipAngle';" tagPropPerColl.js > prop.txt
For custom start and end years:
mongo --eval "var minYear=2016; var maxYear=2017;" tagPropPerColl.js > prop.txt
Log:
2020-02-03 - BP - Create initial script with default on MR, tag AngioFlag
2020-02-04 - BP - Add aggregate for tag value counts
- Is there a way to combine tagMatches and tagValues queries?
2020-02-05 - BP - Enable specification of terminal arguments for custom tag names
*/
const DB_NAME = "dicom";
const CONN = new Mongo();
CONN.getDB("").auth("", ""); // enter authorisation details
var db = CONN.getDB(DB_NAME);
var counts = {};
function initDict() {
counts = {};
var min = (typeof minYear === "undefined") ? 2010 : minYear;
var max = (typeof maxYear === "undefined") ? 2018 : maxYear;
for (year = min; year <= max; year++) {
counts[year] = {};
for (month = 1; month <= 12; month++) {
var monthKey = prependZero(month);
var noDays = daysInMonth(year, month);
counts[year][monthKey] = {};
for (day = 1; day <= noDays; day++) {
var dayKey = prependZero(day);
// day = [totalCount, tagCount]
counts[year][monthKey][dayKey] = {
"total_count": 0,
"tag_count": 0,
"values": {}
};
}
}
}
}
function count() {
var collection = (typeof coll === "undefined") ? "image_MR" : coll;
var dbColl = db.getCollection(collection);
var tag = (typeof tagArg === "undefined") ? "AngioFlag" : tagArg;
for (var year in counts) {
for (var month in counts[year]) {
for (var day in counts[year][month]) {
totalCount = 0;
tagCount = 0;
totalMatches = dbColl.find({"header.DicomFilePath": {$regex: "^" + year + "/" + month + "/" + day}});
tagMatches = dbColl.find({"header.DicomFilePath": {$regex: "^" + year + "/" + month + "/" + day}, [tag]: {"$exists": true}});
tagValues = dbColl.aggregate([
{ $match: { "header.DicomFilePath": {$regex: "^" + year + "/" + month + "/" + day}} },
{ $match: { [tag] : {"$exists": true}} },
{ $group: {
"_id": "$" + [tag],
"count": {$sum: 1}
}
},
{ $group: {
"_id": null,
"counts": { $push: {"k": "$_id", "v": "$count"} }
}
},
{ $replaceRoot: { "newRoot": {$arrayToObject: "$counts"} }},
{ $limit: 3 }
]);
totalNo = totalMatches.count();
tagNo = tagMatches.count();
counts[year][month][day]["total_count"] += totalNo;
counts[year][month][day]["tag_count"] += tagNo;
counts[year][month][day]["values"] = tagValues.toArray()[0];
}
}
}
printjson(counts);
}
function prependZero(number) {
return (number <= 9) ? ("0" + number.toString()) : number.toString();
}
function daysInMonth(year, month) {
return new Date(year, month, 0).getDate();
}
initDict();
count();