dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03195
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1056: Implemented totals for category report tables.
------------------------------------------------------------
revno: 1056
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-11-19 16:25:06 +0100
message:
Implemented totals for category report tables.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/jdbc/JdbcDataMartStore.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java
dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableManagerTest.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/datamart/DataMartStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartStore.java 2009-08-09 12:33:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartStore.java 2009-11-19 15:25:06 +0000
@@ -57,6 +57,16 @@
// ----------------------------------------------------------------------
/**
+ * Gets the total aggregated value from the datamart table for the given parameters.
+ *
+ * @param dataElement The DataElement.
+ * @param period The Period.
+ * @param organisationUnit The OrganisationUnit.
+ * @return the aggregated value, or -1 if no value exists.
+ */
+ Double getTotalAggregatedValue( final DataElement dataElement, final Period period, final OrganisationUnit organisationUnit );
+
+ /**
* Gets the aggregated value from the datamart table for the given parameters.
*
* @param dataElement The DataElement.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2009-11-17 07:40:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2009-11-19 15:25:06 +0000
@@ -81,6 +81,8 @@
public static final String REGRESSION_COLUMN_PREFIX = "regression_";
+ public static final String NAME_TOTAL_COLUMN = "total";
+
private static final String EMPTY_REPLACEMENT = "_";
private static final String TABLE_PREFIX = "_report_";
private static final String REGEX_NUMERIC = "([0-9]*)";
@@ -653,6 +655,15 @@
return dimensionSetType != null;
}
+ /**
+ * Tests whether a total column should be included.
+ */
+ public boolean doTotal()
+ {
+ return !isDoIndicators() && !isDoPeriods() && !isDoUnits() && isDoCategoryOptionCombos() &&
+ isDimensional() && mode.equals( MODE_DATAELEMENTS );
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/jdbc/JdbcDataMartStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/jdbc/JdbcDataMartStore.java 2009-09-30 20:26:58 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/jdbc/JdbcDataMartStore.java 2009-11-19 15:25:06 +0000
@@ -66,6 +66,15 @@
public class JdbcDataMartStore
implements DataMartStore
{
+ private static final Map<String, String> functionMap = new HashMap<String, String>();
+
+ static
+ {
+ functionMap.put( DataElement.AGGREGATION_OPERATOR_SUM, "SUM" );
+ functionMap.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, "AVG" );
+ functionMap.put( DataElement.AGGREGATION_OPERATOR_COUNT, "SUM" );
+ }
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -88,6 +97,18 @@
// AggregatedDataValue
// -------------------------------------------------------------------------
+ public Double getTotalAggregatedValue( final DataElement dataElement, final Period period, final OrganisationUnit organisationUnit )
+ {
+ final String sql =
+ "SELECT " + functionMap.get( dataElement.getAggregationOperator() ) + "(value) " +
+ "FROM aggregateddatavalue " +
+ "WHERE dataelementid = " + dataElement.getId() + " " +
+ "AND periodid = " + period.getId() + " " +
+ "AND organisationunitid = " + organisationUnit.getId();
+
+ return statementManager.getHolder().queryForDouble( sql );
+ }
+
public double getAggregatedValue( final DataElement dataElement, final Period period, final OrganisationUnit organisationUnit )
{
final StatementHolder holder = statementManager.getHolder();
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2009-10-27 15:12:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2009-11-19 15:25:06 +0000
@@ -650,6 +650,15 @@
{
grid.addValue( parseAndReplaceNull( map.get( identifier ) ) );
}
+
+ // -----------------------------------------------------
+ // Values
+ // -----------------------------------------------------
+
+ if ( reportTable.doTotal() )
+ {
+ grid.addValue( String.valueOf( dataMartStore.getTotalAggregatedValue( (DataElement) metaObject, period, unit ) ) );
+ }
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java 2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/statement/CreateReportTableStatement.java 2009-11-19 15:25:06 +0000
@@ -88,7 +88,7 @@
buffer.append( ReportTable.REPORTING_MONTH_COLUMN_NAME + SPACE + LONG_TEXT_COLUMN_TYPE + SEPARATOR );
// ---------------------------------------------------------------------
- // Crosstab columns
+ // Crosstab
// ---------------------------------------------------------------------
for ( String column : reportTable.getCrossTabColumns() )
@@ -97,6 +97,15 @@
}
// ---------------------------------------------------------------------
+ // Total
+ // ---------------------------------------------------------------------
+
+ if ( reportTable.doTotal() )
+ {
+ buffer.append( ReportTable.NAME_TOTAL_COLUMN + SPACE + statementBuilder.getDoubleColumnType() + SEPARATOR );
+ }
+
+ // ---------------------------------------------------------------------
// Regression
// ---------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableManagerTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableManagerTest.java 2009-11-16 14:10:08 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableManagerTest.java 2009-11-19 15:25:06 +0000
@@ -376,7 +376,7 @@
reportTable.init();
Map<String, Double> map = reportTableManager.getAggregatedValueMap( reportTable, null, null, null, unitA );
-System.out.println( map );
+
assertNotNull( map );
assertEquals( 4, map.entrySet().size() );