=== 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 ids = this.executeSQL( sql ); if ( hasOrgunitProgramStageCompleted( caseExpression ) ) { - Collection 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 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 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 @@
  • $i18n.getString("dataelements")
  • $i18n.getString("patient_attributes")
  • $i18n.getString("program")
  • -
  • $i18n.getString("orgunit")
  • @@ -74,6 +73,7 @@ - - #foreach( $program in $programs ) - - #end - - - - - - - - - -