dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06617
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1834: Modified aggregation service so that totals for a data element can be retrieved by providing null...
------------------------------------------------------------
revno: 1834
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Sat 2010-07-10 17:19:02 +0200
message:
Modified aggregation service so that totals for a data element can be retrieved by providing null as the category option combo argument
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationStore.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AbstractDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregationStore.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/AggregationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationStore.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationStore.java 2010-07-10 15:19:02 +0000
@@ -54,7 +54,7 @@
* @param periodIds a collection of period ids.
* @return collection of DataValues for the given parameters.
*/
- Collection<DataValue> getDataValues( Collection<Integer> sourceIds, int dataElementId, int optionComboId, Collection<Integer> periodIds );
+ Collection<DataValue> getDataValues( Collection<Integer> sourceIds, Integer dataElementId, Integer optionComboId, Collection<Integer> periodIds );
/**
* Gets all DataValues for the given parameters. This method can be used in conjunction with the
@@ -67,7 +67,7 @@
* @param periodIds a collection of period ids.
* @return collection of DataValues for the given parameters.
*/
- Collection<DataValue> getDataValues( int sourceId, int dataElementId, int optionComboId, Collection<Integer> periodIds );
+ Collection<DataValue> getDataValues( Integer sourceId, Integer dataElementId, Integer optionComboId, Collection<Integer> periodIds );
/**
* Generates a collection of strings on the form <data element id>-<period id>-<source id>
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AbstractDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AbstractDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AbstractDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -94,7 +94,7 @@
* @param hierarchy the organisation unit hierarchy
* @return collection a datavalues
*/
- protected abstract Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected abstract Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate );
protected abstract double[] getAggregateOfValues( Collection<DataValue> values, Date startDate, Date endDate,
@@ -114,10 +114,12 @@
* @return double array with sum of the data values at position 0 and number
* of relevant days at position 1
*/
- protected double[] getSumAndRelevantDays( int dataElementId, int optionComboId, Date aggregationStartDate,
- Date aggregationEndDate, int organisationUnitId )
+ protected double[] getSumAndRelevantDays( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Date aggregationStartDate,
+ Date aggregationEndDate, Integer organisationUnitId )
{
- Collection<DataValue> dataValues = getDataValues( dataElementId, optionComboId, organisationUnitId,
+ Integer categoryOptionComboId = categoryOptionCombo != null ? categoryOptionCombo.getId() : null;
+
+ Collection<DataValue> dataValues = getDataValues( dataElement.getId(), categoryOptionComboId, organisationUnitId,
aggregationStartDate, aggregationEndDate );
return getAggregateOfValues( dataValues, aggregationStartDate, aggregationEndDate,
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -49,8 +49,7 @@
public Double getAggregatedValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date aggregationStartDate, Date aggregationEndDate,
OrganisationUnit organisationUnit )
{
- double[] sums = getSumAndRelevantDays( dataElement.getId(), optionCombo.getId(), aggregationStartDate, aggregationEndDate,
- organisationUnit.getId() );
+ double[] sums = getSumAndRelevantDays( dataElement, optionCombo, aggregationStartDate, aggregationEndDate, organisationUnit.getId() );
if ( sums[1] > 0 )
{
@@ -64,7 +63,7 @@
}
}
- protected Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate )
{
OrganisationUnitHierarchy hierarchy = aggregationCache.getOrganisationUnitHierarchy();
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -59,7 +59,7 @@
for ( Integer id : organisationUnitIds )
{
- double[] sums = getSumAndRelevantDays( dataElement.getId(), optionCombo.getId(), aggregationStartDate, aggregationEndDate, id );
+ double[] sums = getSumAndRelevantDays( dataElement, optionCombo, aggregationStartDate, aggregationEndDate, id );
if ( sums[1] > 0 )
{
@@ -85,7 +85,7 @@
* and hierarchy.
* @throws AggregationStoreException
*/
- protected Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate )
{
Collection<Integer> periods = aggregationCache.getIntersectingPeriodIds( startDate, endDate );
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -49,13 +49,12 @@
public Double getAggregatedValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date aggregationStartDate, Date aggregationEndDate,
OrganisationUnit organisationUnit )
{
- double[] sums = getSumAndRelevantDays( dataElement.getId(), optionCombo.getId(), aggregationStartDate, aggregationEndDate,
- organisationUnit.getId() );
+ double[] sums = getSumAndRelevantDays( dataElement, optionCombo, aggregationStartDate, aggregationEndDate, organisationUnit.getId() );
return sums[1] > 0 ? sums[0] : null;
}
- protected Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate )
{
OrganisationUnitHierarchy hierarchy = aggregationCache.getOrganisationUnitHierarchy();
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -50,13 +50,12 @@
public Double getAggregatedValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date aggregationStartDate, Date aggregationEndDate,
OrganisationUnit organisationUnit )
{
- double[] sums = getSumAndRelevantDays( dataElement.getId(), optionCombo.getId(), aggregationStartDate, aggregationEndDate,
- organisationUnit.getId() );
+ double[] sums = getSumAndRelevantDays( dataElement, optionCombo, aggregationStartDate, aggregationEndDate, organisationUnit.getId() );
return sums[1] > 0 ? getFloor( sums[0] ) : null;
}
- protected Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate )
{
OrganisationUnitHierarchy hierarchy = aggregationCache.getOrganisationUnitHierarchy();
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java 2010-07-10 15:19:02 +0000
@@ -49,13 +49,12 @@
public Double getAggregatedValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date aggregationStartDate, Date aggregationEndDate,
OrganisationUnit organisationUnit )
{
- double[] sums = getSumAndRelevantDays( dataElement.getId(), optionCombo.getId(), aggregationStartDate, aggregationEndDate,
- organisationUnit.getId() );
+ double[] sums = getSumAndRelevantDays( dataElement, optionCombo, aggregationStartDate, aggregationEndDate, organisationUnit.getId() );
return sums[1] > 0 ? sums[0] : null;
}
- protected Collection<DataValue> getDataValues( int dataElementId, int optionComboId, int organisationUnitId,
+ protected Collection<DataValue> getDataValues( Integer dataElementId, Integer optionComboId, Integer organisationUnitId,
Date startDate, Date endDate )
{
OrganisationUnitHierarchy hierarchy = aggregationCache.getOrganisationUnitHierarchy();
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregationStore.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregationStore.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregationStore.java 2010-07-10 15:19:02 +0000
@@ -61,19 +61,21 @@
// DataValue
// ----------------------------------------------------------------------
- public Collection<DataValue> getDataValues( Collection<Integer> sourceIds, int dataElementId, int optionComboId, Collection<Integer> periodIds )
+ public Collection<DataValue> getDataValues( Collection<Integer> sourceIds, Integer dataElementId, Integer optionComboId, Collection<Integer> periodIds )
{
if ( sourceIds != null && sourceIds.size() > 0 && periodIds != null && periodIds.size() > 0 )
{
StatementHolder holder = statementManager.getHolder();
-
+
+ String categoryOptionComboCriteria = optionComboId != null ? "AND categoryoptioncomboid = " + optionComboId + " " : "";
+
try
{
String sql =
"SELECT periodid, value " +
"FROM datavalue " +
"WHERE dataelementid = " + dataElementId + " " +
- "AND categoryoptioncomboid = " + optionComboId + " " +
+ categoryOptionComboCriteria +
"AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
"AND sourceid IN ( " + getCommaDelimitedString( sourceIds ) + " )";
@@ -94,11 +96,13 @@
return new ArrayList<DataValue>();
}
- public Collection<DataValue> getDataValues( int sourceId, int dataElementId, int optionComboId, Collection<Integer> periodIds )
+ public Collection<DataValue> getDataValues( Integer sourceId, Integer dataElementId, Integer optionComboId, Collection<Integer> periodIds )
{
if ( periodIds != null && periodIds.size() > 0 )
{
StatementHolder holder = statementManager.getHolder();
+
+ String categoryOptionComboCriteria = optionComboId != null ? "AND categoryoptioncomboid = " + optionComboId + " " : "";
try
{
@@ -106,7 +110,7 @@
"SELECT periodid, value " +
"FROM datavalue " +
"WHERE dataelementid = " + dataElementId + " " +
- "AND categoryoptioncomboid = " + optionComboId + " " +
+ categoryOptionComboCriteria +
"AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
"AND sourceid = " + sourceId;
@@ -146,7 +150,11 @@
return identifiers;
}
-
+
+ // ----------------------------------------------------------------------
+ // Supportive methods
+ // ----------------------------------------------------------------------
+
private Collection<String> getDataValueIdentifiers( int min, int limit )
{
StatementHolder holder = statementManager.getHolder();
@@ -180,10 +188,6 @@
}
}
- // ----------------------------------------------------------------------
- // Supportive methods
- // ----------------------------------------------------------------------
-
private Collection<DataValue> getDataValues( ResultSet resultSet )
{
try