← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2959: Improved performance in completeness export. Now its getting acceptable.

 

------------------------------------------------------------
revno: 2959
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-03-02 00:29:00 +0100
message:
  Improved performance in completeness export. Now its getting acceptable.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.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/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceExportTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.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 20:32:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java	2011-03-01 23:29:00 +0000
@@ -28,12 +28,7 @@
  */
 
 import java.util.Collection;
-import java.util.Date;
 
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
-import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.RelativePeriods;
 
 /**
@@ -92,16 +87,6 @@
     Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, int parentOrganisationUnitId, int dataSetId );
     
     /**
-     * Returns a Collection of DataSetCompletenessResults.
-     * 
-     * @param period the Period.
-     * @param unit the OrganisationUnit.
-     * @param dataSet the DataSet.
-     * @return a Collection of DataSetCompletenessResults.
-     */
-    DataSetCompletenessResult getDataSetCompleteness( Period period, Date deadline, OrganisationUnit unit, OrganisationUnitHierarchy hierarchy, DataSet dataSet );
-    
-    /**
      * Creates an index on the aggregateddatasetcompleteness table.
      */
     void createIndex();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java	2011-03-01 22:01:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java	2011-03-01 23:29:00 +0000
@@ -41,9 +41,9 @@
 {
     String ID = DataSetCompletenessStore.class.getName();
     
-    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources );
+    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> relevantSources );
     
-    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources, Date deadline );
+    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> relevantSources, Date deadline );
     
     /**
      * Gets the percentage value for the datasetcompleteness with the given parameters.

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-03-01 17:14:27 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-03-01 23:29:00 +0000
@@ -31,7 +31,6 @@
 
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.dataelement.DataElement;
@@ -43,9 +42,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.RelativePeriods;
-import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
 import org.hisp.dhis.system.process.OutputHolderState;
-import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -123,11 +120,7 @@
     {
         if ( relatives != null )
         {
-            List<Period> periods = relatives.getRelativePeriods( 1, null, false );
-            
-            FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
-            
-            periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( periods ) ) );
+            periodIds.addAll( getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) ) );
         }
         
         return dataMartEngine.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, useIndexes, new OutputHolderState() );

=== 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 22:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-03-01 23:29:00 +0000
@@ -29,13 +29,11 @@
 
 import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_COMPLETENESS_OFFSET;
 import static org.hisp.dhis.options.SystemSettingManager.KEY_COMPLETENESS_OFFSET;
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
-import java.util.List;
 
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
@@ -56,9 +54,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.RelativePeriods;
-import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
 import org.hisp.dhis.system.util.ConversionUtils;
-import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -132,11 +128,11 @@
     // Abstract methods
     // -------------------------------------------------------------------------
     
-    public abstract int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period );
-    
-    public abstract int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline );
-    
-    public abstract int getSources( DataSet dataSet, Collection<Integer> children );
+    public abstract int getRegistrations( DataSet dataSet, Collection<Integer> relevantSources, Period period );
+    
+    public abstract int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> relevantSources, Period period, Date deadline );
+    
+    public abstract int getSources( DataSet dataSet, Collection<Integer> relevantSources );
     
     // -------------------------------------------------------------------------
     // DataSetCompleteness
@@ -146,11 +142,7 @@
     {
         if ( relatives != null )
         {
-            List<Period> periods = relatives.getRelativePeriods( 1, null, false );
-            
-            FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
-            
-            Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( periods ) );
+            Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( relatives.getRelativePeriods( 1, null, false ) ) );
             
             exportDataSetCompleteness( dataSetIds, periodIds, organisationUnitIds );
         }
@@ -181,17 +173,21 @@
         
         //TODO Re-implement period aggregation with sql to improve performance
         
-        for ( final Period period : periods )
-        {
-            for ( final DataSet dataSet : dataSets )
+        for ( final DataSet dataSet : dataSets )
+        {                
+            for ( final OrganisationUnit unit : units )
             {
-                if ( period.getPeriodType() != null && dataSet.getPeriodType() != null && period.getPeriodType().equals( dataSet.getPeriodType() ) )
+                Collection<Integer> sources = hierarchy.getChildren( unit.getId() );
+                
+                Collection<Integer> relevantSources = getRelevantSources( dataSet, sources );
+                
+                for ( final Period period : periods )
                 {
-                    for ( final OrganisationUnit unit : units )
+                    if ( period.getPeriodType() != null && dataSet.getPeriodType() != null && period.getPeriodType().equals( dataSet.getPeriodType() ) )
                     {
                         final Date deadline = getDeadline( period, days );
-                                
-                        final DataSetCompletenessResult result = getDataSetCompleteness( period, deadline, unit, hierarchy, dataSet );
+                        
+                        final DataSetCompletenessResult result = getDataSetCompleteness( period, deadline, unit, relevantSources, dataSet );
                         
                         if ( result.getSources() > 0 )
                         {
@@ -201,12 +197,12 @@
                 }
             }
             
-            log.info( "Exported data completeness for period " + period.getId() );
+            log.info( "Exported completeness for data set: " + dataSet );
         }
         
         batchHandler.flush();
         
-        log.info( "Export process done" );
+        log.info( "Completeness export process done" );
     }
     
     public Collection<DataSetCompletenessResult> getDataSetCompleteness( int periodId, int organisationUnitId )
@@ -217,22 +213,24 @@
         Date deadline = getDeadline( period, days );
         
         final Collection<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren( organisationUnitId );
-        
+                
         final Collection<DataSet> dataSets = dataSetService.getAllDataSets();
         
         final Collection<DataSetCompletenessResult> results = new ArrayList<DataSetCompletenessResult>();
         
         for ( final DataSet dataSet : dataSets )
         {
+            final Collection<Integer> relevantSources = getRelevantSources( dataSet, children );
+            
             final DataSetCompletenessResult result = new DataSetCompletenessResult();
             
-            result.setSources( getSources( dataSet, children ) );
+            result.setSources( getSources( dataSet, relevantSources ) );
             
             if ( result.getSources() > 0 )
             {
                 result.setName( dataSet.getName() );
-                result.setRegistrations( getRegistrations( dataSet, children, period ) );
-                result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, children, period, deadline ) : 0 );
+                result.setRegistrations( getRegistrations( dataSet, relevantSources, period ) );
+                result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, relevantSources, period, deadline ) : 0 );
                             
                 result.setDataSetId( dataSet.getId() );
                 result.setPeriodId( periodId );
@@ -264,15 +262,17 @@
         {
             final Collection<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren( unit.getId() );
             
+            final Collection<Integer> relevantSources = getRelevantSources( dataSet, children );
+            
             final DataSetCompletenessResult result = new DataSetCompletenessResult();
 
-            result.setSources( getSources( dataSet, children ) );
+            result.setSources( getSources( dataSet, relevantSources ) );
             
             if ( result.getSources() > 0 )
             {
                 result.setName( unit.getName() );
-                result.setRegistrations( getRegistrations( dataSet, children, period ) );
-                result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, children, period, deadline ) : 0 );
+                result.setRegistrations( getRegistrations( dataSet, relevantSources, period ) );
+                result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, relevantSources, period, deadline ) : 0 );
                 
                 result.setDataSetId( dataSetId );
                 result.setPeriodId( periodId );
@@ -285,25 +285,6 @@
         return results;
     }
 
-    public DataSetCompletenessResult getDataSetCompleteness( Period period, Date deadline, OrganisationUnit unit, OrganisationUnitHierarchy hierarchy, DataSet dataSet )
-    {
-        final Collection<Integer> children = hierarchy.getChildren( unit.getId() );
-        
-        final DataSetCompletenessResult result = new DataSetCompletenessResult();
-        
-        result.setName( unit.getName() );
-        result.setRegistrations( getRegistrations( dataSet, children, period ) );
-        result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, children, period, deadline ) : 0 );
-        result.setSources( getSources( dataSet, children ) );
-        
-        result.setDataSetId( dataSet.getId() );
-        result.setPeriodId( period.getId() );
-        result.setPeriodName( period.getName() );
-        result.setOrganisationUnitId( unit.getId() );
-        
-        return result;
-    }
-        
     // -------------------------------------------------------------------------
     // Index
     // -------------------------------------------------------------------------
@@ -322,12 +303,35 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    protected int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<Integer> sources )
+    private DataSetCompletenessResult getDataSetCompleteness( Period period, Date deadline, OrganisationUnit unit, Collection<Integer> relevantSources, DataSet dataSet )
+    {   
+        final DataSetCompletenessResult result = new DataSetCompletenessResult();
+        
+        result.setName( unit.getName() );
+        result.setSources( getSources( dataSet, relevantSources ) );
+        
+        if ( result.getSources() > 0 )
+        {        
+            result.setRegistrations( getRegistrations( dataSet, relevantSources, period ) );
+            result.setRegistrationsOnTime( deadline != null ? getRegistrationsOnTime( dataSet, relevantSources, period, deadline ) : 0 );
+            
+            result.setDataSetId( dataSet.getId() );
+            result.setPeriodId( period.getId() );
+            result.setPeriodName( period.getName() );
+            result.setOrganisationUnitId( unit.getId() );
+        }
+        
+        return result;
+    }
+    
+    @SuppressWarnings("unchecked")
+    private Collection<Integer> getRelevantSources( DataSet dataSet, Collection<Integer> sources )
     {
-        Collection<Integer> dataSetSources = getIdentifiers( OrganisationUnit.class, dataSet.getSources() );
-        return CollectionUtils.intersection( dataSetSources, sources ).size();
+        Collection<Integer> dataSetSources = ConversionUtils.getIdentifiers( OrganisationUnit.class, dataSet.getSources() );
+        
+        return CollectionUtils.intersection( dataSetSources, sources );
     }
-
+    
     private Date getDeadline( Period period, int days )
     {
         Calendar cal = Calendar.getInstance();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java	2011-03-01 23:29:00 +0000
@@ -39,18 +39,18 @@
 public class CompulsoryDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {    
-    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> relevantSources, Period period )
     {
-        return completenessStore.getRegistrations( dataSet, children, period );
+        return completenessStore.getRegistrations( dataSet, relevantSources, period );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> relevantSources, Period period, Date deadline )
     {
-        return completenessStore.getRegistrations( dataSet, children, period, deadline );
+        return completenessStore.getRegistrations( dataSet, relevantSources, period, deadline );
     }
     
-    public int getSources( DataSet dataSet, Collection<Integer> children )
+    public int getSources( DataSet dataSet, Collection<Integer> relevantSources )
     {
-        return getSourcesAssociatedWithDataSet( dataSet, children );
+        return relevantSources.size();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java	2011-03-01 23:29:00 +0000
@@ -41,20 +41,20 @@
 public class RatioDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {
-    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> relevantSources, Period period )
     {
-        return completenessStore.getNumberOfValues( dataSet, children, period, null );
+        return completenessStore.getNumberOfValues( dataSet, relevantSources, period, null );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> relevantSources, Period period, Date deadline )
     {
-        return completenessStore.getNumberOfValues( dataSet, children, period, null );
+        return completenessStore.getNumberOfValues( dataSet, relevantSources, period, null );
     }
     
-    public int getSources( DataSet dataSet, Collection<Integer> children )
+    public int getSources( DataSet dataSet, Collection<Integer> relevantSources )
     {
         Collection<DataElementOperand> operands = dataElementService.getAllGeneratedOperands( dataSet.getDataElements() );
         
-        return operands != null && children != null ? operands.size() * children.size() : 0; // Number of operands in data set times number of organisation units
+        return operands != null && relevantSources != null ? operands.size() * relevantSources.size() : 0; // Number of operands in data set times number of organisation units
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java	2011-03-01 23:29:00 +0000
@@ -39,18 +39,18 @@
 public class RegistrationDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {
-    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> relevantSources, Period period )
     {
-        return completenessStore.getCompleteDataSetRegistrations( dataSet, period, children );
+        return completenessStore.getCompleteDataSetRegistrations( dataSet, period, relevantSources );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> relevantSources, Period period, Date deadline )
     {
-        return completenessStore.getCompleteDataSetRegistrations( dataSet, period, children, deadline );
+        return completenessStore.getCompleteDataSetRegistrations( dataSet, period, relevantSources, deadline );
     }
     
-    public int getSources( DataSet dataSet, Collection<Integer> children )
+    public int getSources( DataSet dataSet, Collection<Integer> relevantSources )
     {
-        return getSourcesAssociatedWithDataSet( dataSet, children );
+        return relevantSources.size();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java	2011-03-01 22:01:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java	2011-03-01 23:29:00 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
 import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
 
@@ -36,12 +35,10 @@
 import java.util.Date;
 
 import org.amplecode.quick.StatementManager;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.completeness.DataSetCompletenessStore;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.TextUtils;
@@ -70,12 +67,9 @@
     // DataSetCompletenessStore
     // -------------------------------------------------------------------------
 
-    @SuppressWarnings("unchecked")
-    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources )
+    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> relevantSources )
     {
-        final Collection<Integer> intersectingSources = CollectionUtils.intersection( sources, getIdentifiers( OrganisationUnit.class, dataSet.getSources() ) );
-        
-        if ( intersectingSources == null || intersectingSources.size() == 0 )
+        if ( relevantSources == null || relevantSources.size() == 0 )
         {
             return 0;
         }        
@@ -85,17 +79,14 @@
             "FROM completedatasetregistration " +
             "WHERE datasetid = " + dataSet.getId() + " " +
             "AND periodid = " + period.getId() + " " +
-            "AND sourceid IN ( " + getCommaDelimitedString( intersectingSources ) + " )";
+            "AND sourceid IN ( " + getCommaDelimitedString( relevantSources ) + " )";
         
         return statementManager.getHolder().queryForInteger( sql );
     }
 
-    @SuppressWarnings("unchecked")
-    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources, Date deadline )
+    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> relevantSources, Date deadline )
     {
-        final Collection<Integer> intersectingSources = CollectionUtils.intersection( sources, getIdentifiers( OrganisationUnit.class, dataSet.getSources() ) );
-        
-        if ( intersectingSources == null || intersectingSources.size() == 0 )
+        if ( relevantSources == null || relevantSources.size() == 0 )
         {
             return 0;
         }        
@@ -105,7 +96,7 @@
             "FROM completedatasetregistration " +
             "WHERE datasetid = " + dataSet.getId() + " " +
             "AND periodid = " + period.getId() + " " +
-            "AND sourceid IN ( " + getCommaDelimitedString( intersectingSources ) + " ) " +
+            "AND sourceid IN ( " + getCommaDelimitedString( relevantSources ) + " ) " +
             "AND date <= '" + getMediumDateString( deadline ) + "'";
         
         return statementManager.getHolder().queryForInteger( sql );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceExportTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceExportTest.java	2011-03-01 21:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceExportTest.java	2011-03-01 23:29:00 +0000
@@ -39,7 +39,6 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
@@ -161,22 +160,6 @@
         registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodB, unitB, null ) );
         registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodB, unitA, null ) );
         
-        OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy();
-        
-        DataSetCompletenessResult resultA = completenessService.getDataSetCompleteness( periodA, null, unitB, hierarchy, dataSetA );
-        DataSetCompletenessResult resultB = completenessService.getDataSetCompleteness( periodA, null, unitC, hierarchy, dataSetA );
-        DataSetCompletenessResult resultC = completenessService.getDataSetCompleteness( periodA, null, unitA, hierarchy, dataSetA );
-        DataSetCompletenessResult resultD = completenessService.getDataSetCompleteness( periodB, null, unitB, hierarchy, dataSetA );
-        DataSetCompletenessResult resultE = completenessService.getDataSetCompleteness( periodB, null, unitC, hierarchy, dataSetA );
-        DataSetCompletenessResult resultF = completenessService.getDataSetCompleteness( periodB, null, unitA, hierarchy, dataSetA );
-        
-        assertEquals( new DataSetCompletenessResult( unitB.getName(), 1, 1, 0 ), resultA );
-        assertEquals( new DataSetCompletenessResult( unitC.getName(), 1, 1, 0 ), resultB );
-        assertEquals( new DataSetCompletenessResult( unitA.getName(), 3, 2, 0 ), resultC );
-        assertEquals( new DataSetCompletenessResult( unitB.getName(), 1, 1, 0 ), resultD );
-        assertEquals( new DataSetCompletenessResult( unitC.getName(), 1, 0, 0 ), resultE );
-        assertEquals( new DataSetCompletenessResult( unitA.getName(), 3, 2, 0 ), resultF );
-        
         completenessService.exportDataSetCompleteness( getIdentifiers( DataSet.class, dataSets ),
             getIdentifiers( Period.class, periods ), getIdentifiers( OrganisationUnit.class, units ) );
         

=== 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 20:32:55 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java	2011-03-01 23:29:00 +0000
@@ -42,7 +42,6 @@
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
@@ -373,30 +372,4 @@
         assertTrue( results.contains( resultA ) );
         assertTrue( results.contains( resultB ) );        
     }
-
-    @Test
-    public void testGetDataSetCompletenessPeriodOrganisationUnitDataSet()
-    {
-        dataSetA.getSources().add( unitE );
-        dataSetA.getSources().add( unitF );
-        
-        dataSetIdA = dataSetService.addDataSet( dataSetA );
-        
-        registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitE, onTimeA ) );
-        registrationService.saveCompleteDataSetRegistration( new CompleteDataSetRegistration( dataSetA, periodA, unitF, onTimeA ) );
-        
-        OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy();
-        
-        DataSetCompletenessResult resultA = completenessService.getDataSetCompleteness( periodA, tooLateA, unitB, hierarchy, dataSetA );
-        DataSetCompletenessResult resultB = completenessService.getDataSetCompleteness( periodA, tooLateA, unitE, hierarchy, dataSetA );
-        DataSetCompletenessResult resultC = completenessService.getDataSetCompleteness( periodA, tooLateA, unitG, hierarchy, dataSetA );
-        
-        DataSetCompletenessResult referenceA = new DataSetCompletenessResult( unitB.getName(), 2, 2, 2 );
-        DataSetCompletenessResult referenceB = new DataSetCompletenessResult( unitE.getName(), 1, 1, 1 );
-        DataSetCompletenessResult referenceC = new DataSetCompletenessResult( unitG.getName(), 0, 0, 0 );
-        
-        assertEquals( referenceA, resultA );
-        assertEquals( referenceB, resultB );
-        assertEquals( referenceC, resultC );        
-    }
 }