dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06348
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2001: Applied the frequency/aggregation period trick to calculated dataelement datamart. Minor fixes.
------------------------------------------------------------
revno: 2001
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Thu 2010-06-17 23:08:46 +0200
message:
Applied the frequency/aggregation period trick to calculated dataelement datamart. Minor fixes.
added:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceAggregationLevelsTest.java
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTimeDimensionTest.java
--
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-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-06-17 21:08:46 +0000
@@ -39,7 +39,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.common.GenericStore;
-import org.hisp.dhis.period.DailyPeriodType;
+import org.hisp.dhis.period.TwoYearlyPeriodType;
import org.hisp.dhis.system.util.Filter;
import org.hisp.dhis.system.util.FilterUtils;
import org.hisp.dhis.system.util.UUIdUtils;
@@ -396,7 +396,7 @@
Set<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo()
.getOptionCombos();
- int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : new DailyPeriodType().getFrequencyOrder(); //TODO improve
+ int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : new TwoYearlyPeriodType().getFrequencyOrder(); // Assume lowest frequency if no PeriodType
if ( categoryOptionCombos.size() > 1 && !(dataElement instanceof CalculatedDataElement) )
{
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2010-06-17 21:08:46 +0000
@@ -88,7 +88,7 @@
getCrossTabDataValues( operandIndexMap, period.getStartDate(), period.getEndDate(), unit.getId(), hierarchy );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
- period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <data element id, [total value, total relevant days]>
+ period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( entries.size() ); // <Operand, total value>
@@ -204,8 +204,7 @@
for ( final DataElementOperand operand : operands )
{
- if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) &&
- operand.getFrequencyOrder() < periodType.getFrequencyOrder() ) )
+ if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) )
{
avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
}
=== added file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2010-06-17 21:08:46 +0000
@@ -0,0 +1,213 @@
+package org.hisp.dhis.datamart.aggregation.dataelement;
+
+/*
+ * Copyright (c) 2004-2010, 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 static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.DataElementOperand;
+import org.hisp.dhis.datamart.CrossTabDataValue;
+import org.hisp.dhis.datamart.DataMartStore;
+import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id: AverageIntAggregator.java 6049 2008-10-28 09:36:17Z larshelg $
+ */
+public class AverageIntSingleValueAggregator
+ implements DataElementAggregator
+{
+ private static final Log log = LogFactory.getLog( AverageIntSingleValueAggregator.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ protected DataMartStore dataMartStore;
+
+ public void setDataMartStore( DataMartStore dataMartStore )
+ {
+ this.dataMartStore = dataMartStore;
+ }
+
+ protected AggregationCache aggregationCache;
+
+ public void setAggregationCache( AggregationCache aggregationCache )
+ {
+ this.aggregationCache = aggregationCache;
+ }
+
+ // -------------------------------------------------------------------------
+ // DataElementAggregator implementation
+ // -------------------------------------------------------------------------
+
+ public Map<DataElementOperand, Double> getAggregatedValues( final Map<DataElementOperand, Integer> operandIndexMap,
+ final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy )
+ {
+ if ( operandIndexMap == null || operandIndexMap.size() == 0 )
+ {
+ return new HashMap<DataElementOperand, Double>();
+ }
+
+ double average = 0.0;
+ double existingAverage = 0.0;
+
+ final Collection<CrossTabDataValue> crossTabValues =
+ getCrossTabDataValues( operandIndexMap, period.getStartDate(), period.getEndDate(), unit.getId(), hierarchy );
+
+ final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
+ period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
+
+ final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>(); // <Operand, total value>
+
+ for ( final Entry<DataElementOperand, double[]> entry : entries.entrySet() )
+ {
+ if ( entry.getValue() != null && entry.getValue()[ 1 ] > 0 )
+ {
+ values.put( entry.getKey(), entry.getValue()[ 0 ] );
+ /*
+ average = entry.getValue()[ 0 ] / entry.getValue()[ 1 ];
+
+ existingAverage = values.containsKey( entry.getKey() ) ? values.get( entry.getKey() ) : 0;
+
+ values.put( entry.getKey(), average + existingAverage ); //TODO simplify
+ */
+ }
+ }
+
+ return values;
+ }
+
+ public Collection<CrossTabDataValue> getCrossTabDataValues( final Map<DataElementOperand, Integer> operandIndexMap,
+ final Date startDate, final Date endDate, final int parentId, final OrganisationUnitHierarchy hierarchy )
+ {
+ final Collection<Period> periods = aggregationCache.getIntersectingPeriods( startDate, endDate );
+
+ final Collection<Integer> periodIds = new ArrayList<Integer>( periods.size() );
+
+ for ( final Period period : periods )
+ {
+ periodIds.add( period.getId() );
+ }
+
+ return dataMartStore.getCrossTabDataValues( operandIndexMap, periodIds, hierarchy.getChildren( parentId ) );
+ }
+
+ public Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
+ final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel )
+ {
+ final Map<DataElementOperand, double[]> totalSums = new HashMap<DataElementOperand, double[]>(); // <Operand, [total value, total relevant days]>
+
+ Period period = null;
+ Date currentStartDate = null;
+ Date currentEndDate = null;
+
+ double value = 0.0;
+ double relevantDays = 0.0;
+ double existingValue = 0.0;
+ double existingRelevantDays = 0.0;
+
+ int dataValueLevel = 0;
+
+ for ( final CrossTabDataValue crossTabValue : crossTabValues )
+ {
+ period = aggregationCache.getPeriod( crossTabValue.getPeriodId() );
+
+ currentStartDate = period.getStartDate();
+ currentEndDate = period.getEndDate();
+
+ dataValueLevel = aggregationCache.getLevelOfOrganisationUnit( crossTabValue.getSourceId() );
+
+ for ( final Entry<DataElementOperand, String> entry : crossTabValue.getValueMap().entrySet() ) // <Operand, value>
+ {
+ if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) )
+ {
+ value = 0.0;
+
+ try
+ {
+ value = Double.parseDouble( entry.getValue() );
+ }
+ catch ( NumberFormatException ex )
+ {
+ log.warn( "Value skipped, not numeric: '" + entry.getValue() +
+ "', for data element with id: '" + entry.getKey() +
+ "', for period with id: '" + crossTabValue.getPeriodId() +
+ "', for source with id: '" + crossTabValue.getSourceId() + "'" );
+ }
+
+ relevantDays = 0.0;
+
+ if ( currentStartDate.compareTo( endDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 ) // Value is intersecting
+ {
+ relevantDays = getDaysInclusive( startDate, endDate );
+ }
+
+ existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0;
+ existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0;
+
+ final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) };
+
+ totalSums.put( entry.getKey(), values );
+ }
+ }
+ }
+
+ return totalSums;
+ }
+
+ public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
+ {
+ Map<DataElementOperand, Integer> avgOperandIndexMap = new HashMap<DataElementOperand, Integer>();
+
+ for ( final DataElementOperand operand : operands )
+ {
+ if ( operand.getValueType().equals( VALUE_TYPE_INT ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) &&
+ operand.getFrequencyOrder() >= periodType.getFrequencyOrder() )
+ {
+ avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
+ }
+ }
+
+ return avgOperandIndexMap;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-17 21:08:46 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
@@ -210,8 +209,7 @@
for ( final DataElementOperand operand : operands )
{
- if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ||
- ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && operand.getFrequencyOrder() >= periodType.getFrequencyOrder() ) ) )
+ if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) )
{
sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-17 21:08:46 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
@@ -218,8 +217,7 @@
for ( final DataElementOperand operand : operands )
{
- if ( operand.getValueType().equals( VALUE_TYPE_INT ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ||
- ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && operand.getFrequencyOrder() >= periodType.getFrequencyOrder() ) ) )
+ if ( operand.getValueType().equals( VALUE_TYPE_INT ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) )
{
sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2010-06-17 21:08:46 +0000
@@ -31,7 +31,6 @@
import static org.hisp.dhis.system.util.MathUtils.calculateExpression;
import static org.hisp.dhis.system.util.MathUtils.getRounded;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -98,6 +97,13 @@
this.averageIntAggregator = averageIntDataElementAggregator;
}
+ private DataElementAggregator averageIntSingleValueAggregator;
+
+ public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator )
+ {
+ this.averageIntSingleValueAggregator = averageIntSingleValueAggregator;
+ }
+
private CrossTabService crossTabService;
public void setCrossTabService( CrossTabService crossTabService )
@@ -136,11 +142,7 @@
public int exportCalculatedDataElements( final Collection<Integer> calculatedDataElementIds, final Collection<Integer> periodIds,
final Collection<Integer> organisationUnitIds, final Collection<DataElementOperand> operands )
{
- final Collection<DataElementOperand> sumOperands = filterOperands( operands, DataElement.AGGREGATION_OPERATOR_SUM );
- final Collection<DataElementOperand> averageOperands = filterOperands( operands, DataElement.AGGREGATION_OPERATOR_AVERAGE );
-
- final Map<DataElementOperand, Integer> sumOperandIndexMap = crossTabService.getOperandIndexMap( sumOperands );
- final Map<DataElementOperand, Integer> averageOperandIndexMap = crossTabService.getOperandIndexMap( averageOperands );
+ final Map<DataElementOperand, Integer> operandIndexMap = crossTabService.getOperandIndexMap( operands );
final Collection<DataElement> calculatedDataElements = dataElementService.getDataElements( calculatedDataElementIds );
final Collection<Period> periods = periodService.getPeriods( periodIds );
@@ -152,52 +154,42 @@
batchHandler.init();
- OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
+ final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
int count = 0;
- int level = 0;
- Map<DataElementOperand, Double> sumIntValueMap = null;
- Map<DataElementOperand, Double> averageIntValueMap = null;
-
- Map<String, Map<DataElementOperand, Double>> valueMapMap = null;
-
- Map<DataElementOperand, Double> valueMap = null;
-
CalculatedDataElement calculatedDataElement = null;
- PeriodType periodType = null;
-
double aggregatedValue = 0.0;
final AggregatedDataValue dataValue = new AggregatedDataValue();
- for ( final OrganisationUnit unit : organisationUnits )
+ for ( final Period period : periods )
{
- level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
-
- for ( final Period period : periods )
+ final PeriodType periodType = period.getPeriodType();
+
+ final Map<DataElementOperand, Integer> sumOperandIndexMap = sumIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
+ final Map<DataElementOperand, Integer> averageOperandIndexMap = averageIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
+ final Map<DataElementOperand, Integer> averageSingleValueOperandIndexMap = averageIntSingleValueAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
+
+ for ( final OrganisationUnit unit : organisationUnits )
{
- sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy );
- averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy );
-
- valueMapMap = new HashMap<String, Map<DataElementOperand, Double>>( 2 );
-
- valueMapMap.put( DataElement.AGGREGATION_OPERATOR_SUM, sumIntValueMap );
- valueMapMap.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, averageIntValueMap );
-
- periodType = period.getPeriodType();
+ final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
+
+ final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy );
+ final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy );
+ final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperandIndexMap, period, unit, level, hierarchy );
+
+ final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>( sumIntValueMap );
+ valueMap.putAll( averageIntValueMap );
+ valueMap.putAll( averageIntSingleValueMap );
for ( final DataElement element : calculatedDataElements )
{
calculatedDataElement = (CalculatedDataElement) element;
- valueMap = valueMapMap.get( calculatedDataElement.getAggregationOperator() );
-
aggregatedValue = calculateExpression( generateExpression( calculatedDataElement.getExpression().getExpression(), valueMap ) );
- //TODO improve logic for performance
-
dataValue.clear();
dataValue.setDataElementId( calculatedDataElement.getId() );
@@ -219,25 +211,4 @@
return count;
}
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private Collection<DataElementOperand> filterOperands( final Collection<DataElementOperand> operands, final String aggregationOperator )
- {
- final Collection<DataElementOperand> filteredOperands = new ArrayList<DataElementOperand>();
-
- for ( final DataElementOperand operand : operands )
- {
- final DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
-
- if ( aggregationOperator.equals( dataElement.getAggregationOperator() ) )
- {
- filteredOperands.add( operand );
- }
- }
-
- return filteredOperands;
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2010-06-17 21:08:46 +0000
@@ -115,14 +115,9 @@
batchHandler.init();
- OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
+ final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
int count = 0;
- int level = 0;
-
- Map<DataElementOperand, Double> valueMap = null;
-
- PeriodType periodType = null;
final AggregatedDataValue value = new AggregatedDataValue();
@@ -132,11 +127,11 @@
for ( final OrganisationUnit unit : organisationUnits )
{
- level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
-
- valueMap = dataElementAggregator.getAggregatedValues( currentOperandIndexMap, period, unit, level, hierarchy );
-
- periodType = period.getPeriodType();
+ final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
+
+ final Map<DataElementOperand, Double> valueMap = dataElementAggregator.getAggregatedValues( currentOperandIndexMap, period, unit, level, hierarchy );
+
+ final PeriodType periodType = period.getPeriodType();
for ( Entry<DataElementOperand, Double> entry : valueMap.entrySet() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2010-06-17 21:08:46 +0000
@@ -129,6 +129,13 @@
this.averageIntAggregator = averageIntDataElementAggregator;
}
+ private DataElementAggregator averageIntSingleValueAggregator;
+
+ public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator )
+ {
+ this.averageIntSingleValueAggregator = averageIntSingleValueAggregator;
+ }
+
private DataElementAggregator sumBoolAggregator;
public void setSumBoolAggregator( DataElementAggregator sumBooleanDataElementAggregator )
@@ -283,6 +290,13 @@
log.info( "Exported values for data elements with average aggregation operator of type number: " + TimeUtils.getHMS() );
}
+ if ( intNonCalculatedDataElementOperands.size() > 0 )
+ {
+ count += dataElementDataMart.exportDataValues( intNonCalculatedDataElementOperands, periodIds, organisationUnitIds, averageIntSingleValueAggregator );
+
+ log.info( "Exported values for data elements with average aggregation operator with single value of type number: " + TimeUtils.getHMS() );
+ }
+
if ( boolNonCalculatedDataElementOperands.size() > 0 )
{
count += dataElementDataMart.exportDataValues( boolNonCalculatedDataElementOperands, periodIds, organisationUnitIds, sumBoolAggregator );
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2010-06-17 21:08:46 +0000
@@ -107,6 +107,13 @@
{
this.averageIntAggregator = averageIntDataElementAggregator;
}
+
+ private DataElementAggregator averageIntSingleValueAggregator;
+
+ public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator )
+ {
+ this.averageIntSingleValueAggregator = averageIntSingleValueAggregator;
+ }
private CrossTabService crossTabService;
@@ -149,7 +156,7 @@
batchHandler.init();
- OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
+ final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds );
int count = 0;
@@ -168,6 +175,7 @@
final Map<DataElementOperand, Integer> sumOperandIndexMap = sumIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
final Map<DataElementOperand, Integer> averageOperandIndexMap = averageIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
+ final Map<DataElementOperand, Integer> averageSingleValueOperandIndexMap = averageIntSingleValueAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
for ( final OrganisationUnit unit : organisationUnits )
{
@@ -175,9 +183,11 @@
final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy );
final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy);
+ final Map<DataElementOperand, Double> averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperandIndexMap, period, unit, level, hierarchy );
final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>( sumIntValueMap );
valueMap.putAll( averageIntValueMap );
+ valueMap.putAll( averageIntSingleValueMap );
for ( final Indicator indicator : indicators )
{
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2010-06-14 16:27:39 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2010-06-17 21:08:46 +0000
@@ -51,6 +51,8 @@
ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/>
<property name="averageIntAggregator"
ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntAggregator"/>
+ <property name="averageIntSingleValueAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"/>
<property name="sumBoolAggregator"
ref="org.hisp.dhis.datamart.aggregation.dataelement.SumBoolAggregator"/>
<property name="averageBoolAggregator"
@@ -126,6 +128,14 @@
ref="org.hisp.dhis.datamart.aggregation.cache.AggregationCache"/>
</bean>
+ <bean id="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"
+ class="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator">
+ <property name="dataMartStore"
+ ref="org.hisp.dhis.datamart.DataMartStore"/>
+ <property name="aggregationCache"
+ ref="org.hisp.dhis.datamart.aggregation.cache.AggregationCache"/>
+ </bean>
+
<bean id="org.hisp.dhis.datamart.aggregation.dataelement.AverageBoolAggregator"
class="org.hisp.dhis.datamart.aggregation.dataelement.AverageBoolAggregator">
<property name="dataMartStore"
@@ -163,6 +173,8 @@
ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/>
<property name="averageIntAggregator"
ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntAggregator"/>
+ <property name="averageIntSingleValueAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"/>
<property name="crossTabService"
ref="org.hisp.dhis.datamart.crosstab.CrossTabService"/>
<property name="aggregationCache"
@@ -183,6 +195,8 @@
ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/>
<property name="averageIntAggregator"
ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntAggregator"/>
+ <property name="averageIntSingleValueAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"/>
<property name="crossTabService"
ref="org.hisp.dhis.datamart.crosstab.CrossTabService"/>
<property name="dataElementService"
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceAggregationLevelsTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceAggregationLevelsTest.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceAggregationLevelsTest.java 2010-06-17 21:08:46 +0000
@@ -32,7 +32,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Date;
import java.util.HashSet;
import org.hisp.dhis.DhisTest;
@@ -41,6 +40,8 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -101,6 +102,8 @@
dataElementService = (DataElementService) getBean( DataElementService.ID );
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
+
periodService = (PeriodService) getBean( PeriodService.ID );
organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
@@ -126,6 +129,16 @@
dataElement = createDataElement( 'A', DataElement.VALUE_TYPE_INT, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo );
dataElementIds.add( dataElementService.addDataElement( dataElement ) );
+
+ // ---------------------------------------------------------------------
+ // Setup DataSets (to get correct PeriodType for DataElements)
+ // ---------------------------------------------------------------------
+
+ DataSet dataSet = createDataSet( 'A', new MonthlyPeriodType() );
+ dataSet.getDataElements().add( dataElement );
+ dataSetService.addDataSet( dataSet );
+ dataElement.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElement );
// ---------------------------------------------------------------------
// Setup Periods
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceMultiDimensionTest.java 2010-06-17 21:08:46 +0000
@@ -42,6 +42,8 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.expression.Expression;
import org.hisp.dhis.indicator.Indicator;
@@ -49,9 +51,11 @@
import org.hisp.dhis.indicator.IndicatorType;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.QuarterlyPeriodType;
import org.junit.Ignore;
import org.junit.Test;
@@ -113,6 +117,8 @@
dataElementService = (DataElementService) getBean( DataElementService.ID );
indicatorService = (IndicatorService) getBean( IndicatorService.ID );
+
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
periodService = (PeriodService) getBean( PeriodService.ID );
@@ -169,19 +175,33 @@
dataElementIds.add( dataElementService.addDataElement( dataElementB ) );
// ---------------------------------------------------------------------
+ // Setup DataSets (to get correct PeriodType for DataElements)
+ // ---------------------------------------------------------------------
+
+ DataSet dataSet = createDataSet( 'A', new MonthlyPeriodType() );
+ dataSet.getDataElements().add( dataElementA );
+ dataSet.getDataElements().add( dataElementB );
+ dataSetService.addDataSet( dataSet );
+ dataElementA.getDataSets().add( dataSet );
+ dataElementB.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElementA );
+ dataElementService.updateDataElement( dataElementB );
+
+ // ---------------------------------------------------------------------
// Setup Periods
// ---------------------------------------------------------------------
- PeriodType periodType = periodService.getAllPeriodTypes().iterator().next();
+ PeriodType monthly = new MonthlyPeriodType();
+ PeriodType quarterly = new QuarterlyPeriodType();
Date jul01 = getDate( 2005, 7, 1 );
Date jul31 = getDate( 2005, 7, 31 );
Date aug01 = getDate( 2005, 8, 1 );
Date aug31 = getDate( 2005, 8, 31 );
- periodA = createPeriod( periodType, jul01, jul31 );
- periodB = createPeriod( periodType, aug01, aug31 );
- periodC = createPeriod( periodType, jul01, aug31 );
+ periodA = createPeriod( monthly, jul01, jul31 );
+ periodB = createPeriod( monthly, aug01, aug31 );
+ periodC = createPeriod( quarterly, jul01, aug31 ); //TODO fix
periodIds.add( periodService.addPeriod( periodA ) );
periodIds.add( periodService.addPeriod( periodB ) );
@@ -206,7 +226,7 @@
return true;
}
- @Ignore
+ @Ignore //TODO fix
@Test
public void testSumIntDataElementDataMart()
{
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java 2010-06-15 10:15:01 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java 2010-06-17 21:08:46 +0000
@@ -40,6 +40,8 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.expression.Expression;
import org.hisp.dhis.expression.ExpressionService;
@@ -81,6 +83,8 @@
private DataElement dataElementA;
private DataElement dataElementB;
+ private DataSet dataSet;
+
private Period periodA;
private Period periodB;
private Period periodC;
@@ -108,6 +112,8 @@
dataElementService = (DataElementService) getBean( DataElementService.ID );
indicatorService = (IndicatorService) getBean( IndicatorService.ID );
+
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
periodService = (PeriodService) getBean( PeriodService.ID );
@@ -139,6 +145,19 @@
dataElementIds.add( dataElementService.addDataElement( dataElementA ) );
dataElementIds.add( dataElementService.addDataElement( dataElementB ) );
+
+ // ---------------------------------------------------------------------
+ // Setup DataSets (to get correct PeriodType for DataElements)
+ // ---------------------------------------------------------------------
+
+ dataSet = createDataSet( 'A', new MonthlyPeriodType() );
+ dataSet.getDataElements().add( dataElementA );
+ dataSet.getDataElements().add( dataElementB );
+ dataSetService.addDataSet( dataSet );
+ dataElementA.getDataSets().add( dataSet );
+ dataElementB.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElementA );
+ dataElementService.updateDataElement( dataElementB );
// ---------------------------------------------------------------------
// Setup Periods
@@ -277,7 +296,7 @@
dataElementService.updateDataElement( dataElementA );
dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds );
-
+
assertEquals( dataMartStore.getAggregatedValue( dataElementA, categoryOptionCombo, periodA, unitA ), 240.0 );
assertEquals( dataMartStore.getAggregatedValue( dataElementA, categoryOptionCombo, periodA, unitB ), 150.0 );
assertEquals( dataMartStore.getAggregatedValue( dataElementA, categoryOptionCombo, periodA, unitC ), 90.0 );
@@ -370,6 +389,20 @@
int idE = dataElementService.addDataElement( dataElementE );
int idF = dataElementService.addDataElement( dataElementF );
+ dataSet.getDataElements().add( dataElementC );
+ dataSet.getDataElements().add( dataElementD );
+ dataSet.getDataElements().add( dataElementE );
+ dataSet.getDataElements().add( dataElementF );
+ dataSetService.updateDataSet( dataSet );
+ dataElementC.getDataSets().add( dataSet );
+ dataElementD.getDataSets().add( dataSet );
+ dataElementE.getDataSets().add( dataSet );
+ dataElementF.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElementC );
+ dataElementService.updateDataElement( dataElementD );
+ dataElementService.updateDataElement( dataElementE );
+ dataElementService.updateDataElement( dataElementF );
+
// ---------------------------------------------------------------------
// Setup DataValues
// ---------------------------------------------------------------------
@@ -466,6 +499,20 @@
int idE = dataElementService.addDataElement( dataElementE );
int idF = dataElementService.addDataElement( dataElementF );
+ dataSet.getDataElements().add( dataElementC );
+ dataSet.getDataElements().add( dataElementD );
+ dataSet.getDataElements().add( dataElementE );
+ dataSet.getDataElements().add( dataElementF );
+ dataSetService.updateDataSet( dataSet );
+ dataElementC.getDataSets().add( dataSet );
+ dataElementD.getDataSets().add( dataSet );
+ dataElementE.getDataSets().add( dataSet );
+ dataElementF.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElementC );
+ dataElementService.updateDataElement( dataElementD );
+ dataElementService.updateDataElement( dataElementE );
+ dataElementService.updateDataElement( dataElementF );
+
// ---------------------------------------------------------------------
// Setup DataValues
// ---------------------------------------------------------------------
@@ -531,6 +578,14 @@
int idC = dataElementService.addDataElement( dataElementC );
int idD = dataElementService.addDataElement( dataElementD );
+
+ dataSet.getDataElements().add( dataElementC );
+ dataSet.getDataElements().add( dataElementD );
+ dataSetService.updateDataSet( dataSet );
+ dataElementC.getDataSets().add( dataSet );
+ dataElementD.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElementC );
+ dataElementService.updateDataElement( dataElementD );
// ---------------------------------------------------------------------
// Setup DataValues
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTimeDimensionTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTimeDimensionTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTimeDimensionTest.java 2010-06-17 21:08:46 +0000
@@ -38,6 +38,8 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -79,6 +81,8 @@
dataElementService = (DataElementService) getBean( DataElementService.ID );
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
+
periodService = (PeriodService) getBean( PeriodService.ID );
organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
@@ -111,6 +115,12 @@
dataElementIds.add( dataElementService.addDataElement( dataElement ) );
+ DataSet dataSet = createDataSet( 'A', new YearlyPeriodType() );
+ dataSet.getDataElements().add( dataElement );
+ dataSetService.addDataSet( dataSet );
+ dataElement.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElement );
+
Period dataPeriod = createPeriod( new YearlyPeriodType(), getDate( 2000, 1, 1 ), getDate( 2000, 12, 31 ) );
OrganisationUnit unit = createOrganisationUnit( 'A' );
@@ -144,6 +154,12 @@
dataElementIds.add( dataElementService.addDataElement( dataElement ) );
+ DataSet dataSet = createDataSet( 'A', new MonthlyPeriodType() );
+ dataSet.getDataElements().add( dataElement );
+ dataSetService.addDataSet( dataSet );
+ dataElement.getDataSets().add( dataSet );
+ dataElementService.updateDataElement( dataElement );
+
Period dataPeriodA = createPeriod( new MonthlyPeriodType(), getDate( 2000, 3, 1 ), getDate( 2000, 3, 31 ) );
Period dataPeriodB = createPeriod( new MonthlyPeriodType(), getDate( 2000, 4, 1 ), getDate( 2000, 4, 30 ) );
Period dataPeriodC = createPeriod( new MonthlyPeriodType(), getDate( 2000, 5, 1 ), getDate( 2000, 5, 31 ) );