← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10180: Fix bug on Case-based tabular report.

 

------------------------------------------------------------
revno: 10180
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-03-13 21:52:25 +0700
message:
  Fix bug on Case-based 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/jsonTabularReportResult.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 09:30:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2013-03-13 14:52:25 +0000
@@ -1073,11 +1073,7 @@
                 }
                 else
                 {
-                    sql += "(SELECT ( 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 ";
                 sql += "        JOIN patientdatavalue pdv_1 ";
@@ -1087,6 +1083,10 @@
                     + " )  AND ";
                 sql += "     psi_1.executiondate >= '" + startDate + "' AND ";
                 sql += "     psi_1.executiondate <= '" + endDate + "' AND ";
+                if ( deSum != null )
+                {
+                    sql += " dataelementid=" + deSum + " AND ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " psi_1.completed = true AND ";
@@ -1156,11 +1156,7 @@
                 }
                 else
                 {
-                    sql += "(SELECT ( 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 ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
@@ -1169,6 +1165,10 @@
                 sql += "WHERE ";
                 sql += "    ou.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) AND ";
                 sql += "    psi_1.programstageid=" + programStage.getId() + " AND ";
+                if ( deSum != null )
+                {
+                    sql += " dataelementid=" + deSum + " AND ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " psi_1.completed = true AND ";
@@ -1233,11 +1233,7 @@
                 }
                 else
                 {
-                    sql += "(SELECT ( 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 ";
                 sql += "   patientdatavalue pdv_1 JOIN programstageinstance psi_1 ";
@@ -1246,6 +1242,10 @@
                 sql += "WHERE ";
                 sql += "    ou.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) AND ";
                 sql += "    psi_1.programstageid=" + programStage.getId() + " AND ";
+                if ( deSum != null )
+                {
+                    sql += " dataelementid=" + deSum + " AND ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " psi_1.completed = true AND ";
@@ -1297,11 +1297,7 @@
             }
             else
             {
-                sql += "(SELECT ( 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 ";
             sql += "    patientdatavalue pdv_1 RIGHT JOIN programstageinstance psi_1 ";
@@ -1322,6 +1318,11 @@
             {
                 sql += " AND psi_1.completed = true ";
             }
+            if ( deSum != null )
+            {
+                sql += " AND dataelementid=" + deSum + "  ";
+            }
+            
             sql += " LIMIT 1 ) as " + aggregateType + "  ) ";
             sql += " UNION ";
         }
@@ -1351,7 +1352,8 @@
         dataValueSql += "FROM patientdatavalue pdv JOIN programstageinstance psi";
         dataValueSql += "       ON pdv.programstageinstanceid=psi.programstageinstanceid ";
         dataValueSql += "WHERE pdv.dataelementid=" + deGroupBy + " AND ";
-        dataValueSql += "       psi.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) AND ";
+        dataValueSql += "       psi.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds )
+            + " ) AND ";
         dataValueSql += "       psi.programstageid=" + programStage.getId() + " AND ( ";
         for ( Period period : periods )
         {
@@ -1403,11 +1405,7 @@
                     }
                     else
                     {
-                        sql += "(SELECT ( 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 ";
                     sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
@@ -1428,6 +1426,10 @@
                 sql += "    on psi.programstageinstanceid = pdv.programstageinstanceid ";
                 sql += "WHERE ";
                 sql += "    psi.programstageid=" + programStage.getId() + " ";
+                if ( deSum != null )
+                {
+                    sql += " AND dataelementid=" + deSum + "  ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " AND psi.completed = true ";
@@ -1484,11 +1486,7 @@
             }
             else
             {
-                sql += "(SELECT ( 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 ";
             sql += "    on psi_1.programstageinstanceid = pdv_1.programstageinstanceid ";
@@ -1505,6 +1503,10 @@
             sql += "    on psi.programstageinstanceid = pdv.programstageinstanceid ";
             sql += "WHERE ";
             sql += "    psi.programstageid=" + programStage.getId() + " ";
+            if ( deSum != null )
+            {
+                sql += " AND dataelementid=" + deSum + "  ";
+            }
             if ( useCompletedEvents )
             {
                 sql += " AND psi.completed = true ";
@@ -1547,11 +1549,7 @@
                 }
                 else
                 {
-                    sql += "(SELECT ( 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 patientdatavalue pdv_1 ";
                 sql += "        inner join programstageinstance psi_1 ";
@@ -1561,6 +1559,10 @@
                 sql += "        psi_1.executiondate <= '" + format.formatDate( period.getEndDate() ) + "' AND ";
                 sql += "        psi_1.organisationunitid in (" + TextUtils.getCommaDelimitedString( orgunitIds )
                     + ") AND ";
+                if ( deSum != null )
+                {
+                    sql += " dataelementid=" + deSum + " AND ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " psi_1.completed = true AND ";
@@ -1611,11 +1613,7 @@
             }
             else
             {
-                sql += "(SELECT ( 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 patientdatavalue pdv_1 ";
@@ -1624,6 +1622,10 @@
             sql += "WHERE ";
             sql += "        psi_1.executiondate >= '" + format.formatDate( period.getStartDate() ) + "' AND ";
             sql += "        psi_1.executiondate <= '" + format.formatDate( period.getEndDate() ) + "' AND ";
+            if ( deSum != null )
+            {
+                sql += " dataelementid=" + deSum + " AND ";
+            }
             if ( useCompletedEvents )
             {
                 sql += " psi_1.completed = true AND ";
@@ -1704,8 +1706,9 @@
         dataValueSql += "FROM patientdatavalue pdv JOIN programstageinstance psi";
         dataValueSql += "         ON pdv.programstageinstanceid=psi.programstageinstanceid ";
         dataValueSql += "WHERE pdv.dataelementid=" + deGroupBy + " AND ";
-        dataValueSql += "       psi.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds ) + " ) AND ";
-         dataValueSql += "      psi.programstageid=" + programStage.getId() + " AND ( ";
+        dataValueSql += "       psi.organisationunitid in ( " + TextUtils.getCommaDelimitedString( orgunitIds )
+            + " ) AND ";
+        dataValueSql += "      psi.programstageid=" + programStage.getId() + " AND ( ";
         for ( Period period : periods )
         {
             dataValueSql += " ( psi.executiondate >= '" + format.formatDate( period.getStartDate() ) + "' AND ";
@@ -1780,6 +1783,10 @@
                 sql += "        (SELECT value from patientdatavalue ";
                 sql += "        WHERE programstageinstanceid=psi_1.programstageinstanceid AND ";
                 sql += "              dataelementid=" + deGroupBy + ") = '" + deValue + "' ";
+                if ( deSum != null )
+                {
+                    sql += " AND dataelementid=" + deSum + " ";
+                }
                 if ( useCompletedEvents )
                 {
                     sql += " AND psi_1.completed = true ";
@@ -1804,7 +1811,7 @@
                 sql += " LIMIT " + limit;
             }
         }
-System.out.println("\n\n === \n " + sql );
+
         return sql;
     }
 

=== 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-11 13:18:17 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-03-13 14:52:25 +0000
@@ -520,12 +520,12 @@
 						params.valueField = 'value';
 						params.displayField = 'name';
 						params.editable = false;
-						params.value = 'true';
 						if( fixedId=='fixedAttr_gender')
 						{
 							params.store = new Ext.data.ArrayStore({
 								fields: ['value', 'name'],
-								data: [['M', TR.i18n.male], 
+								data: [['', TR.i18n.please_select], 
+									['M', TR.i18n.male], 
 									['F', TR.i18n.female],
 									['T', TR.i18n.transgender]]
 							});
@@ -534,7 +534,8 @@
 						{
 							params.store = new Ext.data.ArrayStore({
 								fields: ['value', 'name'],
-								data: [['V', TR.i18n.verified], 
+								data: [['', TR.i18n.please_select],
+									['V', TR.i18n.verified], 
 									['D', TR.i18n.declared],
 									['A', TR.i18n.approximated]]
 							});
@@ -543,7 +544,8 @@
 						{
 							params.store = new Ext.data.ArrayStore({
 								fields: ['value', 'name'],
-								data: [['true', TR.i18n.yes], 
+								data: [['', TR.i18n.please_select], 
+									['true', TR.i18n.yes], 
 									['false', TR.i18n.no]]
 							});
 						}
@@ -554,10 +556,9 @@
 						params.valueField = 'value';
 						params.displayField = 'name';
 						params.editable = false;
-						params.value = 'true';
 						params.store = new Ext.data.ArrayStore({
 							fields: ['value', 'name'],
-							data: [['true', TR.i18n.yes]]
+							data: [['', TR.i18n.please_select],['true', TR.i18n.yes]]
 						});
 					}
 					else if(valueType=='username'){
@@ -598,6 +599,7 @@
 						});
 					}					
 				}
+				params.value = '';
 				return params;
 			},
 			addFieldBtn: function( p, id, name, valueType, idx ){
@@ -1767,9 +1769,13 @@
 					for(var idx=0;idx<length;idx++)
 					{
 						var id = deId + '_' + idx;
-						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						var filterValue = Ext.getCmp('filter_' + id).getValue();
+						if(filterValue==null)
+						{
+							filterValue = Ext.getCmp('filter_' + id).rawValue;
+						}
 						var filter = deId + '_' + hidden 
-						if( filterValue!=''){
+						if( filterValue!='' && filterValue!=TR.i18n.please_select ){
 							var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
 							filter += '_' + filterOpt + ' ';
 							if( filterOpt == 'IN' )
@@ -1816,8 +1822,7 @@
 				// Get searching values
 				
 				var searchingValues = document.getElementById('searchingValues');
-				TR.util.list.clearList(searchingValues);
-				
+				TR.util.list.clearList(searchingValues);				
 				
 				// Patient properties
 				
@@ -1832,7 +1837,7 @@
 						var id = propId + '_' + idx;
 						var filterValue = Ext.getCmp('filter_' + id).rawValue;
 						var filter = propId + '_' + hidden 
-						if( filterValue!=''){
+						if( filterValue!='' && filterValue!=TR.i18n.please_select ){
 							var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
 							filter += '_' + filterOpt + ' ';
 							if( filterOpt == 'IN' )
@@ -1863,7 +1868,11 @@
 					for(var idx=0;idx<length;idx++)
 					{
 						var id = deId + '_' + idx;
-						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						var filterValue = Ext.getCmp('filter_' + id).getValue();
+						if(filterValue==null)
+						{
+							filterValue = Ext.getCmp('filter_' + id).rawValue;
+						}
 						var filter = deId + '_' + hidden 
 						if( filterValue!=''){
 							var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
@@ -2118,24 +2127,31 @@
 					{
 						var id = deId + '_' + idx;
 						var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
-						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						var filterValue = Ext.getCmp('filter_' + id).getValue();
+						if(filterValue==null)
+						{
+							filterValue = Ext.getCmp('filter_' + id).rawValue;
+						}
 						var filter = deId.split('_')[1] + "_" + filterOpt + '_';
 					
-						if( valueType == 'list' )
-						{
-							var filterValues = filterValue.split(";");
-							filter +="(";
-							for(var i=0;i<filterValues.length;i++)
-							{
-								filter += "'"+ filterValues[i] +"',";
-							}
-							filter = filter.substr(0,filter.length - 1) + ")";
-						}
-						else 
-						{
-							filter += "'" + filterValue + "'";
-						}
-						p.deFilters.push( filter );
+						if( filterValue!=TR.i18n.please_select)
+						{
+							if( valueType == 'list' )
+							{
+								var filterValues = filterValue.split(";");
+								filter +="(";
+								for(var i=0;i<filterValues.length;i++)
+								{
+									filter += "'"+ filterValues[i] +"',";
+								}
+								filter = filter.substr(0,filter.length - 1) + ")";
+							}
+							else 
+							{
+								filter += "'" + filterValue + "'";
+							}
+							p.deFilters.push( filter );
+						}
 					}
 				});
 				
@@ -2222,24 +2238,31 @@
 					{
 						var id = deId + '_' + idx;
 						var filterOpt = Ext.getCmp('filter_opt_' + id).rawValue;
-						var filterValue = Ext.getCmp('filter_' + id).rawValue;
+						var filterValue = Ext.getCmp('filter_' + id).getValue();
+						if(filterValue==null)
+						{
+							filterValue = Ext.getCmp('filter_' + id).rawValue;
+						}
 						var filter = deId.split('_')[1] + "_" + filterOpt + '_';
 					
-						if( valueType == 'list' )
-						{
-							var filterValues = filterValue.split(";");
-							filter +="(";
-							for(var i=0;i<filterValues.length;i++)
-							{
-								filter += "'"+ filterValues[i] +"',";
-							}
-							filter = filter.substr(0,filter.length - 1) + ")";
-						}
-						else 
-						{
-							filter += "'" + filterValue + "'";
-						}
-						TR.util.list.addOptionToList(deFiltersList, filter, '');
+						if(filterValue!=TR.i18n.please_select)
+						{
+							if( valueType == 'list' )
+							{
+								var filterValues = filterValue.split(";");
+								filter +="(";
+								for(var i=0;i<filterValues.length;i++)
+								{
+									filter += "'"+ filterValues[i] +"',";
+								}
+								filter = filter.substr(0,filter.length - 1) + ")";
+							}
+							else 
+							{
+								filter += "'" + filterValue + "'";
+							}
+							TR.util.list.addOptionToList(deFiltersList, filter, '');
+						}
 					}
 				});
 				
@@ -2334,7 +2357,8 @@
 						{
 							var id = deId + '_' + idx;
 							var filterValue = Ext.getCmp('filter_' + id).getValue();
-							if( filterValue == null || ( filterValue == '' && filterValue != 0 )){
+							if( filterValue == null || ( filterValue == '' && filterValue != 0 )
+							|| filterValue==TR.i18n.please_select ){
 								isValid = false;
 							}
 						}
@@ -3875,14 +3899,6 @@
 													render: function() {
 														this.rendered = true;
 													},
-													afterrender: function( treePanel, eOpts ){
-														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);
-														}
-													},
 													itemclick : function(view,rec,item,index,eventObj){
 														TR.state.orgunitIds = [];
 														var selectedNodes = TR.cmp.params.organisationunit.treepanel.getSelectionModel().getSelection();
@@ -5929,6 +5945,13 @@
 				Ext.getCmp('relativePeriodsDiv').setVisible(false); 
 				Ext.getCmp('fixedPeriodsDiv').setVisible(false);
 				Ext.getCmp('dateRangeDiv').expand();
+				
+				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) {
                 TR.cmp.region.west.setWidth(TR.conf.layout.west_width);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularReportResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularReportResult.vm	2013-01-21 09:52:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularReportResult.vm	2013-03-13 14:52:25 +0000
@@ -27,11 +27,7 @@
   #foreach( $row in $grid.getRows() )
   [
   #foreach( $col in $row )
-	#if( $velocityCount < 3)
-		"$!col"
-	#else
-		"$!encoder.jsonEncode($!col)"
-	#end
+	"$!col"
   #if( $velocityCount < $noHeader ),#end
   #end
   ]#if( $velocityCount < $noRows ),#end