dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07141
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2016: Modified ExpressionService to optionally use aggregated data
------------------------------------------------------------
revno: 2016
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Tue 2010-08-31 10:14:32 +0200
message:
Modified ExpressionService to optionally use aggregated data
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.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-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java 2010-08-31 07:06:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregatedDataValueService.java 2010-08-31 08:14:32 +0000
@@ -20,6 +20,16 @@
// ----------------------------------------------------------------------
// AggregatedDataValue
// ----------------------------------------------------------------------
+
+ /**
+ * Gets the total aggregated value from the datamart table for the given parameters.
+ *
+ * @param dataElement The DataElement identifier.
+ * @param period The Period identifier.
+ * @param organisationUnit The OrganisationUnit identifier.
+ * @return the aggregated value.
+ */
+ Double getAggregatedDataValue( int dataElement, int period, int organisationUnit );
/**
* Gets the total aggregated value from the datamart table for the given parameters.
@@ -34,6 +44,17 @@
/**
* Gets the total aggregated value from the datamart table for the given parameters.
*
+ * @param dataElement The DataElement identifier.
+ * @param dimensionOptionElement the DimensionOptionElement identifier.
+ * @param period The Period identifier.
+ * @param organisationUnit The OrganisationUnit identifier.
+ * @return the aggregated value.
+ */
+ Double getAggregatedDataValue( int dataElement, int categoryOptionCombo, int period, int organisationUnit );
+
+ /**
+ * Gets the total aggregated value from the datamart table for the given parameters.
+ *
* @param dataElement The DataElement.
* @param dimensionOptionElement the DimensionOptionElement.
* @param period The Period.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2010-08-31 08:14:32 +0000
@@ -100,11 +100,13 @@
* @param period The Period.
* @param nullIfNoValues indicates whether null should be returned if no
* DataValues are registered for a DataElement in the expression.
+ * @param aggregated indicates whether aggregated or raw data should be
+ * used when evaluating the expression.
* @return The value of the given Expression, or null
* if no values are registered for a given combination of
* DataElement, Source, and Period.
*/
- Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues );
+ Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues, boolean aggregate );
/**
* Returns all DataElements associated with the CalculatedDataElement.
@@ -191,7 +193,9 @@
* @param source The Source.
* @param nullIfNoValues indicates whether null should be returned if no
* DataValues are registered for a DataElement in the expression.
+ * @param aggregated indicates whether aggregated or raw data should be
+ * used when evaluating the expression.
* @return A numerical expression.
*/
- String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues );
+ String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues, boolean aggregated );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2010-08-31 08:14:32 +0000
@@ -40,6 +40,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.aggregation.AggregatedDataValueService;
import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.dataelement.CalculatedDataElement;
import org.hisp.dhis.dataelement.DataElement;
@@ -95,6 +96,13 @@
{
this.dataValueService = dataValueService;
}
+
+ private AggregatedDataValueService aggregatedDataValueService;
+
+ public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService )
+ {
+ this.aggregatedDataValueService = aggregatedDataValueService;
+ }
private DataElementCategoryService categoryService;
@@ -136,9 +144,9 @@
// Business logic
// -------------------------------------------------------------------------
- public Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues )
+ public Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues, boolean aggregate )
{
- final String expressionString = generateExpression( expression.getExpression(), period, source, nullIfNoValues );
+ final String expressionString = generateExpression( expression.getExpression(), period, source, nullIfNoValues, aggregate );
return expressionString != null ? calculateExpression( expressionString ) : null;
}
@@ -403,7 +411,7 @@
return buffer != null ? buffer.toString() : null;
}
- public String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues )
+ public String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues, boolean aggregated )
{
StringBuffer buffer = null;
@@ -419,7 +427,18 @@
final DataElementOperand operand = getOperand( replaceString );
- final String value = dataValueService.getValue( operand.getDataElementId(), period.getId(), source.getId(), operand.getOptionComboId() );
+ String value = null;
+
+ if ( aggregated )
+ {
+ Double aggregatedValue = aggregatedDataValueService.getAggregatedDataValue( operand.getDataElementId(), operand.getOptionComboId(), period.getId(), source.getId() );
+
+ value = aggregatedValue != null ? String.valueOf( aggregatedValue ) : null;
+ }
+ else
+ {
+ value = dataValueService.getValue( operand.getDataElementId(), period.getId(), source.getId(), operand.getOptionComboId() );
+ }
if ( value == null && nullIfNoValues )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2010-08-30 13:04:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2010-08-31 08:14:32 +0000
@@ -210,8 +210,8 @@
for ( final ValidationRule validationRule : validationRules )
{
- leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), period, source, true );
- rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source, true );
+ leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), period, source, true, false );
+ rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source, true, false );
if ( leftSide != null && rightSide != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2010-08-31 08:14:32 +0000
@@ -155,13 +155,13 @@
{
Expression expression = new Expression( expressionA, descriptionA, dataElements );
- Double value = expressionService.getExpressionValue( expression, period, source, false );
+ Double value = expressionService.getExpressionValue( expression, period, source, false, false );
assertEquals( value, 15.0 );
expression = new Expression( expressionB, descriptionB, dataElements );
- value = expressionService.getExpressionValue( expression, period, source, false );
+ value = expressionService.getExpressionValue( expression, period, source, false, false );
assertEquals( 0.0, value );
}
@@ -250,11 +250,11 @@
@Test
public void testGenerateExpression()
{
- String expression = expressionService.generateExpression( expressionA, period, source, false );
+ String expression = expressionService.generateExpression( expressionA, period, source, false, false );
assertEquals( "10 + 5", expression );
- expression = expressionService.generateExpression( expressionB, period, source, false );
+ expression = expressionService.generateExpression( expressionB, period, source, false, false );
assertEquals( "0 - 0", expression );
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java 2010-08-31 08:14:32 +0000
@@ -139,7 +139,7 @@
for ( CalculatedDataElement cde : cdes )
{
- value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit, false ).toString();
+ value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit, false, false ).toString();
if ( value == null )
{