← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14673: TEI query, implemented support for query by enrollment date (program date)

 

------------------------------------------------------------
revno: 14673
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-04 19:20:41 +0200
message:
  TEI query, implemented support for query by enrollment date (program 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-core/src/main/resources/org/hisp/dhis/dataapproval/hibernate/DataApprovalLevel.hbm.xml
  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-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-01 08:58:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceQueryParams.java	2014-04-04 17:20:41 +0000
@@ -34,6 +34,7 @@
 import java.util.Set;
 
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.common.QueryFilter;
 import org.hisp.dhis.common.QueryItem;
 import org.hisp.dhis.common.SetMap;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -88,6 +89,11 @@
     private ProgramStatus programStatus;
     
     /**
+     * Enrollment dates for the given program.
+     */
+    private List<QueryFilter> programDates = new ArrayList<QueryFilter>();
+    
+    /**
      * Tracked entity of the instances in the response.
      */
     private TrackedEntity trackedEntity;
@@ -218,6 +224,15 @@
     }
     
     /**
+     * Indicates whether this params specifies any program dates.
+     * @return
+     */
+    public boolean hasProgramDates()
+    {
+        return programDates != null && !programDates.isEmpty();
+    }
+    
+    /**
      * Indicates whether this params specifies a tracked entity.
      */
     public boolean hasTrackedEntity()
@@ -329,6 +344,16 @@
         this.programStatus = programStatus;
     }
 
+    public List<QueryFilter> getProgramDates()
+    {
+        return programDates;
+    }
+
+    public void setProgramDates( List<QueryFilter> programDates )
+    {
+        this.programDates = programDates;
+    }
+
     public TrackedEntity getTrackedEntity()
     {
         return trackedEntity;

=== 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-03-30 17:33:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-04-04 17:20:41 +0000
@@ -73,6 +73,7 @@
      * @param ouMode the OrganisationUnitSelectionMode.
      * @param program the Program uid.
      * @param programStatus the ProgramStatus of the given Program.
+     * @param programDate the set of filters for program enrollment dates.
      * @param trackedEntity the TrackedEntity uid.
      * @param skipMeta indicates whether to include meta data in the response.
      * @param page the page number.
@@ -80,7 +81,7 @@
      * @return a TrackedEntityInstanceQueryParams.
      */
     TrackedEntityInstanceQueryParams getFromUrl( String query, Set<String> attribute, Set<String> filter, 
-        Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, 
+        Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Set<String> programDate,
         String trackedEntity, boolean skipMeta, Integer page, Integer pageSize );
     
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataapproval/hibernate/DataApprovalLevel.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataapproval/hibernate/DataApprovalLevel.hbm.xml	2014-04-04 12:15:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataapproval/hibernate/DataApprovalLevel.hbm.xml	2014-04-04 17:20:41 +0000
@@ -27,7 +27,6 @@
     <property name="publicAccess" length="8" />
 
     <set name="userGroupAccesses" table="dataapprovallevelusergroupaccesses">
-      <cache usage="read-write" />
       <key column="dataapprovallevelid" />
       <many-to-many class="org.hisp.dhis.user.UserGroupAccess" column="usergroupaccessid" unique="true" />
     </set>

=== 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-01 08:58:32 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-04-04 17:20:41 +0000
@@ -55,6 +55,7 @@
 import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.QueryFilter;
 import org.hisp.dhis.common.QueryItem;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -294,7 +295,7 @@
     
     @Override
     public TrackedEntityInstanceQueryParams getFromUrl( String query, Set<String> attribute, Set<String> filter, Set<String> ou, 
-        OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, String trackedEntity, boolean skipMeta, Integer page, Integer pageSize )
+        OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Set<String> programDate, String trackedEntity, boolean skipMeta, Integer page, Integer pageSize )
     {
         TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
 
@@ -340,6 +341,16 @@
             throw new IllegalQueryException( "Program does not exist: " + program );
         }
         
+        if ( programDate != null )
+        {
+            for ( String date : programDate )
+            {
+                QueryFilter queryFilter = getQueryFilter( date );
+                
+                params.getProgramDates().add( queryFilter );
+            }
+        }
+        
         TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity( trackedEntity ) : null;
         
         if ( trackedEntity != null && te == null )
@@ -366,6 +377,18 @@
         return params;
     }
 
+    private QueryFilter getQueryFilter( String filter )
+    {
+        String[] split = filter.split( DimensionalObjectUtils.DIMENSION_NAME_SEP );
+        
+        if ( split == null || split.length != 2 )
+        {
+            throw new IllegalQueryException( "Program date filter has invalid format: " + filter );
+        }
+        
+        return new QueryFilter( split[0], split[1] );
+    }
+    
     private QueryItem getQueryItem( String item )
     {
         if ( !item.contains( DimensionalObjectUtils.DIMENSION_NAME_SEP ) )

=== 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-01 08:58:32 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-04-04 17:20:41 +0000
@@ -62,6 +62,7 @@
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.common.QueryFilter;
 import org.hisp.dhis.common.QueryItem;
 import org.hisp.dhis.common.SetMap;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
@@ -301,7 +302,17 @@
             
             if ( params.hasProgramStatus() )
             {
-                sql += "and pi.status = " + PROGRAM_STATUS_MAP.get( params.getProgramStatus() );
+                sql += "and pi.status = " + PROGRAM_STATUS_MAP.get( params.getProgramStatus() + " " );
+            }
+            
+            if ( params.hasProgramDates() )
+            {
+                for ( QueryFilter date : params.getProgramDates() )
+                {
+                    String filter = statementBuilder.encode( date.getFilter(), false );
+                    
+                    sql += "and pi.enrollmentdate " + date.getSqlOperator() + " " + date.getSqlFilter( filter ) + " ";                    
+                }
             }
             
             sql += ") ";

=== 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-03-30 17:33:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityInstanceController.java	2014-04-04 17:20:41 +0000
@@ -105,6 +105,7 @@
         @RequestParam(required=false) OrganisationUnitSelectionMode ouMode,
         @RequestParam(required=false) String program,
         @RequestParam(required=false) ProgramStatus programStatus,
+        @RequestParam(required=false) Set<String> programDate,
         @RequestParam(required=false) String trackedEntity,
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) Integer page,
@@ -114,7 +115,7 @@
     {
         Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );        
         TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode, 
-            program, programStatus, trackedEntity, skipMeta, page, pageSize );
+            program, programStatus, programDate, trackedEntity, skipMeta, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE );
         Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -133,6 +134,7 @@
         @RequestParam(required=false) OrganisationUnitSelectionMode ouMode,
         @RequestParam(required=false) String program,
         @RequestParam(required=false) ProgramStatus programStatus,
+        @RequestParam(required=false) Set<String> programDate,
         @RequestParam(required=false) String trackedEntity,
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) Integer page,
@@ -142,7 +144,7 @@
     {
         Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );        
         TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode, 
-            program, programStatus, trackedEntity, skipMeta, page, pageSize );
+            program, programStatus, programDate, trackedEntity, skipMeta, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE );
         Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -158,6 +160,7 @@
         @RequestParam(required=false) OrganisationUnitSelectionMode ouMode,
         @RequestParam(required=false) String program,
         @RequestParam(required=false) ProgramStatus programStatus,
+        @RequestParam(required=false) Set<String> programDate,
         @RequestParam(required=false) String trackedEntity,
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) Integer page,
@@ -167,7 +170,7 @@
     {
         Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );        
         TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode, 
-            program, programStatus, trackedEntity, skipMeta, page, pageSize );
+            program, programStatus, programDate, trackedEntity, skipMeta, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.NO_CACHE );
         Grid grid = instanceService.getTrackedEntityInstances( params );
@@ -183,6 +186,7 @@
         @RequestParam(required=false) OrganisationUnitSelectionMode ouMode,
         @RequestParam(required=false) String program,
         @RequestParam(required=false) ProgramStatus programStatus,
+        @RequestParam(required=false) Set<String> programDate,
         @RequestParam(required=false) String trackedEntity,
         @RequestParam(required=false) boolean skipMeta,
         @RequestParam(required=false) Integer page,
@@ -192,7 +196,7 @@
     {
         Set<String> orgUnits = new HashSet<String>( ContextUtils.getQueryParamValues( ou ) );        
         TrackedEntityInstanceQueryParams params = instanceService.getFromUrl( query, attribute, filter, orgUnits, ouMode, 
-            program, programStatus, trackedEntity, skipMeta, page, pageSize );
+            program, programStatus, programDate, trackedEntity, skipMeta, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.NO_CACHE );
         Grid grid = instanceService.getTrackedEntityInstances( params );