← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1924: Generating multi-condition for Beneficiary Aggregation QueryBuilder function - work in process.

 

------------------------------------------------------------
revno: 1924
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-08-17 14:47:51 +0700
message:
  Generating multi-condition for Beneficiary Aggregation QueryBuilder function - work in process.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationMappingService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggMapping.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.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/caseaggregation/DefaultCaseAggregationMappingService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationMappingService.java	2010-07-06 09:34:47 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationMappingService.java	2010-08-17 07:47:51 +0000
@@ -88,7 +88,7 @@
     {
         this.caseAggregationMappingStore = caseAggregationMappingStore;
     }
-
+    
     // -------------------------------------------------------------------------
     // CaseAggregationMapping
     // -------------------------------------------------------------------------
@@ -350,7 +350,7 @@
         
         String queryFrom = "Select " +  function + " from ";
         
-        String queryWhere = " where ";
+        String queryWhere = "  ";
 
         Map<String, String> map =   new HashMap<String, String>();
         map.put( MAP_CONSTANT_QUERYWHERE , queryWhere );
@@ -364,11 +364,12 @@
             map = buildQueryForExpression( c, map, i );
             if( c.getNext() != null )
             {
-                map.put( MAP_CONSTANT_QUERYWHERE , map.get( MAP_CONSTANT_QUERYWHERE ) + " " + c.getNext() + " " ) ;
+                String condition = map.get( MAP_CONSTANT_QUERYWHERE )  + c.getNext();
+                map.put( MAP_CONSTANT_QUERYWHERE , condition ) ;
             }
         }
         queryFrom =  map.get( MAP_CONSTANT_QUERYFROM );
-        queryWhere = map.get( MAP_CONSTANT_QUERYWHERE );
+        queryWhere = " where "+ map.get( MAP_CONSTANT_QUERYWHERE );
         
         
         if( queryFrom.charAt(  queryFrom.length() - 1 ) == ',' )
@@ -381,7 +382,11 @@
         queryWhere = queryWhere.replace( "$STARTDATE$", "" + period.getStartDate() );
         queryWhere = queryWhere.replace( "$ORGUNITID$", "" + organisationUnit.getId() );
         
-        System.out.println("queryyyyyyyyyyyy:\n "+queryFrom + queryWhere );
+//        queryWhere = queryWhere.replace( "$ENDDATE$",   "" + "2010-08-01"  );
+//        queryWhere = queryWhere.replace( "$STARTDATE$", "" + "2010-08-31" );
+//        queryWhere = queryWhere.replace( "$ORGUNITID$", "" + "37" );
+        
+        System.out.println("queryyyyyyyyyyyy 123:\n "+queryFrom + queryWhere );
         System.out.println("=================================================");
         return queryFrom + queryWhere;
     }
@@ -404,7 +409,7 @@
         String casePropertyName = null;
         
         String tmpFromQuery = "";
-        String tmpWhereQuery = " where ";
+        String tmpWhereQuery = "";
                 
         String curAliasDataValue = null;
         String curAliasProgramStageInstance = null;
@@ -427,6 +432,9 @@
             singleExpression = true;
             tmpFromQuery = map.get( MAP_CONSTANT_QUERYFROM );
             tmpWhereQuery = map.get( MAP_CONSTANT_QUERYWHERE );
+//            if( CaseAggregationCondition.CONDITION.equals( condition.getType())){
+                tmpWhereQuery += " ( ";
+//            }
         }
         String arg = null;
         for ( int i=0; i < listArg.size(); i++ )
@@ -719,6 +727,9 @@
             if( curAliasProgramInstance != null         ) tmpWhereQuery = tmpWhereQuery.replace( "$ALIAS_PROGRAMINSTANCE$", curAliasProgramInstance );
             if( curAliasPatientAttributeValue != null   ) tmpWhereQuery = tmpWhereQuery.replace( "$ALIAS_PATIENTATTRIBUTEVALUE$", curAliasPatientAttributeValue );
             
+//            if( CaseAggregationCondition.CONDITION.equals( condition.getType())){
+                tmpWhereQuery += " ) ";
+//            }
         }
         
         map.put( MAP_CONSTANT_QUERYWHERE , tmpWhereQuery );
@@ -735,9 +746,12 @@
     
     public static void main( String[] args )
     {
-        String string = "SUM@ COND{ ([DE:8.57.1]) < ([VL:2500]) } AND COND{ ([CP:gender]) = ([VL:'M']) }   ";
+        //String string = "SUM@ COND{ ([DE:8.57.1]) < ([VL:2500]) } AND COND{ ([CP:gender]) = ([VL:'M']) }   ";
         
-        //String input = "COUNT@ COND{([DE:1.3923.1]) > ([VL:100])}";
+        //String string = "COUNT@ COND{ ( [DE:1.13.1] ) < ( [VL:2500] ) } AND COND{ ( [DE:1.16.1] ) = ( [VL:2500] ) } ";
+        // String string = "COUNT@ COND{ ( [CP:GENDER] ) < ( [VL:23] ) } ";
+        //String string = "COUNT@ COND{ ( [CP:GENDER] ) = ( [VL:'F'] ) } AND COND{ ( [DE:1.13.1] ) < ( [VL:2500] ) }";
+        String string = "COUNT@ SCOND{ ( [DE:8.75.1] ) } AND COND{ ( [CP:gender] ) = ( [VL:'F'] ) }";
         DefaultCaseAggregationMappingService test = new DefaultCaseAggregationMappingService();
         CaseAggregationQuery query = test.scan( string );
         System.out.println( test.buildQuery(  null, null, query ) );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggMapping.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggMapping.vm	2010-08-05 12:25:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggMapping.vm	2010-08-17 07:47:51 +0000
@@ -78,8 +78,8 @@
                                 <td>
                                     $i18n.getString( "case_properties" )<br>
                                     <select id="caseProperty" name="caseProperty" size="5" style="width:100px" ondblclick="displayCPInfo()">
-                                        <option value="[CP:GENDER]">$i18n.getString( "gender" )</option>
-                                        <option value="[CP:DOB]">$i18n.getString( "dob" )</option>
+                                        <option value="[CP:gender]">$i18n.getString( "gender" )</option>
+                                        <option value="[CP:dob]">$i18n.getString( "dob" )</option>
                                     </select>
                                 </td>
                                 <td>&nbsp;</td>
@@ -121,12 +121,12 @@
                     <td>
                         <select id="operator0" name="operator0">
                             <!--0--><option value="NA">$i18n.getString( "select" )</option>
-                            <!--1--><option value="less_than">&lt;</option>
-                            <!--2--><option value="greater_than">&gt;</option>
-                            <!--3--><option value="less_than_equal">&le;</option>
-                            <!--4--><option value="greater_than_equal">&ge;</option>
-                            <!--5--><option value="equal">=</option>
-                            <!--6--><option value="not_equal">!=</option>
+                            <!--1--><option value="<">&lt;</option>
+                            <!--2--><option value=">">&gt;</option>
+                            <!--3--><option value="<=">&le;</option>
+                            <!--4--><option value=">=">&ge;</option>
+                            <!--5--><option value="=">=</option>
+                            <!--6--><option value="!=">!=</option>
                             <!--7--><option value="in">IN</option>
                             <!--8--><option value="diff">DIFF</option>
                         </select>
@@ -135,8 +135,8 @@
                     <td>
                         <select id="andor0" name="andor0" onchange="addNewRow()">
                             <option value="NA">$i18n.getString( "select" )</option>
-                            <option value="and">$i18n.getString( "AND" )</option>
-                            <option value="or">$i18n.getString( "OR" )</option>
+                            <option value="AND">$i18n.getString( "AND" )</option>
+                            <option value="OR">$i18n.getString( "OR" )</option>
                         </select>                       
                     </td>
                     <td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js	2010-08-05 12:25:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js	2010-08-17 07:47:51 +0000
@@ -297,13 +297,13 @@
 	    oCell.innerHTML = "<input type='text' id='le"+ tableRowCount +"' name='le"+ tableRowCount +"' data='{pos:\"left\"}' onfocus='updateFocus(this)'>";
 	
 	    oCell = newRow.insertCell(1);
-	    oCell.innerHTML = "<select id='operator"+ tableRowCount +"' name='operator"+ tableRowCount +"'><option value='NA'>Select</option><option value='less_than'>&lt;</option><option value='greater_than'>&gt;</option><option value='less_than_equal'>&le;</option><option value='greater_than_equal'>&ge;</option><option value='equal'>=</option><option value='not_equal'>!=</option><option value='in'>IN</option><option value='diff'>DIFF</option></select>";
+	    oCell.innerHTML = "<select id='operator"+ tableRowCount +"' name='operator"+ tableRowCount +"'><option value='NA'>Select</option><option value='\<'>&lt;</option><option value='\>'>&gt;</option><option value='\<='>&le;</option><option value='\>='>&ge;</option><option value='\='>=</option><option value='!='>!=</option><option value='in'>IN</option><option value='diff'>DIFF</option></select>";
 	        
 	    oCell = newRow.insertCell(2);
 	    oCell.innerHTML = "<input type='text' id='re"+ tableRowCount +"' name='re"+ tableRowCount +"' data='{pos:\"right\"}' onfocus='updateFocus(this)'>";
 	    
 	    oCell = newRow.insertCell(3);    	
-		oCell.innerHTML = "<select id='andor"+ tableRowCount +"' name='andor"+ tableRowCount +"' onchange='addNewRow()'><option value='NA'>Select</option><option value='and'>AND</option><option value='or'>OR</option></select>";
+		oCell.innerHTML = "<select id='andor"+ tableRowCount +"' name='andor"+ tableRowCount +"' onchange='addNewRow()'><option value='NA'>Select</option><option value='AND'>AND</option><option value='OR'>OR</option></select>";
 	
 	    oCell = newRow.insertCell(4);
 		oCell.innerHTML = "<a href='#Delete table row' onclick='removeRecord(this,"+tableRowCount+")' title='remove' )><img src='../images/delete.png' alt='remove'></a>";