← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14770: Analytics, impl support for approval level column in analytics tables

 

------------------------------------------------------------
revno: 14770
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-10 15:40:11 +0200
message:
  Analytics, impl support for approval level column in analytics tables
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-04-10 13:40:11 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.setting.SystemSettingManager;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -78,6 +79,9 @@
     
     @Autowired
     protected DataElementCategoryService categoryService;
+    
+    @Autowired
+    protected SystemSettingManager systemSettingManager;
    
     @Autowired
     protected StatementBuilder statementBuilder;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2014-04-10 13:40:11 +0000
@@ -47,8 +47,10 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.MathUtils;
+import org.hisp.dhis.system.util.TextUtils;
 import org.springframework.scheduling.annotation.Async;
 
 /**
@@ -188,6 +190,23 @@
         jdbcTemplate.execute( sql );
     }
 
+    private String getApprovalSubquery( Collection<OrganisationUnitLevel> levels )
+    {
+        String sql = "(" +
+            "select min(dal.level) " +
+            "from dataapproval da " +
+            "inner join dataapprovallevel dal on da.dataapprovallevelid = dal.dataapprovallevelid " +
+            "inner join _dataelementstructure des on da.datasetid = des.datasetid and des.dataelementid = dv.dataelementid " +
+            "where da.periodid = dv.periodid and (";
+        
+        for ( OrganisationUnitLevel level : levels )
+        {
+            sql += "ous.idlevel" + level.getLevel() + " = da.organisationunitid or ";
+        }
+        
+        return TextUtils.removeLastOr( sql ) + ") ) as approvallevel";        
+    }
+
     public List<String[]> getDimensionColumns( AnalyticsTable table )
     {
         List<String[]> columns = new ArrayList<String[]>();
@@ -261,6 +280,12 @@
         String[] level = { quote( "level" ), "integer", "ous.level" };
         
         columns.addAll( Arrays.asList( de, co, level ) );
+
+        if ( isApprovalEnabled() )
+        {            
+            String[] al = { quote( "approvallevel" ), "integer", getApprovalSubquery( levels ) };
+            columns.add( al );
+        }
         
         return columns;
     }
@@ -318,4 +343,13 @@
 
         return null;
     }
+
+    /**
+     * Indicates whether the system should ignore data which has not been approved
+     * in analytics tables.
+     */
+    private boolean isApprovalEnabled()
+    {
+        return (Boolean) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_HIDE_UNAPPROVED_DATA_IN_ANALYTICS, false );
+    }
 }