← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8536: Allow filter with many criteria for number column in tabular report.

 

------------------------------------------------------------
revno: 8536
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-16 15:33:54 +0700
message:
  Allow filter with many criteria for number column in 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/anonymousRegistration.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js


--
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	2012-10-16 04:05:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-10-16 08:33:54 +0000
@@ -32,6 +32,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.hibernate.Query;
 import org.hibernate.criterion.Order;
@@ -339,6 +340,7 @@
         Collection<Integer> orgUnits, int level, int maxLevel, Date startDate, Date endDate, boolean descOrder,
         Integer min, Integer max )
     {
+        Set<String> deKeys = new HashSet<String>();
         String selector = count ? "count(*) " : "* ";
 
         String sql = "select " + selector + "from ( select DISTINCT psi.programstageinstanceid, psi.executiondate,";
@@ -387,10 +389,16 @@
             }
             if ( column.isNumberDataElement() )
             {
-                sql += "(select cast( value as "
-                    + statementBuilder.getDoubleColumnType()
-                    + " ) from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
-                    + column.getIdentifier() + ") as element_" + column.getIdentifier() + ",";
+                String deKey = "element_" + column.getIdentifier();
+                if ( !deKeys.contains( deKey ) )
+                {
+                    sql += "(select cast( value as "
+                        + statementBuilder.getDoubleColumnType()
+                        + " ) from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
+                        + column.getIdentifier() + ") as element_" + column.getIdentifier() + ",";
+                    deKeys.add( deKey );
+                }
+                
                 if ( column.hasQuery() )
                 {
                     where += operator + "element_" + column.getIdentifier() + " " + column.getQuery() + " ";
@@ -399,9 +407,14 @@
             }
             else if ( column.isDataElement() )
             {
-                sql += "(select value from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
-                    + column.getIdentifier() + ") as element_" + column.getIdentifier() + ",";
-
+                String deKey = "element_" + column.getIdentifier();
+                if ( !deKeys.contains( deKey ) )
+                {
+                    sql += "(select value from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
+                        + column.getIdentifier() + ") as element_" + column.getIdentifier() + ",";
+                    deKeys.add( deKey );
+                }
+                
                 if ( column.hasQuery() )
                 {
                     where += operator + "lower(element_" + column.getIdentifier() + ") " + column.getQuery() + " ";

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-10-15 04:35:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-10-16 08:33:54 +0000
@@ -145,6 +145,13 @@
 	var i18n_confirm_remove_empty_events = '$encoder.jsEscape( $i18n.getString( "confirm_remove_empty_events" ) , "'")';
 	var i18n_report_date = '$encoder.jsEscape( $i18n.getString( "report_date" ) , "'")';
 	
+	var i18n_male = '$encoder.jsEscape( $i18n.getString( "male" ) , "'")';
+	var i18n_female = '$encoder.jsEscape( $i18n.getString( "female" ) , "'")';
+	var i18n_transgender = '$encoder.jsEscape( $i18n.getString( "transgender" ) , "'")';
+	var i18n_yes = '$encoder.jsEscape( $i18n.getString( "yes" ) , "'")';
+	var i18n_no = '$encoder.jsEscape( $i18n.getString( "no" ) , "'")';
+	var i18n_specify_search_criteria = '$encoder.jsEscape( $i18n.getString( "specify_search_criteria" ) , "'")';
+	
 	isAjax = true;
 	contentDiv = '';
 	var unSave = false;

=== 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	2012-10-06 04:54:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2012-10-16 08:33:54 +0000
@@ -375,8 +375,7 @@
                 return text.replace(/[^a-zA-Z 0-9(){}<>_!+;:?*&%#-]+/g,'');
             }
         },
-        getValueFormula: function( value )
-		{
+        getValueFormula: function( value ){
 			if( value.indexOf('"') != value.lastIndexOf('"') )
 			{
 				value = value.replace(/"/g,"'");
@@ -406,7 +405,6 @@
 					value = "="+ value;
 				}
 			}
-			
 			return value;
 		},
         crud: {
@@ -837,6 +835,7 @@
 			var grid = TR.datatable.datatable;
 			
 			var filters = grid.filters.getFilterData();
+			var value = "";
 			for( var i=0; i<filters.length; i++ )
 			{
 				var filter = filters[i];
@@ -847,10 +846,9 @@
 				else if( filter.data.comparison == 'gt' )
 					compare = '>' ;
 					
-				var value = compare + "'"+ filter.data.value + "'";
-				
-				var record = grid.getView().getRecord( grid.getView().getNode(0) );
-				record.set(filter.field, value.toLowerCase());
+				value = compare + "'"+ filter.data.value + "'";
+				//var record = grid.getView().getRecord( grid.getView().getNode(0) );
+				//record.set(filter.field, value.toLowerCase());
 			}
 		},
 		getParams: function() {
@@ -875,23 +873,29 @@
 			if( !TR.state.paramChanged() )
 			{
 				var cols = TR.datatable.datatable.columns;
-				for( var i=0; i<cols.length; i++ )
+				for( var k in cols )
 				{
-					var col = cols[i];
+					var col = cols[k];
 					if( col.name && col.name.indexOf('meta_')!=-1 )
 					{
-						var param = TR.state.getFilterValueByColumn(col.name);
-						p.searchingValues.push(param);
+						var params = TR.state.getFilterValueByColumn(col.name);
+						for(var i in params){
+							p.searchingValues.push(params[i]);
+						}
 					}
 				}
 				var colNames = new Array();
 				TR.cmp.params.patientProperty.selected.store.each( function(r) {
-					var param = TR.state.getFilterValueByColumn(r.data.id);
-					p.searchingValues.push(param);
+					var params = TR.state.getFilterValueByColumn(r.data.id);
+					for(var i in params){
+						p.searchingValues.push(params[i]);
+					}
 				});
 				TR.cmp.params.dataelement.selected.store.each( function(r) {
-					var param = TR.state.getFilterValueByColumn(r.data.id);
-					p.searchingValues.push(param);
+					var params = TR.state.getFilterValueByColumn(r.data.id);
+					for(var i in params){
+						p.searchingValues.push(params[i]);
+					}
 				});
 			}
 			else
@@ -963,30 +967,49 @@
 			var grid = TR.datatable.datatable;
 			var cols = grid.columns;
 			var editor = grid.getStore().getAt(0);
-			var p = "";
+			var params = [];
 			for( var i=0; i<cols.length; i++ )
 			{
 				var col = cols[i];
+				var p = "";
 				if( col.name && col.name == colname )
 				{
-					var value = '';
-					if(editor.data[col.dataIndex]!=undefined){
-						value = editor.data[col.dataIndex].toLowerCase();
-					}
-					var hidden = (col.hidden==undefined)? false : col.hidden;
-					if( value!=null && value!= '')
+					var filters = grid.filters.getFilterData();
+					var value = "";
+					for( var i=0; i<filters.length; i++ )
 					{
-						value = TR.util.getValueFormula(value);
-						p = colname + '_' + hidden + "_" + value ;
+						var filter = filters[i];
+						if(col.dataIndex == filter.field)
+						{
+							var compare = '=';
+							if( filter.data.comparison == 'lt')
+								compare = '<' ;
+							else if( filter.data.comparison == 'gt' )
+								compare = '>' ;
+							value = compare + "'"+ filter.data.value + "'";
+							var hidden = (col.hidden==undefined)? false : col.hidden;
+							if( value!=null && value!= ''){	
+								var value = TR.util.getValueFormula(value);
+								p = colname + '_' + hidden + "_" + value;
+							}
+							params.push(p);
+						}
 					}
-					else 
+					
+					//if(editor.data[col.dataIndex]!=undefined){
+					//	value = editor.data[col.dataIndex].toLowerCase();
+					//}
+					
+					if (value=='')
 					{
 						p = colname + '_' + col.hidden + "_";
+						params.push(p);
 					}
-					return p;
+					return params;
 				}
 			}		
-			return colname + "_false_";
+			params.push(colname + "_false_");
+			return params
 		},
 		paramChanged: function() {
 			if( TR.store.datatable && TR.store.datatable.data.length > 0 )
@@ -1892,7 +1915,6 @@
 												TR.cmp.params.organisationunit.panel = this;
 											},
 											expand: function() {
-												alert(TR.cmp.params.organisationunit.panel.getHeight() - TR.conf.layout.west_fill_accordion_organisationunit);
 												TR.cmp.params.organisationunit.treepanel.setHeight(TR.cmp.params.organisationunit.panel.getHeight() - TR.conf.layout.west_fill_accordion_organisationunit);
 											}
 										}