← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9766: Analytics, proper handling of requests with both data elements, category option combos, indicator...

 

------------------------------------------------------------
revno: 9766
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-07 15:00:56 +0200
message:
  Analytics, proper handling of requests with both data elements, category option combos, indicators and data sets
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DimensionOption.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  resources/sql/div.sql


--
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/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-02-07 12:24:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-02-07 13:00:56 +0000
@@ -130,6 +130,23 @@
             removeDimension( CATEGORYOPTIONCOMBO_DIM_ID );
         }
     }
+
+    /**
+     * Returns the index of the category option combo dimension as it will appear
+     * in the data value query for data elements. Returns null if this query
+     * does not contain the category option combo dimension.
+     */
+    public Integer getDeQueryCocIndex()
+    {
+        List<Dimension> list = new ArrayList<Dimension>( dimensions );
+                
+        list.remove( new Dimension( INDICATOR_DIM_ID ) );
+        list.remove( new Dimension( DATASET_DIM_ID ) );
+        
+        int index = list.indexOf( new Dimension( CATEGORYOPTIONCOMBO_DIM_ID ) );
+        
+        return index == -1 ? null : index;
+    }
     
     /**
      * Creates a list of dimensions for use as headers. Will replace any of

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DimensionOption.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DimensionOption.java	2013-01-17 14:26:35 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DimensionOption.java	2013-02-07 13:00:56 +0000
@@ -111,7 +111,7 @@
         {
             for ( DimensionOption option : options )
             {
-                optionUids.add( option.getOption().getUid() );
+                optionUids.add( option != null ? option.getOption().getUid() : null );
             }
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-02-07 12:24:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-02-07 13:00:56 +0000
@@ -142,6 +142,10 @@
         
         params.conform();
         
+        Integer cocIndex = params.getDeQueryCocIndex();
+        
+        log.info( "Category option combo index: " + cocIndex );
+        
         // ---------------------------------------------------------------------
         // Headers and meta-data
         // ---------------------------------------------------------------------
@@ -200,6 +204,17 @@
                             
                             row.add( indicatorIndex, new DimensionOption( INDICATOR_DIM_ID, indicator ) );
                             
+                            if ( cocIndex != null )
+                            {
+                                // ---------------------------------------------
+                                // Add null to get same number of columns
+                                // ---------------------------------------------
+
+                                row.add( cocIndex, null );
+                                
+                                System.out.println("setting coc at indeex " + cocIndex);
+                            }
+                            
                             grid.addRow();
                             grid.addValues( DimensionOption.getOptionIdentifiers( row ) );
                             grid.addValue( MathUtils.getRounded( value, 1 ) );
@@ -245,8 +260,19 @@
 
             for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
             {
+                List<String> row = new ArrayList<String>( Arrays.asList( entry.getKey().split( DIMENSION_SEP ) ) );
+
+                if ( cocIndex != null )
+                {
+                    // ---------------------------------------------------------
+                    // Add null to get same number of columns
+                    // ---------------------------------------------------------
+
+                    row.add( cocIndex, null );
+                }
+                
                 grid.addRow();
-                grid.addValues( entry.getKey().split( DIMENSION_SEP ) );
+                grid.addValues( row.toArray() );
                 grid.addValue( entry.getValue() );
             }
         }

=== modified file 'resources/sql/div.sql'
--- resources/sql/div.sql	2013-02-06 16:46:14 +0000
+++ resources/sql/div.sql	2013-02-07 13:00:56 +0000
@@ -125,7 +125,8 @@
 select userinfoid, 'dashboardConfig', (
   select value
   from usersetting
-  where userinfoid=7666) as value
+  where userinfoid=7666
+  and name='dashboardConfig') as value
 from userinfo
 where userinfoid not in (
   select userinfoid