← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10186: Fix bug in aggreagete Tabular report.

 

------------------------------------------------------------
revno: 10186
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-14 00:24:42 +0700
message:
  Fix bug in aggreagete Tabular report.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageInstancesList.vm


--
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-03-13 14:52:25 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-03-13 17:24:42 +0000
@@ -674,7 +674,7 @@
             sql = getAggregateReportSQL8( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods
                 .iterator().next(), aggregateType, limit, useCompletedEvents, format );
         }
-
+ System.out.println("\n\n === \n " + sql );       
         if ( !sql.isEmpty() )
         {
             SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -1069,11 +1069,11 @@
 
                 if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                 {
-                    sql += "(SELECT " + aggregateType + "(*) ";
+                    sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                 }
                 else
                 {
-                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                 }
                 sql += "FROM programstageinstance psi_1 ";
                 sql += "        JOIN patientdatavalue pdv_1 ";
@@ -1152,11 +1152,11 @@
 
                 if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                 {
-                    sql += "( SELECT " + aggregateType + "(pdv_1.value) ";
+                    sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                 }
                 else
                 {
-                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                 }
                 sql += "FROM ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
@@ -1197,7 +1197,7 @@
     }
 
     /**
-     * Aggregate report Period Rows - Orgunit Filter - Data Filter
+     * Aggregate report Orgunit Filter - Period Rows - Data Filter
      * 
      **/
     private String getAggregateReportSQL4( int position, ProgramStage programStage, Collection<Integer> roots,
@@ -1229,11 +1229,11 @@
 
                 if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                 {
-                    sql += "( SELECT " + aggregateType + "(pdv_1.value) ";
+                    sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                 }
                 else
                 {
-                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                 }
                 sql += "FROM ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
@@ -1293,11 +1293,11 @@
 
             if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
             {
-                sql += "(select " + aggregateType + "(pdv_1.value)  ";
+                sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
             }
             else
             {
-                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
             }
             sql += "FROM ";
             sql += "    patientdatavalue pdv_1 RIGHT JOIN programstageinstance psi_1 ";
@@ -1401,11 +1401,11 @@
                 {
                     if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                     {
-                        sql += "(SELECT " + aggregateType + "(value) ";
+                        sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                     }
                     else
                     {
-                        sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                        sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                     }
                     sql += "FROM programstageinstance psi_1 JOIN patientdatavalue pdv_1 ";
                     sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
@@ -1441,7 +1441,7 @@
             }
 
             sql = sql.substring( 0, sql.length() - 6 );
-            sql += "ORDER BY  \"" + deValues.iterator().next() + "\" desc ";
+            
             if ( limit != null )
             {
                 sql += " LIMIT " + limit;
@@ -1482,11 +1482,11 @@
 
             if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
             {
-                sql += "(SELECT " + aggregateType + "(value) ";
+                sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
             }
             else
             {
-                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
             }
             sql += "FROM programstageinstance psi_1 JOIN patientdatavalue pdv_1 ";
             sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
@@ -1534,7 +1534,7 @@
         Integer limit, Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
-
+        
         for ( Integer root : roots )
         {
             Collection<Integer> orgunitIds = getOrganisationUnits( root, facilityLB );
@@ -1545,11 +1545,11 @@
             {
                 if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                 {
-                    sql += "( SELECT " + aggregateType + "(value) ";
+                    sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                 }
                 else
                 {
-                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                 }
                 sql += "FROM patientdatavalue pdv_1 ";
                 sql += "        inner join programstageinstance psi_1 ";
@@ -1609,11 +1609,11 @@
 
             if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
             {
-                sql += "( SELECT " + aggregateType + "(value) ";
+                sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
             }
             else
             {
-                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION ))";
+                sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
             }
 
             sql += "FROM patientdatavalue pdv_1 ";
@@ -1735,10 +1735,12 @@
         }
 
         String firstPeriodName = "";
+        
+        String groupByName = dataElementService.getDataElement( deGroupBy ).getDisplayName();
         for ( String deValue : deValues )
         {
 
-            sql += "(SELECT DISTINCT '" + deValue + "' as devalue, ";
+            sql += "(SELECT DISTINCT '" + deValue + "' as \"" + groupByName +"\", ";
 
             for ( Period period : periods )
             {
@@ -1761,15 +1763,11 @@
 
                 if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
                 {
-                    sql += "( SELECT " + aggregateType + "(value) ";
+                    sql += "(SELECT count(DISTINCT psi_1.programstageinstanceid) ";
                 }
                 else
                 {
-                    sql += "( SELECT " + aggregateType + "( cast( value as " + statementBuilder.getDoubleColumnType()
-                        + " ))";
-                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and "
-                        + "          programstageinstanceid=psi_1.programstageinstanceid and dataelementid=" + deSum
-                        + " ";
+                    sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) ";
                 }
 
                 sql += "FROM programstageinstance psi_1 JOIN patientdatavalue pdv_1 ";
@@ -1822,7 +1820,6 @@
         {
             // Get filter criteria
             Iterator<Integer> iterFilter = deFilters.keySet().iterator();
-            boolean flag = false;
             while ( iterFilter.hasNext() )
             {
                 Integer id = iterFilter.next();
@@ -1835,11 +1832,6 @@
                     filter += "AND (SELECT value ";
                     filter += "FROM patientdatavalue ";
                     filter += "WHERE programstageinstanceid=psi_1.programstageinstanceid AND ";
-                    if ( !flag )
-                    {
-                        filter += "dataelementid= pdv_1.dataelementid AND ";
-                        flag = true;
-                    }
                     filter += "dataelementid=" + id + "  ";
                     filter += ") " + operator + " " + value + " ";
                 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-03-13 14:52:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-03-13 17:24:42 +0000
@@ -1769,13 +1769,13 @@
 					for(var idx=0;idx<length;idx++)
 					{
 						var id = deId + '_' + idx;
-						var filterValue = Ext.getCmp('filter_' + id).getValue();
-						if(filterValue==null)
+						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						if(filterValue==null || filterValue==TR.i18n.please_select)
 						{
-							filterValue = Ext.getCmp('filter_' + id).rawValue;
+							filterValue = Ext.getCmp('filter_' + id).getValue();
 						}
 						var filter = deId + '_' + hidden 
-						if( filterValue!='' && filterValue!=TR.i18n.please_select ){
+						if( filterValue!='' ){
 							var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
 							filter += '_' + filterOpt + ' ';
 							if( filterOpt == 'IN' )
@@ -1868,10 +1868,10 @@
 					for(var idx=0;idx<length;idx++)
 					{
 						var id = deId + '_' + idx;
-						var filterValue = Ext.getCmp('filter_' + id).getValue();
-						if(filterValue==null)
+						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						if(filterValue==null || filterValue==TR.i18n.please_select)
 						{
-							filterValue = Ext.getCmp('filter_' + id).rawValue;
+							filterValue = Ext.getCmp('filter_' + id).getValue();
 						}
 						var filter = deId + '_' + hidden 
 						if( filterValue!=''){
@@ -2127,10 +2127,10 @@
 					{
 						var id = deId + '_' + idx;
 						var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
-						var filterValue = Ext.getCmp('filter_' + id).getValue();
-						if(filterValue==null)
+						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						if(filterValue==null || filterValue==TR.i18n.please_select)
 						{
-							filterValue = Ext.getCmp('filter_' + id).rawValue;
+							filterValue = Ext.getCmp('filter_' + id).getValue();
 						}
 						var filter = deId.split('_')[1] + "_" + filterOpt + '_';
 					
@@ -2138,7 +2138,7 @@
 						{
 							if( valueType == 'list' )
 							{
-								var filterValues = filterValue.split(";");
+								var filterValues = filterValue.split(';');
 								filter +="(";
 								for(var i=0;i<filterValues.length;i++)
 								{
@@ -2238,10 +2238,10 @@
 					{
 						var id = deId + '_' + idx;
 						var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
-						var filterValue = Ext.getCmp('filter_' + id).getValue();
-						if(filterValue==null)
+						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						if(filterValue==null || filterValue==TR.i18n.please_select)
 						{
-							filterValue = Ext.getCmp('filter_' + id).rawValue;
+							filterValue = Ext.getCmp('filter_' + id).getValue();
 						}
 						var filter = deId.split('_')[1] + "_" + filterOpt + '_';
 					
@@ -2356,7 +2356,11 @@
 						for(var idx=0;idx<length;idx++)
 						{
 							var id = deId + '_' + idx;
-							var filterValue = Ext.getCmp('filter_' + id).getValue();
+							var filterValue = Ext.getCmp('filter_' + id).rawValue;
+							if(filterValue==null || filterValue==TR.i18n.please_select)
+							{
+								filterValue = Ext.getCmp('filter_' + id).getValue();
+							}
 							if( filterValue == null || ( filterValue == '' && filterValue != 0 )
 							|| filterValue==TR.i18n.please_select ){
 								isValid = false;
@@ -4671,6 +4675,16 @@
 																	Ext.getCmp('positionPeriodCbx').setValue('3');
 																}
 																Ext.getCmp('positionDataCbx').setValue('1');
+																Ext.getCmp('aggregateType').items.items[1].setValue(false);
+																Ext.getCmp('aggregateType').items.items[2].setValue(false);
+																Ext.getCmp('aggregateType').items.items[1].disable();
+																Ext.getCmp('aggregateType').items.items[2].disable();
+																Ext.getCmp('aggregateType').items.items[0].setValue(true);
+															}
+															else
+															{
+																Ext.getCmp('aggregateType').items.items[1].enable();
+																Ext.getCmp('aggregateType').items.items[2].enable();
 															}
 														}
 													}
@@ -5949,8 +5963,6 @@
 				TR.state.orgunitIds = [];
 				for( var i in TR.init.system.rootnodes){
 					TR.state.orgunitIds.push( TR.init.system.rootnodes[i].localid );
-					var node = TR.cmp.params.organisationunit.treepanel.getRootNode().findChild('id', TR.init.system.rootnodes[i].id, true);
-					TR.cmp.params.organisationunit.treepanel.getSelectionModel().select(node);
 				}
             },
             resize: function(vp) {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageInstancesList.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageInstancesList.vm	2013-03-10 13:01:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageInstancesList.vm	2013-03-13 17:24:42 +0000
@@ -26,7 +26,7 @@
 					<tr>
 						<th>#</th>
 						#set($noCols = $grid.getHeaders().size() )
-						#set($metaData = $noCols - $valueTypes.size() - 1)
+						#set($metaData = $noCols - $valueTypes.size() )
 						#set($index = 0)
 						#foreach( $col in $grid.getHeaders() )
 							#if($index < $noCols - 2 )