dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10768
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2957: Filtering datasets and periods without complete registrations before export
------------------------------------------------------------
revno: 2957
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-03-01 23:01:40 +0100
message:
Filtering datasets and periods without complete registrations before export
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.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/jdbc/JDBCDataSetCompletenessStore.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/DataSetCompletenessStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java 2011-03-01 19:32:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java 2011-03-01 22:01:40 +0000
@@ -75,6 +75,10 @@
int getNumberOfValues( DataSet dataSet, Collection<Integer> children, Period period, Date deadline );
+ Collection<DataSet> getDataSetsWithRegistrations( Collection<DataSet> dataSets );
+
+ Collection<Period> getPeriodsWithRegistrations( Collection<Period> periods );
+
void createIndex();
void dropIndex();
=== 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 21:07:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java 2011-03-01 22:01:40 +0000
@@ -172,6 +172,9 @@
Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnits( organisationUnitIds );
Collection<DataSet> dataSets = dataSetService.getDataSets( dataSetIds );
+ periods = completenessStore.getPeriodsWithRegistrations( periods );
+ dataSets = completenessStore.getDataSetsWithRegistrations( dataSets );
+
OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy();
hierarchy.prepareChildren( units );
@@ -179,17 +182,20 @@
for ( final Period period : periods )
{
- for ( final OrganisationUnit unit : units )
+ for ( final DataSet dataSet : dataSets )
{
- for ( final DataSet dataSet : dataSets )
+ 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 );
-
- if ( result.getSources() > 0 )
+ for ( final OrganisationUnit unit : units )
{
- batchHandler.addObject( result );
+ final Date deadline = getDeadline( period, days );
+
+ final DataSetCompletenessResult result = getDataSetCompleteness( period, deadline, unit, hierarchy, dataSet );
+
+ if ( result.getSources() > 0 )
+ {
+ batchHandler.addObject( result );
+ }
}
}
}
=== 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 19:32:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java 2011-03-01 22:01:40 +0000
@@ -31,6 +31,7 @@
import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -179,8 +180,42 @@
"AND sourceid IN (" + childrenIds + ")";
return statementManager.getHolder().queryForInteger( sql );
- }
+ }
+
+ public Collection<DataSet> getDataSetsWithRegistrations( Collection<DataSet> dataSets )
+ {
+ Collection<DataSet> selection = new ArrayList<DataSet>();
+
+ for ( DataSet dataSet : dataSets )
+ {
+ final String sql = "SELECT count(*) FROM completedatasetregistration WHERE datasetid = " + dataSet.getId();
+
+ if ( statementManager.getHolder().queryForInteger( sql ) > 0 )
+ {
+ selection.add( dataSet );
+ }
+ }
+
+ return selection;
+ }
+ public Collection<Period> getPeriodsWithRegistrations( Collection<Period> periods )
+ {
+ Collection<Period> selection = new ArrayList<Period>();
+
+ for ( Period period : periods )
+ {
+ final String sql = "SELECT count(*) FROM completedatasetregistration WHERE periodid = " + period.getId();
+
+ if ( statementManager.getHolder().queryForInteger( sql ) > 0 )
+ {
+ selection.add( period );
+ }
+ }
+
+ return selection;
+ }
+
public void createIndex()
{
try