← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15211: Event aggreagete analytics, impl query params uniqueInstances=true which returns count of distinc...

 

------------------------------------------------------------
revno: 15211
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-05-10 13:18:29 +0200
message:
  Event aggreagete analytics, impl query params uniqueInstances=true which returns count of distinct TEIs as apposed to count of events
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.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/EventQueryParams.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/JdbcEventAnalyticsTableManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm


--
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/AnalyticsTable.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java	2014-05-10 11:18:29 +0000
@@ -45,7 +45,11 @@
     private Period period;
     
     private Program program;
-    
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
     public AnalyticsTable()
     {
     }
@@ -70,7 +74,11 @@
         this.period = period;
         this.program = program;
     }
-    
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
     public String getTableName()
     {
         String name = baseName;
@@ -104,13 +112,27 @@
         
         return name;
     }
+
+    public boolean hasPeriod()
+    {
+        return period != null;
+    }
+    
+    public boolean hasProgram()
+    {
+        return program != null;
+    }
     
     @Override
     public String toString()
     {
         return getTableName();
     }
-    
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
     public String getBaseName()
     {
         return baseName;

=== 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	2014-03-27 11:13:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2014-05-10 11:18:29 +0000
@@ -49,7 +49,8 @@
      * Used for aggregate query.
      */
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
-        Set<String> dimension, Set<String> filter, boolean skipMeta, boolean hierarchyMeta, SortOrder sortOrder, Integer limit, I18nFormat format );
+        Set<String> dimension, Set<String> filter, boolean skipMeta, boolean hierarchyMeta, SortOrder sortOrder, 
+        Integer limit, boolean uniqueInstances, I18nFormat format );
 
     /**
      * Used for event query.

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-05-06 16:30:43 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-05-10 11:18:29 +0000
@@ -80,6 +80,8 @@
     
     private Integer limit;
     
+    private boolean uniqueInstances;
+    
     private boolean coordinatesOnly;
     
     // -------------------------------------------------------------------------
@@ -123,6 +125,7 @@
         params.pageSize = this.pageSize;
         params.sortOrder = this.sortOrder;
         params.limit = this.limit;
+        params.uniqueInstances = this.uniqueInstances;
         params.coordinatesOnly = this.coordinatesOnly;
         
         params.periodType = this.periodType;
@@ -241,6 +244,15 @@
     }
     
     /**
+     * Indicates whether the program of this query requires registration of
+     * tracked entity instances.
+     */
+    public boolean isProgramRegistration()
+    {
+        return program != null && program.isRegistration();
+    }
+    
+    /**
      * Returns a negative integer in case of ascending sort order, a positive in
      * case of descending sort order and 0 in case of no sort order.
      */
@@ -404,6 +416,16 @@
     {
         this.limit = limit;
     }
+    
+    public boolean isUniqueInstances()
+    {
+        return uniqueInstances;
+    }
+
+    public void setUniqueInstances( boolean uniqueInstances )
+    {
+        this.uniqueInstances = uniqueInstances;
+    }
 
     public boolean isCoordinatesOnly()
     {

=== 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	2014-05-08 17:33:45 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-05-10 11:18:29 +0000
@@ -295,14 +295,15 @@
     }
 
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
-        Set<String> dimension, Set<String> filter, boolean skipMeta, boolean hierarchyMeta, SortOrder sortOrder, Integer limit,
-        I18nFormat format )
+        Set<String> dimension, Set<String> filter, boolean skipMeta, boolean hierarchyMeta, SortOrder sortOrder, 
+        Integer limit, boolean uniqueInstances, I18nFormat format )
     {
         EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null,
             skipMeta, hierarchyMeta, false, null, null, format );
         
         params.setSortOrder( sortOrder );
         params.setLimit( limit );
+        params.setUniqueInstances( uniqueInstances );
         params.setAggregate( true );
 
         return params;

=== 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	2014-05-06 15:50:09 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-05-10 11:18:29 +0000
@@ -84,7 +84,9 @@
 
     public Grid getAggregatedEventData( EventQueryParams params, Grid grid )
     {
-        String sql = "select count(psi) as value," + getSelectColumns( params ) + " ";
+        String countClause = ( params.isProgramRegistration() && params.isUniqueInstances() ) ? "count(distinct tei)" : "count(psi)";
+        
+        String sql = "select " + countClause + " as value," + getSelectColumns( params ) + " ";
 
         // ---------------------------------------------------------------------
         // Criteria

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2014-04-07 14:27:23 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2014-05-10 11:18:29 +0000
@@ -160,17 +160,19 @@
 
             sql = removeLast( sql, 1 ) + " ";
 
-            sql += "from programstageinstance psi "
-                + "left join programinstance pi on psi.programinstanceid=pi.programinstanceid "
-                + "left join programstage ps on psi.programstageid=ps.programstageid "
-                + "left join program pr on pi.programid=pr.programid "
-                + "left join trackedentityinstance pa on pi.trackedentityinstanceid=pa.trackedentityinstanceid "
-                + "left join organisationunit ou on psi.organisationunitid=ou.organisationunitid "
-                + "left join _orgunitstructure ous on psi.organisationunitid=ous.organisationunitid "
-                + "left join _dateperiodstructure dps on psi.executiondate=dps.dateperiod "
-                + "where psi.executiondate >= '" + start + "' " + "and psi.executiondate <= '" + end + "' "
-                + "and pr.programid=" + table.getProgram().getId() + " " + "and psi.organisationunitid is not null "
-                + "and psi.executiondate is not null";
+            sql += "from programstageinstance psi " +
+                "left join programinstance pi on psi.programinstanceid=pi.programinstanceid " +
+                "left join programstage ps on psi.programstageid=ps.programstageid " +
+                "left join program pr on pi.programid=pr.programid " +
+                "left join trackedentityinstance tei on pi.trackedentityinstanceid=tei.trackedentityinstanceid " +
+                "left join organisationunit ou on psi.organisationunitid=ou.organisationunitid " +
+                "left join _orgunitstructure ous on psi.organisationunitid=ous.organisationunitid " +
+                "left join _dateperiodstructure dps on psi.executiondate=dps.dateperiod " +
+                "where psi.executiondate >= '" + start + "' " + 
+                "and psi.executiondate <= '" + end + "' " +
+                "and pr.programid=" + table.getProgram().getId() + " " + 
+                "and psi.organisationunitid is not null " +
+                "and psi.executiondate is not null";
 
             log.info( "Populate SQL: " + sql );
 
@@ -246,6 +248,12 @@
 
         columns.addAll( Arrays.asList( psi, ps, ed, longitude, latitude, ou, oun, ouc ) );
 
+        if ( table.hasProgram() && table.getProgram().isRegistration() )
+        {
+            String[] tei = { quote( "tei" ), "character(11)", "tei.uid" };
+            columns.add( tei );
+        }
+        
         return columns;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2014-03-26 09:26:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2014-05-10 11:18:29 +0000
@@ -85,11 +85,13 @@
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) boolean hierarchyMeta,
         @RequestParam(required=false) Integer limit,
+        @RequestParam(required=false) boolean uniqueInstances,
         @RequestParam(required=false) SortOrder sortOrder,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, skipMeta, hierarchyMeta, sortOrder, limit, i18nManager.getI18nFormat() );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, 
+            skipMeta, hierarchyMeta, sortOrder, limit, uniqueInstances, i18nManager.getI18nFormat() );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -109,11 +111,13 @@
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) boolean hierarchyMeta,
         @RequestParam(required=false) Integer limit,
+        @RequestParam(required=false) boolean uniqueInstances,
         @RequestParam(required=false) SortOrder sortOrder,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, skipMeta, hierarchyMeta, sortOrder, limit, i18nManager.getI18nFormat() );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, 
+            skipMeta, hierarchyMeta, sortOrder, limit, uniqueInstances, i18nManager.getI18nFormat() );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xml", false );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -131,11 +135,13 @@
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) boolean hierarchyMeta,
         @RequestParam(required=false) Integer limit,
+        @RequestParam(required=false) boolean uniqueInstances,
         @RequestParam(required=false) SortOrder sortOrder,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, skipMeta, hierarchyMeta, sortOrder, limit, i18nManager.getI18nFormat() );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, 
+            skipMeta, hierarchyMeta, sortOrder, limit, uniqueInstances, i18nManager.getI18nFormat() );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -153,11 +159,13 @@
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) boolean hierarchyMeta,
         @RequestParam(required=false) Integer limit,
+        @RequestParam(required=false) boolean uniqueInstances,
         @RequestParam(required=false) SortOrder sortOrder,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, skipMeta, hierarchyMeta, sortOrder, limit, i18nManager.getI18nFormat() );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, 
+            skipMeta, hierarchyMeta, sortOrder, limit, uniqueInstances, i18nManager.getI18nFormat() );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.csv", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -175,11 +183,13 @@
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) boolean hierarchyMeta,
         @RequestParam(required=false) Integer limit,
+        @RequestParam(required=false) boolean uniqueInstances,
         @RequestParam(required=false) SortOrder sortOrder,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, skipMeta, hierarchyMeta, sortOrder, limit, i18nManager.getI18nFormat() );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, 
+            skipMeta, hierarchyMeta, sortOrder, limit, uniqueInstances, i18nManager.getI18nFormat() );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.html", false );
         Grid grid = analyticsService.getAggregatedEventData( params );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm	2014-05-07 10:09:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm	2014-05-10 11:18:29 +0000
@@ -1,6 +1,4 @@
-#if( $auth.hasAccess( "dhis-web-caseentry", "trackedEntityInstance" ) 
-	|| $auth.hasAccess( "dhis-web-caseentry", "activityPlanSelect" ) 
-	|| $auth.hasAccess( "dhis-web-caseentry", "smsReminderSelect" ) )
+#if( $auth.hasAccess( "dhis-web-caseentry", "trackedEntityInstance" ) || $auth.hasAccess( "dhis-web-caseentry", "activityPlanSelect" ) || $auth.hasAccess( "dhis-web-caseentry", "smsReminderSelect" ) )
 <h2>$i18n.getString( "tracked_entity_instance" )&nbsp;</h2>
 #end
 <ul>
@@ -14,8 +12,7 @@
 		<li><a href="smsReminderSelect.action">$i18n.getString( "program_tracking" )</a></li>     
 	#end
 </ul>
-#if( $auth.hasAccess( "dhis-web-caseentry", "singleEventSelect" ) 
-	|| $auth.hasAccess( "dhis-web-caseentry", "anonymousRegistration" ) )
+#if( $auth.hasAccess( "dhis-web-caseentry", "singleEventSelect" ) )
 <h2>$i18n.getString( "data_entry" )&nbsp;</h2>
 #end
 <ul>
@@ -24,9 +21,7 @@
 	#end
 </ul>
 
-#if( $auth.hasAccess( "dhis-web-caseentry", "reportSelect" ) 
-	|| $auth.hasAccess( "dhis-web-caseentry", "statisticalProgramReportSelect" ) 
-	|| $auth.hasAccess( "dhis-web-caseentry", "programStageCompletenessSelect" ) )	
+#if( $auth.hasAccess( "dhis-web-caseentry", "reportSelect" ) || $auth.hasAccess( "dhis-web-caseentry", "statisticalProgramReportSelect" ) || $auth.hasAccess( "dhis-web-caseentry", "programStageCompletenessSelect" ) )	
 <h2>$i18n.getString( "reports" )&nbsp;</h2>
 #end
 <ul>