← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10709: Modify Aggregate Query Builder.

 

------------------------------------------------------------
revno: 10709
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-29 19:08:00 +0700
message:
  Modify Aggregate Query Builder.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.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/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2013-04-28 08:54:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2013-04-29 12:08:00 +0000
@@ -35,6 +35,8 @@
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_ID;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
+import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_ORGUNIT_COMPLETE_PROGRAM_STAGE;
+
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.ArrayList;
@@ -426,7 +428,8 @@
                     }
                     matcher.appendReplacement( description, "[" + programDes + "]" );
                 }
-                else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE ) )
+                else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE ) 
+                        || info[0].equalsIgnoreCase( OBJECT_ORGUNIT_COMPLETE_PROGRAM_STAGE ) )
                 {
                     int objectId = Integer.parseInt( ids[0] );
                     ProgramStage programStage = programStageService.getProgramStage( objectId );
@@ -437,7 +440,7 @@
                     }
 
                     String count = (ids.length == 2) ? SEPARATOR_ID + ids[1] : "";
-                    matcher.appendReplacement( description, "[" + OBJECT_PROGRAM_STAGE + SEPARATOR_OBJECT
+                    matcher.appendReplacement( description, "[" + info[0] + SEPARATOR_OBJECT
                         + programStage.getDisplayName() + count + "]" );
                 }
             }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-04-29 09:41:34 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-04-29 12:08:00 +0000
@@ -177,16 +177,15 @@
             || operator.equals( CaseAggregationCondition.AGGRERATION_SUM ) )
         {
             String sql = parseExpressionToSql( caseExpression, operator, deSumId, orgunitId, startDate, endDate );
+            Collection<Integer> ids = this.executeSQL( sql );
 
             if ( hasOrgunitProgramStageCompleted( caseExpression ) )
             {
-                Collection<Integer> ids = this.executeSQL( sql );
-                return (ids == null) ? null : ids.iterator().next() + 0.0;
+                return (ids == null || ids.size() == 0) ? null : ids.iterator().next() + 0.0;
             }
             else
             {
-                Collection<Integer> ids = this.executeSQL( sql );
-                return (ids == null) ? null : ids.size() + 0.0;
+                return (ids == null || ids.size() == 0) ? null : ids.size() + 0.0;
             }
         }
 
@@ -203,7 +202,7 @@
             sql = sql + " AND pdv.programstageinstanceid in ( "
                 + parseExpressionToSql( caseExpression, operator, deSumId, orgunitId, startDate, endDate ) + " ) ";
         }
-
+System.out.println("\n " + sql + " \n ");
         Collection<Integer> ids = this.executeSQL( sql );
         return (ids == null) ? null : ids.iterator().next() + 0.0;
     }
@@ -457,7 +456,7 @@
      */
     private String createSQL( String caseExpression, String operator, int orgunitId, String startDate, String endDate )
     {
-        Boolean orgunitCompletedProgramStage = false;
+        boolean orgunitCompletedProgramStage = false;
 
         String sqlOrgunitCompleted = "";
 
@@ -945,13 +944,11 @@
         {
             sql = "SELECT '1' FROM organisationunit ou WHERE ou.organisationunitid=" + orgunitId + "  ";
         }
-        else
-        {
-            sql = " AND NOT EXISTS ( SELECT programstageinstanceid FROM programstageinstance psi "
-                + " WHERE psi.organisationunitid=ou.organisationunitid " + " AND psi.programstageid = "
-                + programStageId + " and psi.completed=false " + " AND psi.executiondate >= '" + startDate
-                + "' and psi.executiondate <= '" + endDate + "' ) ";
-        }
+        
+        sql += " AND EXISTS ( SELECT programstageinstanceid FROM programstageinstance psi "
+            + " WHERE psi.organisationunitid=ou.organisationunitid AND psi.programstageid = " + programStageId
+            + " AND psi.completed=true AND psi.executiondate >= '" + startDate + "' AND psi.executiondate <= '"
+            + endDate + "' ) ";
 
         return sql;
     }
@@ -992,7 +989,7 @@
         }
 
         sql += sqlAnd;
-
+        
         return sql;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-04-28 08:54:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-04-29 12:08:00 +0000
@@ -390,4 +390,5 @@
 update_program_indicator = Edit program indicator
 disable_registration_fields = Disable registration fields
 data_entry = Data entry
-combine = Combine
\ No newline at end of file
+combine = Combine
+completed = Completed
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2013-04-28 08:54:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2013-04-29 12:08:00 +0000
@@ -3,7 +3,6 @@
 		<li><a href="#tab-1">$i18n.getString("dataelements")</a></li>
 		<li><a href="#tab-2">$i18n.getString("patient_attributes")</a></li>
 		<li><a href="#tab-3">$i18n.getString("program")</a></li>
-		<li><a href="#tab-4">$i18n.getString("orgunit")</a></li>
 	</ul>	
 	
 	<div id="tab-1">
@@ -74,6 +73,7 @@
 				<td>
 					<select multiple id="programStageProperty" size="10" name="programStageProperty" ondblclick="insertInfo(this, true);" disabled >
 						<option value="[PS:*]">$i18n.getString( "visit_selected_program_stage" )</option>
+						<option value="[PSIC:*]">$i18n.getString( "completed" )</option>
 						<option value="[PS:*.COUNT]" name="multiProgram">$i18n.getString( "visit_selected_program_stage_x_th_time" )</option>
 						<option value="[PS:*] AND [PSP:DATE@executionDate#-DATE@dueDate#]" name="multiProgram">$i18n.getString( "report_date" ) - $i18n.getString( "due_date" )</option>
 						<option value="[PS:*] AND [PC:DATE@executionDate#-DATE@birthDate#]" name="multiProgram">$i18n.getString( "age_at_visit_days_since_birth" )</option>
@@ -83,30 +83,6 @@
 			</tr>
 		</table>
 	</div>
-	
-	<div id="tab-4">
-		<table>
-			<tr>
-				<td><label>$i18n.getString('program')</label></td>
-			</tr>
-			<tr>
-				<td>
-					<select id="orgunitProgramId" name="orgunitProgramId" onchange='getProgramStages();' >
-						<option value=''>[$i18n.getString("please_select")]</option>
-						#foreach( $program in $programs )
-							<option value='$program.id'>$encoder.htmlEncode($program.name)</option>
-						#end
-					</select>
-				</td>
-			</tr>
-			<tr>
-				<td>
-					<select multiple id="orgunitProgramStageId" name="orgunitProgramStageId"  size="10" name="programStageProperty" ondblclick="insertInfo(this, true);" >
-					</select>
-				</td>
-			</tr>
-		</table>
-	</div>
 </div>
 
 <p></p>