dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29478
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14900: TEI query, impl support for event status, event start date and event end date
------------------------------------------------------------
revno: 14900
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-18 16:01:25 +0200
message:
TEI query, impl support for event status, event start date and event end date
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java
dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityInstanceController.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/trackedentity/TrackedEntityInstanceQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java 2014-04-18 09:52:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java 2014-04-18 14:01:25 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.common.QueryItem;
import org.hisp.dhis.common.SetMap;
+import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStatus;
@@ -114,6 +115,21 @@
* Selection mode for the specified organisation units.
*/
private OrganisationUnitSelectionMode organisationUnitMode;
+
+ /**
+ * Status of any events in the specified program.
+ */
+ private EventStatus eventStatus;
+
+ /**
+ * Start date for event for the given program.
+ */
+ private Date eventStartDate;
+
+ /**
+ * End date for event for the given program.
+ */
+ private Date eventEndDate;
/**
* Indicates whether not to include meta data in the response.
@@ -372,7 +388,7 @@
}
/**
- * Indicates whethert this params is of the given organisation unit mode.
+ * Indicates whether this params is of the given organisation unit mode.
*/
public boolean isOrganisationUnitMode( OrganisationUnitSelectionMode mode )
{
@@ -380,6 +396,39 @@
}
/**
+ * Indicates whether this params specifies an event status.
+ */
+ public boolean hasEventStatus()
+ {
+ return eventStatus != null;
+ }
+
+ /**
+ * Indicates whether the event status specified for the params is equal to
+ * the given event status.
+ */
+ public boolean isEventStatus( EventStatus eventStatus )
+ {
+ return this.eventStatus != null && this.eventStatus.equals( eventStatus );
+ }
+
+ /**
+ * Indicates whether this params specifies an event start date.
+ */
+ public boolean hasEventStartDate()
+ {
+ return eventStartDate != null;
+ }
+
+ /**
+ * Indicates whether this params specifies an event end date.
+ */
+ public boolean hasEventEndDate()
+ {
+ return eventEndDate != null;
+ }
+
+ /**
* Indicates whether paging is enabled.
*/
public boolean isPaging()
@@ -445,14 +494,14 @@
this.filters = filters;
}
- public OrganisationUnitSelectionMode getOrganisationUnitMode()
+ public Set<OrganisationUnit> getOrganisationUnits()
{
- return organisationUnitMode;
+ return organisationUnits;
}
- public void setOrganisationUnitMode( OrganisationUnitSelectionMode organisationUnitMode )
+ public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
{
- this.organisationUnitMode = organisationUnitMode;
+ this.organisationUnits = organisationUnits;
}
public Program getProgram()
@@ -515,14 +564,44 @@
this.trackedEntity = trackedEntity;
}
- public Set<OrganisationUnit> getOrganisationUnits()
- {
- return organisationUnits;
- }
-
- public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
- {
- this.organisationUnits = organisationUnits;
+ public OrganisationUnitSelectionMode getOrganisationUnitMode()
+ {
+ return organisationUnitMode;
+ }
+
+ public void setOrganisationUnitMode( OrganisationUnitSelectionMode organisationUnitMode )
+ {
+ this.organisationUnitMode = organisationUnitMode;
+ }
+
+ public EventStatus getEventStatus()
+ {
+ return eventStatus;
+ }
+
+ public void setEventStatus( EventStatus eventStatus )
+ {
+ this.eventStatus = eventStatus;
+ }
+
+ public Date getEventStartDate()
+ {
+ return eventStartDate;
+ }
+
+ public void setEventStartDate( Date eventStartDate )
+ {
+ this.eventStartDate = eventStartDate;
+ }
+
+ public Date getEventEndDate()
+ {
+ return eventEndDate;
+ }
+
+ public void setEventEndDate( Date eventEndDate )
+ {
+ this.eventEndDate = eventEndDate;
}
public boolean isSkipMeta()
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-04-18 09:52:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-04-18 14:01:25 +0000
@@ -36,6 +36,7 @@
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -79,6 +80,9 @@
* @param programStartDate the start date for enrollment in the given Program.
* @param programEndDate the end date for enrollment in the given Program.
* @param trackedEntity the TrackedEntity uid.
+ * @param eventStatus the event status for the given Program.
+ * @param eventStartDate the event start date for the given Program.
+ * @param eventEndDate the event end date for the given Program.
* @param skipMeta indicates whether to include meta data in the response.
* @param page the page number.
* @param pageSize the page size.
@@ -86,7 +90,7 @@
*/
TrackedEntityInstanceQueryParams getFromUrl( String query, Set<String> attribute, Set<String> filter,
Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Boolean followUp, Date programStartDate, Date programEndDate,
- String trackedEntity, boolean skipMeta, Integer page, Integer pageSize );
+ String trackedEntity, EventStatus eventStatus, Date eventStartDate, Date eventEndDate, boolean skipMeta, Integer page, Integer pageSize );
/**
* Validates the given TrackedEntityInstanceQueryParams. The params is
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-04-18 09:52:56 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-04-18 14:01:25 +0000
@@ -56,6 +56,7 @@
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.QueryItem;
+import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -305,6 +306,11 @@
violation = "Program must be defined when program end date is specified";
}
+ if ( params.hasEventStatus() && ( !params.hasEventStartDate() || !params.hasEventEndDate() ) )
+ {
+ violation = "Event start and end date must be specified when event status is specified";
+ }
+
if ( params.isOrQuery() && params.hasFilters() )
{
violation = "Query cannot be specified together with filters";
@@ -331,7 +337,7 @@
@Override
public TrackedEntityInstanceQueryParams getFromUrl( String query, Set<String> attribute, Set<String> filter, Set<String> ou,
OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Boolean followUp, Date programStartDate, Date programEndDate,
- String trackedEntity, boolean skipMeta, Integer page, Integer pageSize )
+ String trackedEntity, EventStatus eventStatus, Date eventStartDate, Date eventEndDate, boolean skipMeta, Integer page, Integer pageSize )
{
TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
@@ -392,6 +398,9 @@
params.setProgramEndDate( programEndDate );
params.setTrackedEntity( te );
params.setOrganisationUnitMode( ouMode );
+ params.setEventStatus( eventStatus );
+ params.setEventStartDate( eventStartDate );
+ params.setEventEndDate( eventEndDate );
params.setSkipMeta( skipMeta );
params.setPage( page );
params.setPageSize( pageSize );
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-04-18 10:14:28 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-04-18 14:01:25 +0000
@@ -45,6 +45,7 @@
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.ORG_UNIT_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_INSTANCE_ID;
+import static org.hisp.dhis.program.ProgramStageInstance.SKIPPED_STATUS;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -68,6 +69,7 @@
import org.hisp.dhis.common.QueryItem;
import org.hisp.dhis.common.SetMap;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -251,8 +253,8 @@
final String joinClause = item.hasFilter() ? "inner join" : "left join";
- sql += joinClause +
- " trackedentityattributevalue as " + col + " " + "on " + col + ".trackedentityinstanceid = tei.trackedentityinstanceid " +
+ sql += joinClause + " " +
+ "trackedentityattributevalue as " + col + " " + "on " + col + ".trackedentityinstanceid = tei.trackedentityinstanceid " +
"and " + col + ".trackedentityattributeid = " + item.getItem().getId() + " ";
final String filter = statementBuilder.encode( item.getFilter(), false );
@@ -300,8 +302,17 @@
if ( params.hasProgram() )
{
sql += hlp.whereAnd() + " exists (" +
- "select trackedentityinstanceid " +
- "from programinstance pi " +
+ "select pi.trackedentityinstanceid " +
+ "from programinstance pi ";
+
+ if ( params.hasEventStatus() )
+ {
+ sql +=
+ "left join programstageinstance psi " +
+ "on pi.programinstanceid = psi.programinstanceid ";
+ }
+
+ sql +=
"where pi.trackedentityinstanceid = tei.trackedentityinstanceid " +
"and pi.programid = " + params.getProgram().getId() + " ";
@@ -324,6 +335,11 @@
{
sql += "and pi.enrollmentdate <= '" + getMediumDateString( params.getProgramEndDate() ) + "' ";
}
+
+ if ( params.hasEventStatus() )
+ {
+ sql += getEventStatusWhereClause( params );
+ }
sql += ") ";
}
@@ -358,6 +374,37 @@
return sql;
}
+ private String getEventStatusWhereClause( TrackedEntityInstanceQueryParams params )
+ {
+ String start = getMediumDateString( params.getEventStartDate() );
+ String end = getMediumDateString( params.getEventEndDate() );
+
+ String sql = StringUtils.EMPTY;
+
+ if ( params.isEventStatus( EventStatus.COMPLETED ) )
+ {
+ sql = "and psi.executiondate >= '" + start + "' and psi.executiondate <= '" + end + "' and psi.completed = true ";
+ }
+ else if ( params.isEventStatus( EventStatus.VISITED ) )
+ {
+ sql = "and psi.executiondate >= '" + start + "' and psi.executiondate <= '" + end + "' and psi.completed = false ";
+ }
+ else if ( params.isEventStatus( EventStatus.FUTURE_VISIT ) )
+ {
+ sql = "and psi.duedate >= '" + start + "' and psi.duedate <= '" + end + "' and psi.status is not null and date(now()) < date(psi.duedate) ";
+ }
+ else if ( params.isEventStatus( EventStatus.LATE_VISIT ) )
+ {
+ sql = "and psi.duedate >= '" + start + "' and psi.duedate <= '" + end + "' and psi.status is not null and date(now()) > date(psi.duedate) ";
+ }
+ else if ( params.isEventStatus( EventStatus.SKIPPED ) )
+ {
+ sql = "and psi.duedate >= '" + start + "' and psi.duedate <= '" + end + "' and psi.status = " + SKIPPED_STATUS + " ";
+ }
+
+ return sql;
+ }
+
@Override
@SuppressWarnings( "unchecked" )
public Collection<TrackedEntityInstance> getByOrgUnit( OrganisationUnit organisationUnit, Integer min, Integer max )
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java 2014-04-13 13:14:11 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/eventreport/EventReportServiceTest.java 2014-04-18 14:01:25 +0000
@@ -52,9 +52,9 @@
@Override
public void setUpTest()
- {System.out.println("\n\n === \n 1 ");
- prA = createProgram( 'A', null, null );System.out.println("\n\n === \n 2 ");
- programService.addProgram( prA );System.out.println("\n\n === \n 3 ");
+ {
+ prA = createProgram( 'A', null, null );
+ programService.addProgram( prA );
}
@Test
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityInstanceController.java 2014-04-18 09:52:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityInstanceController.java 2014-04-18 14:01:25 +0000
@@ -52,6 +52,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.program.ProgramStatus;
import org.hisp.dhis.system.grid.GridUtils;
import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
@@ -111,6 +112,9 @@
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programStartDate,
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programEndDate,
@RequestParam(required=false) String trackedEntity,
+ @RequestParam(required=false) EventStatus eventStatus,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventStartDate,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventEndDate,
@RequestParam(required=false) boolean skipMeta,
@RequestParam(required=false) Integer page,
@RequestParam(required=false) Integer pageSize,
@@ -119,7 +123,8 @@
{
Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );
TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode,
- program, programStatus, followUp, programStartDate, programEndDate, trackedEntity, skipMeta, page, pageSize );
+ program, programStatus, followUp, programStartDate, programEndDate, trackedEntity,
+ eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE );
Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -142,6 +147,9 @@
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programStartDate,
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programEndDate,
@RequestParam(required=false) String trackedEntity,
+ @RequestParam(required=false) EventStatus eventStatus,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventStartDate,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventEndDate,
@RequestParam(required=false) boolean skipMeta,
@RequestParam(required=false) Integer page,
@RequestParam(required=false) Integer pageSize,
@@ -150,7 +158,8 @@
{
Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );
TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode,
- program, programStatus, followUp, programStartDate, programEndDate, trackedEntity, skipMeta, page, pageSize );
+ program, programStatus, followUp, programStartDate, programEndDate, trackedEntity,
+ eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE );
Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -170,6 +179,9 @@
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programStartDate,
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programEndDate,
@RequestParam(required=false) String trackedEntity,
+ @RequestParam(required=false) EventStatus eventStatus,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventStartDate,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventEndDate,
@RequestParam(required=false) boolean skipMeta,
@RequestParam(required=false) Integer page,
@RequestParam(required=false) Integer pageSize,
@@ -178,7 +190,8 @@
{
Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );
TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode,
- program, programStatus, followUp, programStartDate, programEndDate, trackedEntity, skipMeta, page, pageSize );
+ program, programStatus, followUp, programStartDate, programEndDate, trackedEntity,
+ eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.NO_CACHE );
Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -198,6 +211,9 @@
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programStartDate,
@RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date programEndDate,
@RequestParam(required=false) String trackedEntity,
+ @RequestParam(required=false) EventStatus eventStatus,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventStartDate,
+ @RequestParam(required=false) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date eventEndDate,
@RequestParam(required=false) boolean skipMeta,
@RequestParam(required=false) Integer page,
@RequestParam(required=false) Integer pageSize,
@@ -206,7 +222,8 @@
{
Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );
TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode,
- program, programStatus, followUp, programStartDate, programEndDate, trackedEntity, skipMeta, page, pageSize );
+ program, programStatus, followUp, programStartDate, programEndDate, trackedEntity,
+ eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.NO_CACHE );
Grid grid = instanceService.getTrackedEntityInstances( params );