← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1974: Add paging function for multi-dataentry form into Patient module and Remove unnessesary files.

 

------------------------------------------------------------
revno: 1974
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-10-30 12:54:51 +0700
message:
  Add paging function for multi-dataentry form into Patient module and Remove unnessesary files.
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/PagingUtil.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/RequestUtil.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/paging.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/style/paging.css
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml


--
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/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2010-10-22 06:43:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2010-10-30 05:54:51 +0000
@@ -33,6 +33,7 @@
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.program.Program;
 
 /**
  * @author Abyot Asalefew Gizaw
@@ -52,26 +53,107 @@
 
     Collection<Patient> getAllPatients();
 
+    /**
+     * Get Patients base on isDead property
+     * 
+     * @param isDead
+     * @return Patient List
+     */
     Collection<Patient> getAllPatients( Boolean isDead );
 
+    /**
+     * Search Patient base on firstname/middlename/lastname/birthDate/gender
+     * 
+     * @param firstName
+     * @param middleName
+     * @param lastName
+     * @param birthdate
+     * @param gender
+     * @return Patient List
+     */
     Collection<Patient> getPatient( String firstName, String middleName, String lastName, Date birthdate, String gender );
     
+    /**
+     * Search Patient base on gender
+     * 
+     * @param gender
+     * @return Patient List
+     */
     Collection<Patient> getPatiensByGender( String gender );
 
+    /**
+     * Search Patient base on birthDate
+     * 
+     * @param birthdate
+     * @return Patient List
+     */
     Collection<Patient> getPatientsByBirthDate( Date birthDate );
 
+    /**
+     * Search Patient base on firstname/middlename/lastname/
+     * 
+     * @param name firstName/middleName/lastName/
+     * @return Patient List
+     */
     Collection<Patient> getPatientsByNames( String name );
     
+    /**
+     * Search Patient base on firstname/middlename/lastname/
+     * 
+     * @param name firstName/middleName/lastName/
+     * @return Patient List
+     */
     Collection<Patient> getPatients( String searchText );
     
+    /**
+     * Search Patient base on identifier value with result limited
+     * 
+     * @param searchText value
+     * @param min
+     * @param max
+     * @return Patient List
+     */
     Collection<Patient> getPatients( String searchText, int min, int max );
     
+    /**
+     * Search Patient base on organisation unit  with result limited
+     * 
+     * @param organisationUnit organisationUnit
+     * @return Patient List
+     */
     Collection<Patient> getPatients( OrganisationUnit organisationUnit );
     
+    /**
+     * Search Patient base on organisation unit with result limited
+     * 
+     * @param organisationUnit organisationUnit
+     * @param min
+     * @param max
+     * @return Patient List
+     */
     Collection<Patient> getPatients( OrganisationUnit organisationUnit, int min, int max );
 
+    /**
+     * Search Patient base on organisation unit and sort the result by PatientAttribute
+     * 
+     * @param organisationUnit organisationUnit
+     * @param min
+     * @param max
+     * @param patientAttribute
+     * @return Patient List
+     */
     Collection<Patient> getPatients( OrganisationUnit organisationUnit, int min, int max, PatientAttribute patientAttribute );
-
+    
+    /**
+     * Search Patient base on organisationUnit and identifier value
+     * name
+     * 
+     * @param organisationUnit
+     * @param searchText identifier value
+     * @param min 
+     * @param max 
+     * @return
+     */
     Collection<Patient> getPatients( OrganisationUnit organisationUnit, String searchText, int min, int max );
     
     /**
@@ -85,12 +167,51 @@
      */
     Collection<Patient> getPatient( Integer identifierTypeId, Integer attributeId, String value );
 
+    /**
+     * Search Patient base on OrganisationUnit and Program with result limited
+     * name
+     * 
+     * @param organisationUnit
+     * @param program
+     * @param min 
+     * @param max 
+     * @return
+     */
+    Collection<Patient> getPatients( OrganisationUnit organisationUnit, Program program, int min, int max );
+
+    /**
+     * Sort the result by PatientAttribute
+     * 
+     * @param patients
+     * @param patientAttribute
+     * @return Patient List
+     */
     Collection<Patient> sortPatientsByAttribute( Collection<Patient> patients, PatientAttribute patientAttribute );
 
+    /**
+     * Search Patient base on firstname/middlename/lastname with result limited
+     * 
+     * @param name firstName/middleName/lastName
+     * @param min 
+     * @param max 
+     * @return Patient List
+     */
     Collection<Patient> getPatientsByNames( String name, int min, int max );
     
+    /**
+     * Search Patient base on identifier value and get number of result
+     * 
+     * @param searchText
+     * @return number of patients
+     */
     int countGetPatients( String searchText );
 
+    /**
+     * Search Patient base on firstname/middlename/lastname and get number of result
+     * 
+     * @param name
+     * @return number of patients
+     */
     int countnGetPatientsByNames( String name );
 
     int createPatient( Patient patient,Integer representativeId,
@@ -102,4 +223,6 @@
     
     int countGetPatientsByOrgUnit( OrganisationUnit organisationUnit );
     
+    int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program );
+    
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2010-10-20 13:34:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2010-10-30 05:54:51 +0000
@@ -32,6 +32,7 @@
 
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.Program;
 
 /**
  * @author Abyot Asalefew Gizaw
@@ -58,7 +59,11 @@
     
     Collection<Patient> getByOrgUnit( OrganisationUnit organisationUnit, int min, int max );
     
+    Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, int min, int max );
+    
     int countListPatientByOrgunit(OrganisationUnit organisationUnit);
     
     int countGetPatientsByNames( String name );
+    
+    int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2010-10-20 13:34:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2010-10-30 05:54:51 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.program.Program;
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
@@ -481,5 +482,13 @@
             }
         }
     }
+    
+    public Collection<Patient> getPatients( OrganisationUnit organisationUnit, Program program, int min, int max ){
+        return patientStore.getByOrgUnitProgram( organisationUnit, program, min, max );
+    }
+
+    public int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program ){
+        return patientStore.countGetPatientsByOrgUnitProgram( organisationUnit, program );
+    }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2010-10-20 13:34:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2010-10-30 05:54:51 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientStore;
+import org.hisp.dhis.program.Program;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -49,20 +50,21 @@
  */
 @Transactional
 public class HibernatePatientStore
-    extends HibernateGenericStore<Patient> implements PatientStore
-{    
+    extends HibernateGenericStore<Patient>
+    implements PatientStore
+{
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> get( Boolean isDead )
-    {        
+    {
         return getCriteria( Restrictions.eq( "isDead", isDead ) ).list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByGender( String gender )
     {
         return getCriteria( Restrictions.eq( "gender", gender ) ).list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByBirthDate( Date birthDate )
     {
@@ -72,68 +74,80 @@
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByNames( String name )
     {
-        return getCriteria( 
+        return getCriteria(
             Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
-            Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
-            Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) ).list();        
+                Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
+                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) ).list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByNames( String name, int min, int max )
     {
-        return getCriteria( 
+        return getCriteria(
             Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
                 Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
-                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) ).setFirstResult( min ).setMaxResults( max ).list(); 
+                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).addOrder( Order.asc( "firstName" ) )
+            .setFirstResult( min ).setMaxResults( max ).list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
-    public Collection<Patient> getPatient( String firstName, String middleName, String lastName, Date birthdate , String gender)
+    public Collection<Patient> getPatient( String firstName, String middleName, String lastName, Date birthdate,
+        String gender )
     {
-        Criteria crit = getCriteria( );
+        Criteria crit = getCriteria();
         Conjunction con = Restrictions.conjunction();
-        
-        if( StringUtils.isNotBlank( firstName ))
+
+        if ( StringUtils.isNotBlank( firstName ) )
             con.add( Restrictions.eq( "firstName", firstName ) );
-        
-        if( StringUtils.isNotBlank( middleName ))
-            con.add(Restrictions.eq( "middleName", middleName ) );
-        
-        if( StringUtils.isNotBlank( lastName ))
-            con.add(Restrictions.eq( "lastName",  lastName ) );
-        
-        con.add( Restrictions.eq( "gender",  gender ) ) ;
-        con.add( Restrictions.eq( "birthDate",  birthdate ) );
-        
+
+        if ( StringUtils.isNotBlank( middleName ) )
+            con.add( Restrictions.eq( "middleName", middleName ) );
+
+        if ( StringUtils.isNotBlank( lastName ) )
+            con.add( Restrictions.eq( "lastName", lastName ) );
+
+        con.add( Restrictions.eq( "gender", gender ) );
+        con.add( Restrictions.eq( "birthDate", birthdate ) );
+
         crit.add( con );
-        
-        crit.addOrder( Order.asc( "firstName" ) );   
-        
+
+        crit.addOrder( Order.asc( "firstName" ) );
+
         return crit.list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByOrgUnit( OrganisationUnit organisationUnit )
     {
         String hql = "select distinct p from Patient p where p.organisationUnit = :organisationUnit order by p.id";
-    
+
         return getQuery( hql ).setEntity( "organisationUnit", organisationUnit ).list();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<Patient> getByOrgUnit( OrganisationUnit organisationUnit, int min, int max )
     {
         String hql = "select p from Patient p where p.organisationUnit = :organisationUnit order by p.id";
-       
-        return getQuery( hql ).setEntity( "organisationUnit", organisationUnit ).setFirstResult( min ).setMaxResults( max ).list(); 
-    }
-    
+
+        return getQuery( hql ).setEntity( "organisationUnit", organisationUnit ).setFirstResult( min ).setMaxResults(
+            max ).list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, int min, int max )
+    {
+        return getCriteria( Restrictions.eq( "organisationUnit", organisationUnit ) ).createAlias( "programs",
+            "program" ).add( Restrictions.eq( "program.id", program.getId() ) ).addOrder(Order.asc("id")).setFirstResult( min ).setMaxResults(
+            max ).list();
+    }
+
     public int countGetPatientsByNames( String name )
     {
-        Number rs =  (Number)getCriteria( 
+        Number rs = (Number) getCriteria(
             Restrictions.disjunction().add( Restrictions.ilike( "firstName", "%" + name + "%" ) ).add(
                 Restrictions.ilike( "middleName", "%" + name + "%" ) ).add(
-                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).setProjection( Projections.rowCount() ).uniqueResult();
+                Restrictions.ilike( "lastName", "%" + name + "%" ) ) ).setProjection( Projections.rowCount() )
+            .uniqueResult();
 
         return rs != null ? rs.intValue() : 0;
     }
@@ -141,13 +155,23 @@
     @Override
     public int countListPatientByOrgunit( OrganisationUnit organisationUnit )
     {
-        Query query = getQuery("select count(p.id) from Patient p where p.organisationUnit.id=:orgUnitId ");
-
-        query.setParameter("orgUnitId", organisationUnit.getId());
-        
+        Query query = getQuery( "select count(p.id) from Patient p where p.organisationUnit.id=:orgUnitId " );
+
+        query.setParameter( "orgUnitId", organisationUnit.getId() );
+
         Number rs = (Number) query.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    @Override
+    public int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program )
+    {
+        Number rs = (Number) getCriteria( Restrictions.eq( "organisationUnit", organisationUnit ) ).createAlias(
+            "programs", "program" ).add( Restrictions.eq( "program.id", program.getId() ) ).setProjection(
+            Projections.rowCount() ).uniqueResult();
         
         return rs != null ? rs.intValue() : 0;
     }
-    
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2010-10-30 05:54:51 +0000
@@ -8,6 +8,7 @@
 
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeService;
@@ -21,9 +22,8 @@
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 
-import com.opensymphony.xwork2.Action;
-
-public class GetDataRecordsAction implements Action
+public class GetDataRecordsAction
+    extends ActionPagingSupport<Patient>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -70,20 +70,20 @@
     {
         this.patientAttributeService = patientAttributeService;
     }
-    
+
     private PatientAttributeValueService patientAttributeValueService;
-    
+
     public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
     {
         this.patientAttributeValueService = patientAttributeValueService;
     }
-    
+
     // -------------------------------------------------------------------------
     // Input/output
     // -------------------------------------------------------------------------
 
     private Integer sortPatientAttributeId;
-    
+
     public void setSortPatientAttributeId( Integer sortPatientAttributeId )
     {
         this.sortPatientAttributeId = sortPatientAttributeId;
@@ -100,12 +100,19 @@
     {
         this.programId = programId;
     }
-    
+
     public Integer getProgramId()
     {
         return programId;
     }
 
+    private Integer total;
+
+    public Integer getTotal()
+    {
+        return total;
+    }
+
     private OrganisationUnit organisationUnit;
 
     public OrganisationUnit getOrganisationUnit()
@@ -133,49 +140,49 @@
     {
         return colorMap;
     }
-    
+
     private Map<Patient, ProgramInstance> programInstanceMap = new HashMap<Patient, ProgramInstance>();
-    
+
     public Map<Patient, ProgramInstance> getProgramInstanceMap()
     {
         return programInstanceMap;
     }
-    
+
     private Map<Patient, PatientAttributeValue> patinetAttributeValueMap = new HashMap<Patient, PatientAttributeValue>();
-    
+
     public Map<Patient, PatientAttributeValue> getPatinetAttributeValueMap()
     {
         return patinetAttributeValueMap;
     }
 
     Collection<Patient> patientListByOrgUnit;
-    
+
     public Collection<Patient> getPatientListByOrgUnit()
     {
         return patientListByOrgUnit;
     }
-    
+
     List<Program> programs;
-    
+
     public List<Program> getPrograms()
     {
         return programs;
     }
-    
+
     private Collection<PatientAttribute> patientAttributes = new ArrayList<PatientAttribute>();
-    
+
     public Collection<PatientAttribute> getPatientAttributes()
     {
         return patientAttributes;
     }
-    
+
     private PatientAttribute sortingAttribute;
-    
+
     public PatientAttribute getSortingAttribute()
     {
         return sortingAttribute;
     }
-    
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -186,69 +193,79 @@
         // ---------------------------------------------------------------------
         // Patient Attribute List
         // ---------------------------------------------------------------------
+
         patientAttributes = patientAttributeService.getAllPatientAttributes();
 
         organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
-        
+
         programs = new ArrayList<Program>( programService.getPrograms( organisationUnit ) );
-        
-        if( programId == 0 )
+
+        if ( programId == 0 )
         {
             selectedStateManager.clearSelectedProgram();
-            
+
             return SUCCESS;
         }
-        
+
         program = programService.getProgram( programId );
 
         selectedStateManager.setSelectedProgram( program );
-        
+
         // ---------------------------------------------------------------------
         // Program instances for the selected program
         // ---------------------------------------------------------------------
         
-        Collection<ProgramInstance> selectedProgramInstances = programInstanceService.getProgramInstances( program, organisationUnit );
-        
         Collection<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
-
-        for ( ProgramInstance programInstance : selectedProgramInstances )
+        
+        total = patientService.countGetPatientsByOrgUnitProgram( organisationUnit, program );
+        
+        this.paging = createPaging( total );
+        
+        patientListByOrgUnit = new ArrayList<Patient>( patientService.getPatients( organisationUnit, program, paging
+            .getStartPos(), paging.getPageSize() ) );
+        
+        for ( Patient patient : patientListByOrgUnit )
         {
-            Patient patient = programInstance.getPatient();
-            
-            if ( !programInstance.isCompleted() )
-            {
-                programInstanceMap.put( patient, programInstance );
-                
-                programInstances.add( programInstance );
-                
-                PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( patient, sortingAttribute );
-                
-                patinetAttributeValueMap.put( patient, patientAttributeValue );
-            }
-
-            programStageInstances.addAll( programInstance.getProgramStageInstances() );
+            Collection<ProgramInstance> _programInstances = programInstanceService.getProgramInstances( patient,
+                program, true );
+
+            if ( _programInstances == null || _programInstances.size() == 0 )
+            {
+                programInstanceMap.put( patient, null );
+            }
+            else
+            {
+                for ( ProgramInstance programInstance : _programInstances )
+                {
+                    programInstanceMap.put( patient, programInstance );
+
+                    programInstances.add( programInstance );
+
+                    PatientAttributeValue patientAttributeValue = patientAttributeValueService
+                        .getPatientAttributeValue( patient, sortingAttribute );
+
+                    patinetAttributeValueMap.put( patient, patientAttributeValue );
+
+                    programStageInstances.addAll( programInstance.getProgramStageInstances() );
+                }
+            }
         }
-        
-        // ---------------------------------------------------------------------
-        // Sorting PatientList by slected Patient Attribute
-        // ---------------------------------------------------------------------
 
-        patientListByOrgUnit = new ArrayList<Patient>();
+        // ---------------------------------------------------------------------
+        // Sorting PatientList by selected Patient Attribute
+        // ---------------------------------------------------------------------
         
-        if( sortPatientAttributeId != null )
+        if ( sortPatientAttributeId != null )
         {
             sortingAttribute = patientAttributeService.getPatientAttribute( sortPatientAttributeId );
-            
-            patientListByOrgUnit = patientService.sortPatientsByAttribute( programInstanceMap.keySet(), sortingAttribute );
-        }
-        else
-        {
-            patientListByOrgUnit = programInstanceMap.keySet();
+
+            patientListByOrgUnit = patientService.sortPatientsByAttribute( patientListByOrgUnit,
+                sortingAttribute );
         }
 
         colorMap = programStageInstanceService.colorProgramStageInstances( programStageInstances );
 
         return SUCCESS;
-    }    
+    }
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2010-10-30 05:54:51 +0000
@@ -159,9 +159,10 @@
 	      javascript/customcheckbox/prettyCheckboxes.js
       </param> 
       <param name="stylesheets">
-	      ../dhis-web-commons/jQuery/ui/css/redmond/jquery-ui.css,
-	      style/patient.css,
-	      javascript/customcheckbox/prettyCheckboxes.css
+	      ../dhis-web-commons/jQuery/ui/css/redmond/jquery-ui.css
+	      ,style/patient.css
+	      ,javascript/customcheckbox/prettyCheckboxes.css
+	      ,../dhis-web-commons/paging/paging.css
       </param>     
     </action>
 	

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm	2010-08-25 05:51:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm	2010-10-30 05:54:51 +0000
@@ -28,9 +28,9 @@
                     <tr #alternate( $mark )>
 						#if( $sortPatientAttributeId )
 							#set( $patientAttributeValue = $patinetAttributeValueMap.get( $patient ) )
-							<td>$encoder.htmlEncode( $!patientAttributeValue.value )</td>
+							<td>$!patientAttributeValue.value</td>
 						#end
-                        <td><a href="javascript:showPatientDetails( $programInstance.patient.id )" title="$i18n.getString( "show_details" )">$encoder.htmlEncode( $programInstance.patient.getFullName() )</a></td>                    
+                        <td><a href="javascript:showPatientDetails( $programInstance.patient.id )" title="$i18n.getString( "show_details" )">$patient.getFullName()</a></td>                    
                         #foreach( $programStageInstance in $programInstance.programStageInstances )
                             #if( $programStageInstance.executionDate )
                                 <td style="text-align:center" bgcolor="$colorMap.get( $programStageInstance.id )">
@@ -50,12 +50,15 @@
                     #end 
                 #end    
             </tbody>
-    
         </table>
         </td>
     </tr>
 </table>
 
+<div class="paging-container">
+	#parse( "/dhis-web-commons/paging/paging.vm" )
+</div>
+
 <div id="detailsArea" style="display:none;overflow:auto;height:250px;width:250px" ondblclick="javascript:hideDetails()">
     <div style="float:right;" onclick="javascript:hideDetails()">
         <a href="javascript:hideDetails()" title="$i18n.getString( "hide_details" )"><img src="../images/close.png" alt="$i18n.getString( "hide_details" )"></a>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java	2010-10-21 16:27:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java	2010-10-30 05:54:51 +0000
@@ -27,8 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Enumeration;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.system.paging.Paging;
 
@@ -37,47 +40,65 @@
 /**
  * @author Quang Nguyen
  */
-public abstract class ActionPagingSupport<T> extends ActionSupport
+public abstract class ActionPagingSupport<T>
+    extends ActionSupport
 {
     protected static final Integer DEFAULT_PAGE_SIZE = 50;
-    
+
     protected Integer currentPage;
-    
+
     public void setCurrentPage( Integer currentPage )
     {
         this.currentPage = currentPage;
     }
 
     protected Integer pageSize;
-    
+
     public void setPageSize( Integer pageSize )
     {
         this.pageSize = pageSize;
     }
-    
+
     protected Paging paging;
-    
+
     public Paging getPaging()
     {
         return paging;
     }
-
+    
+    @SuppressWarnings("unchecked")
     private String getCurrentLink()
     {
-        return ServletActionContext.getRequest().getRequestURI();
+        HttpServletRequest request = ServletActionContext.getRequest();
+        
+        String baseLink = request.getRequestURI() + "?";
+
+        Enumeration<String> paramNames = request.getParameterNames();
+        
+        while ( paramNames.hasMoreElements() )
+        {
+            String paramName = paramNames.nextElement();
+            if ( !paramName.equalsIgnoreCase( "pageSize" ) && !paramName.equalsIgnoreCase( "currentPage" ) )
+            {
+                String value = request.getParameter( paramName );
+                baseLink += paramName + "=" + value + "&";
+            }
+        }
+
+        return baseLink.substring( 0, baseLink.length()-1 );
     }
 
     protected Paging createPaging( Integer totalRecord )
     {
         Paging resultPaging = new Paging( getCurrentLink(), pageSize == null ? DEFAULT_PAGE_SIZE : pageSize );
-        
+
         resultPaging.setCurrentPage( currentPage == null ? 0 : currentPage );
-           
+
         resultPaging.setTotal( totalRecord );
-        
+
         return resultPaging;
     }
-    
+
     protected List<T> getBlockElement( List<T> elementList, int startPos, int pageSize )
     {
         List<T> returnList;

=== removed directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging'
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/PagingUtil.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/PagingUtil.java	2010-03-09 07:55:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/PagingUtil.java	1970-01-01 00:00:00 +0000
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2004-2009, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.hisp.dhis.patient.paging;
-
-public class PagingUtil
-{
-    static final int MAX_ALLOWED_PAGE_SIZE = 50;
-
-    private int currentPage;
-
-    private int pageSize;
-
-    private int total;
-
-    private String link;
-   
-    public PagingUtil()
-    {
-    }
-
-    public PagingUtil( String link, int pageSize )
-    {
-        currentPage = 1;
-        this.pageSize = pageSize;
-        total = 0;
-        this.link = link;
-    }
-
-    public String getBaseLink()
-    {
-        if ( link.indexOf( "?" ) < 0 )
-            return (new StringBuilder( String.valueOf( link ) )).append( "?" ).toString();
-        else
-            return (new StringBuilder( String.valueOf( link ) )).append( "&" ).toString();
-    }
-
-    public int getNumberOfPages()
-    {
-        if ( total % pageSize == 0 )
-            return total / pageSize;
-        else
-            return total / pageSize + 1;
-    }
-
-    public int getStartPage()
-    {
-        int startPage = 1;
-        if ( currentPage > 2 )
-        {
-            startPage = currentPage - 2;
-            if ( getNumberOfPages() - startPage < 4 )
-            {
-                startPage = getNumberOfPages() - 4;
-                if ( startPage <= 0 )
-                    startPage = 1;
-            }
-        }
-        return startPage;
-    }
-
-    public int getStartPos()
-    {
-        return currentPage <= 0 ? 0 : (currentPage - 1) * pageSize;
-    }
-
-    public int getEndPos()
-    {
-        int endPos = (getStartPos() + getPageSize()) - 1;
-        endPos = endPos >= getTotal() ? getTotal() - 1 : endPos;
-        return endPos;
-    }
-
-    public int getCurrentPage()
-    {
-        if ( currentPage > total )
-            currentPage = total;
-        return currentPage;
-    }
-
-    public void setCurrentPage( int currentPage )
-    {
-        if ( currentPage > 0 )
-            this.currentPage = currentPage;
-        else
-            this.currentPage = 1;
-    }
-
-    public int getPageSize()
-    {
-        return pageSize;
-    }
-
-    public void setPageSize( int pageSize )
-    {
-        if ( pageSize > 0 )
-            this.pageSize = pageSize;
-        else
-            this.pageSize = 50;
-    }
-
-    public int getTotal()
-    {
-        return total;
-    }
-
-    public void setTotal( int total )
-    {
-        this.total = total;
-    }
-
-    public String getLink()
-    {
-        return link;
-    }
-
-    public void setLink( String link )
-    {
-        this.link = link;
-    }
-
-}
-

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/RequestUtil.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/RequestUtil.java	2010-06-21 12:52:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/paging/RequestUtil.java	1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
-package org.hisp.dhis.patient.paging;
-
-/*
- * Copyright (c) 2004-2009, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.lang.StringUtils;
-
-public class RequestUtil
-{
-    public RequestUtil()
-    {
-    }
-
-    public static String getBaseLink( HttpServletRequest request )
-    {
-        String baseLink = (new StringBuilder( String.valueOf( request.getScheme() ) )).append( "://" ).append(
-            request.getServerName() ).append(
-            request.getServerPort() == 80 ? "" : (new StringBuilder( ":" )).append( request.getServerPort() )
-                .toString() ).append( StringUtils.isBlank( request.getContextPath() ) ? "/" : request.getContextPath() )
-            .append( request.getServletPath() ).append( "/" ).toString();
-        return baseLink;
-    }
-
-    public static String getRootLink( HttpServletRequest request )
-    {
-        String baseLink = (new StringBuilder( String.valueOf( request.getScheme() ) )).append( "://" ).append(
-            request.getServerName() ).append(
-            request.getServerPort() == 80 ? "" : (new StringBuilder( ":" )).append( request.getServerPort() )
-                .toString() ).append( StringUtils.isBlank( request.getContextPath() ) ? "/" : request.getContextPath() )
-            .append( "/" ).toString();
-        return baseLink;
-    }
-
-    public static String getCurrentLink( HttpServletRequest request )
-    {
-        //return request.getServletPath();
-    	
-    	return request.getRequestURI();
-        
-    }
-
-    public static String getPathInfo( HttpServletRequest request )
-    {
-        return request.getPathInfo().substring( 1 );
-    }
-
-    public static String getSessionString( HttpServletRequest request, String attributeName )
-    {
-        HttpSession session = request.getSession();
-        if ( session.getAttribute( attributeName ) == null )
-            return null;
-        else
-            return session.getAttribute( attributeName ).toString();
-    }
-
-    public static Object getSessionObject( HttpServletRequest request, String attributeName, Class<?> clazz )
-    {
-        HttpSession session = request.getSession();
-        if ( session != null )
-        {
-            Object object = session.getAttribute( attributeName );
-            if ( object != null )
-                try
-                {
-                    return object;
-                }
-                catch ( Exception exception )
-                {
-                }
-        }
-        return null;
-    }
-
-    public static void removeAttribute( HttpServletRequest request, String attributeName )
-    {
-        HttpSession session = request.getSession( false );
-        if ( session != null )
-            session.removeAttribute( attributeName );
-    }
-
-    public static String getSessionStringAndRemove( HttpServletRequest request, String attributeName )
-    {
-        String value = getSessionString( request, attributeName );
-        removeAttribute( request, attributeName );
-        return value;
-    }
-
-    public static String unescapeUrl( String url )
-    {
-        url = StringUtils.trimToNull( url );
-        if ( StringUtils.isBlank( url ) )
-            return null;
-        else
-            return url.replaceAll( "%3A", ":" ).replaceAll( "%3F", "?" ).replaceAll( "%3D", "=" ).replaceAll( "%26",
-                "&" );
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2010-10-29 05:24:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2010-10-30 05:54:51 +0000
@@ -359,7 +359,7 @@
 			<param name="menuTreeHeight">285</param>
 			<param name="javascripts">
 				../dhis-web-commons/ouwt/ouwt.js,javascript/patient.js</param>
-			<param name="stylesheets">style/paging.css</param>
+			<param name="stylesheets">../dhis-web-commons/paging/paging.css</param>
 		</action>
 
 		<action name="listAllPatients"

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/paging.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/paging.vm	2010-10-04 10:59:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/paging.vm	1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
-	
-	#set ( $baseLink 		= $pagingUtil.baseLink )
-	#set ( $pageSize 		= $pagingUtil.pageSize )
-	#set ( $currentPage 	= $pagingUtil.currentPage )
-	#set ( $startPage 		= $pagingUtil.startPage )
-	#set ( $numberOfPages	= $pagingUtil.numberOfPages )
-	
-	<input type="hidden" id="baseLink" value="$!baseLink"/>
-	<input type="hidden" id="currentPage" value="$!currentPage"/>
-	<input type="hidden" id="numberOfPages" value="$!numberOfPages"/>
-	#if ( $numberOfPages > 0 )
-		<ul class="pageSizeSelection">
-			<li><span > $i18n.getString("no_of_pages"):</span> $numberOfPages</li>
-		  	<li> <span >$i18n.getString("size_of_page"):</span>
-			 <input type="text" id="sizeOfPage" value="$!pageSize" style="width:50px" onchange="changePageSize('$baseLink');"></li>
-			<li> <span >$i18n.getString("jump_to_page"):</span>
-			 <input type="text" id="jumpToPage" value="$!currentPage" style="width:50px" onchange="jumpToPage('$baseLink');" ></li>
-		</ul>
-		<div class="paging">
-		#if ($currentPage > 1)
-			#set ( $prev = $currentPage - 1 )
-                        #if($mapPatientPatientAttr.size()!=0)
-                            <a href="${baseLink}currentPage=1&pageSize=${pageSize}&sortPatientAttributeId=$patientAttribute.id" class="first" title="First">&laquo;&laquo;</a>
-                            <a href="${baseLink}currentPage=${prev}&pageSize=${pageSize}&sortPatientAttributeId=$patientAttribute.id" class="prev" title="Previous">&laquo;</a>
-                        #else
-                            <a href="${baseLink}currentPage=1&pageSize=${pageSize}" class="first" title="First">&laquo;&laquo;</a>
-                            <a href="${baseLink}currentPage=${prev}&pageSize=${pageSize}" class="prev" title="Previous">&laquo;</a>
-                        #end
-			
-		#else
-			<span class="first" title="First">&laquo;&laquo;</span>
-			<span class="prev" title="Previous">&laquo;</span>
-		#end
-		
-		#foreach( $i in [0..4]   )
-			#set( $p = $startPage + $i )
-			#if ( $p <= $numberOfPages )
-				#if( $i > 0 )
-					<span class="seperator">|</span>
-				#end
-				#if( $p != $currentPage )
-                                    #if($mapPatientPatientAttr.size()!=0)
-                                        <a href="${baseLink}currentPage=${p}&pageSize=${pageSize}&sortPatientAttributeId=$patientAttribute.id" class="page" title="Page $p">$p</a>
-                                    #else
-					<a href="${baseLink}currentPage=${p}&pageSize=${pageSize}" class="page" title="Page $p">$p</a>
-                                    #end
-				#else
-					<span class="page" title="Page $p">$p</span>
-				#end
-			#end
-		#end
-		
-		#if ( $currentPage < $numberOfPages )
-			#set ( $next = $currentPage + 1 )
-                        #if($mapPatientPatientAttr.size()!=0)
-                            <a href="${baseLink}currentPage=${next}&pageSize=${pageSize}&sortPatientAttributeId=$patientAttribute.id" class="next" title="Next">&raquo;</a>
-                            <a href="${baseLink}currentPage=${numberOfPages}&pageSize=${pageSize}&sortPatientAttributeId=$patientAttribute.id" class="last" title="Last">&raquo;&raquo;</a>
-                        #else
-                            <a href="${baseLink}currentPage=${next}&pageSize=${pageSize}" class="next" title="Next">&raquo;</a>
-                            <a href="${baseLink}currentPage=${numberOfPages}&pageSize=${pageSize}" class="last" title="Last">&raquo;&raquo;</a>
-                        #end
-		#else
-			<span class="next" title="Next">&raquo; </span>
-			<span class="last" title="Last">&raquo;&raquo;</span>
-		#end
-		</div>
-	#end

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/style/paging.css'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/style/paging.css	2010-03-09 07:55:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/style/paging.css	1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
-.paging-container {text-align: right; }
-div.paging {width:400px;float:right; margin-right:22em; text-align: right; height:16px; }
-div.paging span, div.paging a {padding: 0 5px;font-weight: bold; font-size: 11px;}
-div.paging a {text-decoration: none; color: #FF9900;}
-div.paging a:hover {color: #000;}
-div.paging span.page {color:#000;}
-div.paging span.seperator {display:none;}
-ul.pageSizeSelection {list-style:none; float:left; width: 160px; margin: 0; padding: 0;}
-ul.pageSizeSelection span {width: 100px; display: block; float :left;}
-ul.pageSizeSelection input {text-align: right}
\ No newline at end of file