← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13882: sort by lastUpdated in person search

 

------------------------------------------------------------
revno: 13882
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-28 19:12:50 +0700
message:
  sort by lastUpdated in person search
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2014-01-28 11:18:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2014-01-28 12:12:50 +0000
@@ -32,6 +32,7 @@
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Conjunction;
 import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.api.controller.exception.NotFoundException;
@@ -94,16 +95,16 @@
     @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCESS_PATIENT_ATTRIBUTES')" )
     public String getPersons( @RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
         @RequestParam( value = "program", required = false ) String programUid,
-        @RequestParam( value = "attribute", required = false ) List<String> filters,
+        @RequestParam( value = "attribute", required = false ) List<String> attributeFilters,
         @RequestParam( required = false ) Map<String, String> parameters, Model model )
         throws Exception
     {
         WebOptions options = new WebOptions( parameters );
         Persons persons = new Persons();
 
-        if ( filters != null )
+        if ( attributeFilters != null )
         {
-            persons = personsByFilter( filters, orgUnitUid );
+            persons = personsByFilter( attributeFilters, orgUnitUid );
         }
         else if ( orgUnitUid != null )
         {
@@ -132,7 +133,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    private Persons personsByFilter( List<String> filters, String orgUnitUid )
+    private Persons personsByFilter( List<String> attributeFilters, String orgUnitUid )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( Patient.class );
         criteria.createAlias( "attributeValues", "attributeValue" );
@@ -155,7 +156,7 @@
         }
 
         // validate attributes, and build criteria
-        for ( String filter : filters )
+        for ( String filter : attributeFilters )
         {
             String[] split = filter.split( ":" );
 
@@ -219,6 +220,8 @@
             }
         }
 
+        criteria.addOrder( Order.desc( "lastUpdated" ) );
+
         return personService.getPersons( criteria.list() );
     }