=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2011-03-24 16:58:40 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2011-07-13 02:28:39 +0000 @@ -60,7 +60,7 @@ public static String OBJECT_PROGRAM_PROPERTY = "PP"; - + public static String OBJECT_PROGRAM = "PG"; // ------------------------------------------------------------------------- // Fields === 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 2011-07-07 08:03:22 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-07-13 02:28:39 +0000 @@ -30,6 +30,7 @@ import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.AGGRERATION_SUM; import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE; import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROPERTY; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM; import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_PROPERTY; import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT; import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OPERATOR_AND; @@ -69,7 +70,7 @@ public class DefaultCaseAggregationConditionService implements CaseAggregationConditionService { - private final String regExp = "\\[(" + OBJECT_PROGRAM_STAGE_DATAELEMENT + "|" + OBJECT_PATIENT_ATTRIBUTE + "|" + private final String regExp = "\\[(" + OBJECT_PROGRAM + "|" + OBJECT_PROGRAM_STAGE_DATAELEMENT + "|" + OBJECT_PATIENT_ATTRIBUTE + "|" + OBJECT_PATIENT_PROPERTY + "|" + OBJECT_PROGRAM_PROPERTY + ")" + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+[" + SEPARATOR_ID + "[0-9]*]*)" + "\\]"; @@ -438,7 +439,11 @@ { condition = getConditionForProgramProperty( orgunitId, startDate, endDate ) + info[1]; } - + else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) ) + { + condition = getConditionForProgram( info[1], orgunitId, startDate, endDate ); + } + // ------------------------------------------------------------- // Replacing the operand with 1 in order to later be able to // verify @@ -543,6 +548,16 @@ + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' AND "; } + private String getConditionForProgram ( String programId, int orgunitId, String startDate, String endDate ) + { + return "SELECT distinct(p.patientid) FROM programstageinstance as psi " + + "INNER JOIN programinstance as pi ON psi.programinstanceid = pi.programinstanceid " + + "INNER JOIN patient as p ON p.patientid = pi.patientid " + + "WHERE pi.programid=" + programId + " " + + "AND p.organisationunitid = " + orgunitId + " " + + "AND pi.enrollmentdate >= '" + startDate + "' AND pi.enrollmentdate <= '" + endDate + "' "; + } + private String getSQL( List conditions, List operators ) { String sql = conditions.get( 0 ); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2011-05-01 09:07:35 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2011-07-13 02:28:39 +0000 @@ -230,54 +230,57 @@ CaseAggregationCondition condition = aggregationConditionService.getCaseAggregationCondition( dElement, optionCombo ); - if ( condition == null ) - break; - - for ( Period period : periodList ) + if ( condition != null ) { - String message = i18n.getString( "in" ) + " " + format.formatPeriod( period ); - - double resultValue = aggregationConditionService.parseConditition( condition, orgUnit, period ); - - DataValue dataValue = dataValueService.getDataValue( orgUnit, dElement, period, optionCombo ); - - if ( resultValue != 0 ) - { - if ( dataValue == null ) - { - dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, storedBy, - new Date(), null, optionCombo ); - - dataValueService.addDataValue( dataValue ); - mapDataValues.put( dataValue, i18n.getString( "added" ) + " " + message ); - } - else - { - dataValue.setValue( "" + resultValue ); - dataValue.setTimestamp( new Date() ); - dataValue.setStoredBy( storedBy ); - - dataValueService.updateDataValue( dataValue ); - - mapDataValues.put( dataValue, i18n.getString( "updated" ) + " " + message ); - } - - mapCaseAggCondition.put( dataValue, condition ); - - } - else if ( dataValue != null ) - { - DataValue dvalue = new DataValue( dElement, period, orgUnit, "", storedBy, new Date(), - null, optionCombo ); - dvalue.setValue( dataValue.getValue() + " " + i18n.getString( "old_value" ) ); - - dataValueService.deleteDataValue( dataValue ); - - mapDataValues.put( dvalue, i18n.getString( "deleted" ) + " " + message ); + + for ( Period period : periodList ) + { + String message = i18n.getString( "in" ) + " " + format.formatPeriod( period ); + + double resultValue = aggregationConditionService.parseConditition( condition, orgUnit, + period ); + + DataValue dataValue = dataValueService + .getDataValue( orgUnit, dElement, period, optionCombo ); + + if ( resultValue != 0 ) + { + if ( dataValue == null ) + { + dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, storedBy, + new Date(), null, optionCombo ); + + dataValueService.addDataValue( dataValue ); + mapDataValues.put( dataValue, i18n.getString( "added" ) + " " + message ); + } + else + { + dataValue.setValue( "" + resultValue ); + dataValue.setTimestamp( new Date() ); + dataValue.setStoredBy( storedBy ); + + dataValueService.updateDataValue( dataValue ); + + mapDataValues.put( dataValue, i18n.getString( "updated" ) + " " + message ); + } + + mapCaseAggCondition.put( dataValue, condition ); + + } + else if ( dataValue != null ) + { + DataValue dvalue = new DataValue( dElement, period, orgUnit, "", storedBy, new Date(), + null, optionCombo ); + dvalue.setValue( dataValue.getValue() + " " + i18n.getString( "old_value" ) ); + + dataValueService.deleteDataValue( dataValue ); + + mapDataValues.put( dvalue, i18n.getString( "deleted" ) + " " + message ); + } + } } - } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addCaseAggregation.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addCaseAggregation.vm 2011-05-19 08:12:45 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addCaseAggregation.vm 2011-07-13 02:28:39 +0000 @@ -147,6 +147,9 @@ + #foreach( $program in $programs ) + + #end