← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20617: Event analytics. Impl support for program indicators in event reports/charts.

 

------------------------------------------------------------
revno: 20617
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-10-11 22:24:39 +0200
message:
  Event analytics. Impl support for program indicators in event reports/charts.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityProgramIndicatorDimension.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramIndicatorDimension.hbm.xml
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventchart/EventChart.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventreport/EventReport.hbm.xml


--
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-10-11 19:50:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2015-10-11 20:24:39 +0000
@@ -77,6 +77,7 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension;
 import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
+import org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension;
 import org.hisp.dhis.user.User;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -148,6 +149,9 @@
     @Scanned
     protected List<TrackedEntityDataElementDimension> dataElementDimensions = new ArrayList<>();
     
+    @Scanned
+    protected List<TrackedEntityProgramIndicatorDimension> programIndicatorDimensions = new ArrayList<>();
+ 
     private Program program;
 
     protected boolean userOrganisationUnit;
@@ -475,6 +479,17 @@
 
                 return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_DATAELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter() );
             }
+
+            // Tracked entity program indicator
+            
+            Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex( programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid );
+                        
+            if ( programIndicators.containsKey( dimension ) )
+            {
+                TrackedEntityProgramIndicatorDimension teid = programIndicators.get( dimension );
+                
+                return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter() );
+            }            
         }
 
         IdentifiableObjectUtils.removeDuplicates( items );
@@ -657,6 +672,17 @@
 
                 return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_DATAELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter() );
             }
+
+            // Tracked entity program indicator
+            
+            Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex( programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid );
+                        
+            if ( programIndicators.containsKey( dimension ) )
+            {
+                TrackedEntityProgramIndicatorDimension teid = programIndicators.get( dimension );
+                
+                return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter() );
+            }
         }
 
         throw new IllegalArgumentException( "Not a valid dimension: " + dimension );
@@ -797,6 +823,7 @@
         categoryOptionGroups.clear();
         attributeDimensions.clear();
         dataElementDimensions.clear();
+        programIndicatorDimensions.clear();
         userOrganisationUnit = false;
         userOrganisationUnitChildren = false;
         userOrganisationUnitGrandChildren = false;
@@ -837,6 +864,7 @@
             categoryOptionGroups.addAll( object.getCategoryOptionGroups() );
             attributeDimensions.addAll( object.getAttributeDimensions() );
             dataElementDimensions.addAll( object.getDataElementDimensions() );
+            programIndicatorDimensions.addAll( object.getProgramIndicatorDimensions() );
             userOrganisationUnitChildren = object.isUserOrganisationUnitChildren();
             userOrganisationUnitGrandChildren = object.isUserOrganisationUnitGrandChildren();
             itemOrganisationUnitGroups = object.getItemOrganisationUnitGroups();
@@ -1009,6 +1037,20 @@
     }
 
     @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "programIndicatorDimensions", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "programIndicatorDimension", namespace = DxfNamespaces.DXF_2_0 )
+    public List<TrackedEntityProgramIndicatorDimension> getProgramIndicatorDimensions()
+    {
+        return programIndicatorDimensions;
+    }
+
+    public void setProgramIndicatorDimensions( List<TrackedEntityProgramIndicatorDimension> programIndicatorDimensions )
+    {
+        this.programIndicatorDimensions = programIndicatorDimensions;
+    }
+
+    @JsonProperty
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityProgramIndicatorDimension.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityProgramIndicatorDimension.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityProgramIndicatorDimension.java	2015-10-11 20:24:39 +0000
@@ -0,0 +1,208 @@
+package org.hisp.dhis.trackedentity;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.legend.LegendSet;
+import org.hisp.dhis.program.ProgramIndicator;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+
+/**
+* @author Lars Helge Overland
+*/
+@JacksonXmlRootElement( localName = "programIndicatorDimension", namespace = DxfNamespaces.DXF_2_0 )
+public class TrackedEntityProgramIndicatorDimension
+{
+    private int id;
+    
+    /**
+     * Program indicator.
+     */
+    private ProgramIndicator programIndicator;
+
+    /**
+     * Legend set.
+     */
+    private LegendSet legendSet;
+    
+    /**
+     * Operator and filter on this format:
+     * <operator>:<filter>;<operator>:<filter>
+     * Operator and filter pairs can be repeated any number of times.
+     */
+    private String filter;
+    
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public TrackedEntityProgramIndicatorDimension()
+    {
+    }
+    
+    public TrackedEntityProgramIndicatorDimension( ProgramIndicator programIndicator, LegendSet legendSet, String filter )
+    {
+        this.programIndicator = programIndicator;
+        this.legendSet = legendSet;
+        this.filter = filter;
+    }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public String getUid()
+    {
+        return programIndicator != null ? programIndicator.getUid() : null;
+    }
+    
+    public String getDisplayName()
+    {
+        return programIndicator != null ? programIndicator.getDisplayName() : null;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "[Id: " + id + ", program indicator: " + programIndicator + ", legend set: " + legendSet + ", filter: " + filter + "]";
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int result = id;
+        result = 31 * result + ( programIndicator != null ? programIndicator.hashCode() : 0 );
+        result = 31 * result + ( legendSet != null ? legendSet.hashCode() : 0 );
+        result = 31 * result + ( filter != null ? filter.hashCode() : 0 );
+
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+
+        if ( o == null )
+        {
+            return false;
+        }
+
+        if ( !getClass().isAssignableFrom( o.getClass() ) )
+        {
+            return false;
+        }
+
+        final TrackedEntityProgramIndicatorDimension other = (TrackedEntityProgramIndicatorDimension) o;
+
+        if ( programIndicator != null ? !programIndicator.equals( other.programIndicator ) : other.programIndicator != null )
+        {
+            return false;
+        }
+        
+        if ( legendSet != null ? !legendSet.equals( other.legendSet ) : other.legendSet != null )
+        {
+            return false;
+        }
+        
+        if ( filter != null ? !filter.equals( other.filter ) : other.filter != null )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public int getId()
+    {
+        return id;
+    }
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JsonView( {DetailedView.class, ExportView.class} )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    public ProgramIndicator getProgramIndicator()
+    {
+        return programIndicator;
+    }
+
+    public void setProgramIndicator( ProgramIndicator programIndicator )
+    {
+        this.programIndicator = programIndicator;
+    }
+
+    @JsonProperty
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JsonView( {DetailedView.class, ExportView.class} )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    public LegendSet getLegendSet()
+    {
+        return legendSet;
+    }
+
+    public void setLegendSet( LegendSet legendSet )
+    {
+        this.legendSet = legendSet;
+    }
+
+    @JsonProperty
+    @JsonView( {DetailedView.class, ExportView.class} )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    public String getFilter()
+    {
+        return filter;
+    }
+
+    public void setFilter( String filter )
+    {
+        this.filter = filter;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2015-10-08 13:50:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2015-10-11 20:24:39 +0000
@@ -37,6 +37,7 @@
 import static org.hisp.dhis.common.DimensionType.PERIOD;
 import static org.hisp.dhis.common.DimensionType.PROGRAM_ATTRIBUTE;
 import static org.hisp.dhis.common.DimensionType.PROGRAM_DATAELEMENT;
+import static org.hisp.dhis.common.DimensionType.PROGRAM_INDICATOR;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.commons.util.TextUtils.splitSafe;
 import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
@@ -87,10 +88,12 @@
 import org.hisp.dhis.period.RelativePeriodEnum;
 import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.security.acl.AclService;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension;
 import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
+import org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -174,6 +177,14 @@
             return pde;
         }
         
+        ProgramIndicator pin = identifiableObjectManager.get( ProgramIndicator.class, uid );
+        
+        if ( pin != null )
+        {
+            pin.setDimensionType( DimensionType.PROGRAM_INDICATOR );
+            return pin;
+        }
+        
         return null;
     }
     
@@ -283,6 +294,13 @@
         {
             return DimensionType.PROGRAM_DATAELEMENT;
         }
+        
+        ProgramIndicator pin = identifiableObjectManager.get( ProgramIndicator.class, uid );
+        
+        if ( pin != null )
+        {
+            return DimensionType.PROGRAM_INDICATOR;
+        }
 
         final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
 
@@ -568,6 +586,15 @@
                     
                     object.getDataElementDimensions().add( dataElementDimension );
                 }
+                else if ( PROGRAM_INDICATOR.equals( type ) )
+                {
+                    TrackedEntityProgramIndicatorDimension programIndicatorDimension = new TrackedEntityProgramIndicatorDimension();
+                    programIndicatorDimension.setProgramIndicator( identifiableObjectManager.get( ProgramIndicator.class, dimensionId ) );
+                    programIndicatorDimension.setLegendSet( dimension.hasLegendSet() ? identifiableObjectManager.get( LegendSet.class, dimension.getLegendSet().getUid() ) : null );
+                    programIndicatorDimension.setFilter( dimension.getFilter() );
+                    
+                    object.getProgramIndicatorDimensions().add( programIndicatorDimension );
+                }
             }
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventchart/EventChart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventchart/EventChart.hbm.xml	2015-09-15 11:43:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventchart/EventChart.hbm.xml	2015-10-11 20:24:39 +0000
@@ -73,6 +73,13 @@
         foreign-key="fk_eventchart_dataelementdimensions_dataelementdimensionid" />
     </list>
 
+    <list name="programIndicatorDimensions" table="eventchart_programindicatordimensions" cascade="all, delete-orphan">
+      <key column="eventchartid" foreign-key="fk_eventchart_programindicatordimensions_eventchartid" />
+      <list-index column="sort_order" base="0" />
+      <many-to-many column="trackedentityprogramindicatordimensionid" class="org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension"
+        foreign-key="fk_eventchart_programindicatordimensions_programindicatordimensionid" />
+    </list>
+
     <property name="userOrganisationUnit" />
 
     <property name="userOrganisationUnitChildren" />

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventreport/EventReport.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventreport/EventReport.hbm.xml	2015-09-17 07:17:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/eventreport/EventReport.hbm.xml	2015-10-11 20:24:39 +0000
@@ -73,6 +73,13 @@
         foreign-key="fk_eventreport_dataelementdimensions_dataelementdimensionid" />
     </list>
 
+    <list name="programIndicatorDimensions" table="eventreport_programindicatordimensions" cascade="all, delete-orphan">
+      <key column="eventreportid" foreign-key="fk_eventreport_programindicatordimensions_eventreportid" />
+      <list-index column="sort_order" base="0" />
+      <many-to-many column="trackedentityprogramindicatordimensionid" class="org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension"
+        foreign-key="fk_eventreport_programindicatordimensions_programindicatordimensionid" />
+    </list>
+
     <property name="userOrganisationUnit" />
 
     <property name="userOrganisationUnitChildren" />

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramIndicatorDimension.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramIndicatorDimension.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityProgramIndicatorDimension.hbm.xml	2015-10-11 20:24:39 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
+
+<hibernate-mapping>
+  <class name="org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension" table="trackedentityprogramindicatordimension">
+
+    <id name="id" column="trackedentityprogramindicatordimensionid">
+      <generator class="native" />
+    </id>
+
+    <many-to-one name="programIndicator" class="org.hisp.dhis.program.ProgramIndicator" 
+        column="programindicatorid" foreign-key="fk_programindicatordimension_programindicatorid" />
+
+	<many-to-one name="legendSet" class="org.hisp.dhis.legend.LegendSet"
+		column="legendsetid" foreign-key="fk_dataelementdimension_legendsetid" />
+
+    <property name="filter" />
+
+  </class>
+</hibernate-mapping>