← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8281: Improve activity plan; export result to excel file.

 

------------------------------------------------------------
revno: 8281
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-09-27 15:00:40 +0700
message:
  Improve activity plan; export result to excel file.
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/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  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/activityPlanRecords.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/colorHelp.vm
  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/javascript/activityPlan.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm


--
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	2012-09-27 06:54:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2012-09-27 08:00:40 +0000
@@ -31,6 +31,8 @@
 import java.util.Date;
 import java.util.List;
 
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
@@ -210,5 +212,7 @@
     Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max );
 
     Collection<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max );
+    
+    Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, I18n i18n );
 
 }

=== 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	2012-09-27 06:54:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2012-09-27 08:00:40 +0000
@@ -32,6 +32,7 @@
 import java.util.List;
 
 import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 
@@ -74,4 +75,7 @@
 
     Collection<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Integer min,
         Integer max );
+    
+    Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit );
+
 }

=== 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	2012-09-27 06:54:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2012-09-27 08:00:40 +0000
@@ -27,7 +27,18 @@
 
 package org.hisp.dhis.patient;
 
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
@@ -37,11 +48,9 @@
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.relationship.RelationshipTypeService;
+import org.hisp.dhis.system.grid.ListGrid;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.lang.reflect.Type;
-import java.util.*;
-
 /**
  * @author Abyot Asalefew Gizaw
  * @version $Id$
@@ -115,7 +124,7 @@
 
     @Override
     public int createPatient( Patient patient, Integer representativeId, Integer relationshipTypeId,
-                              List<PatientAttributeValue> patientAttributeValues )
+        List<PatientAttributeValue> patientAttributeValues )
     {
         int patientid = savePatient( patient );
 
@@ -183,7 +192,7 @@
 
     @Override
     public Collection<Patient> getPatients( String firstName, String middleName, String lastName, Date birthdate,
-                                            String gender )
+        String gender )
     {
         return patientStore.get( firstName, middleName, lastName, birthdate, gender );
     }
@@ -248,7 +257,8 @@
         patients.addAll( patientIdentifierService.getPatientsByIdentifier( searchText, 0, Integer.MAX_VALUE ) );
         patients.addAll( getPatientsByNames( searchText, 0, Integer.MAX_VALUE ) );
 
-        // if an orgunit has been selected, filter out every patient that has a different ou
+        // if an orgunit has been selected, filter out every patient that has a
+        // different ou
         if ( orgUnitId != 0 )
         {
             Set<Patient> toRemoveList = new HashSet<Patient>();
@@ -275,7 +285,7 @@
 
     @Override
     public Collection<Patient> getPatients( OrganisationUnit organisationUnit, PatientAttribute patientAttribute,
-                                            Integer min, Integer max )
+        Integer min, Integer max )
     {
         List<Patient> patientList = new ArrayList<Patient>( patientStore.getByOrgUnit( organisationUnit, min, max ) );
 
@@ -291,7 +301,7 @@
 
     @Override
     public Collection<Patient> getPatients( OrganisationUnit organisationUnit, String searchText, Integer min,
-                                            Integer max )
+        Integer max )
     {
         Collection<Patient> patients = new ArrayList<Patient>();
 
@@ -402,8 +412,8 @@
 
     @Override
     public void updatePatient( Patient patient, Integer representativeId, Integer relationshipTypeId,
-                               List<PatientAttributeValue> valuesForSave, List<PatientAttributeValue> valuesForUpdate,
-                               Collection<PatientAttributeValue> valuesForDelete )
+        List<PatientAttributeValue> valuesForSave, List<PatientAttributeValue> valuesForUpdate,
+        Collection<PatientAttributeValue> valuesForDelete )
     {
 
         patientStore.update( patient );
@@ -496,7 +506,8 @@
             }
 
             return value;
-        } catch ( Exception ex )
+        }
+        catch ( Exception ex )
         {
             ex.printStackTrace();
         }
@@ -514,7 +525,8 @@
         patientStore.removeErollmentPrograms( program );
     }
 
-    public Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max )
+    public Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Integer min,
+        Integer max )
     {
         return patientStore.search( searchKeys, orgunit, min, max );
     }
@@ -523,16 +535,52 @@
     {
         return patientStore.countSearch( searchKeys, orgunit );
     }
-    
-    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max )
+
+    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Integer min,
+        Integer max )
     {
         return patientStore.getPatientPhoneNumbers( searchKeys, orgunit, min, max );
     }
-    
-    public Collection<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max )
+
+    public Collection<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit,
+        Integer min, Integer max )
     {
         return patientStore.getProgramStageInstances( searchKeys, orgunit, min, max );
     }
-    
+
+    public Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, I18n i18n )
+    {
+        String startDate = "";
+        String endDate = "";
+        for ( String searchKey : searchKeys )
+        {
+            String[] keys = searchKey.split( "_" );
+            if ( keys[0].equals( Patient.PREFIX_PROGRAM_EVENT_BY_STATUS ) )
+            {
+                startDate = keys[2];
+                endDate = keys[3];
+            }
+        }
+
+        Grid grid = new ListGrid();
+        grid.setTitle( i18n.getString( "activity_plan" ) );
+        if ( !startDate.isEmpty() && !endDate.isEmpty() )
+        {
+            grid.setSubtitle( i18n.getString( "from" ) + " " + startDate + " " + i18n.getString( "to" ) + endDate );
+        }
+        
+        grid.addHeader( new GridHeader( "patientid", true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "first_name" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "middle_name" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "last_name" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "gender" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "phone_number" ), false, true ) );
+        grid.addHeader( new GridHeader( "orgunitid", true, true ) );
+        grid.addHeader( new GridHeader( "programstageinstanceid", true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
+
+        return patientStore.getPatientEventReport( grid, searchKeys, orgunit );
+    }
 
 }

=== 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	2012-09-27 06:54:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2012-09-27 08:00:40 +0000
@@ -42,6 +42,7 @@
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -49,8 +50,10 @@
 import org.hisp.dhis.patient.PatientStore;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.system.grid.GridUtils;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -323,6 +326,22 @@
 
         return jdbcTemplate.queryForInt( sql );
     }
+    
+    @Override
+    public Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit )
+    {
+        // ---------------------------------------------------------------------
+        // Get SQL and build grid
+        // ---------------------------------------------------------------------
+
+        String sql = searchPatientSql( false, searchKeys, orgunit, null, null );
+
+        SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
+
+        GridUtils.addRows( grid, rowSet );
+        
+        return grid;
+    }
 
     // -------------------------------------------------------------------------
     // Supportive methods
@@ -333,12 +352,11 @@
     {
         String selector = count ? "count(*) " : "* ";
 
-        String sql = "select "
-            + selector
-            + " from ( select distinct p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber, p.birthdate, p.deathdate,";
+        String sql = "select " + selector
+            + " from ( select distinct p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber,";
         String patientWhere = "";
         String patientOperator = " where ";
-        String patientGroupBy = " GROUP BY  p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber, p.birthdate, p.deathdate ";
+        String patientGroupBy = " GROUP BY  p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber ";
         String otherWhere = "";
         String operator = " where ";
         String orderBy = "";
@@ -404,10 +422,9 @@
             }
             else if ( keys[0].equals( Patient.PREFIX_PROGRAM_EVENT_BY_STATUS ) )
             {
-                patientGroupBy += ",pgi.programid ";
                 isSearchEvent = true;
                 patientWhere += patientOperator + "pgi.patientid=p.patientid and ";
-                patientWhere += "programid=" + id + " and ";
+                patientWhere += "pgi.programid=" + id + " and ";
                 patientWhere += "psi.duedate>='" + keys[2] + "' and psi.duedate<='" + keys[3] + "' and ";
                 patientWhere += "pgi.completed = false ";
 
@@ -433,16 +450,20 @@
                         condition = "";
                         continue;
                     case ProgramStageInstance.FUTURE_VISIT_STATUS:
-                        patientWhere += condition + operatorStatus + "("
-                            + " psi.status is null and psi.executiondate is null and psi.duedate >= now() and p.organisationunitid=" + keys[4]
-                            + ")";
+                        patientWhere += condition
+                            + operatorStatus
+                            + "("
+                            + " psi.status is null and psi.executiondate is null and psi.duedate >= now() and p.organisationunitid="
+                            + keys[4] + ")";
                         operatorStatus = " OR ";
                         condition = "";
                         continue;
                     case ProgramStageInstance.LATE_VISIT_STATUS:
-                        patientWhere += condition + operatorStatus + "("
-                            + " psi.status is null and psi.executiondate is null and psi.duedate < now() and p.organisationunitid=" + keys[4]
-                            + ")";
+                        patientWhere += condition
+                            + operatorStatus
+                            + "("
+                            + " psi.status is null and psi.executiondate is null and psi.duedate < now() and p.organisationunitid="
+                            + keys[4] + ")";
                         operatorStatus = " OR ";
                         condition = "";
                         continue;
@@ -501,9 +522,10 @@
         String from = " from patient p ";
         if ( isSearchEvent )
         {
-            String subSQL = " ,MIN( psi.programstageinstanceid ) as programstageinstanceid,min(psi.duedate) as duedate ";
-            sql = sql + subSQL + from + " left join programinstance pgi on " + " (pgi.patientid=p.patientid) "
-                + " left join programstageinstance psi on " + " (psi.programinstanceid=pgi.programinstanceid) ";
+            String subSQL = " ,MIN( psi.programstageinstanceid ) as programstageinstanceid, min(pgs.name) as programstagename, min(psi.duedate) as duedate ";
+            sql = sql + subSQL + from + " inner join programinstance pgi on " + " (pgi.patientid=p.patientid) "
+                + " inner join programstageinstance psi on " + " (psi.programinstanceid=pgi.programinstanceid) "
+                + " inner join programstage pgs on (pgs.programstageid=psi.programstageid)";
             orderBy = " ORDER BY duedate DESC ";
             from = " ";
         }
@@ -527,8 +549,7 @@
         {
             sql += statementBuilder.limitRecord( min, max );
         }
-        
+
         return sql;
     }
-
 }

=== 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	2012-09-12 13:36:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2012-09-27 08:00:40 +0000
@@ -29,12 +29,13 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.patient.Patient;
@@ -43,9 +44,6 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.program.comparator.ProgramStageInstanceDueDateComparator;
 
 public class GetDataRecordsAction
     extends ActionPagingSupport<Patient>
@@ -82,11 +80,11 @@
         this.programInstanceService = programInstanceService;
     }
 
-    private ProgramStageInstanceService programStageInstanceService;
+    private I18n i18n;
 
-    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    public void setI18n( I18n i18n )
     {
-        this.programStageInstanceService = programStageInstanceService;
+        this.i18n = i18n;
     }
 
     // -------------------------------------------------------------------------
@@ -121,6 +119,13 @@
         this.searchTexts = searchTexts;
     }
 
+    private String type;
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
     private Integer total;
 
     public Integer getTotal()
@@ -128,27 +133,6 @@
         return total;
     }
 
-    private Collection<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
-
-    public Collection<ProgramInstance> getProgramInstances()
-    {
-        return programInstances;
-    }
-
-    private Map<ProgramInstance, List<ProgramStageInstance>> programStageInstanceMap = new HashMap<ProgramInstance, List<ProgramStageInstance>>();
-
-    public Map<ProgramInstance, List<ProgramStageInstance>> getProgramStageInstanceMap()
-    {
-        return programStageInstanceMap;
-    }
-
-    private Map<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
-
-    public Map<Integer, Integer> getStatusMap()
-    {
-        return statusMap;
-    }
-
     private Map<Patient, ProgramInstance> programInstanceMap = new HashMap<Patient, ProgramInstance>();
 
     public Map<Patient, ProgramInstance> getProgramInstanceMap()
@@ -163,13 +147,6 @@
         return patients;
     }
 
-    private Collection<Integer> programStageInstanceIds;
-
-    public Collection<Integer> getProgramStageInstanceIds()
-    {
-        return programStageInstanceIds;
-    }
-
     private Program program;
 
     public Program getProgram()
@@ -177,6 +154,13 @@
         return program;
     }
 
+    private Grid grid;
+
+    public Grid getGrid()
+    {
+        return grid;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation Action
     // -------------------------------------------------------------------------
@@ -191,68 +175,52 @@
         // ---------------------------------------------------------------------
         // Program instances for the selected program
         // ---------------------------------------------------------------------
-
-        // List all patients
-        if ( listAll )
-        {
-            if ( program == null )
-            {
-                total = patientService.countGetPatientsByOrgUnit( orgunit );
-            }
-            else
-            {
-                total = patientService.countGetPatientsByOrgUnitProgram( orgunit, program );
-            }
-            
-            this.paging = createPaging( total );
-
-            patients = new ArrayList<Patient>( patientService.getPatients( orgunit, program, paging.getStartPos(),
-                paging.getPageSize() ) );
-
-        }
-        // search patients
-        else if ( searchTexts.size() > 0 )
-        {
-            orgunit = (searchBySelectedOrgunit) ? orgunit : null;
-
-            total = patientService.countSearchPatients( searchTexts, orgunit );
-            this.paging = createPaging( total );
-            patients = patientService.searchPatients( searchTexts, orgunit, paging.getStartPos(), paging.getPageSize() );
-
-            programStageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunit,
-                paging.getStartPos(), paging.getPageSize() );
-        }
-
-        Collection<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
-
-        for ( Patient patient : patients )
-        {
-            Collection<ProgramInstance> _programInstances = programInstanceService.getProgramInstances( patient,
-                program, false );
-
-            if ( _programInstances == null || _programInstances.size() == 0 )
-            {
-                programInstanceMap.put( patient, null );
-            }
-            else
-            {
-                for ( ProgramInstance programInstance : _programInstances )
-                {
-                    programInstanceMap.put( patient, programInstance );
-                    programInstances.add( programInstance );
-
-                    List<ProgramStageInstance> programStageInstanceList = new ArrayList<ProgramStageInstance>(
-                        programInstance.getProgramStageInstances() );
-                    Collections.sort( programStageInstanceList, new ProgramStageInstanceDueDateComparator() );
-
-                    programStageInstanceMap.put( programInstance, programStageInstanceList );
-                    programStageInstances.addAll( programStageInstanceList );
-                }
-            }
-        }
-
-        statusMap = programStageInstanceService.statusProgramStageInstances( programStageInstances );
-
-        return SUCCESS;
+        if ( type == null ) // Tabular report
+        {
+            // List all patients
+            if ( listAll )
+            {
+                total = (program == null) ? patientService.countGetPatientsByOrgUnit( orgunit ) : patientService
+                    .countGetPatientsByOrgUnitProgram( orgunit, program );
+
+                this.paging = createPaging( total );
+
+                patients = new ArrayList<Patient>( patientService.getPatients( orgunit, program, paging.getStartPos(),
+                    paging.getPageSize() ) );
+
+            }
+            // search patients
+            else if ( searchTexts.size() > 0 )
+            {
+                orgunit = (searchBySelectedOrgunit) ? orgunit : null;
+
+                total = patientService.countSearchPatients( searchTexts, orgunit );
+                this.paging = createPaging( total );
+                patients = patientService.searchPatients( searchTexts, orgunit, paging.getStartPos(),
+                    paging.getPageSize() );
+            }
+
+            for ( Patient patient : patients )
+            {
+                Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient,
+                    program, false );
+
+                if ( programInstances == null || programInstances.size() == 0 )
+                {
+                    programInstanceMap.put( patient, null );
+                }
+                else
+                {
+                    programInstanceMap.put( patient, programInstances.iterator().next() );
+                }
+            }
+        }
+        else
+        // Download as Excel
+        {
+            grid = patientService.getScheduledEventsReport( searchTexts, orgunit, i18n );
+        }
+        
+        return type == null ? SUCCESS : type;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-09-26 05:19:53 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-09-27 08:00:40 +0000
@@ -170,8 +170,6 @@
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
-		<property name="programStageInstanceService"
-			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-09-26 09:39:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-09-27 08:00:40 +0000
@@ -463,4 +463,5 @@
 change_location = Change location
 user_access = User access
 history = History
-use_calendar = Use calendar
\ No newline at end of file
+use_calendar = Use calendar
+export_xls = Export XLS
\ No newline at end of file

=== 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	2012-09-26 08:42:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-09-27 08:00:40 +0000
@@ -987,6 +987,12 @@
 			<param name="page">/dhis-web-caseentry/activityPlanRecords.vm</param>
 			<param name="stylesheets">style/style.css</param>
 		</action>
+		
+		<action name="exportActitityList"
+			class="org.hisp.dhis.caseentry.action.caseentry.GetDataRecordsAction">
+			<result name="xls" type="gridXlsResult" />
+			<result name="pdf" type="gridPdfResult" />
+		</action>
 
 	</package>
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanRecords.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanRecords.vm	2012-09-21 01:10:53 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanRecords.vm	2012-09-27 08:00:40 +0000
@@ -47,8 +47,7 @@
 					<td class='bold' name="toggleFlowBtn" style='cursor:pointer;font-size:25px' onclick="eventFlowToggle($programInstance.id)">
 						<a>&raquo;</a>
 					</td>
-					#if($!programStageInstanceMap.get($programInstance))
-						#set($programStageInstances = $programStageInstanceMap.get($programInstance) )
+					#set( $programStageInstances = $programInstance.programStageInstances )
 					<td>
 						<table id='tb_$programInstance.id'>	
 							<tr>
@@ -71,18 +70,11 @@
 														#set( $index = $index + 1 )
 													#end
 												#end
-												#foreach( $sms in $programStageInstance.outboundSms)
-													#if( $index < 5)
-														#set( $title= $title + "$format.formatDate( $sms.date ) - $sms.message &#13;&#10;")
-														#set( $index = $index + 1)
-													#end
-												#end
-												
 												#set($valueDate=$format.formatDate( $programStageInstance.dueDate ))
 												#if($!programStageInstance.executionDate)
 													#set($valueDate=$format.formatDate( $programStageInstance.executionDate ))
 												#end
-												<input type="button" name="programStageBtn"
+												 <input type="button" name="programStageBtn"
 													id="ps_$!programStageInstance.id"
 													psid="$programStageInstance.programStage.id"
 													psname="$programStageInstance.programStage.name"
@@ -97,10 +89,10 @@
 													value="$programStageInstance.programStage.name&#13;&#10;$valueDate" 
 													onclick="javascript:loadDataEntry( $programStageInstance.id );">
 												<script>	
-													var status = $statusMap.get( $programStageInstance.id ); 
+													var status = $programStageInstance.getEventStatus();
 													setEventColorStatus( $programStageInstance.id ,status);
 												</script>
-											</td>
+											</td> 
 										#end
 										</tr>
 									</table></div>
@@ -112,8 +104,7 @@
 							</tr>
 						</table>
 					</td>
-					#end
-				</tr>
+					</tr>
 			#if( $mark )
 				#set( $mark = false )
 			#else

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm	2012-09-26 09:39:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/activityPlanSelect.vm	2012-09-27 08:00:40 +0000
@@ -90,6 +90,7 @@
 				<td></td>
 				<td>
 					<input type="submit" class='large-button' id='listPatientBtn' value="$i18n.getString( 'show_activity_list' )">
+					<input type="button" class='large-button' value="$i18n.getString( 'export_xls' )" onclick='exportActitityList("xls");'>
 				</td>
 			</tr>
 		</table>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/colorHelp.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/colorHelp.vm	2012-09-20 07:20:37 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/colorHelp.vm	2012-09-27 08:00:40 +0000
@@ -24,7 +24,7 @@
 		</tr>
 		<tr>
 			<td id='colorGreyTD'><script>byId('colorGreyTD').style.backgroundColor = COLOR_GREY;</script></td>
-			<td>$i18n.getString('stages_skipped')</td>
+			<td>$i18n.getString('stage_skipped')</td>
 		</tr>
 	</table>
 </div>
\ No newline at end of file

=== 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	2012-09-21 01:10:53 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm	2012-09-27 08:00:40 +0000
@@ -44,12 +44,10 @@
 						<input type='button' class='patient-object' value="$value"
 							onclick='javascript:showPatientHistory( "$patient.id" );' title='$i18n.getString( "patient_details_and_history" )'>
 					</td>
-					#if($!programStageInstanceMap.get($programInstance))
-						#set($programStageInstances = $programStageInstanceMap.get($programInstance) )
-						<td>
-							#parse( "/dhis-web-caseentry/programStageInstanceFlow.vm" )
-						</td>
-					#end
+					#set( $programStageInstances = $programInstance.programStageInstances )
+					<td>
+						#parse( "/dhis-web-caseentry/programStageInstanceFlow.vm" )
+					</td>
 				</tr>
 			#if( $mark )
 				#set( $mark = false )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js	2012-09-26 09:39:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/activityPlan.js	2012-09-27 08:00:40 +0000
@@ -47,7 +47,6 @@
 	hideById('listPatientDiv');
 	contentDiv = 'listPatientDiv';
 	$('#contentDataRecord').html('');
-	var searchBySelectedOrgunit = false;
 	var programId = getFieldValue('programIdAddPatient');
 	var searchTexts = "stat_" + programId
 					+ "_" + getFieldValue('startDueDate')
@@ -60,7 +59,7 @@
 		{
 			programId:programId,
 			listAll:false,
-			searchBySelectedOrgunit: searchBySelectedOrgunit,
+			searchBySelectedOrgunit: false,
 			searchTexts: searchTexts
 		}, 
 		function()
@@ -72,6 +71,25 @@
 		});
 }
 
+function exportActitityList( type )
+{
+	var programId = getFieldValue('programIdAddPatient');
+	var searchTexts = "stat_" + programId
+					+ "_" + getFieldValue('startDueDate')
+					+ "_" + getFieldValue('endDueDate')
+					+ "_" + getFieldValue('orgunitId')
+					+ "_" + getFieldValue('statusEvent');
+	var params = "searchTexts=" + searchTexts;
+		params += "&listAll=fase";
+		params += "&type=" + type;
+		params += "&programId=" + getFieldValue('programIdAddPatient');
+		params += "&searchBySelectedOrgunit=false";
+	
+	var url = "exportActitityList.action?" + params;
+	window.location.href = url;
+}
+
+
 function eventFlowToggle( programInstanceId )
 {
 	jQuery("#tb_" + programInstanceId + " .stage-object").each( function(){

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm	2012-08-15 02:57:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm	2012-09-27 08:00:40 +0000
@@ -7,7 +7,7 @@
 		"programStageId": "$programStageInstance.programStage.id",
 		"programStageName": "$programStageInstance.programStage.name",
 		"dueDate": "$format.formatDate( $programStageInstance.dueDate )",
-		"status": "$statusMap.get( $programStageInstance.id )"
+		"status": "$programStageInstance.getEventStatus()"
 	  }#if( $velocityCount < $size ),#end
 	#end]
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2012-09-26 08:42:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm	2012-09-27 08:00:40 +0000
@@ -95,7 +95,7 @@
 										
 										#set($flag = 'false')
 										#foreach( $programStageInstance in $programInstance.programStageInstances )
-											#set( $status = $statusMap.get( $programStageInstance.id ) )
+											#set( $status = $programStageInstance.getEventStatus() )
 											#if( $status!=1 && $status!=5 && $flag=='false')
 												<tr id='tr1_$programInstance.id' type='$programInstance.program.type'
 													programStageInstanceId='$programStageInstanceId' style='cursor:pointer;'

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm	2012-09-25 02:50:39 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm	2012-09-27 08:00:40 +0000
@@ -47,8 +47,7 @@
 					<td class='bold' style='cursor:pointer;font-size:25px' onclick="eventFlowToggle($programInstance.id)">
 						<a>&raquo;</a>
 					</td>
-					#if($!programStageInstanceMap.get($programInstance))
-						#set($programStageInstances = $programStageInstanceMap.get($programInstance) )
+					#set( $programStageInstances = $programInstance.programStageInstances )
 					<td>
 						<table id='tb_$programInstance.id' class="stage-container">	
 							<tr>
@@ -71,12 +70,6 @@
 														#set( $index = $index + 1 )
 													#end
 												#end
-												#foreach( $sms in $programStageInstance.outboundSms)
-													#if( $index < 5)
-														#set( $title= $title + "$format.formatDate( $sms.date ) - $sms.message &#13;&#10;")
-														#set( $index = $index + 1)
-													#end
-												#end
 												
 												#set($valueDate=$format.formatDate( $programStageInstance.dueDate ))
 												#if($!programStageInstance.executionDate)
@@ -88,12 +81,12 @@
 													programStageId='$programStageInstance.programStage.id' 
 													programInstanceId='$programInstance.id'
 													dueDate='$format.formatDate( $programStageInstance.dueDate )'
-													status='$statusMap.get( $programStageInstance.id )'
+													status='$programStageInstance.getEventStatus()'
 													class='stage-object'
 													value='$programStageInstance.programStage.name&#13;&#10;$valueDate' 
 													title="$title" onclick='javascript:programTrackingList( $programStageInstance.id, false );'>
 												<script>
-													var status = $statusMap.get( $programStageInstance.id ); 
+													var status = $programStageInstance.getEventStatus(); 
 													var dueDate = "$format.formatDate($programStageInstance.dueDate)";
 													setEventColorStatus( $programStageInstance.id ,status, dueDate );
 												</script>
@@ -109,7 +102,6 @@
 							</tr>
 						</table>
 					</td>
-					#end
 				</tr>
 			#if( $mark )
 				#set( $mark = false )