← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6239: (patient) Improve tabular report.

 

------------------------------------------------------------
revno: 6239
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-03-10 12:06:47 +0700
message:
  (patient) Improve tabular report.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/DataRecordingSelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/TabularReportSelectAction.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/webapp/dhis-web-caseentry/caseAggregationForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTabularReportResult.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportResult.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.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/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-03-09 03:20:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-03-10 05:06:47 +0000
@@ -87,11 +87,11 @@
 
     List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed );
             
-    List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, int min, int max );
+    List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, int min, int max );
 
-    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, int min, int max, I18nFormat format, I18n i18n );
+    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, int min, int max, I18nFormat format, I18n i18n );
     
-    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, I18nFormat format, I18n i18n );
+    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, I18nFormat format, I18n i18n );
 
     int countProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate );
     

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2012-03-07 05:54:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2012-03-10 05:06:47 +0000
@@ -71,9 +71,9 @@
     
     List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max );
     
-    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, int min, int max );
+    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, int min, int max );
     
-    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate );
+    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc );
 
     int count( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate );
     

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-03-09 08:19:09 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-03-10 05:06:47 +0000
@@ -187,34 +187,37 @@
     }
 
     public List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage,
-        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, int min,
-        int max )
+        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+        boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, int min, int max )
     {
-        return programStageInstanceStore.get( programStage, searchingKeys, orgunitIds, startDate, endDate, min, max );
+        return programStageInstanceStore.get( programStage, searchingKeys, orgunitIds, startDate, endDate,
+            orderByOrgunitAsc, orderByExecutionDateByAsc, min, max );
     }
 
     public List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage,
-        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate )
+        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+        boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc )
     {
-        return programStageInstanceStore.get( programStage, searchingKeys, orgunitIds, startDate, endDate );
+        return programStageInstanceStore.get( programStage, searchingKeys, orgunitIds, startDate, endDate,
+            orderByOrgunitAsc, orderByExecutionDateByAsc );
     }
 
     public Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements,
-        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate, int min,
-        int max, I18nFormat format, I18n i18n )
+        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+        boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, int min, int max, I18nFormat format, I18n i18n )
     {
         List<ProgramStageInstance> programStageInstances = searchProgramStageInstances( programStage, searchingKeys,
-            orgunitIds, startDate, endDate, min, max );
+            orgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc, min, max );
 
         return createTabularGrid( programStage, programStageInstances, dataElements, startDate, endDate, format, i18n );
     }
 
     public Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements,
         Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate,
-        I18nFormat format, I18n i18n )
+        boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc, I18nFormat format, I18n i18n )
     {
         List<ProgramStageInstance> programStageInstances = searchProgramStageInstances( programStage, searchingKeys,
-            orgunitIds, startDate, endDate );
+            orgunitIds, startDate, endDate, orderByOrgunitAsc, orderByExecutionDateByAsc );
 
         return createTabularGrid( programStage, programStageInstances, dataElements, startDate, endDate, format, i18n );
     }
@@ -320,6 +323,9 @@
             // Headers
             // ---------------------------------------------------------------------
 
+            grid.addHeader( new GridHeader( i18n.getString( "report_unit" ), false, true ) );
+            grid.addHeader( new GridHeader( i18n.getString( "report_date" ), false, true ) );
+
             for ( DataElement dataElement : dataElements )
             {
                 grid.addHeader( new GridHeader( dataElement.getName(), false, true ) );
@@ -337,6 +343,8 @@
             for ( ProgramStageInstance programStageInstance : programStageInstances )
             {
                 grid.addRow();
+                grid.addValue( programStageInstance.getOrganisationUnit().getName() );
+                grid.addValue( format.formatDate( programStageInstance.getExecutionDate() ) );
 
                 for ( DataElement dataElement : dataElements )
                 {
@@ -359,13 +367,12 @@
                         grid.addValue( "" );
                     }
                 }
-                
+
                 if ( programStageInstance.getProgramInstance().getPatient() != null )
                 {
-                    grid.addValue( programStageInstance.getProgramInstance().getPatient()
-                        .getId() );
+                    grid.addValue( programStageInstance.getProgramInstance().getPatient().getId() );
                 }
-                else if( !anonymous )
+                else if ( !anonymous )
                 {
                     grid.addValue( "" );
                 }
@@ -374,5 +381,4 @@
 
         return grid;
     }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-03-09 04:46:32 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-03-10 05:06:47 +0000
@@ -37,6 +37,7 @@
 
 import org.amplecode.quick.StatementHolder;
 import org.amplecode.quick.StatementManager;
+import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
@@ -188,11 +189,13 @@
 
     @SuppressWarnings( "unchecked" )
     public List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer, String> searchingKeys,
-        Collection<Integer> orgunitIds, Date startDate, Date endDate, int min, int max )
+        Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc,
+        boolean orderByExecutionDateByAsc, int min, int max )
     {
         if ( searchingKeys.keySet().size() > 0 )
         {
-            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunitIds, startDate, endDate )
+            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunitIds, startDate, endDate,
+                orderByOrgunitAsc, orderByExecutionDateByAsc )
                 + statementBuilder.limitRecord( min, max );
 
             List<Integer> ids = executeSQL( sql );
@@ -203,22 +206,43 @@
             {
                 programStageInstances.add( get( id ) );
             }
-
             return programStageInstances;
         }
 
-        return (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.in( "organisationUnit.id",
-            orgunitIds ), Restrictions.between( "dueDate", startDate, endDate ) )).setFirstResult( min ).setMaxResults(
-            max ).list();
+        Criteria criteria = (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.in(
+            "organisationUnit.id", orgunitIds ), Restrictions.between( "executionDate", startDate, endDate ) ))
+            .setFirstResult( min ).setMaxResults( max );
+
+        if ( orderByOrgunitAsc )
+        {
+            criteria.addOrder( Order.asc( "organisationUnit" ) );
+        }
+        else
+        {
+            criteria.addOrder( Order.desc( "organisationUnit" ) );
+        }
+
+        if ( orderByExecutionDateByAsc )
+        {
+            criteria.addOrder( Order.asc( "executionDate" ) );
+        }
+        else
+        {
+            criteria.addOrder( Order.desc( "executionDate" ) );
+        }
+
+        return criteria.list();
     }
 
     @SuppressWarnings( "unchecked" )
     public List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer, String> searchingKeys,
-        Collection<Integer> orgunitIds, Date startDate, Date endDate )
+        Collection<Integer> orgunitIds, Date startDate, Date endDate, boolean orderByOrgunitAsc,
+        boolean orderByExecutionDateByAsc )
     {
         if ( searchingKeys.keySet().size() > 0 )
         {
-            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunitIds, startDate, endDate );
+            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunitIds, startDate, endDate,
+                orderByOrgunitAsc, orderByExecutionDateByAsc );
 
             List<Integer> ids = executeSQL( sql );
 
@@ -232,8 +256,29 @@
             return programStageInstances;
         }
 
-        return (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.in( "organisationUnit.id",
-            orgunitIds ), Restrictions.between( "dueDate", startDate, endDate ) )).list();
+        Criteria criteria = (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.in(
+            "organisationUnit.id", orgunitIds ), Restrictions.between( "executionDate", startDate, endDate ) ))
+            .addOrder( Order.desc( "organisationUnit" ) ).addOrder( Order.desc( "executionDate" ) );
+
+        if ( orderByOrgunitAsc )
+        {
+            criteria = criteria.addOrder( Order.asc( "organisationUnit" ) );
+        }
+        else
+        {
+            criteria = criteria.addOrder( Order.desc( "organisationUnit" ) );
+        }
+
+        if ( orderByExecutionDateByAsc )
+        {
+            criteria = criteria.addOrder( Order.asc( "executionDate" ) );
+        }
+        else
+        {
+            criteria = criteria.addOrder( Order.desc( "executionDate" ) );
+        }
+
+        return criteria.list();
     }
 
     public int count( ProgramStage programStage, Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds,
@@ -241,7 +286,8 @@
     {
         if ( searchingKeys.keySet().size() > 0 )
         {
-            String sql = getBySearchingValues( true, programStage, searchingKeys, orgunitIds, startDate, endDate );
+            String sql = getBySearchingValues( true, programStage, searchingKeys, orgunitIds, startDate, endDate, true,
+                true );
             List<Integer> countRow = executeSQL( sql );
             return (countRow != null && countRow.size() > 0) ? countRow.get( 0 ) : 0;
         }
@@ -254,14 +300,19 @@
     }
 
     private String getBySearchingValues( boolean isCount, ProgramStage programStage,
-        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate )
+        Map<Integer, String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate,
+        boolean orderByOrgunitAsc, boolean orderByExecutionDateByAsc )
     {
-        String sql = "select distinct( psi.programstageinstanceid) from patientdatavalue pdv "
+        String sql = " select distinct psi.programstageinstanceid from patientdatavalue pdv "
             + "inner join programstageinstance psi on pdv.programstageinstanceid=psi.programstageinstanceid ";
 
-        String condition = " WHERE psi.duedate >= '" + DateUtils.getMediumDateString( startDate )
-            + "' AND psi.duedate <= '" + DateUtils.getMediumDateString( endDate ) + "' "
-            + " AND psi.organisationunitid in " + splitListHelper ( orgunitIds ) + " ";
+        String select = "select distinct psi.programstageinstanceid, psi.organisationunitid, psi.executiondate ";
+
+        String condition = " from patientdatavalue pdv "
+            + "inner join programstageinstance psi on pdv.programstageinstanceid=psi.programstageinstanceid "
+            + "WHERE psi.executiondate >= '" + DateUtils.getMediumDateString( startDate )
+            + "' AND psi.executiondate <= '" + DateUtils.getMediumDateString( endDate ) + "' "
+            + " AND psi.organisationunitid in " + splitListHelper( orgunitIds ) + " ";
 
         Iterator<Integer> keys = searchingKeys.keySet().iterator();
         boolean index = false;
@@ -295,12 +346,15 @@
 
         if ( isCount )
         {
-            return "select count(psi.programstageinstanceid) from patientdatavalue pdv "
-                + "inner join programstageinstance psi on pdv.programstageinstanceid=psi.programstageinstanceid "
-                + condition;
+            return "select count(psi.programstageinstanceid) " + condition;
         }
 
-        return (sql + condition);
+        condition += " ORDER BY psi.organisationunitid ";
+        condition += orderByOrgunitAsc ? "asc" : "desc";
+        condition += ", psi.executiondate ";
+        condition += orderByExecutionDateByAsc ? "asc" : "desc";
+
+        return select + condition;
     }
 
     private List<Integer> executeSQL( String sql )
@@ -335,7 +389,7 @@
             holder.close();
         }
     }
-    
+
     /**
      * Splits a list of integers by comma. Use this method if you have a list
      * that will be used in f.ins. a WHERE xxx IN (list) clause in SQL.

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/DataRecordingSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/DataRecordingSelectAction.java	2012-02-27 08:39:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/DataRecordingSelectAction.java	2012-03-10 05:06:47 +0000
@@ -28,7 +28,6 @@
 
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2012-03-09 11:46:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2012-03-10 05:06:47 +0000
@@ -136,6 +136,20 @@
         this.searchingValues = searchingValues;
     }
 
+    private boolean orderByOrgunitAsc;
+
+    public void setOrderByOrgunitAsc( boolean orderByOrgunitAsc )
+    {
+        this.orderByOrgunitAsc = orderByOrgunitAsc;
+    }
+
+    private boolean orderByExecutionDateByAsc;
+
+    public void setOrderByExecutionDateByAsc( boolean orderByExecutionDateByAsc )
+    {
+        this.orderByExecutionDateByAsc = orderByExecutionDateByAsc;
+    }
+
     private Grid grid;
 
     public Grid getGrid()
@@ -258,18 +272,18 @@
 
         if ( type == null )
         {
-            total = programStageInstanceService.countProgramStageInstances( programStage, searchingKeys,
-                orgunitIds, startValue, endValue );
+            total = programStageInstanceService.countProgramStageInstances( programStage, searchingKeys, orgunitIds,
+                startValue, endValue );
 
             this.paging = createPaging( total );
 
-            grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys,
-                orgunitIds, startValue, endValue, paging.getStartPos(), paging.getPageSize(), format, i18n );
+            grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys, orgunitIds,
+                startValue, endValue, orderByOrgunitAsc, orderByExecutionDateByAsc, paging.getStartPos(), paging.getPageSize(), format, i18n );
             return SUCCESS;
         }
 
-        grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys,
-            orgunitIds, startValue, endValue, format, i18n );
+        grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys, orgunitIds,
+            startValue, endValue, orderByOrgunitAsc, orderByExecutionDateByAsc, format, i18n );
 
         return type;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/TabularReportSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/TabularReportSelectAction.java	2012-03-09 04:46:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/TabularReportSelectAction.java	2012-03-10 05:06:47 +0000
@@ -29,6 +29,8 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.caseentry.state.SelectedStateManager;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 
@@ -46,6 +48,13 @@
     // Dependencies
     // -------------------------------------------------------------------------
     
+    private SelectedStateManager selectedStateManager;
+
+    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+    {
+        this.selectedStateManager = selectedStateManager;
+    }
+
     private ProgramService programService;
 
     public void setProgramService( ProgramService programService )
@@ -64,13 +73,22 @@
         return programs;
     }
 
+    private OrganisationUnit orgunit;
+
+    public OrganisationUnit getOrgunit()
+    {
+        return orgunit;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
-         programs = programService.getAllPrograms();
+        orgunit = selectedStateManager.getSelectedOrganisationUnit();
+
+        programs = programService.getAllPrograms();
 
         return SUCCESS;
     }

=== 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-03-09 04:46:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-03-10 05:06:47 +0000
@@ -256,6 +256,8 @@
 	<bean id="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction"
 		class="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction"
 		scope="prototype">
+		<property name="selectedStateManager"
+			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 		<property name="programService"
 			ref="org.hisp.dhis.program.ProgramService" />
 	</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-03-09 04:46:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-03-10 05:06:47 +0000
@@ -15,7 +15,7 @@
 generate=Generate
 start_date=Start Date
 end_date=End Date
-reporting_unit=Reporting Unit
+orgunit_boundary= Organisation unit boundary
 invalid_date=Invalid Date
 report_date=Report Date
 program=Program
@@ -250,7 +250,7 @@
 see_history_plan=See history / plan
 name_based_data_entry=Name-based data entry
 multiple_name_based_data_entry=Multiple name-based data entry
-facility_by=Organisation Unit By
+orgunit_level= Organisation unit level
 saved = Saved
 save_selected_values = Save selected values
 save_all_values = Save all values
@@ -272,3 +272,9 @@
 date_of_incident=Date of incident
 patient_details_and_history = Beneficiary details and history
 selected = Selected
+orgunit = Organisation Unit
+add_all = Add all
+refresh_values = Refresh values
+report_unit = Report unit
+order_by_orgunit = Order by organisation unit
+order_by_report_date = Order by report date
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2012-03-09 04:46:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2012-03-10 05:06:47 +0000
@@ -49,7 +49,7 @@
 			
 			<tr>
 				<td>
-				   $i18n.getString( "facility_by" )
+				   $i18n.getString( "orgunit_level" )
 				</td>
 				<td>
 					<select id="facilityLB" name="facilityLB" style="width: 30em">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js	2012-03-09 08:19:09 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js	2012-03-10 05:06:47 +0000
@@ -106,7 +106,7 @@
 	var attrValues = input.attr('options').replace('[', '').replace(']', '').split(', ');
 	for( var i in attrValues )
 	{
-		options.push("='" + attrValues[i] + "'")
+		options.push( attrValues[i] )
 	}
 	options.push(" ");
 
@@ -167,6 +167,7 @@
 	showLoader();
 	isAjax = true;
 	contentDiv = 'contentDiv';
+	jQuery( "#gridContent" ).html( "" );
 	
 	var params = getParams();
 	if( params != '' )
@@ -185,39 +186,44 @@
 	}
 }
 
-function searchTabularReport( event )
+function onkeypressSearch( event )
+{
+var key = event.keyCode || event.charCode || event.which;
+	
+	if ( key == 13 || key == 1 ) // Enter
+	{
+		searchTabularReport();
+	}
+}
+
+function searchTabularReport()
 {	
-	var key = event.keyCode || event.charCode || event.which;
+	showById('loaderDiv');
+	hideById('gridContent');
+	hideById('pagingDiv');
 	
-	if ( key == 13 || key == 1 ) // Enter
-	{
-		showById('loaderDiv');
-		hideById('gridContent');
-		hideById('pagingDiv');
-		
-		isAjax = true;
-		contentDiv = 'gridContent';
+	isAjax = true;
+	contentDiv = 'gridContent';
 
-		var params = getParams();
-		if( params == '' )
-		{
-			hideById('loaderDiv');
-		}
-		else
-		{
-			$.ajax({
-				   type: "POST",
-				   url: "searchTabularReport.action",
-				   data: params,
-				   dataType: "html",
-				   success: function( result ){
-						hideById('loaderDiv');
-						jQuery( "#gridContent" ).html( result );
-						showById( "gridContent" );
-						showById('pagingDiv');
-				   }
-				});
-		}
+	var params = getParams();
+	if( params == '' )
+	{
+		hideById('loaderDiv');
+	}
+	else
+	{
+		$.ajax({
+			   type: "POST",
+			   url: "searchTabularReport.action",
+			   data: params,
+			   dataType: "html",
+			   success: function( result ){
+					hideById('loaderDiv');
+					jQuery( "#gridContent" ).html( result );
+					showById( "gridContent" );
+					showById('pagingDiv');
+			   }
+			});
 	}
 }
 
@@ -231,6 +237,22 @@
 	}
 }
 
+function onchangeOrderBy( element )
+{
+	searchTabularReport();
+	var isAcs = jQuery( element ).attr( 'orderBy' );
+	if( isAcs == 'true')
+	{
+		element.src = "../images/desc.gif";
+		jQuery( element ).attr( 'orderBy' ,'false' );
+	}
+	else
+	{
+		element.src = "../images/asc.gif";
+		jQuery( element ).attr( 'orderBy' ,'true' );
+	}
+}
+
 function getParams()
 {
 	hideMessage();
@@ -240,22 +262,10 @@
 	var regExp = new RegExp([]); 
 	
 	listSeachingValues.each( function( i, item ){
-		if( item.value!= '' )
+		if( item.value != '' )
 		{
-			var value = item.value;
-			var flag = value.match(/[>|>=|<|<=|=|!=]'[%]?.+[%]?'/);
-			
-			if( flag == null )
-			{
-				setMessage( i18n_syntax_error_in_search_value );
-				item.style.backgroundColor = '#ffcc00';
-				return "";
-			}
-			else
-			{
-				item.style.backgroundColor = '#ffffff';
-				searchingValues += "searchingValues=" + item.id + "_" + htmlEncode( item.value ) + "&";
-			}
+			var value = getFormula( item.value );
+			searchingValues += "searchingValues=" + item.id + "_" + htmlEncode( value ) + "&";
 		}
 	});
 	
@@ -266,9 +276,55 @@
 		dataElementIds += ( i < listDataElementIds.length - 1 ) ? "&" : "";
 	});
 	
+	var orderByOrgunitAsc = jQuery( '#orderByOrgunitAsc' ).attr('orderBy');
+	if( orderByOrgunitAsc == null )
+	{
+		orderByOrgunitAsc = 'true';
+	}
+	
+	var orderByExecutionDateByAsc = jQuery( '#orderByExecutionDateByAsc' ).attr('orderBy');
+	if( orderByExecutionDateByAsc == null )
+	{
+		orderByExecutionDateByAsc = 'true';
+	}
+	
 	return searchingValues + dataElementIds
 				+ "&programStageId=" + getFieldValue('programStageId')
 				+ "&startDate=" + getFieldValue('startDate')
 				+ "&endDate=" + getFieldValue('endDate')
-				+ "&facilityLB=" + getFieldValue('facilityLB');
+				+ "&facilityLB=" + getFieldValue('facilityLB')
+				+ "&orderByOrgunitAsc=" + orderByOrgunitAsc
+				+ "&orderByExecutionDateByAsc=" + orderByExecutionDateByAsc;
+}
+
+function getFormula( value )
+{
+	if( value.indexOf('"') != value.lastIndexOf('"') )
+	{
+		value = value.replace(/"/g,"'");
+	}
+	if( value.indexOf("'") == value.lastIndexOf("'") )
+	{
+		value += "'";
+		var flag = value.match(/[>|>=|<|<=|=|!=]+[ ]*/);
+	
+		if( flag == null )
+		{
+			value = "='"+ value;
+		}
+		else
+		{
+			value.replace( flag, flag + "'")
+		}
+	}
+	else
+	{
+		var flag = value.match(/[>|>=|<|<=|=|!=]+/);
+	
+		if( flag == null )
+		{
+			value = "="+ value;
+		}
+	}
+	return value;
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2012-02-17 17:11:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2012-03-10 05:06:47 +0000
@@ -3,7 +3,7 @@
 <form id="dataEntryForm" name="dataEntryForm" method="post" action="multipledataEntrySelect.action">
 	<table> 
 		<tr style="margin-bottom:8px">
-			<td><label>$i18n.getString( "reporting_unit" )</label></td>
+			<td><label>$i18n.getString( "orgunit" )</label></td>
 			<td>
 				<input type="text" readonly="readonly" id='orgunitName' name='orgunitName' #if( $organisationUnit ) value="$organisationUnit.name" #else value="[$i18n.getString( "select" )]" #end style="min-width:350px">
 			</td>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm	2012-03-05 07:32:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm	2012-03-10 05:06:47 +0000
@@ -13,7 +13,7 @@
 
 <table>	
     <tr>
-	  <td><label>$i18n.getString( "reporting_unit" )</label></td>
+	  <td><label>$i18n.getString( "orgunit_boundary" )</label></td>
 	  <td><input type="text" readonly="readonly" id='orgunitname' name='orgunitname' #if($!orgunit) value="$!orgunit.name" #else value="[$i18n.getString( 'select' )]" #end ></td>
     </tr>
     

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTabularReportResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTabularReportResult.vm	2012-03-09 07:59:38 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTabularReportResult.vm	2012-03-10 05:06:47 +0000
@@ -20,10 +20,8 @@
 					#if($col)
 					<a href="javascript:showPatientHistory( '$col' )" title='$i18n.getString( "patient_details_and_history" )'><img src="../images/information.png" alt='$i18n.getString( "patient_details_and_history" )'></a>
 					#end
-				#elseif( $grid.getHeaders().get( $index ).meta )
+				#else
 					$!encoder.htmlEncode( $col )
-				#else
-					$col
 				#end
 			</td>
 		#end

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportResult.vm	2012-03-09 07:59:38 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportResult.vm	2012-03-10 05:06:47 +0000
@@ -1,60 +1,75 @@
-<script>
-	$(document).ready(function() {
-		entryFormContainerOnReady();
-	});
-</script>
-
-<h3>$!encoder.htmlEncode( $grid.title )</h3>
-
-<div>
-<input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportTabularReport( 'xls' )" class="button" >
-<input type="button" value="$i18n.getString( 'get_report_as_pdf' )" onclick="exportTabularReport( 'pdf' )" class="button" >
-</div>
-
-<h5>$!encoder.htmlEncode( $grid.subtitle )</h5>
-
-#set( $anonymous = "true")
-#if( $grid.getVisibleHeaders().size() <  $grid.getHeaders().size() )
-	#set( $anonymous = "false" )
-#end
-
-<table class="listTable grid" id='gridTable'>
-	<tr>
-		<th>#</th>
-		#foreach( $dataElement in $dataElements )
-			<th>
-				$!encoder.htmlEncode( $dataElement.name )
-			</th>
-		#end
-		#if( $anonymous == "false" )
-			<th>$i18n.getString('operator')</th>
-		#end
-	</tr>
-	
-	<tr class='filter'>
-		<td>$i18n.getString('filter')</td>
-		#foreach( $dataElement in $dataElements )
-			<td>
-				<input type='text' id='$dataElement.id' title='$i18n.getString("how_to_search_tabular_report")' onkeypress='searchTabularReport( event );' #if($dataElement.optionSet) options='$dataElement.optionSet.options' #end />
-			</td>
-		#end
-		#if( $anonymous == "false" )
-			<td></td>
-		#end
-	</tr>
-	
-	<tbody id="gridContent">
-		#parse( "/dhis-web-caseentry/searchTabularReportResult.vm" )
-	</tbody>
-	
-</table>
-
-#parse( "dhis-web-commons/loader/loader.vm" )
-
-<p></p>
-
-<div class="paging-container" id='pagingDiv'>
-	#parse( "/dhis-web-commons/paging/paging.vm" )
-</div>
-
-<div id='viewRecordsDiv'></div>
\ No newline at end of file
+#if( $grid.getRows().size() > 0 ) 
+	<script>
+		$(document).ready(function() {
+			entryFormContainerOnReady();
+		});
+	</script>
+
+	<h3>$!encoder.htmlEncode( $grid.title )</h3>
+
+	<div>
+		<input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportTabularReport( 'xls' )" class="button" >
+		<input type="button" value="$i18n.getString( 'get_report_as_pdf' )" onclick="exportTabularReport( 'pdf' )" class="button" >
+		<input type="button" value="$i18n.getString( 'refresh_values' )" onclick="searchTabularReport()" class="button" >
+	</div>
+
+	<h5>$!encoder.htmlEncode( $grid.subtitle )</h5>
+
+	#set( $anonymous = "true")
+	#if( $grid.getVisibleHeaders().size() <  $grid.getHeaders().size() )
+		#set( $anonymous = "false" )
+	#end
+
+	<table class="listTable grid" id='gridTable'>
+		<tr>
+			<th>#</th>
+			<th>
+				$i18n.getString('report_unit')
+					<a href="javascript:searchTabularReport();" title='$i18n.getString( "order_by_orgunit" )'><img src="../images/asc.gif" alt='$i18n.getString( "asc" )' id='orderByOrgunitAsc' orderBy='true' onclick='onchangeOrderBy( this )' style='curser:pointer;'></a>
+			</th>
+			<th>
+				$i18n.getString('report_date')
+					<a href="javascript:searchTabularReport();"  title='$i18n.getString( "order_by_report_date" )'><img src="../images/asc.gif" alt='$i18n.getString( "desc" )' id='orderByExecutionDateByAsc' orderBy='true' onclick='onchangeOrderBy( this )' style='curser:pointer;'></a>
+			</th>
+			#foreach( $dataElement in $dataElements )
+				<th>
+					$!encoder.htmlEncode( $dataElement.name )
+				</th>
+			#end
+			#if( $anonymous == "false" )
+				<th>$i18n.getString('operator')</th>
+			#end
+		</tr>
+		
+		<tr class='filter'>
+			<td>$i18n.getString('filter')</td>
+			<td></td>
+			<td></td>
+			#foreach( $dataElement in $dataElements )
+				<td>
+					<input type='text' id='$dataElement.id' title='$i18n.getString("how_to_search_tabular_report")' onkeypress='onkeypressSearch( event );' #if($dataElement.optionSet) options='$dataElement.optionSet.options' #end />
+				</td>
+			#end
+			#if( $anonymous == "false" )
+				<td></td>
+			#end
+		</tr>
+		
+		<tbody id="gridContent">
+			#parse( "/dhis-web-caseentry/searchTabularReportResult.vm" )
+		</tbody>
+		
+	</table>
+
+	#parse( "dhis-web-commons/loader/loader.vm" )
+
+	<p></p>
+
+	<div class="paging-container" id='pagingDiv'>
+		#parse( "/dhis-web-commons/paging/paging.vm" )
+	</div>
+
+	<div id='viewRecordsDiv'></div>
+#else
+	$i18n.getString('no_result')
+#end
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm	2012-03-09 07:59:38 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm	2012-03-10 05:06:47 +0000
@@ -14,13 +14,13 @@
 
 <table>	
     <tr>
-	  <td><label>$i18n.getString( "reporting_unit" )</label></td>
+	  <td><label>$i18n.getString( "orgunit_boundary" )</label></td>
 	  <td colspan='2'><input type="text" readonly="readonly" id='orgunitname' name='orgunitname' #if($!orgunit) value="$!orgunit.name" #else value="[$i18n.getString( 'select' )]" #end ></td>
     </tr>
 	
     <tr>
 		<td>
-		   $i18n.getString( "facility_by" )
+		   $i18n.getString( "orgunit_level" )
 		</td>
 		<td>
 			<select id="facilityLB" name="facilityLB" style="width: 30em">
@@ -80,9 +80,10 @@
 	
 	<tr>
         <td></td>
-		<td>
-            <input type="button" value="$i18n.getString( 'add_selected' )" title="$i18n.getString( 'add_selected' )" onclick="moveSelectedById( 'availableDataElementIds', 'dataElementIds' )" />
-            <input type="button" value="$i18n.getString( 'remove_selected' )" title="$i18n.getString( 'remove_selected' )" onclick="moveSelectedById( 'dataElementIds', 'availableDataElementIds' )" />
+		<td> <input type="button" value="$i18n.getString( 'add_selected' )" title="$i18n.getString( 'add_selected' )" style="width:120px" onclick="moveSelectedById( 'availableDataElementIds', 'dataElementIds' )" />
+            <input type="button" value="$i18n.getString( 'add_all' )" title="$i18n.getString( 'add_all' )" style="width:120px" onclick="moveAllById( 'availableDataElementIds', 'dataElementIds' )" /> <br>
+            <input type="button" value="$i18n.getString( 'remove_selected' )" title="$i18n.getString( 'remove_selected' )" style="width:120px" onclick="moveSelectedById( 'dataElementIds', 'availableDataElementIds' )" />
+            <input type="button" value="$i18n.getString( 'remove_all' )" title="$i18n.getString( 'remove_all' )" style="width:120px" onclick="moveAllById( 'dataElementIds', 'availableDataElementIds' )" />
         </td>
     </tr>