dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37966
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19398: Analytics, added support for program/tracker data elements in aggregate analytics call. Will retu...
------------------------------------------------------------
revno: 19398
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-06-14 17:30:53 +0200
message:
Analytics, added support for program/tracker data elements in aggregate analytics call. Will return aggregated values per data element.
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.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/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AnalyticsController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2015-03-26 14:25:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2015-06-14 15:30:53 +0000
@@ -164,12 +164,14 @@
* @param displayProperty the property to display for meta-data.
* @param outputIdScheme the identifier scheme to use in the query response.
* @param approvalLevel the approval level identifier.
+ * @param program the program identifier.
+ * @param stage the program stage identifier.
* @param format the i18n format.
* @return a data query parameter object created based on the given URL info.
*/
DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams, AggregationType aggregationType, String measureCriteria,
boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, boolean ignoreLimit, boolean hideEmptyRows, boolean showHierarchy,
- DisplayProperty displayProperty, IdentifiableProperty outputIdScheme, String approvalLevel, I18nFormat format );
+ DisplayProperty displayProperty, IdentifiableProperty outputIdScheme, String approvalLevel, String program, String stage, I18nFormat format );
/**
* Creates a data query parameter object from the given BaseAnalyticalObject.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-06-14 14:37:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-06-14 15:30:53 +0000
@@ -42,6 +42,7 @@
import static org.hisp.dhis.common.DimensionalObject.INDICATOR_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObject.PROGRAM_DATAELEMENT_DIM_ID;
import static org.hisp.dhis.common.NameableObjectUtils.asList;
import static org.hisp.dhis.common.NameableObjectUtils.getList;
@@ -77,6 +78,8 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.util.CollectionUtils;
import org.hisp.dhis.util.ListUtils;
import org.hisp.dhis.system.util.MathUtils;
@@ -101,8 +104,12 @@
public static final int DE_IN_INDEX = 0;
public static final int CO_IN_INDEX = 1;
- public static final List<String> DATA_DIMS = Arrays.asList( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATAELEMENT_OPERAND_ID, DATASET_DIM_ID );
- public static final List<String> FIXED_DIMS = Arrays.asList( DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
+ public static final List<String> DATA_DIMS = Arrays.asList(
+ INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATAELEMENT_OPERAND_ID, DATASET_DIM_ID, PROGRAM_DATAELEMENT_DIM_ID );
+ public static final List<String> FIXED_DIMS = Arrays.asList(
+ DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PROGRAM_DATAELEMENT_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
+ private static final List<String> DIMENSION_PERMUTATION_IGNORE_DIMS = Arrays.asList(
+ INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, CATEGORYOPTIONCOMBO_DIM_ID, DATASET_DIM_ID, PROGRAM_DATAELEMENT_DIM_ID );
private static final List<DimensionType> COMPLETENESS_DIMENSION_TYPES = Arrays.asList( DATASET, ORGANISATIONUNIT, ORGANISATIONUNIT_GROUPSET );
@@ -115,7 +122,7 @@
protected AggregationType aggregationType;
- private Map<MeasureFilter, Double> measureCriteria = new HashMap<>();
+ protected Map<MeasureFilter, Double> measureCriteria = new HashMap<>();
/**
* Indicates if the meta data part of the query response should be omitted.
@@ -133,25 +140,25 @@
* path of all organisation units part of the query should be included as a
* "ouHierarchy" key in the meta-data part of the response.
*/
- private boolean hierarchyMeta;
+ protected boolean hierarchyMeta;
/**
* Indicates whether the maximum number of records to include the response
* should be ignored.
*/
- private boolean ignoreLimit;
+ protected boolean ignoreLimit;
/**
* Indicates whether rows with no values should be hidden in the response.
* Applies to responses with table layout only.
*/
- private boolean hideEmptyRows;
+ protected boolean hideEmptyRows;
/**
* Indicates whether the org unit hierarchy path should be displayed with the
* org unit names on rows.
*/
- private boolean showHierarchy;
+ protected boolean showHierarchy;
/**
* Indicates which property to display for meta-data.
@@ -167,6 +174,20 @@
* The required approval level identifier for data to be included in query response.
*/
protected String approvalLevel;
+
+ // -------------------------------------------------------------------------
+ // Event properties
+ // -------------------------------------------------------------------------
+
+ /**
+ * The program for events.
+ */
+ protected Program program;
+
+ /**
+ * The program stage for events.
+ */
+ protected ProgramStage programStage;
// -------------------------------------------------------------------------
// Transient properties
@@ -190,17 +211,17 @@
/**
* The period type of the data values to query.
*/
- private transient PeriodType dataPeriodType;
+ protected transient PeriodType dataPeriodType;
/**
* Indicates whether to skip partitioning during query planning.
*/
- private transient boolean skipPartitioning;
+ protected transient boolean skipPartitioning;
/**
* Mapping of organisation unit sub-hierarchy roots and lowest available data approval levels.
*/
- private transient Map<OrganisationUnit, Integer> dataApprovalLevels = new HashMap<>();
+ protected transient Map<OrganisationUnit, Integer> dataApprovalLevels = new HashMap<>();
// -------------------------------------------------------------------------
// Constructors
@@ -212,8 +233,11 @@
public DataQueryParams instance()
{
- DataQueryParams params = new DataQueryParams();
-
+ return copyTo( new DataQueryParams() );
+ }
+
+ public <T extends DataQueryParams> T copyTo( T params )
+ {
params.dimensions = new ArrayList<>( this.dimensions );
params.filters = new ArrayList<>( this.filters );
params.aggregationType = this.aggregationType;
@@ -227,6 +251,8 @@
params.displayProperty = this.displayProperty;
params.outputIdScheme = this.outputIdScheme;
params.approvalLevel = this.approvalLevel;
+ params.program = this.program;
+ params.programStage = this.programStage;
params.partitions = new Partitions( this.partitions );
params.dataType = this.dataType;
@@ -251,7 +277,8 @@
{
if ( !dimensions.contains( new BaseDimensionalObject( DATAELEMENT_DIM_ID ) ) ||
dimensions.contains( new BaseDimensionalObject( INDICATOR_DIM_ID ) ) ||
- dimensions.contains( new BaseDimensionalObject( DATASET_DIM_ID ) ) )
+ dimensions.contains( new BaseDimensionalObject( DATASET_DIM_ID ) ) ||
+ dimensions.contains( new BaseDimensionalObject( PROGRAM_DATAELEMENT_DIM_ID ) ) )
{
removeDimension( CATEGORYOPTIONCOMBO_DIM_ID );
}
@@ -301,9 +328,9 @@
/**
* Creates a list of dimensions for use as headers. Will replace any of
- * the indicator, data element or data set dimensions with the common
- * data x dimension. If the category option combo dimension is given but
- * not the data element dimension, the former will be removed.
+ * the indicator, data element, data set or program data element dimensions
+ * with the common data x dimension. If the category option combo dimension
+ * is given but not the data element dimension, the former will be removed.
*/
public List<DimensionalObject> getHeaderDimensions()
{
@@ -323,6 +350,7 @@
list.remove( new BaseDimensionalObject( INDICATOR_DIM_ID ) );
list.remove( new BaseDimensionalObject( DATAELEMENT_DIM_ID ) );
list.remove( new BaseDimensionalObject( DATASET_DIM_ID ) );
+ list.remove( new BaseDimensionalObject( PROGRAM_DATAELEMENT_DIM_ID ) );
return list;
}
@@ -423,7 +451,7 @@
{
for ( String dim : dimension )
{
- this.dimensions.remove( new BaseDimensionalObject( dim ) );
+ removeDimension( dim );
}
}
@@ -707,11 +735,9 @@
{
List<DimensionItem[]> dimensionOptions = new ArrayList<>();
- List<String> ignoreDims = Arrays.asList( DATAELEMENT_DIM_ID, CATEGORYOPTIONCOMBO_DIM_ID, INDICATOR_DIM_ID, DATASET_DIM_ID );
-
for ( DimensionalObject dimension : dimensions )
{
- if ( !ignoreDims.contains( dimension.getDimension() ) )
+ if ( !DIMENSION_PERMUTATION_IGNORE_DIMS.contains( dimension.getDimension() ) )
{
List<DimensionItem> options = new ArrayList<>();
@@ -936,6 +962,14 @@
return items;
}
+
+ /**
+ * Indicates whether this object has a program.
+ */
+ public boolean hasProgram()
+ {
+ return program != null;
+ }
// -------------------------------------------------------------------------
// Static methods
@@ -1281,6 +1315,26 @@
this.approvalLevel = approvalLevel;
}
+ public Program getProgram()
+ {
+ return program;
+ }
+
+ public void setProgram( Program program )
+ {
+ this.program = program;
+ }
+
+ public ProgramStage getProgramStage()
+ {
+ return programStage;
+ }
+
+ public void setProgramStage( ProgramStage programStage )
+ {
+ this.programStage = programStage;
+ }
+
// -------------------------------------------------------------------------
// Get and set methods for transient properties
// -------------------------------------------------------------------------
@@ -1474,7 +1528,7 @@
{
setDimensionOptions( DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, null, asList( dataElements ) );
}
-
+
public void setDataElement( NameableObject dataElement )
{
setDataElements( getList( dataElement ) );
@@ -1524,6 +1578,16 @@
{
setOrganisationUnits( getList( organisationUnit ) );
}
+
+ public List<NameableObject> getProgramDataElements()
+ {
+ return getDimensionOptions( PROGRAM_DATAELEMENT_DIM_ID );
+ }
+
+ public void setProgramDataElements( List<? extends NameableObject> trackerDataElements )
+ {
+ setDimensionOptions( PROGRAM_DATAELEMENT_DIM_ID, DimensionType.PROGRAM_DATAELEMENT, null, asList( trackerDataElements ) );
+ }
public List<DimensionalObject> getDataElementGroupSets()
{
@@ -1611,9 +1675,15 @@
{
setFilterOrganisationUnits( getList( organisationUnit ) );
}
+
+ public List<NameableObject> getFilterProgramDataElements()
+ {
+ return getFilterOptions( PROGRAM_DATAELEMENT_DIM_ID );
+ }
public void setFilter( String filter, DimensionType type, NameableObject item )
{
setFilterOptions( filter, type, null, getList( item ) );
}
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-14 14:37:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-14 15:30:53 +0000
@@ -51,6 +51,7 @@
import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PROGRAM_INDICATOR_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObject.PROGRAM_DATAELEMENT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
import static org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriodIdentifier;
import static org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriodIdentifiers;
@@ -90,6 +91,8 @@
import org.hisp.dhis.analytics.DataQueryParams;
import org.hisp.dhis.analytics.DimensionItem;
import org.hisp.dhis.analytics.QueryPlanner;
+import org.hisp.dhis.analytics.event.EventAnalyticsService;
+import org.hisp.dhis.analytics.event.EventQueryParams;
import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateTimeUnit;
import org.hisp.dhis.common.AnalyticalObject;
@@ -117,6 +120,7 @@
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementDomain;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementOperand;
@@ -135,17 +139,19 @@
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.period.comparator.AscendingPeriodEndDateComparator;
import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.reporttable.ReportTable;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.grid.ListGrid;
import org.hisp.dhis.system.util.MathUtils;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
import org.hisp.dhis.util.DebugUtils;
import org.hisp.dhis.util.ListUtils;
import org.hisp.dhis.util.SystemUtils;
+import org.hisp.dhis.util.Timer;
import org.hisp.dhis.util.UniqueArrayList;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.util.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Lists;
@@ -193,6 +199,15 @@
private SystemSettingManager systemSettingManager;
@Autowired
+ private EventAnalyticsService eventAnalyticsService;
+
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private ProgramStageService programStageService;
+
+ @Autowired
private CurrentUserService currentUserService;
public void setCurrentUserService( CurrentUserService currentUserService )
@@ -238,6 +253,8 @@
addDataElementValues( params, grid );
addDataSetValues( params, grid );
+
+ addProgramDataElementValues( params, grid );
addDynamicDimensionValues( params, grid );
@@ -352,6 +369,7 @@
DataQueryParams dataSourceParams = params.instance();
dataSourceParams.removeDimension( INDICATOR_DIM_ID );
dataSourceParams.removeDimension( DATASET_DIM_ID );
+ dataSourceParams.removeDimension( PROGRAM_DATAELEMENT_DIM_ID );
Map<String, Object> aggregatedDataMap = getAggregatedDataValueMapObjectTyped( dataSourceParams );
@@ -363,6 +381,30 @@
}
}
}
+
+ /**
+ * Adds program data element values to the given grid based on the given data
+ * query parameters.
+ *
+ * @param params the data query parameters.
+ * @param grid the grid.
+ */
+ private void addProgramDataElementValues( DataQueryParams params, Grid grid )
+ {
+ if ( params.getProgramDataElements() != null )
+ {
+ DataQueryParams dataSourceParams = params.instance();
+ dataSourceParams.removeDimension( INDICATOR_DIM_ID );
+ dataSourceParams.removeDimension( DATASET_DIM_ID );
+ dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
+
+ EventQueryParams eventQueryParams = EventQueryParams.fromDataQueryParams( dataSourceParams );
+
+ Grid eventGrid = eventAnalyticsService.getAggregatedEventData( eventQueryParams );
+
+ grid.addRows( eventGrid );
+ }
+ }
/**
* Adds data set values to the given grid based on the given data query
@@ -383,6 +425,7 @@
dataSourceParams.ignoreDataApproval(); // No approval for reporting rates
dataSourceParams.removeDimension( INDICATOR_DIM_ID );
dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
+ dataSourceParams.removeDimension( PROGRAM_DATAELEMENT_DIM_ID );
dataSourceParams.setAggregationType( AggregationType.COUNT );
Map<String, Double> aggregatedDataMap = getAggregatedCompletenessValueMap( dataSourceParams );
@@ -447,7 +490,7 @@
*/
private void addDynamicDimensionValues( DataQueryParams params, Grid grid )
{
- if ( params.getIndicators() == null && params.getDataElements() == null && params.getDataSets() == null )
+ if ( params.getIndicators() == null && params.getDataElements() == null && params.getDataSets() == null && params.getProgramDataElements() == null )
{
Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( params.instance() );
@@ -814,7 +857,8 @@
@Override
public DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams, AggregationType aggregationType,
String measureCriteria, boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, boolean ignoreLimit,
- boolean hideEmptyRows, boolean showHierarchy, DisplayProperty displayProperty, IdentifiableProperty outputIdScheme, String approvalLevel, I18nFormat format )
+ boolean hideEmptyRows, boolean showHierarchy, DisplayProperty displayProperty, IdentifiableProperty outputIdScheme,
+ String approvalLevel, String program, String stage, I18nFormat format )
{
DataQueryParams params = new DataQueryParams();
@@ -845,6 +889,16 @@
params.setOutputIdScheme( outputIdScheme );
params.setApprovalLevel( approvalLevel );
+ if ( program != null )
+ {
+ params.setProgram( programService.getProgram( program ) );
+ }
+
+ if ( stage != null )
+ {
+ params.setProgramStage( programStageService.getProgramStage( stage ) );
+ }
+
return params;
}
@@ -917,6 +971,7 @@
List<NameableObject> dataElements = new ArrayList<>();
List<NameableObject> dataSets = new ArrayList<>();
List<NameableObject> operandDataElements = new ArrayList<>();
+ List<NameableObject> programDataElements = new ArrayList<>();
itemLoop:
for ( String uid : items )
@@ -945,11 +1000,16 @@
DataElement de = idObjectManager.get( DataElement.class, uid );
- if ( de != null )
+ if ( de != null && DataElementDomain.AGGREGATE.equals( de.getDomainType() ) )
{
dataElements.add( de );
continue itemLoop;
}
+ else if ( de != null && DataElementDomain.TRACKER.equals( de.getDomainType() ) )
+ {
+ programDataElements.add( de );
+ continue itemLoop;
+ }
DataSet ds = idObjectManager.get( DataSet.class, uid );
@@ -998,8 +1058,13 @@
dataDimensions.add( new BaseDimensionalObject( DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, operandDataElements ) );
dataDimensions.add( new BaseDimensionalObject( CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<NameableObject>() ) );
}
+
+ if ( !programDataElements.isEmpty() )
+ {
+ dataDimensions.add( new BaseDimensionalObject( PROGRAM_DATAELEMENT_DIM_ID, DimensionType.PROGRAM_DATAELEMENT, programDataElements ) );
+ }
- if ( indicators.isEmpty() && dataElements.isEmpty() && dataSets.isEmpty() && operandDataElements.isEmpty() )
+ if ( indicators.isEmpty() && dataElements.isEmpty() && dataSets.isEmpty() && operandDataElements.isEmpty() && programDataElements.isEmpty() )
{
throw new IllegalQueryException( "Dimension dx is present in query without any valid dimension options" );
}
@@ -1260,7 +1325,7 @@
if ( !dataElements.isEmpty() )
{
- DataQueryParams dataSourceParams = params.instance().removeDimensions( DATAELEMENT_DIM_ID, DATASET_DIM_ID, INDICATOR_DIM_ID );
+ DataQueryParams dataSourceParams = params.instance().removeDimensions( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PROGRAM_DATAELEMENT_DIM_ID );
dataSourceParams.getDimensions().add( DataQueryParams.DE_IN_INDEX, new BaseDimensionalObject(
DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) );
@@ -1286,7 +1351,7 @@
if ( !dataElements.isEmpty() )
{
- DataQueryParams dataSourceParams = params.instance().removeDimensions( DATAELEMENT_DIM_ID, DATASET_DIM_ID, INDICATOR_DIM_ID );
+ DataQueryParams dataSourceParams = params.instance().removeDimensions( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PROGRAM_DATAELEMENT_DIM_ID );
dataSourceParams.getDimensions().add( DataQueryParams.DE_IN_INDEX, new BaseDimensionalObject(
DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2015-06-14 15:30:53 +0000
@@ -36,6 +36,7 @@
import static org.hisp.dhis.common.DimensionalObject.INDICATOR_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObject.PROGRAM_DATAELEMENT_DIM_ID;
import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM;
import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
@@ -155,6 +156,11 @@
violation = "Category option combos cannot be specified when data elements are not specified";
}
+ if ( params.hasDimensionOrFilter( PROGRAM_DATAELEMENT_DIM_ID ) && !params.hasProgram() )
+ {
+ violation = "Program must be specified when tracker data elements are specified";
+ }
+
if ( violation != null )
{
log.warn( "Validation failed: " + violation );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java 2015-03-26 14:25:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java 2015-06-14 15:30:53 +0000
@@ -84,7 +84,7 @@
@Override
public DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams, AggregationType aggregationType,
String measureCriteria, boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, boolean ignoreLimit, boolean hideEmptyRows,
- boolean showHierarchy, DisplayProperty displayProperty, IdentifiableProperty idScheme, String approvalLevel, I18nFormat format )
+ boolean showHierarchy, DisplayProperty displayProperty, IdentifiableProperty idScheme, String approvalLevel, String program, String stage, I18nFormat format )
{
throw new NotImplementedException("");
}
=== 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 2015-06-13 21:26:59 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2015-06-14 15:30:53 +0000
@@ -30,6 +30,7 @@
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PROGRAM_INDICATOR_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObject.PROGRAM_DATAELEMENT_DIM_ID;
import java.util.ArrayList;
import java.util.Date;
@@ -45,12 +46,11 @@
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.NameableObjectUtils;
import org.hisp.dhis.common.QueryItem;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.legend.Legend;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
-import org.hisp.dhis.program.Program;
-import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.util.ListUtils;
/**
@@ -59,10 +59,6 @@
public class EventQueryParams
extends DataQueryParams
{
- private Program program;
-
- private ProgramStage programStage;
-
private Date startDate;
private Date endDate;
@@ -102,12 +98,12 @@
public EventQueryParams()
{
}
-
+
@Override
public EventQueryParams instance()
{
EventQueryParams params = new EventQueryParams();
-
+
params.dimensions = new ArrayList<>( this.dimensions );
params.filters = new ArrayList<>( this.filters );
params.displayProperty = this.displayProperty;
@@ -140,6 +136,32 @@
return params;
}
+
+ public static EventQueryParams fromDataQueryParams( DataQueryParams dataQueryParams )
+ {
+ EventQueryParams params = new EventQueryParams();
+
+ dataQueryParams.copyTo( params );
+
+ for ( NameableObject object : ListUtils.emptyIfNull( dataQueryParams.getProgramDataElements() ) )
+ {
+ DataElement element = (DataElement) object;
+ QueryItem item = new QueryItem( element, element.getLegendSet(), element.getType(), element.getOptionSet() );
+ params.getItems().add( item );
+ }
+
+ for ( NameableObject object : ListUtils.emptyIfNull( dataQueryParams.getFilterProgramDataElements() ) )
+ {
+ DataElement element = (DataElement) object;
+ QueryItem item = new QueryItem( element, element.getLegendSet(), element.getType(), element.getOptionSet() );
+ params.getItemFilters().add( item );
+ }
+
+ params.setAggregateData( true );
+ params.removeDimensionOrFilter( PROGRAM_DATAELEMENT_DIM_ID );
+
+ return params;
+ }
// -------------------------------------------------------------------------
// Logic
@@ -363,26 +385,6 @@
// Getters and setters
// -------------------------------------------------------------------------
- public Program getProgram()
- {
- return program;
- }
-
- public void setProgram( Program program )
- {
- this.program = program;
- }
-
- public ProgramStage getProgramStage()
- {
- return programStage;
- }
-
- public void setProgramStage( ProgramStage programStage )
- {
- this.programStage = programStage;
- }
-
public Date getStartDate()
{
return startDate;
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2015-03-26 14:25:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2015-06-14 15:30:53 +0000
@@ -168,7 +168,8 @@
Set<String> filterParams = new HashSet<>();
filterParams.add( "ou:" + ouA.getUid() + ";" + ouB.getUid() + ";" + ouC.getUid() + ";" + ouD.getUid() + ";" + ouE.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 3, params.getPeriods().size() );
@@ -185,7 +186,8 @@
Set<String> filterParams = new HashSet<>();
filterParams.add( "ou:" + ouA.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 1, params.getFilterOrganisationUnits().size() );
@@ -202,7 +204,8 @@
Set<String> filterParams = new HashSet<>();
filterParams.add( "ou:" + ouA.getUid() + ";" + ouB.getUid() + ";" + ouC.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 3, params.getDataElements().size() );
assertEquals( 2, params.getPeriods().size() );
@@ -220,7 +223,8 @@
Set<String> filterParams = new HashSet<>();
filterParams.add( "ou:" + ouA.getUid() + ";" + ouB.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 12, params.getPeriods().size() );
@@ -235,7 +239,8 @@
dimensionParams.add( "dx:" + deA.getUid() + ";" + deB.getUid() );
dimensionParams.add( "pe:2011;2012" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 1, params.getOrganisationUnits().size() );
assertEquals( 2, params.getDataElements().size() );
@@ -250,7 +255,8 @@
dimensionParams.add( "dx:" + deA.getUid() + ";" + deB.getUid() );
dimensionParams.add( "pe:2011;2012" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 3, params.getOrganisationUnits().size() );
assertEquals( 2, params.getDataElements().size() );
@@ -265,7 +271,8 @@
dimensionParams.add( "dx:" + deA.getUid() + ";" + deB.getUid() );
dimensionParams.add( "pe:2011;2012" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
assertEquals( 2, params.getOrganisationUnits().size() );
assertEquals( 2, params.getDataElements().size() );
@@ -279,7 +286,8 @@
dimensionParams.add( "dx" );
dimensionParams.add( "pe:2012,2012S1,2012S2" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
}
@Test( expected = IllegalQueryException.class )
@@ -289,7 +297,8 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "pe" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
}
@Test( expected = IllegalQueryException.class )
@@ -299,7 +308,8 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "ou" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
}
@Test( expected = IllegalQueryException.class )
@@ -309,7 +319,8 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "yebo:2012,2012S1,2012S2" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, false, false, false, null, null, null, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null,
+ false, false, false, false, false, false, null, null, null, null, null, null );
}
@Test
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AnalyticsController.java 2015-04-03 12:51:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AnalyticsController.java 2015-06-14 15:30:53 +0000
@@ -92,13 +92,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -123,13 +125,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -152,13 +156,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -181,13 +187,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -210,13 +218,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.csv", true );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -239,13 +249,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.xls", true );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -268,13 +280,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) Integer approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, null, null,
- true, false, false, false, false, false, null, null, null, i18nManager.getI18nFormat() );
+ true, false, false, false, false, false, null, null, null, null, null, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.jrxml", false );
Grid grid = analyticsService.getAggregatedDataValues( params );
@@ -298,13 +312,15 @@
@RequestParam( required = false ) DisplayProperty displayProperty,
@RequestParam( required = false ) IdentifiableProperty outputIdScheme,
@RequestParam( required = false ) String approvalLevel,
+ @RequestParam( required = false ) String program,
+ @RequestParam( required = false ) String stage,
@RequestParam( required = false ) String columns,
@RequestParam( required = false ) String rows,
Model model,
HttpServletResponse response ) throws Exception
{
DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, skipRounding,
- hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, i18nManager.getI18nFormat() );
+ hierarchyMeta, ignoreLimit, hideEmptyRows, showHierarchy, displayProperty, outputIdScheme, approvalLevel, program, stage, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_TEXT, CacheStrategy.NO_CACHE, "debug.sql", false );
return AnalyticsUtils.getDebugDataSql( params );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2015-05-28 16:10:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2015-06-14 15:30:53 +0000
@@ -139,7 +139,7 @@
set.add( ou );
DataQueryParams params = analyticsService.getFromUrl( set, null, AggregationType.SUM, null,
- false, false, false, false, false, false, displayProperty, null, null, null );
+ false, false, false, false, false, false, displayProperty, null, null, null, null, null );
DimensionalObject dim = params.getDimension( DimensionalObject.ORGUNIT_DIM_ID );