dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13771
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4506: Added a footer row in completeness report for the parent org unit
------------------------------------------------------------
revno: 4506
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-02 15:11:12 +0200
message:
Added a footer row in completeness report for the parent org unit
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java
dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessAction.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/completeness/DataSetCompletenessService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java 2011-03-01 23:29:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java 2011-09-02 13:11:12 +0000
@@ -84,7 +84,7 @@
* @param dataSetId the identifier of the DataSet.
* @return a Collection of DataSetCompletenessResults.
*/
- Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, int parentOrganisationUnitId, int dataSetId );
+ Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, Collection<Integer> organisationUnitIds, int dataSetId );
/**
* Creates an index on the aggregateddatasetcompleteness table.
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java 2011-03-01 23:48:07 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java 2011-09-02 13:11:12 +0000
@@ -253,7 +253,7 @@
return results;
}
- public Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, int parentOrganisationUnitId, int dataSetId )
+ public Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, Collection<Integer> organisationUnitIds, int dataSetId )
{
final Period period = periodService.getPeriod( periodId );
@@ -262,14 +262,12 @@
final DataSet dataSet = dataSetService.getDataSet( dataSetId );
- final OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
-
- final Collection<OrganisationUnit> units = parent.getChildren();
-
final Collection<DataSetCompletenessResult> results = new ArrayList<DataSetCompletenessResult>();
- for ( final OrganisationUnit unit : units )
+ for ( final Integer unitId : organisationUnitIds )
{
+ final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( unitId );
+
final Collection<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren( unit.getId() );
final Collection<Integer> relevantSources = getRelevantSources( dataSet, children );
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java 2011-03-01 23:29:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java 2011-09-02 13:11:12 +0000
@@ -78,6 +78,9 @@
private OrganisationUnit unitH;
private int unitIdA;
+ private int unitIdB;
+ private int unitIdC;
+ private Collection<Integer> unitIdsA;
private DataSet dataSetA;
private DataSet dataSetB;
@@ -144,14 +147,18 @@
unitC.getChildren().add( unitH );
unitIdA = organisationUnitService.addOrganisationUnit( unitA );
- organisationUnitService.addOrganisationUnit( unitB );
- organisationUnitService.addOrganisationUnit( unitC );
+ unitIdB = organisationUnitService.addOrganisationUnit( unitB );
+ unitIdC = organisationUnitService.addOrganisationUnit( unitC );
organisationUnitService.addOrganisationUnit( unitD );
organisationUnitService.addOrganisationUnit( unitE );
organisationUnitService.addOrganisationUnit( unitF );
organisationUnitService.addOrganisationUnit( unitG );
organisationUnitService.addOrganisationUnit( unitH );
+ unitIdsA = new HashSet<Integer>();
+ unitIdsA.add( unitIdB );
+ unitIdsA.add( unitIdC );
+
sources.add( unitA );
sources.add( unitB );
sources.add( unitC );
@@ -312,7 +319,7 @@
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitF, tooLateA ) );
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitG, tooLateA ) );
- Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdA, dataSetIdA );
+ Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdsA, dataSetIdA );
DataSetCompletenessResult resultA = new DataSetCompletenessResult( unitB.getName(), 2, 2, 0 );
DataSetCompletenessResult resultB = new DataSetCompletenessResult( unitC.getName(), 2, 1, 0 );
@@ -336,7 +343,7 @@
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitG, tooLateA ) );
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitH, tooLateA ) );
- Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdA, dataSetIdA );
+ Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdsA, dataSetIdA );
DataSetCompletenessResult resultA = new DataSetCompletenessResult( unitB.getName(), 2, 1, 0 );
DataSetCompletenessResult resultB = new DataSetCompletenessResult( unitC.getName(), 1, 1, 0 );
@@ -362,7 +369,7 @@
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitG, onTimeA ) );
registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitH, tooLateA ) );
- Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdA, dataSetIdA );
+ Collection<DataSetCompletenessResult> results = completenessService.getDataSetCompleteness( periodIdA, unitIdsA, dataSetIdA );
DataSetCompletenessResult resultA = new DataSetCompletenessResult( unitB.getName(), 2, 2, 1 );
DataSetCompletenessResult resultB = new DataSetCompletenessResult( unitC.getName(), 2, 2, 1 );
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessAction.java 2011-04-15 14:37:44 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/completeness/action/GetDataCompletenessAction.java 2011-09-02 13:11:12 +0000
@@ -28,7 +28,7 @@
*/
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.List;
import org.hisp.dhis.common.Grid;
@@ -36,7 +36,6 @@
import org.hisp.dhis.common.ServiceProvider;
import org.hisp.dhis.completeness.DataSetCompletenessResult;
import org.hisp.dhis.completeness.DataSetCompletenessService;
-import org.hisp.dhis.completeness.comparator.DataSetCompletenessResultComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.i18n.I18n;
@@ -48,6 +47,8 @@
import com.opensymphony.xwork2.Action;
+import static org.hisp.dhis.system.util.ConversionUtils.*;
+
/**
* @author Lars Helge Overland
* @version $Id$
@@ -159,7 +160,7 @@
}
else
{
- OrganisationUnit selectedUnit = selectionTreeManager.getSelectedOrganisationUnit();
+ OrganisationUnit selectedUnit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
if ( periodId == null || selectedUnit == null || criteria == null )
{
@@ -170,26 +171,28 @@
Integer _periodId = periodService.getPeriodByExternalId( periodId ).getId();
DataSet dataSet = null;
- List<DataSetCompletenessResult> results = null;
+ List<DataSetCompletenessResult> mainResults = new ArrayList<DataSetCompletenessResult>();
+ List<DataSetCompletenessResult> footerResults = new ArrayList<DataSetCompletenessResult>();
DataSetCompletenessService completenessService = serviceProvider.provide( criteria );
if ( dataSetId != null && dataSetId != 0 ) // One data set for one organisation unit
{
- results = new ArrayList<DataSetCompletenessResult>( completenessService.getDataSetCompleteness(
- _periodId, selectedUnit.getId(), dataSetId ) );
+ mainResults = new ArrayList<DataSetCompletenessResult>( completenessService.getDataSetCompleteness(
+ _periodId, getIdentifiers( OrganisationUnit.class, selectedUnit.getChildren() ), dataSetId ) );
+
+ footerResults = new ArrayList<DataSetCompletenessResult>( completenessService.getDataSetCompleteness(
+ _periodId, Arrays.asList( selectedUnit.getId() ), dataSetId ) );
dataSet = dataSetService.getDataSet( dataSetId );
}
else // All data sets for children of one organisation unit
{
- results = new ArrayList<DataSetCompletenessResult>( completenessService.getDataSetCompleteness(
+ mainResults = new ArrayList<DataSetCompletenessResult>( completenessService.getDataSetCompleteness(
_periodId, selectedUnit.getId() ) );
}
- Collections.sort( results, new DataSetCompletenessResultComparator() );
-
- grid = getGrid( results, selectedUnit, dataSet );
+ grid = getGrid( mainResults, footerResults, selectedUnit, dataSet );
SessionUtils.setSessionVar( KEY_DATA_COMPLETENESS, grid );
}
@@ -198,7 +201,7 @@
}
}
- private Grid getGrid( List<DataSetCompletenessResult> results, OrganisationUnit unit, DataSet dataSet )
+ private Grid getGrid( List<DataSetCompletenessResult> mainResults, List<DataSetCompletenessResult> footerResults, OrganisationUnit unit, DataSet dataSet )
{
String title = i18n.getString( "data_completeness_report" );
String subtitle = ( unit != null ? unit.getName() : EMPTY ) + SPACE + ( dataSet != null ? dataSet.getName() : EMPTY );
@@ -212,15 +215,9 @@
grid.addHeader( new GridHeader( i18n.getString( "on_time" ), false, false ) );
grid.addHeader( new GridHeader( i18n.getString( "percent" ), false, false ) );
- for ( DataSetCompletenessResult result : results )
+ for ( DataSetCompletenessResult result : mainResults )
{
- grid.addRow();
- grid.addValue( result.getName() );
- grid.addValue( result.getRegistrations() );
- grid.addValue( result.getSources() );
- grid.addValue( result.getPercentage() );
- grid.addValue( result.getRegistrationsOnTime() );
- grid.addValue( result.getPercentageOnTime() );
+ addRow( grid, result );
}
if ( grid.getWidth() >= 4 )
@@ -228,6 +225,22 @@
grid.sortGrid( 4, 1 );
}
+ for ( DataSetCompletenessResult result : footerResults )
+ {
+ addRow( grid, result );
+ }
+
return grid;
}
+
+ private void addRow( Grid grid, DataSetCompletenessResult result )
+ {
+ grid.addRow();
+ grid.addValue( result.getName() );
+ grid.addValue( result.getRegistrations() );
+ grid.addValue( result.getSources() );
+ grid.addValue( result.getPercentage() );
+ grid.addValue( result.getRegistrationsOnTime() );
+ grid.addValue( result.getPercentageOnTime() );
+ }
}