← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18399: Event analytics tables, added support for legends/ranges for attributes

 

------------------------------------------------------------
revno: 18399
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-25 00:41:01 +0100
message:
  Event analytics tables, added support for legends/ranges for attributes
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
  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/JdbcEventAnalyticsTableManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowAddAttributeFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowUpdateAttributeAction.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-02-24 21:18:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2015-02-24 23:41:01 +0000
@@ -203,20 +203,39 @@
         return elements;
     }
     
-
     /**
      * Returns TrackedEntityAttributes from ProgramTrackedEntityAttributes. Use
      * getAttributes() to access the persisted attribute list.
      */
     public List<TrackedEntityAttribute> getTrackedEntityAttributes()
     {
-        List<TrackedEntityAttribute> entityAttributes = new ArrayList<>();
+        List<TrackedEntityAttribute> attributes = new ArrayList<>();
+        
         for ( ProgramTrackedEntityAttribute programAttribute : programAttributes )
         {
-            entityAttributes.add( programAttribute.getAttribute() );
-        }
-
-        return entityAttributes;
+            attributes.add( programAttribute.getAttribute() );
+        }
+
+        return attributes;
+    }
+
+    /**
+     * Returns TrackedEntityAttributes from ProgramTrackedEntityAttributes which
+     * have a legend set and is of numeric value type.
+     */
+    public List<TrackedEntityAttribute> getTrackedEntityAttributesWithLegendSet()
+    {
+        List<TrackedEntityAttribute> attributes = new ArrayList<>();
+        
+        for ( TrackedEntityAttribute attribute : getTrackedEntityAttributes() )
+        {
+            if ( attribute != null && attribute.hasLegendSet() && attribute.isNumericType() )
+            {
+                attributes.add( attribute );
+            }
+        }
+        
+        return attributes;
     }
 
     public ProgramStage getProgramStageByStage( int stage )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2015-02-24 21:48:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2015-02-24 23:41:01 +0000
@@ -139,6 +139,11 @@
         return optionSet != null;
     }
 
+    public boolean hasLegendSet()
+    {
+        return legendSet != null;
+    }
+    
     /**
      * Checks whether the given value is present among the options in the option
      * set of this attribute, matching on code.

=== 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	2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2015-02-24 23:41:01 +0000
@@ -223,26 +223,29 @@
     /**
      * Remove quotes from the given column name.
      */
-    protected String removeQuote( String column )
+    private String removeQuote( String column )
     {
         return column != null ? column.replaceAll( statementBuilder.getColumnQuote(), StringUtils.EMPTY ) : null;
     }
     
     /**
-     * Remove temp part of name from the given column name.
+     * Shortens the given table name.
      */
-    protected String removeTemp( String column )
+    private String shortenTableName( String table )
     {
-        return column != null ? column.replaceAll( TABLE_TEMP_SUFFIX, StringUtils.EMPTY ) : null;
+        table = table.replaceAll( ANALYTICS_TABLE_NAME, "ax" );
+        table = table.replaceAll( TABLE_TEMP_SUFFIX, StringUtils.EMPTY );
+        
+        return table;
     }
     
     /**
      * Returns index name for column. Purpose of code suffix is to avoid uniqueness
-     * collision between indexes for temp and real tables.
+     * collision between indexes for temporary and real tables.
      */
     protected String getIndexName( AnalyticsIndex inx )
     {
-        return quote( PREFIX_INDEX + removeQuote( removeTemp( inx.getColumn() ) ) + "_" + inx.getTable() + "_" + CodeGenerator.generateCode( 5 ) );        
+        return quote( PREFIX_INDEX + removeQuote( inx.getColumn() ) + "_" + shortenTableName( inx.getTable() ) + "_" + CodeGenerator.generateCode( 5 ) );        
     }
     
     /**

=== 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	2015-02-24 21:18:42 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-02-24 23:41:01 +0000
@@ -261,8 +261,8 @@
             String dataClause = dataElement.isNumericType() ? numericClause : "";
             String select = dataElement.isNumericType() ? doubleSelect : "value";
 
-            String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=" + 
-                "psi.programstageinstanceid and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote( dataElement.getUid() );
+            String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + 
+                "and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote( dataElement.getUid() );
 
             String[] col = { quote( dataElement.getUid() ), dataType, sql };
             columns.add( col );
@@ -274,8 +274,8 @@
             
             String sql = "(select l.name from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
                 "inner join trackedentitydatavalue dv on l.startvalue <= " + doubleSelect + " and l.endvalue > " + doubleSelect + " " +
-                "and lsl.legendsetid=" + dataElement.getLegendSet().getId() + " and dv.programstageinstanceid=" + 
-                "psi.programstageinstanceid and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
+                "and lsl.legendsetid=" + dataElement.getLegendSet().getId() + " and dv.programstageinstanceid=psi.programstageinstanceid " + 
+                "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
                 
             String[] col = { column, "character varying(230)", sql };
             columns.add( col );
@@ -287,12 +287,25 @@
             String dataClause = attribute.isNumericType() ? numericClause : "";
             String select = attribute.isNumericType() ? doubleSelect : "value";
 
-            String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid and " + 
-                "trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote( attribute.getUid() );
+            String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + 
+                "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote( attribute.getUid() );
 
             String[] col = { quote( attribute.getUid() ), dataType, sql };
             columns.add( col );
         }
+        
+        for ( TrackedEntityAttribute attribute : table.getProgram().getTrackedEntityAttributesWithLegendSet() )
+        {
+            String column = quote( attribute.getUid() + PartitionUtils.SEP + attribute.getLegendSet().getUid() );
+            
+            String sql = "(select l.name from maplegend l inner join maplegendsetmaplegend lsl on l.maplegendid=lsl.maplegendid " +
+                "inner join trackedentityattributevalue av on l.startvalue <= " + doubleSelect + " and l.endvalue > " + doubleSelect + " " +
+                "and lsl.legendsetid=" + attribute.getLegendSet().getId() + " and av.trackedentityinstanceid=pi.trackedentityinstanceid " +
+                "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
+            
+            String[] col = { column, "character varying(230)", sql };
+            columns.add( col );
+        }
 
         String[] psi = { quote( "psi" ), "character(11) not null", "psi.uid" };
         String[] pi = { quote( "pi" ), "character(11) not null", "pi.uid" };

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowAddAttributeFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowAddAttributeFormAction.java	2015-02-24 21:48:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowAddAttributeFormAction.java	2015-02-24 23:41:01 +0000
@@ -29,6 +29,7 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.legend.LegendService;
@@ -99,12 +100,13 @@
     public String execute()
         throws Exception
     {
-        periodTypes = periodService.getAllPeriodTypes();
-        
+        periodTypes = periodService.getAllPeriodTypes();        
         optionSets =  new ArrayList<>( optionService.getAllOptionSets() );
-        
         legendSets = legendService.getAllLegendSets();
         
+        Collections.sort( optionSets );
+        Collections.sort( legendSets );
+        
         return SUCCESS;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowUpdateAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowUpdateAttributeAction.java	2015-02-24 21:48:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/ShowUpdateAttributeAction.java	2015-02-24 23:41:01 +0000
@@ -29,7 +29,7 @@
  */
 
 import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.legend.LegendService;
@@ -101,9 +101,9 @@
         return attribute;
     }
 
-    private Collection<Program> programs;
+    private List<Program> programs;
 
-    public Collection<Program> getPrograms()
+    public List<Program> getPrograms()
     {
         return programs;
     }
@@ -138,17 +138,16 @@
         throws Exception
     {
         attribute = attributeService.getTrackedEntityAttribute( id );
-
-        programs = programService.getAllPrograms();
-
+        programs = new ArrayList<Program>( programService.getAllPrograms() );
         programs.removeAll( programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) );
-
         periodTypes = periodService.getAllPeriodTypes();
-
         optionSets = new ArrayList<>( optionService.getAllOptionSets() );
-
         legendSets = legendService.getAllLegendSets();
 
+        Collections.sort( programs );
+        Collections.sort( optionSets );
+        Collections.sort( legendSets );
+        
         return SUCCESS;
     }
 }