← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9610: Add ad-hoc aggregated reports in Tabular reports (WIP).

 

------------------------------------------------------------
revno: 9610
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-01-25 17:17:23 +0700
message:
  Add ad-hoc aggregated reports in Tabular reports (WIP).
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-01-25 08:32:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-01-25 10:17:23 +0000
@@ -26,6 +26,7 @@
  */
 package org.hisp.dhis.program.hibernate;
 
+import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -663,7 +664,7 @@
             sql = getAggregateReportSQL8( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods
                 .iterator().next(), aggregateType, limit, useCompletedEvents, format );
         }
-        
+
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
 
         // Type != 2
@@ -985,7 +986,7 @@
                 }
                 sql += "     psi_1.executiondate >= '" + startDate + "' AND ";
                 sql += "     psi_1.executiondate <= '" + endDate + "' ";
-                sql += filterSQL + " ) ) ";
+                sql += filterSQL + " ) as " + aggregateType + "  ) ";
                 sql += " UNION ";
             }
         }
@@ -1389,8 +1390,12 @@
                 total = 0;
                 for ( int i = 2; i <= cols; i++ )
                 {
-                    column.add( rowSet.getInt( i ) );
-                    total += rowSet.getInt( i );
+                    column.add( rowSet.getObject( i ) );
+                    // value
+                    if ( rowSet.getMetaData().getColumnType( i ) != Types.VARCHAR )
+                    {
+                        total += rowSet.getInt( i );
+                    }
                 }
                 column.add( total );
                 columnValues.put( index, column );
@@ -1424,7 +1429,10 @@
                 total = 0;
                 for ( int i = 2; i < index; i++ )
                 {
-                    total += (Integer) columnValues.get( i ).get( j );
+                    if ( rowSet.getMetaData().getColumnType( i ) != Types.VARCHAR )
+                    {
+                        total += (Long) columnValues.get( i ).get( j );
+                    }
                 }
                 column.add( total );
                 allTotal += total;
@@ -1516,12 +1524,12 @@
             int total = 0;
             for ( int i = 1; i <= cols; i++ )
             {
+                // values
+                if ( rs.getMetaData().getColumnType( i ) == Types.VARCHAR )
+                {
+                    grid.addValue( rs.getObject( i ) );
+                }
                 // meta column
-                if ( i == 1 )
-                {
-                    grid.addValue( rs.getObject( i ) );
-                }
-                // values
                 else
                 {
                     Integer value = rs.getInt( i );