← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9657: Add ad-hoc aggregated reports in Tabular reports - Improve with Sum and Avg operator.

 

------------------------------------------------------------
revno: 9657
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-01-30 14:54:43 +0700
message:
  Add ad-hoc aggregated reports in Tabular reports - Improve with Sum and Avg operator.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientAggregateReport.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  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/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  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/css/style.css
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/index.html
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.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-api/src/main/java/org/hisp/dhis/patientreport/PatientAggregateReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientAggregateReport.java	2013-01-29 14:45:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientAggregateReport.java	2013-01-30 07:54:43 +0000
@@ -70,6 +70,7 @@
     public static final int POSITION_ROW_DATA_COLUMN_ORGUNIT = 10; // PIVOT FROM
                                                                    // 7
     
+    public static final String AGGREGATE_TYPE_COUNT = "count";
     public static final String AGGREGATE_TYPE_SUM = "sum";
     public static final String AGGREGATE_TYPE_AVG = "avg";
     

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-01-27 21:03:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2013-01-30 07:54:43 +0000
@@ -111,7 +111,7 @@
         Collection<Integer> orgunitIds, Date startDate, Date endDate, int status, Integer max, Integer min );
 
     Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
-        String facilityLB, Integer dataElementId, Map<Integer, Collection<String>>  deFilters, Collection<Period> periods,
+        String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>>  deFilters, Collection<Period> periods,
         String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n );
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2013-01-27 21:03:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2013-01-30 07:54:43 +0000
@@ -102,7 +102,7 @@
         Collection<Integer> orgunitIds, Date startDate, Date endDate, int status, Integer min, Integer max );
 
     Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
-        String facilityLB, Integer dataElementId, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
+        String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
         String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n );
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-01-23 10:27:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2013-01-30 07:54:43 +0000
@@ -347,11 +347,11 @@
 
     @Override
     public Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
-        String facilityLB, Integer dataElementId, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
+        String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
         String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n )
     {
         return programStageInstanceStore.getAggregateReport( position, programStage, orgunitIds, facilityLB,
-            dataElementId, deFilters, periods, aggregateType, limit, useCompletedEvents, format, i18n );
+            deGroupBy, deSum, deFilters, periods, aggregateType, limit, useCompletedEvents, format, i18n );
     }
 
 }

=== 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-29 14:45:08 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-01-30 07:54:43 +0000
@@ -393,8 +393,9 @@
     }
 
     public Grid getAggregateReport( int position, ProgramStage programStage, Collection<Integer> orgunitIds,
-        String facilityLB, Integer deGroupBy, Map<Integer, Collection<String>> deFilters, Collection<Period> periods,
-        String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format, I18n i18n )
+        String facilityLB, Integer deGroupBy, Integer deSum, Map<Integer, Collection<String>> deFilters,
+        Collection<Period> periods, String aggregateType, Integer limit, Boolean useCompletedEvents, I18nFormat format,
+        I18n i18n )
     {
         String sql = "";
         List<String> deValues = new ArrayList<String>();
@@ -411,7 +412,7 @@
         // Type = 1
         if ( position == PatientAggregateReport.POSITION_ROW_ORGUNIT_COLUMN_PERIOD )
         {
-            sql = getAggregateReportSQL12( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods,
+            sql = getAggregateReportSQL12( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum, periods,
                 aggregateType, useCompletedEvents, format );
         }
         // Type = 2
@@ -421,20 +422,20 @@
             // Get SQL and build grid
             // ---------------------------------------------------------------------
 
-            sql = getAggregateReportSQL12( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods,
+            sql = getAggregateReportSQL12( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum, periods,
                 aggregateType, useCompletedEvents, format );
 
         }
         // Type = 3
         else if ( position == PatientAggregateReport.POSITION_ROW_ORGUNIT_ROW_PERIOD )
         {
-            sql = getAggregateReportSQL3( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy,
+            sql = getAggregateReportSQL3( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum,
                 periods, aggregateType, useCompletedEvents, format );
         }
         // Type = 4
         else if ( position == PatientAggregateReport.POSITION_ROW_PERIOD )
         {
-            sql = getAggregateReportSQL4( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy,
+            sql = getAggregateReportSQL4( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum,
                 periods, aggregateType, useCompletedEvents, format );
         }
         // type = 5
@@ -442,7 +443,7 @@
         {
             List<Period> firstPeriod = new ArrayList<Period>();
             firstPeriod.add( periods.iterator().next() );
-            sql = getAggregateReportSQL5( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, periods
+            sql = getAggregateReportSQL5( position, programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum, periods
                 .iterator().next(), aggregateType, useCompletedEvents, format );
         }
 
@@ -452,7 +453,7 @@
         {
             deValues = dataElementService.getDataElement( deGroupBy ).getOptionSet().getOptions();
 
-            sql = getAggregateReportSQL6( programStage, orgunitIds.iterator().next(), facilityLB, filterSQL, deGroupBy,
+            sql = getAggregateReportSQL6( programStage, orgunitIds.iterator().next(), facilityLB, filterSQL, deGroupBy, deSum,
                 deValues, periods, aggregateType, useCompletedEvents, format );
         }
 
@@ -461,7 +462,7 @@
             && deGroupBy == null )
         {
             sql = getAggregateReportSQL6WithoutGroup( programStage, orgunitIds.iterator().next(), facilityLB,
-                filterSQL, deGroupBy, periods, aggregateType, useCompletedEvents, format );
+                filterSQL, deSum, periods, aggregateType, useCompletedEvents, format );
         }
 
         // Type = 7 && Group-by
@@ -470,7 +471,7 @@
         {
             deValues = dataElementService.getDataElement( deGroupBy ).getOptionSet().getOptions();
 
-            sql = getAggregateReportSQL7( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deValues, periods
+            sql = getAggregateReportSQL7( programStage, orgunitIds, facilityLB, filterSQL, deGroupBy, deSum, deValues, periods
                 .iterator().next(), aggregateType, useCompletedEvents, format );
         }
 
@@ -693,7 +694,7 @@
      * 
      **/
     private String getAggregateReportSQL12( ProgramStage programStage, Collection<Integer> roots, String facilityLB,
-        String filterSQL, Integer deGroupBy, Collection<Period> periods, String aggregateType,
+        String filterSQL, Integer deGroupBy, Integer deSum, Collection<Period> periods, String aggregateType,
         Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
@@ -722,8 +723,18 @@
                 {
                     periodName = startDate + " -> " + endDate;
                 }
-                
-                sql += " ( SELECT " + aggregateType + "(*) ";
+
+                if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+                {
+                    sql += "(SELECT " + aggregateType + "(*) ";
+                }
+                else
+                {
+                    sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                        + statementBuilder.getDoubleColumnType() + " ))";
+                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid="
+                        + deSum + " ) ";
+                }
                 sql += "FROM programstageinstance psi_1 ";
                 sql += "        JOIN patientdatavalue pdv_1 ";
                 sql += "                ON psi_1.programstageinstanceid=pdv_1.programstageinstanceid ";
@@ -763,8 +774,8 @@
      * 
      **/
     private String getAggregateReportSQL3( int position, ProgramStage programStage, Collection<Integer> roots,
-        String facilityLB, String filterSQL, Integer deGroupBy, Collection<Period> periods, String aggregateType,
-        Boolean useCompletedEvents, I18nFormat format )
+        String facilityLB, String filterSQL, Integer deGroupBy, Integer deSum, Collection<Period> periods,
+        String aggregateType, Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
 
@@ -790,7 +801,17 @@
                 sql += "( SELECT ou.name FROM organisationunit ou WHERE organisationunitid=" + root + " ) as orgunit, ";
                 sql += "'" + periodName + "' as period, ";
 
-                sql += " ( SELECT " + aggregateType + "(pdv_1.value)   ";
+                if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+                {
+                    sql += "( SELECT " + aggregateType + "(pdv_1.value) ";
+                }
+                else
+                {
+                    sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                        + statementBuilder.getDoubleColumnType() + " ))";
+                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid="
+                        + deSum + " ) ";
+                }
                 sql += "FROM ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
                 sql += "        ON psi_1.programstageinstanceid=pdv_1.programstageinstanceid ";
@@ -827,8 +848,8 @@
      * 
      **/
     private String getAggregateReportSQL4( int position, ProgramStage programStage, Collection<Integer> roots,
-        String facilityLB, String filterSQL, Integer deGroupBy, Collection<Period> periods, String aggregateType,
-        Boolean useCompletedEvents, I18nFormat format )
+        String facilityLB, String filterSQL, Integer deGroupBy, Integer deSum, Collection<Period> periods,
+        String aggregateType, Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
 
@@ -853,7 +874,17 @@
                 sql += "( SELECT ";
                 sql += "'" + periodName + "' as period, ";
 
-                sql += " ( SELECT " + aggregateType + "(pdv_1.value)   ";
+                if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+                {
+                    sql += "( SELECT " + aggregateType + "(pdv_1.value) ";
+                }
+                else
+                {
+                    sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                        + statementBuilder.getDoubleColumnType() + " ))";
+                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid="
+                        + deSum + " ) ";
+                }
                 sql += "FROM ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
                 sql += "        ON psi_1.programstageinstanceid=pdv_1.programstageinstanceid ";
@@ -888,7 +919,7 @@
      * 
      **/
     private String getAggregateReportSQL5( int position, ProgramStage programStage, Collection<Integer> roots,
-        String facilityLB, String filterSQL, Integer deGroupBy, Period period, String aggregateType,
+        String facilityLB, String filterSQL, Integer deGroupBy, Integer deSum, Period period, String aggregateType,
         Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
@@ -902,7 +933,17 @@
             sql += "FROM organisationunit ou  ";
             sql += "WHERE ou.organisationunitid=" + root + " ) as orgunit, ";
 
-            sql += "(select " + aggregateType + "(pdv_1.value)  ";
+            if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+            {
+                sql += "(select " + aggregateType + "(pdv_1.value)  ";
+            }
+            else
+            {
+                sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                    + statementBuilder.getDoubleColumnType() + " ))";
+                sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid=" + deSum
+                    + " ) ";
+            }
             sql += "FROM ";
             sql += "    patientdatavalue pdv_1 RIGHT JOIN programstageinstance psi_1 ";
             sql += "            ON psi_1.programstageinstanceid=pdv_1.programstageinstanceid ";
@@ -938,7 +979,7 @@
      * with group-by
      **/
     private String getAggregateReportSQL6( ProgramStage programStage, Integer root, String facilityLB,
-        String filterSQL, Integer deGroupBy, Collection<String> deValues, Collection<Period> periods,
+        String filterSQL, Integer deGroupBy, Integer deSum, Collection<String> deValues, Collection<Period> periods,
         String aggregateType, Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
@@ -962,7 +1003,17 @@
             sql += "(SELECT '" + periodName + "' as period, ";
             for ( String deValue : deValues )
             {
-                sql += "(SELECT " + aggregateType + "(value)  ";
+                if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+                {
+                    sql += "(SELECT " + aggregateType + "(value)  ";
+                }
+                else
+                {
+                    sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                        + statementBuilder.getDoubleColumnType() + " ))";
+                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid="
+                        + deSum + " ) ";
+                }
                 sql += "FROM programstageinstance psi_1 JOIN patientdatavalue pdv_1 ";
                 sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
                 sql += "WHERE ";
@@ -1002,7 +1053,7 @@
      * without group-by
      **/
     private String getAggregateReportSQL6WithoutGroup( ProgramStage programStage, Integer root, String facilityLB,
-        String filterSQL, Integer deGroupBy, Collection<Period> periods, String aggregateType,
+        String filterSQL, Integer deSum, Collection<Period> periods, String aggregateType,
         Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
@@ -1025,7 +1076,17 @@
 
             sql += "(SELECT '" + periodName + "' as period, ";
 
-            sql += "(SELECT " + aggregateType + "(value)  ";
+            if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+            {
+                sql += "(SELECT " + aggregateType + "(value) ";
+            }
+            else
+            {
+                sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                    + statementBuilder.getDoubleColumnType() + " ))";
+                sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid=" + deSum
+                    + " ) ";
+            }
             sql += "FROM programstageinstance psi_1 JOIN patientdatavalue pdv_1 ";
             sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
             sql += "WHERE ";
@@ -1033,12 +1094,6 @@
                 + "     ) AND ";
             sql += "    psi_1.executiondate >= '" + startDate + "' AND ";
             sql += "    psi_1.executiondate <= '" + endDate + "' ";
-            if ( deGroupBy != null )
-            {
-                sql += " AND (SELECT value from patientdatavalue ";
-                sql += "WHERE programstageinstanceid=psi_1.programstageinstanceid AND ";
-                sql += "      dataelementid=" + deGroupBy + ") is not null ";
-            }
             sql += filterSQL + ") as \"" + aggregateType + "\",";
 
             sql = sql.substring( 0, sql.length() - 1 ) + " ";
@@ -1066,7 +1121,7 @@
      * 
      **/
     private String getAggregateReportSQL7( ProgramStage programStage, Collection<Integer> roots, String facilityLB,
-        String filterSQL, Integer deGroupBy, List<String> deValues, Period period, String aggregateType,
+        String filterSQL, Integer deGroupBy, Integer deSum, List<String> deValues, Period period, String aggregateType,
         Boolean useCompletedEvents, I18nFormat format )
     {
         String sql = "";
@@ -1079,7 +1134,18 @@
             sql += "( SELECT ou.name FROM organisationunit ou WHERE ou.organisationunitid=" + root + " ) as orgunit, ";
             for ( String deValue : deValues )
             {
-                sql += "( SELECT " + aggregateType + "(value) FROM patientdatavalue pdv_1 ";
+                if ( aggregateType.equals( PatientAggregateReport.AGGREGATE_TYPE_COUNT ) )
+                {
+                    sql += "( SELECT " + aggregateType + "(value) ";
+                }
+                else
+                {
+                    sql += "(SELECT ( SELECT " + aggregateType + "( cast( value as "
+                        + statementBuilder.getDoubleColumnType() + " ))";
+                    sql += "    FROM patientdatavalue where dataelementid=pdv_1.dataelementid and dataelementid="
+                        + deSum + " ) ";
+                }
+                sql += "FROM patientdatavalue pdv_1 ";
                 sql += "        inner join programstageinstance psi_1 ";
                 sql += "          on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
                 sql += "WHERE ";

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java	2013-01-26 07:07:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateAggregateReportAction.java	2013-01-30 07:54:43 +0000
@@ -213,6 +213,13 @@
         this.userOrganisationUnitChildren = userOrganisationUnitChildren;
     }
 
+    private Integer deSum;
+
+    public void setDeSum( Integer deSum )
+    {
+        this.deSum = deSum;
+    }
+
     private String type;
 
     public void setType( String type )
@@ -324,7 +331,7 @@
         }
 
         grid = programStageInstanceService.getAggregateReport( position, programStage, orgunitIds, facilityLB,
-            deGroupBy, deFilterMap, periods, aggregateType, limitRecords, useCompletedEvents, format, i18n );
+            deGroupBy, deSum, deFilterMap, periods, aggregateType, limitRecords, useCompletedEvents, format, i18n );
 
         return type == null ? SUCCESS : type;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-01-29 06:06:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-01-30 07:54:43 +0000
@@ -545,4 +545,5 @@
 select_all_children = Select all children
 total = Total
 confirm_delete_date_range_list=Are you sure you want to delete date range list?
-invalid_position = Please select at most two row positions or two filter positions.
\ No newline at end of file
+invalid_position = Please select at most two row positions or two filter positions.
+select_a_dataelement_for_sum_avg_operator = Please select a data element for sum/avg operator
\ No newline at end of file

=== 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-01-29 06:06:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-01-30 07:54:43 +0000
@@ -1290,6 +1290,8 @@
 						Ext.getCmp('programStageCombobox').disable();
 						var programStageId = TR.store.programStage.data.items[0].raw.id;
 						Ext.getCmp('programStageCombobox').setValue( programStageId );
+						
+						// Load data element list
 						var store = TR.store.dataelement.available;
 						TR.store.dataelement.available.loadData([],false);
 						if( !TR.store.programStage.isLoadFromFavorite)
@@ -1327,6 +1329,16 @@
 						this.isloaded = true;
                         TR.util.store.addToStorage(s);
                         TR.util.multiselect.filterAvailable(TR.cmp.params.dataelement.available, TR.cmp.params.dataelement.selected);
+						
+						TR.store.aggregateDataelement.loadData([],false);
+						TR.cmp.params.dataelement.available.store.each( function(r) {
+							if(r.data.valueType == 'int'){
+								TR.store.aggregateDataelement.add({
+									'id': r.data.id,
+									'name': r.data.name
+								});
+							}
+						});
                     }
 				}
             }),
@@ -1429,6 +1441,10 @@
 		dateRange: Ext.create('Ext.data.Store', {
 			fields: ['startDate', 'endDate'],
 			data: []
+		}),
+		aggregateDataelement: Ext.create('Ext.data.Store', {
+			fields: ['id', 'name'],
+			data: []
 		})
 	}
     
@@ -1903,6 +1919,10 @@
 				var p = {};
 				p.programStageId = TR.cmp.params.programStage.getValue();
 				p.aggregateType = Ext.getCmp('aggregateType').getValue().aggregateType;
+				if( p.aggregateType != 'count')
+				{
+					p.deSum = Ext.getCmp('deSumCbx').getValue();
+				}				
 				
 				// orgunits
 				
@@ -2006,6 +2026,13 @@
 					document.getElementById('limitRecords').value = "";
 				}
 				
+				if( Ext.getCmp('aggregateType').getValue().aggregateType != 'count'){
+					document.getElementById('deSum').value = Ext.getCmp('deSumCbx').getValue();
+				}
+				else{
+					document.getElementById('deSum').value = '';
+				}
+				
 				// orgunits
 				
 				var orgunitIdList = document.getElementById('orgunitIds');
@@ -2178,6 +2205,12 @@
 						return false;
 					}
 					
+					if( Ext.getCmp('aggregateType').getValue().aggregateType != 'count'
+						&& ( Ext.getCmp('deSumCbx').getValue() == null || Ext.getCmp('deSumCbx').getValue=='')){
+						TR.util.notification.error(TR.i18n.select_a_dataelement_for_sum_avg_operator, TR.i18n.select_a_dataelement_for_sum_avg_operator );
+						return false;	
+					}
+				
 					return true;
 				},
 				response: function(r) {
@@ -4146,6 +4179,25 @@
 													}]
 												},
 												{
+													xtype: 'combobox',
+													cls: 'tr-combo',
+													id: 'deSumCbx',
+													fieldLabel: TR.i18n.sum_avg_of,
+													labelWidth: 135,
+													emptyText: TR.i18n.please_select,
+													queryMode: 'local',
+													editable: true,
+													valueField: 'id',
+													displayField: 'name',
+													width: TR.conf.layout.west_fieldset_width - TR.conf.layout.west_width_subtractor - 40,
+													store: TR.store.aggregateDataelement,
+													listeners: {
+														added: function() {
+															TR.cmp.settings.aggregateDataelement = this;
+														}
+													}
+												},
+												{
 													xtype: 'checkbox',
 													cls: 'tr-checkbox',
 													id: 'completedEventsOpt',

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/css/style.css'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/css/style.css	2013-01-29 06:06:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/css/style.css	2013-01-30 07:54:43 +0000
@@ -219,6 +219,7 @@
 .x-form-cb-label-before {
     padding-left: 1px;
     font-size: 11px;
+	padding-right: 10px;
 }
 
 /* TR checkbox */

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/index.html'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/index.html	2013-01-26 07:07:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/index.html	2013-01-30 07:54:43 +0000
@@ -21,6 +21,7 @@
 		<input type="hidden" id="facilityLB" name="facilityLB" >
 		<input type="hidden" id="position" name="position" >
 		<input type="hidden" id="useCompletedEvents" name="useCompletedEvents" >
+		<input type="hidden" id="deSum" name="deSum" >
 		<select multiple id="startDates" name="startDates" class="hidden"></select>
     </form>
 	

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm	2013-01-29 06:06:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/i18n.vm	2013-01-30 07:54:43 +0000
@@ -157,5 +157,7 @@
 select_all_children: '$encoder.jsEscape($i18n.getString( 'select_all_children' ) , "'")',
 total: '$encoder.jsEscape($i18n.getString( 'total' ) , "'")',
 confirm_delete_date_range_list: '$encoder.jsEscape($i18n.getString( 'confirm_delete_date_range_list' ) , "'")',
-invalid_position: '$encoder.jsEscape($i18n.getString( 'invalid_position' ) , "'")'
+invalid_position: '$encoder.jsEscape($i18n.getString( 'invalid_position' ) , "'")',
+sum_avg_of: '$encoder.jsEscape($i18n.getString( 'sum_avg_of' ) , "'")',
+select_a_dataelement_for_sum_avg_operator: '$encoder.jsEscape($i18n.getString( 'select_a_dataelement_for_sum_avg_operator' ) , "'")',
 };
\ No newline at end of file