-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathouwise-progressive-report.js
138 lines (109 loc) · 3.83 KB
/
ouwise-progressive-report.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import sqlQueryBuilder from './sql-query-builder';
import api from 'dhis2api';
import excelBuilder from './excel-builder.js';
function ouWiseProgressiveReport(params,callback){
const SQLVIEWPREFIX = "XL_REPORT_";
var sourceIDQuery = __getSourceIDQuery(params);
var sqlViewService = new api.sqlViewService();
sqlViewService.dip(SQLVIEWPREFIX,sourceIDQuery, doMainQuery);
function doMainQuery(error,response,body){
if (error){
console.log("Source Query Error : "+error)
callback();
return
}
if (body.rows[0] == ""){
alert("No facility found for the parameters selected")
callback();
return;
}
var ouGroupWiseSourceIDs = JSON.parse(body.rows[0]);
var mainQ = __getMainQuery(params,ouGroupWiseSourceIDs);
sqlViewService.dip(SQLVIEWPREFIX,mainQ, function(error,response,body){
if (error){
}
new excelBuilder(params.mapping,
body,
params.excelTemplate,
params.reportName,
params.selectedOUName,
params.startdateText,
params.enddateText,
callback)
});
}
}
function __getMainQuery(params,ouGroupWiseSourceIDs){
ouGroupWiseSourceIDs = ouGroupWiseSourceIDs.reduce((map,obj)=>{
map[obj.ougroup] = obj.sourceids;
return map;
},[])
var qb = new (new sqlQueryBuilder()).
ouWise.
main(
params.selectedOUUID,
params.selectedOUName,
params.selectedOULevel,
params.selectedOUGroupUID,
params.startdate,
params.enddate,
params.ptype,
params.attributeOptionComboId,
params.ouGroupWiseDecocStringMap,
params.ouGroupUIDKeys,
params.ouGroupWiseDeListCommaSeparated,
ouGroupWiseSourceIDs,
params.aggregationType
);
switch(params.selectedOUGroupUID){
case "-1" : // no group
if (params.aggregationType == "use_captured"){
return qb.makeMainQuery();
}
else if (params.aggregationType == "agg_descendants" ||
params.aggregationType == "raw_report"){
return qb.makeMainQuery();
}
break
default : // group case
if (params.aggregationType == "use_captured"){
return qb.makeGroupMainQuery();
}
else if (params.aggregationType == "agg_descendants" ||
params.aggregationType == "raw_report"){
return qb.makeGroupMainQuery();
}
}
}
function __getSourceIDQuery(params){
var qb = new (new sqlQueryBuilder()).
ouWise.
sourceid(params.selectedOUUID,
params.ouGroupUIDKeys,
params.selectedOUGroupUID
);
switch(params.selectedOUGroupUID){
case "-1" : // no group
if (params.aggregationType == "use_captured" ||
params.aggregationType == "raw_report"){
return qb.
makeUseCapturedQuery();
}
else if (params.aggregationType == "agg_descendants"){
return qb.
makeGenAggregatedQuery();
}
break
default : // group case
if (params.aggregationType == "use_captured" ||
params.aggregationType == "raw_report"){
return qb.
makeOuGroupUseCapturedQuery()
}
else if (params.aggregationType == "agg_descendants"){
return qb.
makeOuGroupGenAgrgegatedQuery()
}
}
}
module.exports = ouWiseProgressiveReport;