=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementPeriodTypeAllowAverageFilter.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementPeriodTypeAllowAverageFilter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/DataElementPeriodTypeAllowAverageFilter.java 2013-10-13 19:55:59 +0000 @@ -0,0 +1,68 @@ +package org.hisp.dhis.system.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.system.util.Filter; + +public class DataElementPeriodTypeAllowAverageFilter + implements Filter +{ + private String periodType; + + public DataElementPeriodTypeAllowAverageFilter( String periodType ) + { + this.periodType = periodType; + } + + @Override + public boolean retain( DataElement dataElement ) + { + if ( dataElement == null || dataElement.getPeriodType() == null ) + { + return false; + } + + final PeriodType type = PeriodType.getPeriodTypeByName( periodType ); + + if ( dataElement.getPeriodType().equals( type ) ) + { + return true; + } + + if ( DataElement.AGGREGATION_OPERATOR_AVERAGE.equals( dataElement.getAggregationOperator() ) && + dataElement.getPeriodType().getFrequencyOrder() >= type.getFrequencyOrder() ) + { + return true; + } + + return false; + } +} === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2013-10-13 19:55:59 +0000 @@ -41,6 +41,7 @@ import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.paging.ActionPagingSupport; import org.hisp.dhis.system.filter.AggregatableDataElementFilter; +import org.hisp.dhis.system.filter.DataElementPeriodTypeAllowAverageFilter; import org.hisp.dhis.system.filter.DataElementPeriodTypeFilter; import org.hisp.dhis.system.util.Filter; import org.hisp.dhis.system.util.FilterUtils; @@ -128,13 +129,20 @@ this.periodType = periodType; } - private boolean includeTotals = false; + private boolean periodTypeAllowAverage; + + public void setPeriodTypeAllowAverage( boolean periodTypeAllowAverage ) + { + this.periodTypeAllowAverage = periodTypeAllowAverage; + } + + private boolean includeTotals; public void setIncludeTotals( boolean includeTotals ) { this.includeTotals = includeTotals; } - + // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- @@ -180,10 +188,14 @@ FilterUtils.filter( dataElements, AGGREGATABLE_FILTER ); } - if ( periodType != null ) + if ( periodType != null && !periodTypeAllowAverage ) { FilterUtils.filter( dataElements, new DataElementPeriodTypeFilter( periodType ) ); } + else if ( periodType != null && periodTypeAllowAverage ) + { + FilterUtils.filter( dataElements, new DataElementPeriodTypeAllowAverageFilter( periodType ) ); + } Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE ); @@ -199,4 +211,5 @@ return SUCCESS; } + } === modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expressionBuilder.js' --- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expressionBuilder.js 2013-10-02 12:34:35 +0000 +++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/expressionBuilder.js 2013-10-13 19:55:59 +0000 @@ -13,7 +13,7 @@ title: "Expression" }); - jQuery( "#periodTypeName" ).change(function(){ + jQuery( "#periodTypeName, #ruleType" ).change(function(){ getOperandsPage(); }); @@ -69,8 +69,11 @@ var key = getFieldValue( "expression-container input[id=filter]" ); var periodType = getFieldValue( "periodTypeName" ); + var ruleType = getFieldValue( "ruleType" ); + var periodTypeAllowAverage = ( ruleType && ruleType == "monitoring" ) ? true : false; - dataDictionary.loadOperands( "#expression-container select[id=dataElementId]", {usePaging: true, key: key, periodType: periodType} ); + dataDictionary.loadOperands( "#expression-container select[id=dataElementId]", + {usePaging: true, key: key, periodType: periodType, periodTypeAllowAverage: periodTypeAllowAverage } ); } function clearSearchText()