← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19969: Event analytics, query. Added support for program indicators per individual event. Only expressio...

 

------------------------------------------------------------
revno: 19969
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-03 16:31:20 +0200
message:
  Event analytics, query. Added support for program indicators per individual event. Only expression is evaluated.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/EventAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.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/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2015-09-03 03:11:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2015-09-03 14:31:20 +0000
@@ -74,6 +74,7 @@
 import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension;
 import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
 import org.hisp.dhis.user.User;
@@ -157,6 +158,9 @@
     @Scanned
     protected List<OrganisationUnitGroup> itemOrganisationUnitGroups = new ArrayList<>();
 
+    @Scanned
+    protected List<ProgramIndicator> itemProgramIndicators = new ArrayList<>();
+    
     protected String digitGroupSeparator;
 
     protected int sortOrder;
@@ -219,6 +223,11 @@
         return itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty();
     }
     
+    public boolean hasItemProgramIndicators()
+    {
+        return itemProgramIndicators != null && !itemProgramIndicators.isEmpty();
+    }
+    
     public boolean hasSortOrder()
     {
         return sortOrder != 0;
@@ -840,6 +849,7 @@
         userOrganisationUnitChildren = false;
         userOrganisationUnitGrandChildren = false;
         itemOrganisationUnitGroups.clear();
+        itemProgramIndicators.clear();
     }
 
     @Override
@@ -879,6 +889,7 @@
             userOrganisationUnitChildren = object.isUserOrganisationUnitChildren();
             userOrganisationUnitGrandChildren = object.isUserOrganisationUnitGrandChildren();
             itemOrganisationUnitGroups = object.getItemOrganisationUnitGroups();
+            itemProgramIndicators = object.getItemProgramIndicators();
             digitGroupSeparator = object.getDigitGroupSeparator();
             userOrganisationUnit = object.isUserOrganisationUnit();
             sortOrder = object.getSortOrder();
@@ -1114,6 +1125,20 @@
     }
 
     @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "itemProgramIndicators", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "itemProgramIndicator", namespace = DxfNamespaces.DXF_2_0 )
+    public List<ProgramIndicator> getItemProgramIndicators()
+    {
+        return itemProgramIndicators;
+    }
+
+    public void setItemProgramIndicators( List<ProgramIndicator> itemProgramIndicators )
+    {
+        this.itemProgramIndicators = itemProgramIndicators;
+    }
+
+    @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class, DimensionalView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getDigitGroupSeparator()

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/EventAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/EventAnalyticalObject.java	2015-08-02 14:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/EventAnalyticalObject.java	2015-09-03 14:31:20 +0000
@@ -29,10 +29,12 @@
  */
 
 import java.util.Date;
+import java.util.List;
 
 import org.hisp.dhis.analytics.EventOutputType;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
@@ -60,11 +62,15 @@
     // Base class emulation methods
     // -------------------------------------------------------------------------
     
+    List<ProgramIndicator> getItemProgramIndicators();
+    
+    void setItemProgramIndicators( List<ProgramIndicator> itemProgramIndicators );
+    
     DataElement getDataElementValueDimension();
 
     void setDataElementValueDimension( DataElement dataElementValueDimension );
 
     TrackedEntityAttribute getAttributeValueDimension();
     
-    void setAttributeValueDimension( TrackedEntityAttribute attributeValueDimension );   
+    void setAttributeValueDimension( TrackedEntityAttribute attributeValueDimension );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2015-09-03 09:26:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java	2015-09-03 14:31:20 +0000
@@ -111,7 +111,7 @@
 
     public String getTypeAsString()
     {
-        return valueType.getJavaClass().toString();
+        return valueType.getJavaClass().getName();
     }
 
     public boolean isNumeric()

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-08-04 11:09:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-09-03 14:31:20 +0000
@@ -88,6 +88,7 @@
      * @param endDate the end date.
      * @param dimension the set of dimensions.
      * @param filter the set of filters.
+     * @param indicator the set of program indicators.
      * @param ouMode the organisation unit mode.
      * @param asc the dimensions to be sorted ascending.
      * @param desc the dimensions to be sorted descending.
@@ -100,9 +101,15 @@
      * @param pageSize the page size.
      * @param format the i18n format.
      */
-    EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> dimension, Set<String> filter, 
+    EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> dimension, Set<String> filter, Set<String> indicator,
         String ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean skipData, boolean hierarchyMeta, boolean coordinatesOnly, 
         DisplayProperty displayProperty, Integer page, Integer pageSize, I18nFormat format );
     
+    /**
+     * Get query from event analytical object.
+     * 
+     * @param object the event analytical object.
+     * @param format the i18n format.
+     */
     EventQueryParams getFromAnalyticalObject( EventAnalyticalObject object, I18nFormat format );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-09-03 08:15:09 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-09-03 14:31:20 +0000
@@ -85,6 +85,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.program.ProgramIndicatorService;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageService;
@@ -127,13 +129,16 @@
 
     @Autowired
     private DataElementService dataElementService;
-
+    
+    @Autowired
+    private ProgramIndicatorService programIndicatorService;
+    
     @Autowired
     private TrackedEntityAttributeService attributeService;
     
     @Autowired
     private OrganisationUnitService organisationUnitService;
-
+    
     @Autowired
     private LegendService legendService;
 
@@ -317,6 +322,11 @@
         {
             grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getName(), item.getTypeAsString(), false, true, item.getOptionSetUid(), item.getLegendSetUid() ) );
         }
+        
+        for ( ProgramIndicator in : params.getItemProgramIndicators() )
+        {
+            grid.addHeader( new GridHeader( in.getUid(), in.getName(), Double.class.getName(), false, true ) );
+        }
 
         // ---------------------------------------------------------------------
         // Data
@@ -379,7 +389,7 @@
         boolean hierarchyMeta, boolean showHierarchy, SortOrder sortOrder, Integer limit, EventOutputType outputType, boolean collapseDataDimensions, 
         boolean aggregateData, DisplayProperty displayProperty, I18nFormat format )
     {
-        EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null,
+        EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null, null,
             skipMeta, skipData, hierarchyMeta, false, displayProperty, null, null, format );
                 
         params.setValue( getValueDimension( value ) );
@@ -397,8 +407,9 @@
 
     @Override
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
-        Set<String> dimension, Set<String> filter, String ouMode, Set<String> asc, Set<String> desc,
-        boolean skipMeta, boolean skipData, boolean hierarchyMeta, boolean coordinatesOnly, DisplayProperty displayProperty, Integer page, Integer pageSize, I18nFormat format )
+        Set<String> dimension, Set<String> filter, Set<String> indicator, String ouMode, Set<String> asc, Set<String> desc,
+        boolean skipMeta, boolean skipData, boolean hierarchyMeta, boolean coordinatesOnly, 
+        DisplayProperty displayProperty, Integer page, Integer pageSize, I18nFormat format )
     {
         EventQueryParams params = new EventQueryParams();
 
@@ -469,6 +480,19 @@
                 }
             }
         }
+        
+        if ( indicator != null )
+        {
+            for ( String uid : indicator )
+            {
+                ProgramIndicator in = programIndicatorService.getProgramIndicatorByUid( uid );
+                
+                if ( in != null )
+                {
+                    params.getItemProgramIndicators().add( in );
+                }
+            }
+        }
 
         if ( asc != null )
         {
@@ -542,6 +566,11 @@
                     params.getItemFilters().add( getQueryItem( filter.getDimension(), filter.getFilter() ) );
                 }
             }
+            
+            for ( ProgramIndicator in : object.getItemProgramIndicators() )
+            {
+                params.getItemProgramIndicators().add( in );
+            }
 
             params.setProgram( object.getProgram() );
             params.setProgramStage( object.getProgramStage() );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-08-28 10:23:48 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-09-03 14:31:20 +0000
@@ -50,6 +50,7 @@
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.QueryFilter;
 import org.hisp.dhis.common.QueryItem;
@@ -61,6 +62,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramIndicatorService;
+import org.hisp.dhis.system.util.MathUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -273,8 +275,6 @@
 
     private void getEvents( Grid grid, EventQueryParams params, String sql )
     {
-        int rowLength = grid.getHeaders().size();
-
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
 
         log.debug( "Analytics event query SQL: " + sql );
@@ -283,11 +283,22 @@
         {
             grid.addRow();
             
-            for ( int i = 0; i < rowLength; i++ )
+            int index = 1;
+            
+            for ( GridHeader header : grid.getHeaders() )
             {
-                int index = i + 1;
+                if ( Double.class.getName().equals( header.getType() ) )
+                {
+                    double val = rowSet.getDouble( index );
+                    
+                    grid.addValue( params.isSkipRounding() ? val : MathUtils.getRounded( val ) );
+                }
+                else
+                {                
+                    grid.addValue( rowSet.getString( index ) );
+                }
                 
-                grid.addValue( rowSet.getString( index ) );
+                index++;
             }
         }
     }
@@ -390,6 +401,11 @@
             sql += statementBuilder.columnQuote( queryItem.getItemName() ) + ",";
         }
         
+        for ( ProgramIndicator in : params.getItemProgramIndicators() )
+        {
+            sql += "(" + programIndicatorService.getAnalyticsSQl( in.getExpression() ) + "),";
+        }
+        
         return removeLastComma( sql );
     }
 

=== 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	2015-08-31 15:28:36 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2015-09-03 14:31:20 +0000
@@ -173,6 +173,8 @@
                 "and ( dv.value != '0' or de.aggregationtype in ('" + AGGREGATION_OPERATOR_AVERAGE + ',' + AGGREGATION_OPERATOR_AVERAGE_SUM + "') " +
                 "or de.zeroissignificant = true ) ";
             
+            //TODO upgrade to ValueType enum when database column has been renamed
+            
             populateTable( table, "cast(dv.value as " + dbl + ")", "null", DataElement.VALUE_TYPE_INT, intClause, approvalClause );
             
             populateTable( table, "1", "null", DataElement.VALUE_TYPE_BOOL, "dv.value = 'true'", approvalClause );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-08-04 11:09:17 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-09-03 14:31:20 +0000
@@ -254,6 +254,7 @@
         @RequestParam( required = false ) String endDate,
         @RequestParam Set<String> dimension,
         @RequestParam( required = false ) Set<String> filter,
+        @RequestParam( required = false ) Set<String> indicator,
         @RequestParam( required = false ) String ouMode,
         @RequestParam( required = false ) Set<String> asc,
         @RequestParam( required = false ) Set<String> desc,
@@ -267,7 +268,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode,
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, indicator, ouMode,
             asc, desc, skipMeta, skipData, hierarchyMeta, coordinatesOnly, displayProperty, page, pageSize, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
@@ -285,6 +286,7 @@
         @RequestParam( required = false ) String endDate,
         @RequestParam Set<String> dimension,
         @RequestParam( required = false ) Set<String> filter,
+        @RequestParam( required = false ) Set<String> indicator,
         @RequestParam( required = false ) String ouMode,
         @RequestParam( required = false ) Set<String> asc,
         @RequestParam( required = false ) Set<String> desc,
@@ -298,7 +300,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, indicator,
             ouMode, asc, desc, skipMeta, skipData, hierarchyMeta, coordinatesOnly, displayProperty, page, pageSize, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xml", false );
@@ -314,6 +316,7 @@
         @RequestParam( required = false ) String endDate,
         @RequestParam Set<String> dimension,
         @RequestParam( required = false ) Set<String> filter,
+        @RequestParam( required = false ) Set<String> indicator,
         @RequestParam( required = false ) String ouMode,
         @RequestParam( required = false ) Set<String> asc,
         @RequestParam( required = false ) Set<String> desc,
@@ -327,7 +330,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, indicator,
             ouMode, asc, desc, skipMeta, skipData, hierarchyMeta, coordinatesOnly, displayProperty, page, pageSize, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
@@ -343,6 +346,7 @@
         @RequestParam( required = false ) String endDate,
         @RequestParam Set<String> dimension,
         @RequestParam( required = false ) Set<String> filter,
+        @RequestParam( required = false ) Set<String> indicator,
         @RequestParam( required = false ) String ouMode,
         @RequestParam( required = false ) Set<String> asc,
         @RequestParam( required = false ) Set<String> desc,
@@ -356,7 +360,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, indicator,
             ouMode, asc, desc, skipMeta, skipData, hierarchyMeta, coordinatesOnly, displayProperty, page, pageSize, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.csv", true );
@@ -372,6 +376,7 @@
         @RequestParam( required = false ) String endDate,
         @RequestParam Set<String> dimension,
         @RequestParam( required = false ) Set<String> filter,
+        @RequestParam( required = false ) Set<String> indicator,
         @RequestParam( required = false ) String ouMode,
         @RequestParam( required = false ) Set<String> asc,
         @RequestParam( required = false ) Set<String> desc,
@@ -385,7 +390,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, indicator,
             ouMode, asc, desc, skipMeta, skipData, hierarchyMeta, coordinatesOnly, displayProperty, page, pageSize, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.html", false );