1
package org.hisp.gtool.action;
3
import java.sql.Connection;
4
import java.sql.ResultSet;
5
import java.sql.Statement;
6
import java.util.ArrayList;
7
import java.util.Collections;
8
import java.util.Enumeration;
9
import java.util.Hashtable;
10
import java.util.Iterator;
11
import java.util.List;
12
import java.util.Vector;
14
public class ViewChartBean {
16
String indicatorList[];
23
Connection con = (new DBConnection()).openConnection();
34
/* public Hashtable findChildOrgUnits()
39
Hashtable ht = new Hashtable();
43
String query = "select shortname,id from organisationunit where parent ="+orgUnitID;
44
st = con.createStatement();
45
rs = st.executeQuery(query);
49
ht.put(rs.getString(1),new Integer(rs.getInt(2)));
54
System.out.println(e.getMessage()); return null;
60
if(rs!=null) rs.close();
61
if(st!=null) st.close();
63
catch(Exception e){System.out.println(e.getMessage());return null;}
67
} // findChildOrgUnits end
71
public Hashtable setPeriodIDs()
79
String partsOfEDate[] = e_Date.split("-");
80
tempEDate = partsOfEDate[0]+"-"+partsOfEDate[1]+"-01";
82
Hashtable ht = new Hashtable();
87
if(i_category.equals("Period"))
89
query ="select startdate,id from period where startDate between '"+s_Date+"' and '"+tempEDate+"' and periodType="+periodType+" order by startdate";
91
query ="SELECT startdate,periodid FROM period " +
92
"WHERE startDate BETWEEN '"+s_Date+"' AND" +
93
" '"+tempEDate+"' AND" +
94
" periodtypeid="+periodType+" ORDER BY startdate";
95
else if(i_category.equals("Facility"))
97
query = "select shortname,id from organisationunit where parent ="+orgUnitID;
99
query = "SELECT shortname,organisationunitid FROM organisationunit WHERE parentid ="+orgUnitID;
100
st = con.createStatement();
101
st1 = con.createStatement();
103
rs = st.executeQuery(query);
107
ht.put(rs.getString(1),new Integer(rs.getInt(2)));
111
if(i_category.equals("Period"))
115
else if(i_category.equals("Facility"))
118
query = "select count(*) from period where startDate between '"+s_Date+"' and '"+tempEDate+"' and periodType="+periodType+" order by startdate";
120
query = "SELECT COUNT(*) FROM period " +
121
"WHERE startDate BETWEEN '"+s_Date+"' AND '"+tempEDate+"' AND" +
122
" periodtypeid = "+periodType+" ORDER BY startdate";
123
rs1 = st1.executeQuery(query);
124
if(rs1.next()) noOfPeriods = rs1.getInt(1);
125
else noOfPeriods = 1;
136
if(rs!=null) rs.close();
137
if(st!=null) st.close();
139
catch(Exception e){ return null;}
140
}// finally block end
146
public Hashtable setIndicatorIDs()
152
Hashtable ht = new Hashtable();
159
st = con.createStatement();
160
while(count<indicatorList.length)
162
if(ide_type.equals("indicatorsRadio"))
163
//query = "select id,Target from indicator where name like '"+indicatorList[count]+"'";
164
query = "SELECT indicatorid,Target FROM indicator WHERE name LIKE '"+indicatorList[count]+"'";
166
//query = "select id from dataelement where shortname like '"+indicatorList[count]+"'";
167
query = "SELECT dataelementid FROM dataelement WHERE alternativeName LIKE '"+indicatorList[count]+"'";
168
rs = st.executeQuery(query);
170
if(rs.next()) { ht.put(indicatorList[count],new Integer(rs.getInt(1)));}
182
if(rs!=null) rs.close();
183
if(st!=null) st.close();
185
catch(Exception e){ return null;}
186
}// finally block end
192
public Hashtable getTargetValues()
198
Hashtable ht = new Hashtable();
204
st = con.createStatement();
205
while(count<indicatorList.length)
207
String query = "select Target from indicator where name like '"+indicatorList[count]+"'";
209
rs = st.executeQuery(query);
211
if(rs.next()) { ht.put(indicatorList[count],new Double(rs.getDouble(1)));}
212
else { ht.put(indicatorList[count],new Double(0.0));}
224
if(rs!=null) rs.close();
225
if(st!=null) st.close();
227
catch(Exception e){ return null;}
228
}// finally block end
230
} // getTargetValues end
233
// Indicator Numerator Formula
234
public Hashtable getIndNumeratorFormula()
240
Hashtable ht = new Hashtable();
246
st = con.createStatement();
247
while(count<indicatorList.length)
249
//String query = "select numeratorDescription from indicator where name like '"+indicatorList[count]+"'";
250
String query = "SELECT numeratordescription FROM indicator WHERE name LIKE '"+indicatorList[count]+"'";
251
rs = st.executeQuery(query);
253
if(rs.next()) { ht.put(indicatorList[count],rs.getString(1));}
254
else { ht.put(indicatorList[count]," ");}
267
if(rs!=null) rs.close();
268
if(st!=null) st.close();
270
catch(Exception e){ return null;}
271
}// finally block end
273
} // getIndNumeratorFormula end
277
// Indicator Denominator Formula
278
public Hashtable getIndDenominatorFormula()
284
Hashtable ht = new Hashtable();
290
st = con.createStatement();
291
while(count<indicatorList.length)
293
//String query = "select denominatorDescription from indicator where name like '"+indicatorList[count]+"'";
294
String query = "SELECT denominatordescription FROM indicator WHERE name LIKE '"+indicatorList[count]+"'";
296
rs = st.executeQuery(query);
298
if(rs.next()) { ht.put(indicatorList[count],rs.getString(1));}
299
else { ht.put(indicatorList[count],"");}
311
if(rs!=null) rs.close();
312
if(st!=null) st.close();
314
catch(Exception e){ return null;}
315
}// finally block end
317
} // getIndDenominatorFormula end
320
// Indicator Denominator DataElements
321
public Hashtable getIndDenominatorDEs()
327
Hashtable ht = new Hashtable();
333
st = con.createStatement();
334
while(count<indicatorList.length)
337
String query = "select denominator from indicator where name like '"+indicatorList[count]+"'";
338
rs = st.executeQuery(query);
341
deNames = getDEsofNandD(rs.getString(1));
342
ht.put(indicatorList[count],deNames);
344
else { ht.put(indicatorList[count],"");}
357
if(rs!=null) rs.close();
358
if(st!=null) st.close();
360
catch(Exception e){ return null;}
361
}// finally block end
363
} // getIndDenominatorDEs end
366
// Indicator Numerator DataElements
367
public Hashtable getIndNumeratorDEs()
373
Hashtable ht = new Hashtable();
379
st = con.createStatement();
380
while(count<indicatorList.length)
383
String query = "select numerator from indicator where name like '"+indicatorList[count]+"'";
384
rs = st.executeQuery(query);
387
deNames = getDEsofNandD(rs.getString(1));
388
ht.put(indicatorList[count],deNames);
390
else { ht.put(indicatorList[count],"");}
403
if(rs!=null) rs.close();
404
if(st!=null) st.close();
406
catch(Exception e){ return null;}
407
}// finally block end
409
} // getIndNumeratorDEs end
411
// get DataelementList of Numerator or Denominator
412
public String getDEsofNandD(String tempSD)
417
char[] tempCD = tempSD.toCharArray();
423
st = con.createStatement();
425
for(int i=0;i<tempCD.length;i++)
427
if(tempCD[i]=='[') { flag=1;temp1 = ""; }
428
else if(tempCD[i]==']')
431
int itemp = Integer.parseInt(temp1);
432
//String query = "select alternativeName from dataelement where id="+itemp;
433
String query = "select alternativeName from dataelement where dataelementid="+itemp;
434
rs = st.executeQuery(query);
435
if(rs.next()) { deNames+=rs.getString(1)+", "; }
437
else if(flag==1) temp1 += tempCD[i];
440
catch(Exception e) { return null; }
445
if(rs!=null) rs.close();
446
if(st!=null) st.close();
448
catch(Exception e){ return null;}
449
}// finally block end
452
}// end function getDEsofNandD
455
public Hashtable getIndFactor()
461
Hashtable ht = new Hashtable();
467
st = con.createStatement();
468
while(count<indicatorList.length)
470
//String query = "select indicatortype.factor from indicatortype inner join indicator on indicatortype.id = indicator.indicatorType where indicator.name like '"+indicatorList[count]+"'";
471
String query = "SELECT indicatortype.indicatorfactor FROM indicatortype " +
472
"INNER JOIN indicator ON indicatortype.indicatortypeid = indicator.indicatortypeid " +
473
"WHERE indicator.name LIKE '"+indicatorList[count]+"'";
474
rs = st.executeQuery(query);
476
if(rs.next()) { ht.put(indicatorList[count],rs.getString(1));}
477
else { ht.put(indicatorList[count],"");}
489
if(rs!=null) rs.close();
490
if(st!=null) st.close();
492
catch(Exception e){ return null;}
493
}// finally block end
495
} // getIndFactor end
499
public Hashtable getValuesByPeriod()
501
Statement st1 = null;
502
ResultSet rs1 = null;
504
Statement st2 = null;
505
ResultSet rs2 = null;
507
//int orgUnitLevel = 4;
509
Hashtable ht = new Hashtable();
513
st1 = con.createStatement();
514
st2 = con.createStatement();
516
//rs2 = st2.executeQuery("select level from organisationunitstructure where source = "+orgUnitID);
517
//if(rs2.next()) orgUnitLevel = rs2.getInt(1);
519
//if(orgUnitLevel==1)
521
Hashtable htForIndicator = setIndicatorIDs();
522
Enumeration keysForIndicator = htForIndicator.keys();
524
while(keysForIndicator.hasMoreElements())
526
String keyI = (String) keysForIndicator.nextElement();
527
int iID = ((Integer)htForIndicator.get(keyI)).intValue();
529
List liForValues = new ArrayList();
530
Hashtable htForPeriods = setPeriodIDs();
531
//Enumeration keysForPeriod = htForPeriods.keys();
533
Vector vForPeriods = new Vector(htForPeriods.keySet());
534
Collections.sort(vForPeriods);
535
Iterator iteratorForPeriod = vForPeriods.iterator();
536
while(iteratorForPeriod.hasNext())
538
String keyP = (String) iteratorForPeriod.next();;
539
int pID = ((Integer)htForPeriods.get(keyP)).intValue();
541
if(i_category.equals("Period"))
543
if(ide_type.equals("indicatorsRadio"))
544
//query ="select sum(value) from aggregatedindicatorvalue where periodTypeId ="+periodType+" and organisationUnitId in (select id from organisationunit where id ="+orgUnitID+") and indicatorID="+iID+" and periodID="+pID;
545
query ="SELECT SUM(value) FROM aggregatedindicatorvalue " +
546
"WHERE periodtypeid ="+periodType+" AND " +
547
"organisationunitid ="+orgUnitID+" AND " +
548
"indicatorid="+iID+" AND " +
551
//query ="select value from aggregateddatavalue where periodTypeId ="+periodType+" and organisationUnitId="+orgUnitID+" and dataElementId="+iID+" and periodID="+pID;
552
query ="SELECT value FROM aggregateddatavalue " +
553
"WHERE periodtypeid ="+periodType+" AND " +
554
"organisationunitid="+orgUnitID+" AND " +
555
"dataelementid="+iID+" AND " +
558
else if(i_category.equals("Facility"))
560
if(ide_type.equals("indicatorsRadio"))
561
//query = "select sum(value) from aggregatedindicatorvalue where periodTypeId ="+periodType+" and organisationUnitId in (select id from organisationunit where id ="+pID+") and indicatorID="+iID+" and periodID in (select id from period where startdate between '"+s_Date+"' and '"+tempEDate+"' and periodtype="+periodType+")";
562
query = "SELECT sum(value) FROM aggregatedindicatorvalue " +
563
"WHERE periodtypeid ="+periodType+" AND " +
564
"organisationunitid ="+pID+" AND " +
565
"indicatorid="+iID+" AND " +
566
"periodid IN (SELECT periodid FROM period WHERE startdate BETWEEN '"+s_Date+"' AND '"+tempEDate+"' AND periodtypeid="+periodType+")";
569
//query = "select sum(value) from aggregateddatavalue where periodTypeId ="+periodType+" and organisationUnitId="+pID+" and dataElementId="+iID+" and periodID in (select id from period where startdate between '"+s_Date+"' and '"+tempEDate+"' and periodtype="+periodType+")";
570
query = "SELECT SUM(value) FROM aggregateddatavalue " +
571
"WHERE periodtypeid ="+periodType+" AND " +
572
"organisationunitid="+pID+" AND " +
573
"dataelementid="+iID+" AND " +
574
"periodid IN (SELECT periodid FROM period WHERE startdate BETWEEN '"+s_Date+"' AND '"+tempEDate+"' AND periodtypeid="+periodType+")";
578
rs1 = st1.executeQuery(query);
579
if(rs1.next()) liForValues.add(new Double( (Math.round(rs1.getDouble(1)*Math.pow(10,2))/Math.pow(10,2))/noOfPeriods));
580
else liForValues.add(new Double(0));
581
}// period while loop end
582
ht.put(keyI,liForValues);
584
}// indicator while loop end
588
System.out.println(e.getMessage());return null;
594
if(rs1!=null) rs1.close();
595
if(st1!=null) st1.close();
597
if(rs2!=null) rs2.close();
598
if(st2!=null) st2.close();
600
catch(Exception e){System.out.println(e.getMessage());return null;}
601
}// finally block end
610
public String getI_category() {
615
public void setI_category(String i_category) {
616
this.i_category = i_category;
620
public Connection getCon() {
625
public void setCon(Connection con) {
630
public List getIndicatorIDs() {
635
public void setIndicatorIDs(List indicatorIDs) {
636
this.indicatorIDs = indicatorIDs;
640
public String[] getIndicatorList() {
641
return indicatorList;
645
public void setIndicatorList(String[] indicatorList) {
646
this.indicatorList = indicatorList;
650
public int getOrgUnitID() {
655
public void setOrgUnitID(int orgUnitID) {
656
this.orgUnitID = orgUnitID;
660
public String getOrgUnitName() {
665
public void setOrgUnitName(String orgUnitName) {
666
this.orgUnitName = orgUnitName;
670
public List getPeriodIDs() {
675
public void setPeriodIDs(List periodIDs) {
676
this.periodIDs = periodIDs;
680
public int getPeriodType() {
685
public void setPeriodType(int periodType) {
686
this.periodType = periodType;
690
public String getE_Date() {
695
public void setE_Date(String date) {
700
public String getS_Date() {
705
public void setS_Date(String date) {
711
public int getNoOfPeriods() {
717
public void setNoOfPeriods(int noOfPeriods) {
718
this.noOfPeriods = noOfPeriods;
721
public String getTempEDate() {
727
public void setTempEDate(String tempEDate) {
728
this.tempEDate = tempEDate;
733
public String getIde_type() {
739
public void setIde_type(String ide_type) {
740
this.ide_type = ide_type;