dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39453
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19972: Event analytics. Impl support for program indicators for individual event query. Better approach ...
------------------------------------------------------------
revno: 19972
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-03 17:30:38 +0200
message:
Event analytics. Impl support for program indicators for individual event query. Better approach this time.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.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/event/data/DefaultEventAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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/QueryItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java 2015-09-03 15:25:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryItem.java 2015-09-03 15:30:38 +0000
@@ -111,7 +111,7 @@
public String getTypeAsString()
{
- return valueType.getJavaClass().toString();
+ return valueType.getJavaClass().getName();
}
public boolean isNumeric()
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2015-09-02 16:15:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2015-09-03 15:30:38 +0000
@@ -35,10 +35,12 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.collect.Sets;
+
import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DimensionType;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.MergeStrategy;
@@ -587,6 +589,16 @@
}
// -------------------------------------------------------------------------
+ // DimensionalObject
+ // -------------------------------------------------------------------------
+
+ @Override
+ public DimensionType getDimensionType()
+ {
+ return DimensionType.PROGRAM_DATAELEMENT;
+ }
+
+ // -------------------------------------------------------------------------
// Helper getters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-09-03 08:15:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-09-03 15:30:38 +0000
@@ -28,16 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-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 com.google.common.collect.Sets;
+import java.util.Set;
+import java.util.regex.Pattern;
+
import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.analytics.EventOutputType;
+import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.BaseNameableObject;
+import org.hisp.dhis.common.DimensionType;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.MergeStrategy;
@@ -45,15 +43,19 @@
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
-import java.util.Set;
-import java.util.regex.Pattern;
+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 com.google.common.collect.Sets;
/**
* @author Chau Thu Tran
*/
@JacksonXmlRootElement( localName = "programIndicator", namespace = DxfNamespaces.DXF_2_0 )
public class ProgramIndicator
- extends BaseNameableObject
+ extends BaseDimensionalObject
{
public static final String SEPARATOR_ID = "\\.";
public static final String SEP_OBJECT = ":";
@@ -95,8 +97,6 @@
private String filter;
- private AggregationType aggregationType;
-
private EventOutputType eventOutputType;
/**
@@ -153,7 +153,17 @@
}
// -------------------------------------------------------------------------
- // Getters && Setters
+ // DimensionalObject
+ // -------------------------------------------------------------------------
+
+ @Override
+ public DimensionType getDimensionType()
+ {
+ return DimensionType.PROGRAM_INDICATOR;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getters and setters
// -------------------------------------------------------------------------
@JsonProperty
@@ -212,19 +222,6 @@
@JsonProperty
@JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public AggregationType getAggregationType()
- {
- return aggregationType;
- }
-
- public void setAggregationType( AggregationType aggregationType )
- {
- this.aggregationType = aggregationType;
- }
-
- @JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public EventOutputType getEventOutputType()
{
return eventOutputType;
=== 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-09-03 08:15:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java 2015-09-03 15:30:38 +0000
@@ -34,9 +34,11 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DimensionType;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.MergeStrategy;
@@ -181,6 +183,16 @@
}
// -------------------------------------------------------------------------
+ // DimensionalObject
+ // -------------------------------------------------------------------------
+
+ @Override
+ public DimensionType getDimensionType()
+ {
+ return DimensionType.PROGRAM_ATTRIBUTE;
+ }
+
+ // -------------------------------------------------------------------------
// Helper getters
// -------------------------------------------------------------------------
=== 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 15:25:27 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2015-09-03 15:30:38 +0000
@@ -76,6 +76,7 @@
import org.hisp.dhis.common.QueryFilter;
import org.hisp.dhis.common.QueryItem;
import org.hisp.dhis.common.QueryOperator;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.collection.ListUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
@@ -85,6 +86,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;
@@ -132,6 +135,9 @@
private TrackedEntityAttributeService attributeService;
@Autowired
+ ProgramIndicatorService programIndicatorService;
+
+ @Autowired
private OrganisationUnitService organisationUnitService;
@Autowired
@@ -700,6 +706,13 @@
{
return new QueryItem( at, legendSet, at.getValueType(), at.getAggregationType(), at.getOptionSet() );
}
+
+ ProgramIndicator pi = programIndicatorService.getProgramIndicatorByUid( item );
+
+ if ( pi != null )
+ {
+ return new QueryItem( pi, legendSet, ValueType.NUMBER, pi.getAggregationType(), null );
+ }
throw new IllegalQueryException( "Item identifier does not reference any data element or attribute part of the program: " + item );
}
=== 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-09-03 15:25:27 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2015-09-03 15:30:38 +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,21 @@
{
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++;
}
}
}
@@ -386,8 +396,17 @@
}
for ( QueryItem queryItem : params.getItems() )
- {
- sql += statementBuilder.columnQuote( queryItem.getItemName() ) + ",";
+ {
+ if ( DimensionType.PROGRAM_INDICATOR.equals( queryItem.getItem().getDimensionType() ) )
+ {
+ ProgramIndicator in = (ProgramIndicator) queryItem.getItem();
+
+ sql += "(" + programIndicatorService.getAnalyticsSQl( in.getExpression() ) + "),";
+ }
+ else
+ {
+ sql += statementBuilder.columnQuote( queryItem.getItemName() ) + ",";
+ }
}
return removeLastComma( sql );