dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28781
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14422: Event analytics. Supporting periods for event query by converting periods to start/end dates
------------------------------------------------------------
revno: 14422
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-26 10:25:45 +0100
message:
Event analytics. Supporting periods for event query by converting periods to start/end dates
modified:
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/event/EventQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.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/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2014-03-26 09:25:45 +0000
@@ -379,6 +379,17 @@
return this;
}
+
+ /**
+ * Removes the dimension or filter with the given identifier.
+ */
+ public DataQueryParams removeDimensionOrFilter( String dimension )
+ {
+ removeDimension( dimension );
+ removeFilter( dimension );
+
+ return this;
+ }
/**
* Removes dimensions of the given type.
=== 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-03-24 22:22:06 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java 2014-03-26 09:25:45 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
@@ -40,8 +42,10 @@
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.NameableObject;
+import org.hisp.dhis.common.NameableObjectUtils;
import org.hisp.dhis.common.QueryItem;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
@@ -152,6 +156,34 @@
return uniqueItems;
}
+ /**
+ * Replaces periods with start and end dates, using the earliest start date
+ * from the periods as start date and the latest end date from the periods
+ * as end date. Remove the period dimension or filter.
+ */
+ public void replacePeriodsWithStartEndDates()
+ {
+ List<Period> periods = NameableObjectUtils.asTypedList( getDimensionOrFilter( PERIOD_DIM_ID ), Period.class );
+
+ for ( Period period : periods )
+ {
+ Date start = period.getStartDate();
+ Date end = period.getEndDate();
+
+ if ( startDate == null || ( start != null && start.before( startDate ) ) )
+ {
+ startDate = start;
+ }
+
+ if ( endDate == null || ( end != null && end.after( endDate ) ) )
+ {
+ endDate = end;
+ }
+ }
+
+ removeDimensionOrFilter( PERIOD_DIM_ID );
+ }
+
public boolean isOrganisationUnitMode( String mode )
{
return organisationUnitMode != null && organisationUnitMode.equalsIgnoreCase( mode );
=== 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-03-24 22:19:59 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2014-03-26 09:25:45 +0000
@@ -189,6 +189,8 @@
{
queryPlanner.validate( params );
+ params.replacePeriodsWithStartEndDates();
+
Grid grid = new ListGrid();
// ---------------------------------------------------------------------