-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeDataArray.js
executable file
·280 lines (216 loc) · 9.05 KB
/
makeDataArray.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
var fs = require('fs');
var mysql = require('mysql');
function createArray(length) {
var arr = new Array(length || 0),
i = length;
if (arguments.length > 1) {
var args = Array.prototype.slice.call(arguments, 1);
while(i--) arr[length-1 - i] = createArray.apply(this, args);
}
return arr;
}
if (process.argv.length <= 2) {
// console.log("Usage: " + __filename + " SOME_PARAM");
// process.exit(-1);
}
var entity = process.argv[2];
var db = 'localhost';
var schema = 'HOSPC';
var table = 'hospc_2013_DATA';
var lastReport;
var prod = false;
var entityName = '';
var baseDir = 'static2/';
var sql = "select ITEM from "+schema+"."+table+" where RPT_REC_NUM = "+entity+" and WKSHT_CD = 'S100000' and LINE_NUM = '00100'";
var sql2 = "SELECT *, 2013 myyear from "+schema+"."+table+" where RPT_REC_NUM = "+entity
+" and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ "union SELECT *, 2014 myyear from "+schema+"."+table+" where RPT_REC_NUM = "+entity
+" and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')";
var sql3 = "SELECT distinct(RPT_REC_NUM) entity from "+schema+"."+table+ " where " +
" RPT_REC_NUM in (31394,32352,32494,32589,32672,32675,33085,33229,33312,33471,33962)";
if(prod) {
baseDir = 'static2/';
db = '10.10.10.11';
//entity = 101508;
sql = "select distinct(ITEM) from HOSPC.HOSPC_2009_CLXN where cmsid = "+entity+" and WKSHT_CD = 'S100000' and LINE_NUM = '00100'";
sql2 = "SELECT *,2009 myyear FROM HOSPC.HOSPC_2009_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ " union "+
" SELECT *,2010 myyear FROM HOSPC.HOSPC_2010_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ " union "+
" SELECT *,2011 myyear FROM HOSPC.HOSPC_2011_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ " union "+
" SELECT *,2012 myyear FROM HOSPC.HOSPC_2012_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ " union "+
"SELECT *,2013 myyear FROM HOSPC.HOSPC_2013_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')"
+ " union "+
"SELECT *,2014 myyear FROM HOSPC.HOSPC_2014_CLXN where cmsid = " + entity + " and WKSHT_CD = 'A000000' and CLMN_NUM in('1000') and LINE_NUM in ('01500','01600','01700','01800','01900')";
sql3 = "SELECT distinct(cmsid) entity FROM HOSPC.HOSPC_ALL_CLXN where cmsid in ('101515','101534','101520',"+
"'101545','101502','101526','101528','101549','101500','101551','101513','101577','101527','101527','101550','101507','101529','101537','101525','101516','101523','101518','101527','101510','101553','101530','101548','101536','451781','101543','101552','101527','101540','101512','101532','101511','101508','101521','101533','101517','101522','101537');"
}
if (!fs.existsSync(baseDir)) {
fs.mkdirSync(baseDir);
}
//console.log(sql);
var myRows = new Array();
var connection = mysql.createConnection({
host : db,
user : 'nodeuser',
password : 'Cheese2000',
database : schema
});
connection.connect(function(err) {
if (!err) {
//console.log("Database is connected ... nn");
} else {
console.log("Error connecting database ... nn");
}
});
var connection2 = mysql.createConnection({
host : db,
user : 'nodeuser',
password : 'Cheese2000',
database : schema
});
connection2.connect(function(err) {
if (!err) {
//console.log("Database2 is connected ... nn");
} else {
console.log("Error2 connecting database ... nn");
}
});
var connection3 = mysql.createConnection({
host : db,
user : 'nodeuser',
password : 'Cheese2000',
database : schema
});
connection3.connect(function(err) {
if (!err) {
//console.log("Database3 is connected ... nn");
} else {
console.log("Error3 connecting database ... nn");
}
});
var dataArray = createArray(7,6);
for(var i=0;i<dataArray.length;i++){
for(var j =0;j<dataArray[i].length;j++){
dataArray[i][j] = 0;
}
}
var dataArray2 = createArray(7,7);
for(var i=0;i<dataArray.length;i++){
for(var j =0;j<dataArray[i].length;j++){
dataArray[i][j] = 0;
}
}
connection3.query(sql3,function(err, rows) {
//console.log(rows[0].ITEM + ',' + rows[1].ITEM + ',' +rows[2].ITEM + ',' +rows[3].ITEM + ',' +rows[4].ITEM);
//console.log(sql3);
var tmpString = '';
var myfile3 = 'makeDataArray.sh';
for (var i = 0; i < rows.length; i++) {
tmpString += "echo ' writing array for "+rows[i].entity +" ';\n ";
tmpString += 'node makeDataArray.js ' + rows[i].entity + ' > static2/'+ rows[i].entity+'_data_array.html;\n';
// for (i = 0; i < 1; i++) {
//console.log(rows[i].entity);
//myRows[i] = rows[i].ITEM;
//entityName += rows[i].ITEM.toString() + ',';
//console.log("XXX " + entityName);
} // end top for loop
//var entityName = myRows.join(':');//[0].ITEM + ',' + rows[1].ITEM; //+ ',' +rows[2].ITEM + ',' +rows[3].ITEM + ',' +rows[4].ITEM ;
//console.log(entityName);
fs.writeFile(myfile3, tmpString, function(err) {
if (err)
throw err;
// console.log(myfile3 + ' saved');
//process.exit(0);
// var array = fs.readFileSync(myfile2).toString().split("\n");
//console.log(array);
});
}); // end connection callback
dataArray[1][0] = '2009';
dataArray[2][0] = '2010';
dataArray[3][0] = '2011';
dataArray[4][0] = '2012';
dataArray[5][0] = '2013';
dataArray[6][0] = '2014';
//console.log(sql2);
connection2.query(sql2, function(err, rows2) {
console.log('var data'+entity+' = google.visualization.arrayToDataTable(');
dataArray[0][0] = 'Year';
dataArray[0][1] = 'PHYSICIAN SERVICES';
dataArray[0][2] = 'NURSING CARE';
dataArray[0][3] = 'PHYSICAL THERAPY';
dataArray[0][4] = 'OCCUPATIONAL THERAPY';
dataArray[0][5] = 'SPEECH/LANGUAGE PATHOLOGY';
//dataArray[0][6] = 'HIGH';
//, '1500PHYSICIAN SERVICES', , ,,];
// // ['2013', 3833881, 21988746, 341064, 1790500, 1733100],
// ['2014', 4178930, 21329083, 409276, 1987400, 1819700],
// ['2015', 4555034, 20689211, 491132, 2206000, 1910700],
//['2016', 4964987, 20068534, 589358, 2448700, 2006200]
for (var i = 0; i < rows2.length; i++) {
var thisIndex = 1;
switch (rows2[i].myyear.toString())
{
case "2009":
thisIndex = 1;
dataArray[thisIndex][0] = '2009';
break;
case "2010":
thisIndex = 2;
dataArray[thisIndex][0] = '2010';
break;
case "2011":
thisIndex = 3;
dataArray[thisIndex][0] = '2011';
break;
case "2012":
thisIndex = 4;
dataArray[thisIndex][0] = '2012';
break;
case "2013":
thisIndex = 5;
dataArray[thisIndex][0] = '2013';
break;
case "2014":
thisIndex = 6;
dataArray[thisIndex][0] = '2014';
break;
default:
}
switch (rows2[i].LINE_NUM)
{
case "01500":
dataArray[thisIndex][1]= parseInt(rows2[i].ITEM,10);
break;
case "01600":
dataArray[thisIndex][2]= parseInt(rows2[i].ITEM,10);
break;
case "01700":
dataArray[thisIndex][3]= parseInt(rows2[i].ITEM,10);
break;
case "01800":
dataArray[thisIndex][4]= parseInt(rows2[i].ITEM,10);
break;
case "01900":
dataArray[thisIndex][5]= parseInt(rows2[i].ITEM,10);
break;
default:
}
} // end row2 for loop
console.log(dataArray);
console.log(');\n');
console.log('var options'+entity+' = {');//\n chart: {');
//console.log("title:");
//console.log("\'" + myRows[0].trim() );
//console.log("\',");
// console.log(' subtitle: \'Selected Cost Centers for 2009-2014\'');
console.log("legend: { position: 'top', maxLines: 5 },");
console.log("title:'Selected Cost Centers 2009 - 2014',");
console.log(' isStacked:true\n };');
console.log("// Instantiate and draw the chart.");
console.log("var chart"+entity+" = new google.visualization.ColumnChart(document.getElementById('container"+entity+"'));");
console.log(" chart"+entity+".draw(data"+entity+", options"+entity+");");
process.exit(0);
}); // end connection2 callback