← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6163: (patient) Tabular report.

 

------------------------------------------------------------
revno: 6163
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-03-05 11:22:57 +0700
message:
  (patient) Tabular report.
added:
  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/LoadDataElementsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadProgramStagesAction.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/webapp/dhis-web-caseentry/javascript/tabularReport.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.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/style/report.css
  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
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
  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-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.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-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patientdatavalue/hibernate/PatientDataValue.hbm.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveProvidingFacilityAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.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/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/index.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportsMenu.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.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/patientdatavalue/PatientDataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java	2012-03-05 04:22:57 +0000
@@ -1,4 +1,5 @@
 package org.hisp.dhis.patientdatavalue;
+
 /*
  * Copyright (c) 2004-2009, University of Oslo
  * All rights reserved.
@@ -30,7 +31,6 @@
 import java.util.Date;
 
 import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.ProgramStageInstance;
 
 /**
@@ -49,14 +49,10 @@
 
     private ProgramStageInstance programStageInstance;
 
-    private OrganisationUnit organisationUnit;
-
     private Date timestamp;
 
     private String value;
 
-    private boolean providedByAnotherFacility = false;
-
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -65,43 +61,26 @@
     {
     }
 
-    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement,
-        OrganisationUnit organisationUnit )
-    {
-        this.programStageInstance = programStageInstance;
-        this.dataElement = dataElement;
-        this.organisationUnit = organisationUnit;
-    }
-
-    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement,
-        OrganisationUnit organisationUnit, Date timeStamp )
-    {
-        this.programStageInstance = programStageInstance;
-        this.dataElement = dataElement;
-        this.organisationUnit = organisationUnit;
-        this.timestamp = timeStamp;
-    }
-
-    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement,
-        OrganisationUnit organisationUnit, Date timeStamp, String value )
-    {
-        this.programStageInstance = programStageInstance;
-        this.dataElement = dataElement;
-        this.organisationUnit = organisationUnit;
-        this.timestamp = timeStamp;
-        this.value = value;
-    }
-
-    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement,
-        OrganisationUnit organisationUnit, Date timeStamp, String value,
-        boolean providedByAnotherFacility )
-    {
-        this.programStageInstance = programStageInstance;
-        this.dataElement = dataElement;
-        this.organisationUnit = organisationUnit;
-        this.timestamp = timeStamp;
-        this.value = value;
-        this.providedByAnotherFacility = providedByAnotherFacility;
+    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement )
+    {
+        this.programStageInstance = programStageInstance;
+        this.dataElement = dataElement;
+    }
+
+    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, Date timeStamp )
+    {
+        this.programStageInstance = programStageInstance;
+        this.dataElement = dataElement;
+        this.timestamp = timeStamp;
+    }
+
+    public PatientDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, Date timeStamp,
+        String value )
+    {
+        this.programStageInstance = programStageInstance;
+        this.dataElement = dataElement;
+        this.timestamp = timeStamp;
+        this.value = value;
     }
 
     // -------------------------------------------------------------------------
@@ -114,7 +93,6 @@
         final int prime = 31;
         int result = 1;
         result = prime * result + ((dataElement == null) ? 0 : dataElement.hashCode());
-        result = prime * result + ((organisationUnit == null) ? 0 : organisationUnit.hashCode());
         result = prime * result + ((programStageInstance == null) ? 0 : programStageInstance.hashCode());
         return result;
     }
@@ -136,13 +114,6 @@
         }
         else if ( !dataElement.equals( other.dataElement ) )
             return false;
-        if ( organisationUnit == null )
-        {
-            if ( other.organisationUnit != null )
-                return false;
-        }
-        else if ( !organisationUnit.equals( other.organisationUnit ) )
-            return false;
         if ( programStageInstance == null )
         {
             if ( other.programStageInstance != null )
@@ -196,24 +167,4 @@
     {
         return value;
     }
-
-    public void setOrganisationUnit( OrganisationUnit organisationUnit )
-    {
-        this.organisationUnit = organisationUnit;
-    }
-
-    public OrganisationUnit getOrganisationUnit()
-    {
-        return organisationUnit;
-    }
-
-    public void setProvidedByAnotherFacility( boolean providedByAnotherFacility )
-    {
-        this.providedByAnotherFacility = providedByAnotherFacility;
-    }
-
-    public boolean isProvidedByAnotherFacility()
-    {
-        return providedByAnotherFacility;
-    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2011-12-21 07:16:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2012-03-05 04:22:57 +0000
@@ -29,6 +29,8 @@
 import java.io.Serializable;
 import java.util.Date;
 
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
 /**
  * @author Abyot Asalefew
  * @version $Id$
@@ -61,8 +63,12 @@
 
     private Date executionDate;
     
+    private OrganisationUnit organisationUnit;
+
     private boolean completed = false;
 
+    private Boolean providedByAnotherFacility = false;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -236,4 +242,22 @@
         this.completed = completed;
     }
 
+    public OrganisationUnit getOrganisationUnit()
+    {
+        return organisationUnit;
+    }
+
+    public void setOrganisationUnit( OrganisationUnit organisationUnit )
+    {
+        this.organisationUnit = organisationUnit;
+    }
+    public void setProvidedByAnotherFacility( Boolean providedByAnotherFacility )
+    {
+        this.providedByAnotherFacility = providedByAnotherFacility;
+    }
+
+    public Boolean isProvidedByAnotherFacility()
+    {
+        return providedByAnotherFacility;
+    }
 }

=== 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-01-15 02:14:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-03-05 04:22:57 +0000
@@ -32,6 +32,7 @@
 import java.util.Map;
 
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -64,7 +65,7 @@
     Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate, Boolean completed );
 
     Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate );
-
+    
     Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate, Boolean completed );
 
     Collection<ProgramStageInstance> getAllProgramStageInstances();
@@ -82,7 +83,7 @@
      *        ) or uncompleted (<code>false</code>) instances.
      * @return
      */
-    public List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed );
+    List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed );
 
     List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed );
     
@@ -91,5 +92,12 @@
     int countProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate );
     
     Grid getSingleEventReport( ProgramInstance programInstance, Date startDate, Date endDate, int min, int max, I18nFormat format, I18n i18n );
-
+    
+    List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max );
+
+    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max, I18nFormat format, I18n i18n );
+    
+    Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, I18nFormat format, I18n i18n );
+
+    int countProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, 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-01-15 02:14:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java	2012-03-05 04:22:57 +0000
@@ -29,6 +29,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -47,15 +48,15 @@
 
     Collection<ProgramStageInstance> get( ProgramStage programStage );
 
-    Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate );
-    
-    Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate, Boolean completed );
-
-    Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate );
-    
-    Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate, Boolean completed );
-
-    Collection<ProgramStageInstance> getProgramStageInstances( Collection<ProgramInstance> programInstances );
+    Collection<ProgramStageInstance> get( Date dueDate );
+    
+    Collection<ProgramStageInstance> get( Date dueDate, Boolean completed );
+
+    Collection<ProgramStageInstance> get( Date startDate, Date endDate );
+        
+    Collection<ProgramStageInstance> get( Date startDate, Date endDate, Boolean completed );
+
+    Collection<ProgramStageInstance> get( Collection<ProgramInstance> programInstances );
 
     /** Get all {@link ProgramStageInstance program stage instances} for unit.
      * @param unit - the unit to get instances for.
@@ -64,11 +65,20 @@
      * @param completed - optional flag to only get completed (<code>true</code>) or uncompleted (<code>false</code>) instances. 
      * @return
      */
-    public List<ProgramStageInstance> get(OrganisationUnit unit, Date after, Date before, Boolean completed);
-
-    List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed);
-    
-    List<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate , int min, int max );
-    
-    int countProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate );
+    public List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed );
+
+    List<ProgramStageInstance> get( Patient patient, Boolean completed);
+    
+    List<ProgramStageInstance> get( ProgramInstance programInstance, Date startDate, Date endDate , int min, int max );
+
+    int count( ProgramInstance programInstance, Date startDate, Date endDate );
+    
+    List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max );
+    
+    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max );
+    
+    List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate );
+
+    int count( ProgramStage programStage, Map<Integer,String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate );
+    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2012-03-05 04:22:57 +0000
@@ -368,7 +368,8 @@
                     idTypeName = identifierType.getName();
                 }
 
-                identifiers.add( new org.hisp.dhis.api.mobile.model.PatientIdentifier( idTypeName, id.getIdentifier() ) );
+                identifiers
+                    .add( new org.hisp.dhis.api.mobile.model.PatientIdentifier( idTypeName, id.getIdentifier() ) );
             }
 
             beneficiary.setIdentifiers( identifiers );
@@ -422,8 +423,7 @@
                         programStageInstanceService.updateProgramStageInstance( programStageInstance );
                     }
 
-                    dataValue = new PatientDataValue( programStageInstance, dataElement, orgUnit,
-                        new Date(), value, false );
+                    dataValue = new PatientDataValue( programStageInstance, dataElement, new Date(), value );
 
                     dataValueService.savePatientDataValue( dataValue );
                 }
@@ -437,7 +437,6 @@
                 }
 
                 dataValue.setValue( value );
-                dataValue.setProvidedByAnotherFacility( false );
                 dataValue.setTimestamp( new Date() );
 
                 dataValueService.updatePatientDataValue( dataValue );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-02-23 04:05:16 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-03-05 04:22:57 +0000
@@ -539,7 +539,6 @@
 
     private String createSQL( String aggregationExpression, String operator, int orgunitId, String startDate, String endDate )
     {
-        
         // ---------------------------------------------------------------------
         // get operators
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2012-02-28 01:55:12 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2012-03-05 04:22:57 +0000
@@ -53,7 +53,8 @@
  * @version TableAlteror.java Sep 9, 2010 10:22:29 PM
  */
 public class TableAlteror
-    extends AbstractStartupRoutine{
+    extends AbstractStartupRoutine
+{
     private static final Log log = LogFactory.getLog( TableAlteror.class );
 
     Pattern IDENTIFIER_PATTERN = Pattern.compile( "DE:(\\d+)\\.(\\d+)\\.(\\d+)" );
@@ -70,30 +71,30 @@
     }
 
     private DataElementCategoryService categoryService;
-    
+
     public void setCategoryService( DataElementCategoryService categoryService )
     {
         this.categoryService = categoryService;
     }
-    
+
     private CaseAggregationConditionService aggregationConditionService;
-    
+
     public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
     {
         this.aggregationConditionService = aggregationConditionService;
-    }  
-    
+    }
+
     private ProgramValidationService programValidationService;
 
     public void setProgramValidationService( ProgramValidationService programValidationService )
     {
         this.programValidationService = programValidationService;
     }
-  
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
-  
+
     @Transactional
     public void execute()
         throws Exception
@@ -126,33 +127,36 @@
         executeSql( "UPDATE dataset SET mobile = false WHERE mobile is null" );
 
         executeSql( "UPDATE dataset SET version = 1 WHERE version is null" );
-        
+
         executeSql( "UPDATE program SET singleEvent = false WHERE singleevent is null" );
-        
+
         executeSql( "UPDATE program SET anonymous = false WHERE anonymous is null" );
-        
+
         executeSql( "UPDATE programstage SET irregular = false WHERE irregular is null" );
 
-        executeSql( "Alter table programinstance modify patientid integer null");
-        		
+        executeSql( "Alter table programinstance modify patientid integer null" );
+
         updateSingleProgramValidation();
 
         updateStageInProgram();
 
-        executeSql( "UPDATE programvalidation SET dateType = false WHERE dateType is null");
-        
-        executeSql( "UPDATE programstage_dataelements SET showOnReport = false WHERE showOnReport is null");
-        
+        executeSql( "UPDATE programvalidation SET dateType = false WHERE dateType is null" );
+
+        executeSql( "UPDATE programstage_dataelements SET showOnReport = false WHERE showOnReport is null" );
+
         int categoryOptionId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
-        executeSql( "UPDATE dataelement SET categoryoptioncomboid = " + categoryOptionId + " WHERE domain='patient'");
-        
+        executeSql( "UPDATE dataelement SET categoryoptioncomboid = " + categoryOptionId + " WHERE domain='patient'" );
+        executeSql( "ALTER TABLE patientdatavalue DROP COLUMN categoryoptioncomboid" );
+
         upgradeCaseAggregationFormula();
-        
+
         upgradeProgramValidationFormula();
-        
+
         executeSql( "UPDATE program SET displayProvidedOtherFacility = false WHERE displayProvidedOtherFacility is null" );
-        
-        executeSql( "ALTER TABLE relationshiptype RENAME description TO name");
+
+        executeSql( "ALTER TABLE relationshiptype RENAME description TO name" );
+
+        updateProgramStageInstanceOrgunit();
     }
 
     // -------------------------------------------------------------------------
@@ -320,11 +324,11 @@
             holder.close();
         }
     }
-    
+
     private void upgradeCaseAggregationFormula()
     {
         Collection<CaseAggregationCondition> conditions = aggregationConditionService.getAllCaseAggregationCondition();
-        
+
         for ( CaseAggregationCondition condition : conditions )
         {
             String formula = upgradeFormula( condition.getAggregationExpression() );
@@ -332,11 +336,11 @@
             aggregationConditionService.updateCaseAggregationCondition( condition );
         }
     }
-    
+
     private void upgradeProgramValidationFormula()
     {
         Collection<ProgramValidation> programValidations = programValidationService.getAllProgramValidation();
-        
+
         for ( ProgramValidation programValidation : programValidations )
         {
             String leftSide = upgradeFormula( programValidation.getLeftSide() );
@@ -346,7 +350,7 @@
             programValidationService.updateProgramValidation( programValidation );
         }
     }
-    
+
     private String upgradeFormula( String formula )
     {
         Matcher matcher = IDENTIFIER_PATTERN.matcher( formula );
@@ -361,10 +365,41 @@
         }
 
         matcher.appendTail( out );
-        
+
         return out.toString();
     }
 
+    private void updateProgramStageInstanceOrgunit()
+    {
+        StatementHolder holder = statementManager.getHolder();
+
+        try
+        {
+            Statement statement = holder.getStatement();
+
+            ResultSet resultSet = statement
+                .executeQuery( "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue" );
+            resultSet.next();
+            while ( resultSet.next() )
+            {
+                executeSql( "UPDATE programstageinstance SET organisationunitid=" + resultSet.getInt( 2 )
+                    + ", providedByAnotherFacility=" + resultSet.getBoolean( 3 ) + "  WHERE programstageinstanceid="
+                    + resultSet.getInt( 1 ) );
+            }
+
+            executeSql( "ALTER TABLE patientdatavalue DROP COLUMN organisationUnitid" );
+            executeSql( "ALTER TABLE patientdatavalue DROP COLUMN providedByAnotherFacility" );
+        }
+        catch ( Exception ex )
+        {
+            log.debug( ex );
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
+
     private int executeSql( String sql )
     {
         try

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-02-27 02:09:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-03-05 04:22:57 +0000
@@ -51,12 +51,6 @@
 {
     private static final String EMPTY = "";
 
-    private static final String UNKNOW_CLINIC = "unknow_clinic";
-
-    private static final String NOTAVAILABLE = "not_available";
-
-    private static final String OTHER_FACILITY = "other_facility";
-
     private static final String DATA_ELEMENT_DOES_NOT_EXIST = "[ Data element does not exist ]";
 
     private static final String EMPTY_VALUE_TAG = "value=\"\"";
@@ -116,13 +110,13 @@
         String result = "";
 
         result = populateCustomDataEntryForTextBox( htmlCode, dataValues, disabled, i18n, programStage,
-            programStageInstance, organisationUnit, mapDataValue );
+            programStageInstance, mapDataValue );
 
         result = populateCustomDataEntryForDate( result, dataValues, disabled, i18n, programStage,
-            programStageInstance, organisationUnit, mapDataValue );
+            programStageInstance, mapDataValue );
 
         result = populateCustomDataEntryForBoolean( result, dataValues, disabled, i18n, programStage,
-            programStageInstance, organisationUnit, mapDataValue );
+            programStageInstance, mapDataValue );
 
         result = populateI18nStrings( result, i18n );
 
@@ -185,8 +179,8 @@
                 int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
                 DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
-                String displayValue = (dataElement == null ) ? " value=\""
-                    + DATA_ELEMENT_DOES_NOT_EXIST + "\" " : " value=\"[ " + dataElement.getName() + " ]\"";
+                String displayValue = (dataElement == null) ? " value=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\" "
+                    : " value=\"[ " + dataElement.getName() + " ]\"";
                 inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
                     : inputHTML + " " + displayValue;
 
@@ -344,15 +338,14 @@
 
     private String populateCustomDataEntryForBoolean( String dataEntryFormCode,
         Collection<PatientDataValue> dataValues, String disabled, I18n i18n, ProgramStage programStage,
-        ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit,
-        Map<Integer, Collection<PatientDataValue>> mapDataValue )
+        ProgramStageInstance programStageInstance, Map<Integer, Collection<PatientDataValue>> mapDataValue )
     {
 
         // ---------------------------------------------------------------------
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForBoolean = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', provided:'$PROVIDED'}\" onchange=\"saveOpt( $DATAELEMENTID )\" style=\"  text-align:center;\" ";
+        final String jsCodeForBoolean = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME' }\" onchange=\"saveOpt( $DATAELEMENTID )\" style=\"  text-align:center;\" ";
 
         StringBuffer sb = new StringBuffer();
 
@@ -518,40 +511,14 @@
                 {
                     disabled = "disabled";
                 }
-                else
-                {
-                    // -----------------------------------------------------------
-                    // Add ProvidedByOtherFacility checkbox
-                    // -----------------------------------------------------------
-
-                    appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue, programStage );
-                }
 
                 // -----------------------------------------------------------
                 // 
                 // -----------------------------------------------------------
 
-                String orgUnitName = i18n.getString( NOTAVAILABLE );
-                String provided = i18n.getString( NOTAVAILABLE );
-                ;
-                if ( patientDataValue != null )
-                {
-                    if ( patientDataValue.isProvidedByAnotherFacility() )
-                    {
-                        orgUnitName = i18n.getString( UNKNOW_CLINIC );
-                        provided = i18n.getString( OTHER_FACILITY );
-                    }
-                    else
-                    {
-                        orgUnitName = patientDataValue.getOrganisationUnit().getName();
-                        provided = patientDataValue.getOrganisationUnit().getName();
-                    }
-                }
-
                 appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGENAME", programStageName );
-                appendCode = appendCode.replace( "$ORGUNITNAME", orgUnitName );
                 appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() );
                 appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementType );
                 appendCode = appendCode.replace( "$DISABLED", disabled );
@@ -561,8 +528,6 @@
                 appendCode = appendCode.replace( "i18n_select_value", i18n.getString( "select_value" ) );
                 appendCode = appendCode.replace( "$SAVEMODE", "false" );
 
-                appendCode = appendCode.replace( "$PROVIDED", provided );
-
                 appendCode = appendCode.replaceAll( "\\$", "\\\\\\$" );
 
                 dataElementMatcher.appendReplacement( sb, appendCode );
@@ -576,15 +541,14 @@
 
     private String populateCustomDataEntryForTextBox( String dataEntryFormCode,
         Collection<PatientDataValue> dataValues, String disabled, I18n i18n, ProgramStage programStage,
-        ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit,
-        Map<Integer, Collection<PatientDataValue>> mapDataValue )
+        ProgramStageInstance programStageInstance, Map<Integer, Collection<PatientDataValue>> mapDataValue )
     {
         // ---------------------------------------------------------------------
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
-        final String jsCodeForOptions = " $DISABLED options='$OPTIONS' dataElementId=\"$DATAELEMENTID\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
+        final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
+        final String jsCodeForOptions = " $DISABLED options='$OPTIONS' dataElementId=\"$DATAELEMENTID\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
 
         StringBuffer sb = new StringBuffer();
 
@@ -651,7 +615,6 @@
                     continue;
                 }
 
-
                 if ( !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() )
                     && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) )
                 {
@@ -708,7 +671,8 @@
                 }
                 else
                 {
-                    dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName() + " (" + dataElementType + ")\" ";
+                    dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName() + " ("
+                        + dataElementType + ")\" ";
                 }
 
                 // -------------------------------------------------------------
@@ -725,12 +689,12 @@
                 {
                     appendCode += "value=\"" + dataElementValue + "\"";
                 }
-                
+
                 if ( dataElement.getOptionSet() != null )
                 {
-                   appendCode += jsCodeForOptions;
-                   
-                   appendCode = appendCode.replace( "$OPTIONS", dataElement.getOptionSet().getOptions().toString() ); 
+                    appendCode += jsCodeForOptions;
+
+                    appendCode = appendCode.replace( "$OPTIONS", dataElement.getOptionSet().getOptions().toString() );
                 }
                 else
                 {
@@ -738,7 +702,7 @@
                 }
 
                 appendCode += " />";
-                
+
                 // -----------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable
@@ -750,46 +714,18 @@
                 {
                     disabled = "disabled=\"\"";
                 }
-                else
-                {
-                    // ---------------------------------------------------------
-                    // Add ProvidedByOtherFacility checkbox
-                    // ---------------------------------------------------------
 
-                    appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue, programStage );
-                }
-                
                 // -----------------------------------------------------------
                 // 
                 // -----------------------------------------------------------
 
-                String orgUnitName = i18n.getString( NOTAVAILABLE );
-                String provided = "";
-
-                if ( patientDataValue != null )
-                {
-                    if ( patientDataValue.isProvidedByAnotherFacility() )
-                    {
-                        orgUnitName = i18n.getString( UNKNOW_CLINIC );
-                        provided = i18n.getString( OTHER_FACILITY );
-                    }
-                    else
-                    {
-                        orgUnitName = patientDataValue.getOrganisationUnit().getName();
-                        provided = patientDataValue.getOrganisationUnit().getName();
-                    }
-                }
-
-                appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGENAME", programStageName );
-                appendCode = appendCode.replace( "$ORGUNITNAME", orgUnitName );
                 appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() );
                 appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementType );
                 appendCode = appendCode.replace( "$DISABLED", disabled );
                 appendCode = appendCode.replace( "$COMPULSORY", compulsory );
                 appendCode = appendCode.replace( "$SAVEMODE", "false" );
-                appendCode = appendCode.replace( "$PROVIDED", provided );
 
                 dataElementMatcher.appendReplacement( sb, appendCode );
             }
@@ -802,13 +738,13 @@
 
     private String populateCustomDataEntryForDate( String dataEntryFormCode, Collection<PatientDataValue> dataValues,
         String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
-        OrganisationUnit organisationUnit, Map<Integer, Collection<PatientDataValue>> mapDataValue )
+        Map<Integer, Collection<PatientDataValue>> mapDataValue )
     {
         // ---------------------------------------------------------------------
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForDate = " name=\"entryfield\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', provided:'$PROVIDED'}\" onchange=\"saveVal( $DATAELEMENTID )\" style=\" text-align:center;\" ";
+        final String jsCodeForDate = " name=\"entryfield\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME'}\" onchange=\"saveVal( $DATAELEMENTID )\" style=\" text-align:center;\" ";
 
         // ---------------------------------------------------------------------
         // Metadata code to add to HTML before outputting
@@ -975,47 +911,21 @@
                 {
                     disabled = "disabled=\"\"";
                 }
-                else
-                {
-                    appendCode += jQueryCalendar;
-
-                    // ---------------------------------------------------------
-                    // Add ProvidedByOtherFacility checkbox
-                    // ---------------------------------------------------------
-
-                    appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue, programStage );
-                }
-
-                // -------------------------------------------------------------
-                // Get Org Unit name
-                // -------------------------------------------------------------
-
-                String orgUnitName = i18n.getString( NOTAVAILABLE );
-                String provided = i18n.getString( NOTAVAILABLE );
-                if ( patientDataValue != null )
-                {
-                    if ( patientDataValue.isProvidedByAnotherFacility() )
-                    {
-                        orgUnitName = i18n.getString( UNKNOW_CLINIC );
-                        provided = i18n.getString( OTHER_FACILITY );
-                    }
-                    else
-                    {
-                        orgUnitName = patientDataValue.getOrganisationUnit().getName();
-                        provided = patientDataValue.getOrganisationUnit().getName();
-                    }
-                }
+
+                appendCode += jQueryCalendar;
+
+                // -------------------------------------------------------------
+                // 
+                // -------------------------------------------------------------
 
                 appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) );
                 appendCode = appendCode.replace( "$PROGRAMSTAGENAME", programStageName );
-                appendCode = appendCode.replace( "$ORGUNITNAME", orgUnitName );
                 appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() );
                 appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementType );
                 appendCode = appendCode.replace( "$DISABLED", disabled );
                 appendCode = appendCode.replace( "$COMPULSORY", compulsory );
                 appendCode = appendCode.replace( "$SAVEMODE", "false" );
-                appendCode = appendCode.replace( "$PROVIDED", provided );
 
                 appendCode = appendCode.replaceAll( "\\$", "\\\\\\$" );
 
@@ -1068,33 +978,6 @@
     }
 
     /**
-     * Append a ProvidedByOtherFacility Checkbox to the html code
-     * 
-     * @param appendCode: current html code
-     * @param patientDataValue: currrent PatientDataValue
-     * @return full html code after append the check box
-     */
-    private String addProvidedByOtherFacilityCheckbox( String appendCode, PatientDataValue patientDataValue,
-        ProgramStage programStage )
-    {
-        appendCode += "<label style=\"display:$DISPLAY;\" for=\"$PROGRAMSTAGEID_$DATAELEMENTID_facility\" title=\"is provided by another Facility ?\" >" +
-        		"<input name=\"providedByAnotherFacility\"  title=\"is provided by another Facility ?\"  id=\"$PROGRAMSTAGEID_$DATAELEMENTID_facility\"  type=\"checkbox\" ";
-
-        if ( patientDataValue != null && patientDataValue.isProvidedByAnotherFacility() )
-        {
-            appendCode += " checked=\"checked\" ";
-        }
-        appendCode += "onChange=\"updateProvidingFacility( $DATAELEMENTID, this )\"  >";
-
-        String display = (programStage.getProgram().getDisplayProvidedOtherFacility() ) ? "block" : "none";
-        appendCode = appendCode.replace( "$DISPLAY", display );
-        appendCode += "</label>";
-
-        return appendCode;
-
-    }
-
-    /**
      * Replaces i18n string in the custom form code.
      * 
      * @param dataEntryFormCode the data entry form html.

=== 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-01-15 02:14:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-03-05 04:22:57 +0000
@@ -153,27 +153,27 @@
 
     public Collection<ProgramStageInstance> getProgramStageInstances( Collection<ProgramInstance> programInstances )
     {
-        return programStageInstanceStore.getProgramStageInstances( programInstances );
+        return programStageInstanceStore.get( programInstances );
     }
 
     public Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate )
     {
-        return programStageInstanceStore.getProgramStageInstances( dueDate );
+        return programStageInstanceStore.get( dueDate );
     }
 
     public Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate, Boolean completed )
     {
-        return programStageInstanceStore.getProgramStageInstances( dueDate, completed );
+        return programStageInstanceStore.get( dueDate, completed );
     }
 
     public Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate )
     {
-        return programStageInstanceStore.getProgramStageInstances( startDate, endDate );
+        return programStageInstanceStore.get( startDate, endDate );
     }
 
     public Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate, Boolean completed )
     {
-        return programStageInstanceStore.getProgramStageInstances( startDate, endDate, completed );
+        return programStageInstanceStore.get( startDate, endDate, completed );
     }
 
     public List<ProgramStageInstance> get( OrganisationUnit unit, Date after, Date before, Boolean completed )
@@ -183,25 +183,25 @@
 
     public List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed )
     {
-        return programStageInstanceStore.getProgramStageInstances( patient, completed );
-    }
-
-    public List<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate ,
-        int min, int max )
-    {
-        return programStageInstanceStore.getProgramStageInstances( programInstance, startDate, endDate , min, max );
-    }
-
-    public int countProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate  )
-    {
-        return programStageInstanceStore.countProgramStageInstances( programInstance, startDate, endDate  );
-    }
-
-    public Grid getSingleEventReport( ProgramInstance programInstance, Date startDate, Date endDate , int min, int max,
+        return programStageInstanceStore.get( patient, completed );
+    }
+
+    public List<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, Date startDate,
+        Date endDate, int min, int max )
+    {
+        return programStageInstanceStore.get( programInstance, startDate, endDate, min, max );
+    }
+
+    public int countProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate )
+    {
+        return programStageInstanceStore.count( programInstance, startDate, endDate );
+    }
+
+    public Grid getSingleEventReport( ProgramInstance programInstance, Date startDate, Date endDate, int min, int max,
         I18nFormat format, I18n i18n )
     {
-        List<ProgramStageInstance> programStageInstances = getProgramStageInstances( programInstance, startDate, endDate ,
-            min, max );
+        List<ProgramStageInstance> programStageInstances = getProgramStageInstances( programInstance, startDate,
+            endDate, min, max );
 
         ProgramStage programStage = programInstance.getProgram().getProgramStages().iterator().next();
 
@@ -221,7 +221,8 @@
         // ---------------------------------------------------------------------
 
         Grid grid = new ListGrid().setTitle( programInstance.getProgram().getName() );
-        grid.setSubtitle( i18n.getString( "from" ) + " " + format.formatDate( startDate ) + " " + i18n.getString( "to" ) + " " + format.formatDate( endDate ) );
+        grid.setSubtitle( i18n.getString( "from" ) + " " + format.formatDate( startDate ) + " " + i18n.getString( "to" )
+            + " " + format.formatDate( endDate ) );
 
         // ---------------------------------------------------------------------
         // Headers
@@ -262,4 +263,117 @@
 
         return grid;
     }
+
+    public List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage,
+        Map<Integer, String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max )
+    {
+        return programStageInstanceStore.get( programStage, searchingKeys, orgunit, startDate, endDate, min, max );
+    }
+    
+    public List<ProgramStageInstance> searchProgramStageInstances( ProgramStage programStage,
+        Map<Integer, String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate )
+    {
+        return programStageInstanceStore.get( programStage, searchingKeys, orgunit, startDate, endDate );
+    }
+
+    public Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements,
+        Map<Integer, String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max,
+        I18nFormat format, I18n i18n )
+    {
+        List<ProgramStageInstance> programStageInstances = searchProgramStageInstances( programStage, searchingKeys,
+            orgunit, startDate, endDate, min, max );
+
+        return createTabularGrid( programStage, programStageInstances, dataElements, startDate, endDate, format, i18n );
+    }
+
+    public Grid getTabularReport( ProgramStage programStage, List<DataElement> dataElements,
+        Map<Integer, String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate, I18nFormat format,
+        I18n i18n )
+    {
+        List<ProgramStageInstance> programStageInstances = searchProgramStageInstances( programStage, searchingKeys,
+            orgunit, startDate, endDate );
+
+        return createTabularGrid( programStage, programStageInstances, dataElements, startDate, endDate, format, i18n );
+    }
+
+    @Override
+    public int countProgramStageInstances( ProgramStage programStage, Map<Integer, String> searchingKeys,
+        OrganisationUnit orgunit, Date startDate, Date endDate )
+    {
+        return programStageInstanceStore.count( programStage, searchingKeys, orgunit, startDate, endDate );
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Grid createTabularGrid( ProgramStage programStage, List<ProgramStageInstance> programStageInstances,
+        List<DataElement> dataElements, Date startDate, Date endDate, I18nFormat format, I18n i18n )
+    {
+        Grid grid = new ListGrid();
+
+        if ( dataElements != null && dataElements.size() > 0 && programStageInstances.size() > 0 )
+        {
+            Program program = programStage.getProgram();
+
+            // ---------------------------------------------------------------------
+            // Create a grid
+            // ---------------------------------------------------------------------
+
+            grid.setTitle( program.getName() );
+            grid.setSubtitle( i18n.getString( "from" ) + " " + format.formatDate( startDate ) + " "
+                + i18n.getString( "to" ) + " " + format.formatDate( endDate ) );
+
+            // ---------------------------------------------------------------------
+            // Headers
+            // ---------------------------------------------------------------------
+
+            for ( DataElement dataElement : dataElements )
+            {
+                grid.addHeader( new GridHeader( dataElement.getName(), false, false ) );
+            }
+
+            grid.addHeader( new GridHeader( i18n.getString( "operations" ), true, false ) );
+
+            grid.addHeader( new GridHeader( i18n.getString( "status" ), true, false ) );
+
+            // ---------------------------------------------------------------------
+            // Values
+            // ---------------------------------------------------------------------
+
+            for ( ProgramStageInstance programStageInstance : programStageInstances )
+            {
+                grid.addRow();
+
+                for ( DataElement dataElement : dataElements )
+                {
+                    PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue(
+                        programStageInstance, dataElement );
+
+                    if ( patientDataValue != null )
+                    {
+                        if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
+                        {
+                            grid.addValue( i18n.getString( patientDataValue.getValue() ) );
+                        }
+                        else
+                        {
+                            grid.addValue( patientDataValue.getValue() );
+                        }
+                    }
+                    else
+                    {
+                        grid.addValue( "" );
+                    }
+                }
+
+                grid.addValue( programStageInstance.getId() );
+
+                grid.addValue( programStageInstance.isCompleted() );
+            }
+        }
+
+        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-01-15 02:14:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-03-05 04:22:57 +0000
@@ -26,22 +26,30 @@
  */
 package org.hisp.dhis.program.hibernate;
 
+import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
+import org.amplecode.quick.StatementHolder;
+import org.amplecode.quick.StatementManager;
 import org.hibernate.Query;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
+import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceStore;
+import org.hisp.dhis.system.util.DateUtils;
 
 /**
  * @author Abyot Asalefew
@@ -51,6 +59,29 @@
     extends HibernateGenericStore<ProgramStageInstance>
     implements ProgramStageInstanceStore
 {
+
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    private StatementManager statementManager;
+
+    public void setStatementManager( StatementManager statementManager )
+    {
+        this.statementManager = statementManager;
+    }
+
+    private StatementBuilder statementBuilder;
+
+    public void setStatementBuilder( StatementBuilder statementBuilder )
+    {
+        this.statementBuilder = statementBuilder;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implemented methods
+    // -------------------------------------------------------------------------
+
     @SuppressWarnings( "unchecked" )
     public ProgramStageInstance get( ProgramInstance programInstance, ProgramStage programStage )
     {
@@ -68,31 +99,31 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramStageInstance> getProgramStageInstances( Collection<ProgramInstance> programInstances )
+    public Collection<ProgramStageInstance> get( Collection<ProgramInstance> programInstances )
     {
         return getCriteria( Restrictions.in( "programInstance", programInstances ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate )
+    public Collection<ProgramStageInstance> get( Date dueDate )
     {
         return getCriteria( Restrictions.eq( "dueDate", dueDate ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate, Boolean completed )
+    public Collection<ProgramStageInstance> get( Date dueDate, Boolean completed )
     {
         return getCriteria( Restrictions.eq( "dueDate", dueDate ), Restrictions.eq( "completed", completed ) ).list();
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate )
+    public Collection<ProgramStageInstance> get( Date startDate, Date endDate )
     {
         return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ) )).list();
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<ProgramStageInstance> getProgramStageInstances( Date startDate, Date endDate, Boolean completed )
+    public Collection<ProgramStageInstance> get( Date startDate, Date endDate, Boolean completed )
     {
         return (getCriteria( Restrictions.ge( "dueDate", startDate ), Restrictions.le( "dueDate", endDate ),
             Restrictions.eq( "completed", completed ) )).list();
@@ -139,7 +170,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed )
+    public List<ProgramStageInstance> get( Patient patient, Boolean completed )
     {
         String hql = "from ProgramStageInstance where programInstance.patient = :patient and completed = :completed";
 
@@ -147,18 +178,178 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public List<ProgramStageInstance> getProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate,
-        int min, int max )
+    public List<ProgramStageInstance> get( ProgramInstance programInstance, Date startDate, Date endDate, int min,
+        int max )
     {
         return getCriteria( Restrictions.eq( "programInstance.id", programInstance.getId() ),
-            Restrictions.between( "executionDate", startDate, endDate ) ).setFirstResult( min ).setMaxResults( max ).list();
+            Restrictions.between( "executionDate", startDate, endDate ) ).setFirstResult( min ).setMaxResults( max )
+            .list();
     }
 
-    public int countProgramStageInstances( ProgramInstance programInstance, Date startDate, Date endDate )
+    public int count( ProgramInstance programInstance, Date startDate, Date endDate )
     {
         Number rs = (Number) getCriteria( Restrictions.eq( "programInstance.id", programInstance.getId() ),
-            Restrictions.between( "executionDate", startDate, endDate ) ).setProjection( Projections.rowCount() ).uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
+            Restrictions.between( "executionDate", startDate, endDate ) ).setProjection( Projections.rowCount() )
+            .uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate,
+        Date endDate, int min, int max )
+    {
+        return getCriteria( Restrictions.eq( "programStage", programStage ),
+            Restrictions.between( "dueDate", startDate, endDate ) ).setFirstResult( min ).setMaxResults( max ).list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer, String> searchingKeys,
+        OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max )
+    {
+        if ( searchingKeys.keySet().size() > 0 )
+        {
+            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunit, startDate, endDate )
+                + statementBuilder.limitRecord( min, max );
+
+            List<Integer> ids = executeSQL( sql );
+
+            List<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
+
+            for ( Integer id : ids )
+            {
+                programStageInstances.add( get( id ) );
+            }
+
+            return programStageInstances;
+        }
+        
+        return (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.eq( "organisationUnit",
+            orgunit ), Restrictions.between( "dueDate", startDate, endDate ) )).setFirstResult( min ).setMaxResults( max ).list();
+    }
+    
+    @SuppressWarnings( "unchecked" )
+    public List<ProgramStageInstance> get( ProgramStage programStage, Map<Integer, String> searchingKeys,
+        OrganisationUnit orgunit, Date startDate, Date endDate )
+    {
+        if ( searchingKeys.keySet().size() > 0 )
+        {
+            String sql = getBySearchingValues( false, programStage, searchingKeys, orgunit, startDate, endDate );
+            
+            List<Integer> ids = executeSQL( sql );
+
+            List<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
+
+            for ( Integer id : ids )
+            {
+                programStageInstances.add( get( id ) );
+            }
+
+            return programStageInstances;
+        }
+        
+        return (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.eq( "organisationUnit",
+            orgunit ), Restrictions.between( "dueDate", startDate, endDate ) )).list();
+    }
+
+    public int count( ProgramStage programStage, Map<Integer, String> searchingKeys, OrganisationUnit orgunit,
+        Date startDate, Date endDate )
+    {
+        if ( searchingKeys.keySet().size() > 0 )
+        {
+            String sql = getBySearchingValues( true, programStage, searchingKeys, orgunit, startDate, endDate );
+            List<Integer> countRow = executeSQL( sql );
+            return (countRow != null && countRow.size() > 0) ? countRow.get( 0 ) : 0;
+        }
+
+        Number rs = (Number) (getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.eq(
+            "organisationUnit", orgunit ), Restrictions.between( "dueDate", startDate, endDate ) )).setProjection(
+            Projections.rowCount() ).uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    private String getBySearchingValues( boolean isCount, ProgramStage programStage,
+        Map<Integer, String> searchingKeys, OrganisationUnit orgunit, Date startDate, Date endDate )
+    {
+        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=" + orgunit.getId() + " ";
+
+        Iterator<Integer> keys = searchingKeys.keySet().iterator();
+        boolean index = false;
+        while ( keys.hasNext() )
+        {
+            Integer dataElementId = keys.next();
+
+            if ( index )
+            {
+                condition += " AND psi.programstageinstanceid in ( " + sql + " WHERE 1=1 ";
+            }
+
+            condition += " AND pdv.dataElementid=" + dataElementId + " AND lower(pdv.value) ";
+
+            String compareValue = searchingKeys.get( dataElementId ).toLowerCase();
+
+            if ( compareValue.contains( "%" ) )
+            {
+                compareValue = compareValue.replace( "=", "like " );
+            }
+
+            condition += compareValue;
+
+            if ( index )
+            {
+                condition += ") ";
+            }
+
+            index = true;
+        }
+
+        if ( isCount )
+        {
+            return "select count(psi.programstageinstanceid) from patientdatavalue pdv "
+                + "inner join programstageinstance psi on pdv.programstageinstanceid=psi.programstageinstanceid "
+                + condition;
+        }
+
+        return (sql + condition);
+    }
+
+    private List<Integer> executeSQL( String sql )
+    {
+        StatementHolder holder = statementManager.getHolder();
+
+        List<Integer> ids = new ArrayList<Integer>();
+
+        try
+        {
+            Statement statement = holder.getStatement();
+
+            ResultSet resultSet = statement.executeQuery( sql );
+
+            while ( resultSet.next() )
+            {
+                int id = resultSet.getInt( 1 );
+
+                ids.add( id );
+            }
+
+            return ids;
+
+        }
+        catch ( Exception ex )
+        {
+            ex.printStackTrace();
+            return new ArrayList<Integer>();
+        }
+        finally
+        {
+            holder.close();
+        }
+    }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-02-11 14:51:09 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-03-05 04:22:57 +0000
@@ -37,6 +37,8 @@
 		class="org.hisp.dhis.program.hibernate.HibernateProgramStageInstanceStore">
 		<property name="clazz" value="org.hisp.dhis.program.ProgramStageInstance" />
 		<property name="sessionFactory" ref="sessionFactory" />
+		<property name="statementManager" ref="statementManager" />
+		<property name="statementBuilder" ref="statementBuilder" />
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramInstanceStore"

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patientdatavalue/hibernate/PatientDataValue.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patientdatavalue/hibernate/PatientDataValue.hbm.xml	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/patientdatavalue/hibernate/PatientDataValue.hbm.xml	2012-03-05 04:22:57 +0000
@@ -11,14 +11,10 @@
         column="programstageinstanceid" foreign-key="fk_patientdatavalue_programstageinstanceid" />
       <key-many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid"
         foreign-key="fk_patientdatavalue_dataelementid" />
-       <key-many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit"
-        column="organisationunitid" foreign-key="fk_patientdatavalue_organisationunitid" />
     </composite-id>
     
     <property name="value" />
 
-    <property name="providedByAnotherFacility" column="providedbyanotherfacility" not-null="true" />
-
     <property name="timestamp" type="date" />
 
   </class>

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2011-05-29 11:10:20 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2012-03-05 04:22:57 +0000
@@ -21,8 +21,13 @@
     <property name="dueDate" column="duedate" />
 
     <property name="executionDate" column="executiondate" />
-
+    
     <property name="completed" not-null="true" />
+    
+    <many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit"
+        column="organisationunitid" foreign-key="fk_programstageinstance_organisationunitid" />
+        
+    <property name="providedByAnotherFacility" column="providedbyanotherfacility"  />
 
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2012-02-28 08:07:22 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2012-03-05 04:22:57 +0000
@@ -365,7 +365,6 @@
                  "LIMIT " + max + " OFFSET " + min;
     }
     
-
     public String limitRecord( int min, int max )
     {
         return " LIMIT " + max + " OFFSET " + min;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveProvidingFacilityAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveProvidingFacilityAction.java	2011-07-08 07:22:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveProvidingFacilityAction.java	2012-03-05 04:22:57 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -46,8 +47,6 @@
 public class SaveProvidingFacilityAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( SaveProvidingFacilityAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -59,18 +58,11 @@
         this.selectedStateManager = selectedStateManager;
     }
 
-    private DataElementService dataElementService;
-
-    public void setDataElementService( DataElementService dataElementService )
-    {
-        this.dataElementService = dataElementService;
-    }
-
-    private PatientDataValueService patientDataValueService;
-
-    public void setPatientDataValueService( PatientDataValueService patientDataValueService )
-    {
-        this.patientDataValueService = patientDataValueService;
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
     }
 
     // -------------------------------------------------------------------------
@@ -84,18 +76,6 @@
         this.providedByAnotherFacility = providedByAnotherFacility;
     }
 
-    private int dataElementId;
-
-    public void setDataElementId( int dataElementId )
-    {
-        this.dataElementId = dataElementId;
-    }
-
-    public int getDataElementId()
-    {
-        return dataElementId;
-    }
-
     private int statusCode;
 
     public int getStatusCode()
@@ -110,24 +90,23 @@
     public String execute()
         throws Exception
     {
-        OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
-
         ProgramStageInstance programStageInstance = selectedStateManager.getSelectedProgramStageInstance();
 
-        DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
-        PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance,
-            dataElement, organisationUnit );
-
-        if ( patientDataValue != null )
+        if ( programStageInstance != null )
         {
-            LOG.debug( "Updating PatientDataValue, value added/changed" );
-
-            patientDataValue.setProvidedByAnotherFacility( providedByAnotherFacility );
-
-            patientDataValueService.updatePatientDataValue( patientDataValue );
+            if ( programStageInstance.getOrganisationUnit() == null )
+            {
+                OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
+                programStageInstance.setOrganisationUnit( organisationUnit );
+            }
+            
+            programStageInstance.setProvidedByAnotherFacility( providedByAnotherFacility );
+
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
         }
 
+        statusCode = 0;
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java	2012-02-27 02:09:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java	2012-03-05 04:22:57 +0000
@@ -88,13 +88,6 @@
     // Input/Output
     // -------------------------------------------------------------------------
 
-    private boolean providedByAnotherFacility;
-
-    public void setProvidedByAnotherFacility( boolean providedByAnotherFacility )
-    {
-        this.providedByAnotherFacility = providedByAnotherFacility;
-    }
-
     private String value;
 
     public void setValue( String value )
@@ -121,18 +114,6 @@
         return statusCode;
     }
 
-    private int optionComboId;
-
-    public int getOptionComboId()
-    {
-        return optionComboId;
-    }
-
-    public void setOptionComboId( int optionComboId )
-    {
-        this.optionComboId = optionComboId;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation Action
     // -------------------------------------------------------------------------
@@ -147,7 +128,7 @@
         DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
         PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance,
-            dataElement, organisationUnit );
+            dataElement );
 
         if ( value != null && value.trim().length() == 0 )
         {
@@ -161,15 +142,15 @@
         if ( programStageInstance.getExecutionDate() == null )
         {
             programStageInstance.setExecutionDate( new Date() );
+            programStageInstance.setOrganisationUnit( organisationUnit );
             programStageInstanceService.updateProgramStageInstance( programStageInstance );
         }
 
-        if ( patientDataValue == null  && value != null )
+        if ( patientDataValue == null && value != null )
         {
             LOG.debug( "Adding PatientDataValue, value added" );
 
-            patientDataValue = new PatientDataValue( programStageInstance, dataElement, organisationUnit, new Date(),
-                value, providedByAnotherFacility );
+            patientDataValue = new PatientDataValue( programStageInstance, dataElement, new Date(), value );
 
             patientDataValueService.savePatientDataValue( patientDataValue );
         }
@@ -178,12 +159,13 @@
             LOG.debug( "Updating PatientDataValue, value added/changed" );
 
             patientDataValue.setValue( value );
-            patientDataValue.setProvidedByAnotherFacility( providedByAnotherFacility );
             patientDataValue.setTimestamp( new Date() );
 
             patientDataValueService.updatePatientDataValue( patientDataValue );
         }
 
+        statusCode = 0;
+
         return SUCCESS;
     }
 }

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2012-03-05 04:22:57 +0000
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2004-2012, 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.caseentry.action.report;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hisp.dhis.caseentry.state.SelectedStateManager;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.ProgramStageService;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $GenerateTabularReportAction.java Feb 29, 2012 10:15:05 AM$
+ */
+public class GenerateTabularReportAction
+    extends ActionPagingSupport<ProgramStageInstance>
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SelectedStateManager selectedStateManager;
+
+    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+    {
+        this.selectedStateManager = selectedStateManager;
+    }
+
+    private ProgramStageService programStageService;
+
+    public void setProgramStageService( ProgramStageService programStageService )
+    {
+        this.programStageService = programStageService;
+    }
+
+    private DataElementService dataElementService;
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private Integer programStageId;
+
+    public void setProgramStageId( Integer programStageId )
+    {
+        this.programStageId = programStageId;
+    }
+
+    private List<Integer> dataElementIds = new ArrayList<Integer>();
+
+    public void setDataElementIds( List<Integer> dataElementIds )
+    {
+        this.dataElementIds = dataElementIds;
+    }
+
+    private String startDate;
+
+    public void setStartDate( String startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    private String endDate;
+
+    public void setEndDate( String endDate )
+    {
+        this.endDate = endDate;
+    }
+
+    private Set<String> searchingValues = new HashSet<String>();
+
+    public void setSearchingValues( Set<String> searchingValues )
+    {
+        this.searchingValues = searchingValues;
+    }
+
+    private Grid grid;
+
+    public Grid getGrid()
+    {
+        return grid;
+    }
+
+    private Integer total;
+
+    public Integer getTotal()
+    {
+        return total;
+    }
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    private I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    private List<DataElement> dataElements;
+
+    public List<DataElement> getDataElements()
+    {
+        return dataElements;
+    }
+
+    private String type;
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation Action
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
+
+        ProgramStage programStage = programStageService.getProgramStage( programStageId );
+
+        Date startValue = format.parseDate( startDate );
+
+        Date endValue = format.parseDate( endDate );
+
+        dataElements = new ArrayList<DataElement>();
+
+        for ( Integer dataElementId : dataElementIds )
+        {
+            dataElements.add( dataElementService.getDataElement( dataElementId ) );
+        }
+
+        Map<Integer, String> searchingKeys = new HashMap<Integer, String>();
+
+        for ( String searchingValue : searchingValues )
+        {
+            String[] infor = searchingValue.split( "_" );
+
+            searchingKeys.put( Integer.parseInt( infor[0] ), infor[1] );
+        }
+
+        if ( type == null )
+        {
+            total = programStageInstanceService.countProgramStageInstances( programStage, searchingKeys,
+                organisationUnit, startValue, endValue );
+
+            this.paging = createPaging( total );
+
+            grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys,
+                organisationUnit, startValue, endValue, paging.getStartPos(), paging.getPageSize(), format, i18n );
+            return SUCCESS;
+        }
+        
+        grid = programStageInstanceService.getTabularReport( programStage, dataElements, searchingKeys,
+            organisationUnit, startValue, endValue, format, i18n );
+
+        return type;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadDataElementsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadDataElementsAction.java	2012-03-05 04:22:57 +0000
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2004-2012, 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.caseentry.action.report;
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $LoadDataElementsAction.java Feb 29, 2012 9:40:40 AM$
+ */
+public class LoadDataElementsAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramStageService programStageService;
+
+    public void setProgramStageService( ProgramStageService programStageService )
+    {
+        this.programStageService = programStageService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input/output
+    // -------------------------------------------------------------------------
+
+    private Integer programStageId;
+
+    public void setProgramStageId( Integer programStageId )
+    {
+        this.programStageId = programStageId;
+    }
+
+    private Collection<ProgramStageDataElement> psDataElements;
+
+    public Collection<ProgramStageDataElement> getPsDataElements()
+    {
+        return psDataElements;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        psDataElements = programStageService.getProgramStage( programStageId ).getProgramStageDataElements();
+
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadProgramStagesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadProgramStagesAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/LoadProgramStagesAction.java	2012-03-05 04:22:57 +0000
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2004-2012, 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.caseentry.action.report;
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $LoadProgramStagesAction.java Feb 28, 2012 9:35:50 AM$
+ */
+public class LoadProgramStagesAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input/output
+    // -------------------------------------------------------------------------
+
+    private Integer programId;
+
+    public void setProgramId( Integer programId )
+    {
+        this.programId = programId;
+    }
+
+    private Collection<ProgramStage> programStages;
+
+    public Collection<ProgramStage> getProgramStages()
+    {
+        return programStages;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        programStages = programService.getProgram( programId ).getProgramStages();
+
+        return SUCCESS;
+    }
+}

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/TabularReportSelectAction.java	2012-03-05 04:22:57 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2004-2012, 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.caseentry.action.report;
+
+import java.util.Collection;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $TabularReportSelectAction.java Feb 29, 2012 2:57:50 PM$
+ */
+public class TabularReportSelectAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitSelectionManager selectionManager;
+
+    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnit orgunit;
+
+    public OrganisationUnit getOrgunit()
+    {
+        return orgunit;
+    }
+
+    private Collection<Program> programs;
+
+    public Collection<Program> getPrograms()
+    {
+        return programs;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        orgunit = selectionManager.getSelectedOrganisationUnit();
+
+        programs = programService.getPrograms( orgunit );
+
+        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-02-27 08:39:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-03-05 04:22:57 +0000
@@ -88,9 +88,8 @@
 		scope="prototype">
 		<property name="selectedStateManager"
 			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
-		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="patientDataValueService"
-			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+		<property name="programStageInstanceService"
+			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 	</bean>
 
 	<bean
@@ -261,6 +260,40 @@
         <property name="programStageInstanceService"
  	       	ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction"
+		class="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction"
+		scope="prototype">
+		<property name="selectionManager"
+			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
+		<property name="programService"
+			ref="org.hisp.dhis.program.ProgramService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.caseentry.action.report.LoadProgramStagesAction"
+		class="org.hisp.dhis.caseentry.action.report.LoadProgramStagesAction"
+		scope="prototype">
+		<property name="programService"
+			ref="org.hisp.dhis.program.ProgramService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.caseentry.action.report.LoadDataElementsAction"
+    	class="org.hisp.dhis.caseentry.action.report.LoadDataElementsAction" scope="prototype">
+    	<property name="programStageService"
+        	ref="org.hisp.dhis.program.ProgramStageService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction"
+    	class="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction" scope="prototype">
+    	<property name="programStageService"
+        	ref="org.hisp.dhis.program.ProgramStageService" />
+        <property name="dataElementService"
+        	ref="org.hisp.dhis.dataelement.DataElementService" />
+        <property name="programStageInstanceService"
+        	ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+        <property name="selectedStateManager"
+        	ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
+	</bean>
 
 	<!-- Case Aggregation -->
 

=== 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-02-27 05:35:23 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-03-05 04:22:57 +0000
@@ -243,7 +243,7 @@
 leftSide=Left Side
 rightSide=Right Side
 in_range_due_date_plus_or_minus=In range due date +/-
-anonymous_event_reports=Anonymous Event Reports
+anonymous_event_report=Anonymous Event
 intro_anonymous_event_reports=Create reports based on anonymous events registered in system. Gives an overview of data for each event.
 activity_planning=Activity Planning
 back_to_main_menu=Back to main menu
@@ -255,4 +255,15 @@
 ga_facilityby=Organisation Unit By
 saved = Saved
 save_selected_values = Save selected values
-save_all_values = Save all values
\ No newline at end of file
+save_all_values = Save all values
+intro_tabular_report = An interactive reporting tool for tracker-data using tabular presentation with dynamic filters for each data element (on columns) and support all types of data from data elements including program-based, single and anonymous. 
+tabular_report = Tabular report
+true = Yes
+false = No
+data = Data
+get_report_as_xls = Get report as xls
+get_report_as_pdf = Get report as pdf
+set_complete_status = Set complete status
+orgunit_provided_service = Organisation unit provided service
+how_to_search_tabular_report = Quotes (") match phrases.Character values support %%, %=, %= and =. Numeric values support >=, >, <=, <, = and != operators.
+syntax_error_in_search_value = Syntax error is in search value
\ 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-03-04 16:39:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-03-05 04:22:57 +0000
@@ -242,11 +242,50 @@
 		</action>
 		
         <action name="viewAnonymousEvents"
-                class="org.hisp.dhis.caseentry.action.caseentry.ProgramStageCustomDataEntryAction">
-                <result name="success" type="velocity">/content.vm</result>
-                <param name="page">/dhis-web-caseentry/dataEntryForm.vm</param>
+             class="org.hisp.dhis.caseentry.action.caseentry.ProgramStageCustomDataEntryAction">
+             <result name="success" type="velocity">/content.vm</result>
+             <param name="page">/dhis-web-caseentry/dataEntryForm.vm</param>
         </action>
         
+        <action name="tabularReportSelect"
+			class="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction">
+			<interceptor-ref name="organisationUnitTreeStack" />
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-caseentry/tabularReportSelect.vm</param>
+			<param name="menu">/dhis-web-caseentry/reportsMenu.vm</param>
+			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,javascript/tabularReport.js</param>
+			<param name="stylesheets">../dhis-web-caseentry/style/report.css</param>
+		</action>
+		
+		<action name="loadProgramsByOrgunit"
+			class="org.hisp.dhis.caseentry.action.report.TabularReportSelectAction">
+			<interceptor-ref name="organisationUnitTreeStack" />
+			<result name="success" type="velocity-json">/dhis-web-caseentry/responsePrograms.vm</result>
+		</action>
+		
+		<action name="loadTabularProgramStages"
+			class="org.hisp.dhis.caseentry.action.report.LoadProgramStagesAction">
+			<result name="success" type="velocity-json">/dhis-web-caseentry/responseProgramStages.vm</result>
+		</action>
+		
+		<action name="loadDataElements"
+			class="org.hisp.dhis.caseentry.action.report.LoadDataElementsAction">
+			<result name="success" type="velocity-json">/dhis-web-caseentry/responseDataElements.vm</result>
+		</action>
+		
+        <action name="generateTabularReport"
+			class="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction">
+			<result name="success" type="velocity">/content.vm</result>
+			<result name="xls" type="gridXlsResult" />
+      		<result name="pdf" type="gridPdfResult" />
+			<param name="page">/dhis-web-caseentry/tabularReportResult.vm</param>
+		</action>
+		
+		<action name="searchTabularReport"
+			class="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction">
+			<result name="success" type="velocity">/dhis-web-caseentry/searchTabularReportResult.vm</result>
+		</action>
+		
 		<!-- Case Aggregation -->
 
 		<action name="caseAggregationForm"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-27 02:09:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-03-05 04:22:57 +0000
@@ -39,7 +39,27 @@
 <input type='hidden' name='irregular' id='irregular' value='$!programStageInstance.programStage.irregular'>
 <input type='hidden' name='completed' id='completed' value='$!programStageInstance.completed'>
 
-<div id='entryForm' #if($!programStageInstance.executionDate) class='visible' #else class='hidden' #end;>
+<div id='entryForm' #if($!programStageInstance.executionDate) class='visible' #else class='hidden' #end>
+	##providedByAnotherFacility
+	<table class='entryScreen'>	
+		<tr #alternate( true ) >
+			<td>
+				#if($programStageInstance.programInstance.program.displayProvidedOtherFacility == 'true' )
+					#set( $id = $programStageInstance.programStage.id + '_facility' )
+					#if( $!programStageInstance.providedByAnotherFacility)
+						#if( $!programStageInstance.providedByAnotherFacility == 'true' ) 					
+							$i18n.getString( "orgunit_provided_service" ): $programStageInstance.organisationUnit.name
+						#elseif( $!programStageInstance.providedByAnotherFacility == 'false' ) 
+							$i18n.getString( "orgunit_provided_service" ): $i18n.getString("other_facility")
+						#end
+					#else
+						$i18n.getString( "provided_elsewhere" ) <input type="checkbox" id='$id' onclick="updateProvidingFacility();" #if($programStageInstance.completed) disabled="disabled" #end >
+					#end
+				#end
+			</td>
+		</tr>
+	</table>
+
 	#if( $customDataEntryFormCode )
 		<div id="customEntryScreenContainer">
 		   $customDataEntryFormCode
@@ -54,15 +74,9 @@
 		<table id="defaultEntryScreenContainer" class='entryScreen formSection'>
 			<col id="deCol">    
 			<col id="entryCol">
-			#if( $programStageInstance.programInstance.program.displayProvidedOtherFacility == 'true' )
-			<col id="facilityCol">       
-			#end
 			<tr>
 				<th>$i18n.getString( "data_element" )</th>                   
 				<th>$i18n.getString( "entry" )</th>
-				#if( $programStageInstance.programInstance.program.displayProvidedOtherFacility == 'true' )
-					<th>$i18n.getString( "provided_elsewhere" )</th>             
-				#end
 			</tr>
 		#set( $dataElementRowCount = 0 )
 		#set( $mark = true )
@@ -108,26 +122,6 @@
 						<input name="entryfield" data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" type="text" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveVal( $programStageDataElement.dataElement.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex">
 					#end
 				</td>  
-				
-				##providedByAnotherFacility 
-				#set( $id = $programStageDataElement.programStage.id + '_' + $programStageDataElement.dataElement.id + '_facility' )
-				#if($programStageInstance.programInstance.program.displayProvidedOtherFacility == 'true') 					
-				<td>   
-					#if ( $patientDataValue.value )        
-						#if( !$patientDataValue.providedByAnotherFacility )
-							$patientDataValue.organisationUnit.name
-							<input  name="providedByAnotherFacility" id="$id" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($programStageInstance.completed) disabled="disabled" #end >
-						#else
-							$i18n.getString("other_facility")
-							<input  name="providedByAnotherFacility" id="$id" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($programStageInstance.completed) disabled="disabled" #end >
-						#end
-					 #else
-						<input name="providedByAnotherFacility" id="$id" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($programStageInstance.completed) disabled="disabled" #end >
-					 #end                         
-				</td>
-				#else
-					<input name="providedByAnotherFacility" id="$id" type="hidden">
-				#end					
 			</tr>
 			#set( $tabIndex = $tabIndex + 1 )
 		#end

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/index.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/index.vm	2012-03-04 13:26:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/index.vm	2012-03-05 04:22:57 +0000
@@ -1,7 +1,7 @@
 
 <h3>$i18n.getString( "dhis-web-caseentry" )</h3>
 
-<ul class="introList">
+<ul id="introList">
 	#introListImgItem( "patient.action" "patient" "patient" )
     #introListImgItem( "dataEntrySelect.action" "name_based_data_entry" "dataentry" )
 	#introListImgItem( "multipledataEntrySelect.action" "multiple_name_based_data_entry" "dataentry" )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-02-27 08:39:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-03-05 04:22:57 +0000
@@ -167,7 +167,6 @@
 	
 	var dataElementName = data.deName; 
     var type = data.deType;
-    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
  
 	field.style.backgroundColor = '#ffffcc';
     
@@ -213,29 +212,27 @@
     	
     }
     
-	var valueSaver = new ValueSaver( dataElementId, fieldValue, providedByAnotherFacility, type, '#ccffcc'  );
+	var valueSaver = new ValueSaver( dataElementId, fieldValue, type, '#ccffcc'  );
     valueSaver.save();
 }
 
 function saveOpt( dataElementId )
 {
 	var programStageId = byId('programStageId').value;
-	var field = byId( programStageId + '-' + dataElementId + '-val' );
+	var field = byId( programStageId + '-' + dataElementId + '-val' );	
+	field.style.backgroundColor = '#ffffcc';
 	
-	field.style.backgroundColor = '#ffffcc';
-	var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
- 
-	var valueSaver = new ValueSaver( dataElementId, field.options[field.selectedIndex].value, providedByAnotherFacility, 'bool', '#ccffcc' );
+	var valueSaver = new ValueSaver( dataElementId, field.options[field.selectedIndex].value, 'bool', '#ccffcc' );
     valueSaver.save();
 }
 
-function updateProvidingFacility( dataElementId, checkedBox )
+function updateProvidingFacility()
 {
 	var programStageId = byId( 'programStageId' ).value;
-    checkedBox.style.backgroundColor = '#ffffcc';
-    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
+	var checkField = byId( programStageId + '_facility');
+    checkField.style.backgroundColor = '#ffffcc';
  
-    var facilitySaver = new FacilitySaver( dataElementId, providedByAnotherFacility, '#ccffcc' );
+    var facilitySaver = new FacilitySaver( checkField.checked, '#ccffcc' );
     facilitySaver.save();
     
 }
@@ -377,14 +374,13 @@
 // Save value for dataElement of type text, number, boolean, combo
 //-----------------------------------------------------------------
 
-function ValueSaver( dataElementId_, value_, providedByAnotherFacility_, dataElementType_, resultColor_  )
+function ValueSaver( dataElementId_, value_, dataElementType_, resultColor_  )
 {
     var SUCCESS = '#ccffcc';
     var ERROR = '#ccccff';
 	
     var dataElementId = dataElementId_;
 	var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
 	var type = dataElementType_;
     var resultColor = resultColor_;
 	
@@ -392,7 +388,6 @@
     {
 		 var params = 'dataElementId=' + dataElementId;
 			params += '&value=' + value;
-			params += '&providedByAnotherFacility=' + providedByAnotherFacility;
 		
 		$.ajax({
 			   type: "POST",
@@ -444,19 +439,17 @@
     }
 }
 
-function FacilitySaver( dataElementId_, providedByAnotherFacility_, resultColor_ )
+function FacilitySaver( providedByAnotherFacility_, resultColor_ )
 {
     var SUCCESS = 'success';
     var ERROR = '#error';
 	
-    var dataElementId = dataElementId_;
     var providedByAnotherFacility = providedByAnotherFacility_;
     var resultColor = resultColor_;
 
     this.save = function()
     {
-		var params = 'dataElementId=' + dataElementId 
-					+ '&providedByAnotherFacility=' + providedByAnotherFacility ;
+		var params = 'providedByAnotherFacility=' + providedByAnotherFacility ;
 		$.ajax({
 			   type: "POST",
 			   url: "saveProvidingFacility.action",
@@ -497,12 +490,12 @@
 		var programStageId = byId( 'programStageId' ).value;
         if( result == SUCCESS )
         {
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').toggleClass('checked');
+            jQuery('label[for="' + programStageId + '_facility"]').toggleClass('checked');
         }
         else if( result == ERROR )
         {
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').removeClass('checked');
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').addClass('error');
+            jQuery('label[for="' + programStageId + '_facility"]').removeClass('checked');
+            jQuery('label[for="' + programStageId + '_facility"]').addClass('error');
         }
     }
 }
@@ -663,7 +656,7 @@
 		
 					hideLoader();
 					hideById('contentDiv');
-				},'xml');
+				});
 		}
     }
 }
@@ -709,6 +702,7 @@
 		
         TOGGLE.init();
 		
+		initCustomCheckboxes();
 		
 		jQuery("#entryForm :input").each(function()
 		{ 

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js	2012-03-05 04:22:57 +0000
@@ -0,0 +1,325 @@
+
+function organisationUnitSelected( orgUnits, orgUnitNames )
+{
+	hideById('contentDiv');
+	setFieldValue('startDate', '');
+	setFieldValue('endDate', '');
+	
+	$.postJSON( 'loadProgramsByOrgunit.action',{}
+		, function( json ) 
+		{
+			clearListById( 'programId' );
+			addOptionById( 'programId', '', i18n_please_select );
+			setFieldValue('orgunitname', orgUnitNames[0]);
+			var preSelectedProgramId = getFieldValue('selectedProgramId');
+			for ( i in json.programs ) 
+			{ 
+				$('#programId').append('<option value=' + json.programs[i].id + '>' + json.programs[i].name + '</option>');
+			}
+
+			if( json.programs.length > 0 )
+			{
+				enable('generateBtn');
+			}
+			else
+			{
+				disable('generateBtn');
+			}
+			
+			showCriteria();
+			
+		} );
+}
+
+selection.setListenerFunction( organisationUnitSelected );
+
+function loadProgramStages()
+{
+	clearListById( 'programStageId' );
+	clearListById( 'dataElementIds' );
+	
+	if( getFieldValue('programId') == '' )
+	{
+		return;
+	}
+	$.postJSON( 'loadTabularProgramStages.action',
+		{
+			programId: getFieldValue('programId')
+		}
+		, function( json ) 
+		{
+			addOptionById( 'programStageId', '', i18n_please_select );
+			
+			for ( i in json.programStages ) 
+			{ 
+				$('#programStageId').append('<option value=' + json.programStages[i].id + '>' + json.programStages[i].name + '</option>');
+			}
+		} );
+}
+
+function loadDataElements()
+{
+	clearListById( 'dataElementIds' );
+	if( getFieldValue('programStageId') == '' )
+	{
+		return;
+	}
+	
+	$.postJSON( 'loadDataElements.action',
+		{
+			programStageId: getFieldValue('programStageId')
+		}
+		, function( json ) 
+		{
+			for ( i in json.dataElements ) 
+			{ 
+				$('#dataElementIds').append('<option value=' + json.dataElements[i].id + '>' + json.dataElements[i].name + '</option>');
+			}
+		} );
+}
+
+
+function showCriteria()
+{
+	$( "#criteriaDiv" ).show( "fast" );
+}
+
+function hideCriteria()
+{
+	$( "#criteriaDiv" ).hide( "fast" );
+}
+
+function entryFormContainerOnReady()
+{
+	jQuery("#gridTable :input").each(function()
+		{ 
+			if( jQuery(this).attr( 'options' )!= null )
+			{
+				autocompletedField( jQuery(this).attr('id') );
+			}
+		});
+}
+
+function autocompletedField( idField )
+{
+	var input = jQuery( "#" +  idField )
+	var dataElementId = input.attr( 'dataElementId' );
+	var options = new Array();
+	var attrValues = input.attr('options').replace('[', '').replace(']', '').split(', ');
+	for( var i in attrValues )
+	{
+		options.push("='" + attrValues[i] + "'")
+	}
+	options.push(" ");
+
+	input.autocomplete({
+			delay: 0,
+			minLength: 0,
+			source: options,
+			select: function( event, ui ) {
+				input.val(ui.item.value);
+				input.autocomplete( "close" );
+			},
+			change: function( event, ui ) {
+				if ( !ui.item ) {
+					var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
+						valid = false;
+					for (var i = 0; i < options.length; i++)
+					{
+						if (options[i].match( matcher ) ) {
+							this.selected = valid = true;
+							break;
+						}
+					}
+				}
+			}
+		})
+		.addClass( "ui-widget" );
+
+	this.button = $( "<button type='button'>&nbsp;</button>" )
+		.attr( "tabIndex", -1 )
+		.attr( "title", i18n_show_all_items )
+		.insertAfter( input )
+		.button({
+			icons: {
+				primary: "ui-icon-triangle-1-s"
+			},
+			text: false
+		})
+		.addClass( "small-button" )
+		.click(function() {
+			// close if already visible
+			if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
+				input.autocomplete( "close" );
+				return;
+			}
+
+			// work around a bug (likely same cause as #5265)
+			$( this ).blur();
+
+			// pass empty string as value to search for, displaying all results
+			input.autocomplete( "search", "" );
+			input.focus();
+		});
+}
+
+function loadGeneratedReport()
+{
+	hideCriteria();
+	showLoader();
+	isAjax = true;
+	contentDiv = 'contentDiv';
+	
+	/* var dataElementIds = "";
+	var listDataElementIds = jQuery( "select[id=dataElementIds] option:selected" );
+	listDataElementIds.each( function( i, item ){
+		dataElementIds += "dataElementIds=" + item.value;
+		dataElementIds += ( i < listDataElementIds.length - 1 ) ? "&" : "";
+	});
+	
+	var params = dataElementIds + "&" 
+				+ "programStageId=" + getFieldValue('programStageId') + "&" 
+				+ "startDate=" + getFieldValue('startDate') + "&" 
+				+ "endDate=" + getFieldValue('endDate'); */
+	var params = getParams();
+	if( params != '' )
+	{
+		$.ajax({
+			   type: "POST",
+			   url: "generateTabularReport.action",
+			   data: params,
+			   dataType: "html",
+			   success: function( result ){
+					hideLoader();
+					jQuery( "#contentDiv" ).html( result );
+			   }
+			});
+	}
+}
+
+function searchTabularReport( event )
+{	
+	/* var dataElementIds = "";
+	var listDataElementIds = jQuery( "select[id=dataElementIds] option:selected" );
+	listDataElementIds.each( function( i, item ){
+		dataElementIds += "dataElementIds=" + item.value;
+		dataElementIds += ( i < listDataElementIds.length - 1 ) ? "&" : "";
+	});
+	
+	var searchingValues = "";
+	var listSeachingValues = jQuery("#gridTable input");
+	listSeachingValues.each( function( i, item ){
+		if( item.value!= '' )
+		{
+			searchingValues += "searchingValues=" + item.id + "_" + htmlEncode( item.value ) + "&";
+		}
+	});
+	
+	
+	var params = searchingValues + dataElementIds + "&" 
+				+ "programStageId=" + getFieldValue('programStageId') + "&" 
+				+ "startDate=" + getFieldValue('startDate') + "&" 
+				+ "endDate=" + getFieldValue('endDate'); */
+	
+	var key = event.keyCode || event.charCode || event.which;
+	
+	if ( key == 13 || key == 1 ) // Enter
+	{
+		showById('loaderDiv');
+		hideById('gridContent');
+		hideById('pagingDiv');
+		
+		isAjax = true;
+		contentDiv = 'gridContent';
+
+		var params = getParams();
+		if( params != '' )
+		{
+			$.ajax({
+				   type: "POST",
+				   url: "searchTabularReport.action",
+				   data: params,
+				   dataType: "html",
+				   success: function( result ){
+						hideById('loaderDiv');
+						jQuery( "#gridContent" ).html( result );
+						showById( "gridContent" );
+						showById('pagingDiv');
+				   }
+				});
+		}
+	}
+}
+
+function exportTabularReport( type )
+{
+	/* var dataElementIds = "";
+	var listDataElementIds = jQuery( "select[id=dataElementIds] option:selected" );
+	listDataElementIds.each( function( i, item ){
+		dataElementIds += "dataElementIds=" + item.value;
+		dataElementIds += ( i < listDataElementIds.length - 1 ) ? "&" : "";
+	});
+	
+	var searchingValues = "";
+	var listSeachingValues = jQuery("#gridTable input");
+	listSeachingValues.each( function( i, item ){
+		if( item.value!= '' )
+		{
+			searchingValues += "searchingValues=" + item.id + "_" + htmlEncode( item.value ) + "&";
+		}
+	});
+	
+	var url = "generateTabularReport.action?" + searchingValues + dataElementIds
+				+ "&programStageId=" + getFieldValue('programStageId')
+				+ "&startDate=" + getFieldValue('startDate')
+				+ "&endDate=" + getFieldValue('endDate')
+				+ "&type=" + type; */
+
+	var params = getParams();
+	if( params != '' )
+	{
+		var url = "generateTabularReport.action?" + params + "&type=" + type;
+		window.location.href = url;
+	}
+}
+
+function getParams()
+{
+	hideMessage();
+	
+	var searchingValues = "";
+	var listSeachingValues = jQuery("#gridTable input");
+	var regExp = new RegExp([]); 
+	
+	listSeachingValues.each( function( i, item ){
+		if( item.value!= '' )
+		{
+			var value = item.value;
+			var flag = value.match(/[>|>=|<|<=|=|!=]'[%]?[\w]+[%]?'/);
+			
+			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 dataElementIds = "";
+	var listDataElementIds = jQuery( "select[id=dataElementIds] option:selected" );
+	listDataElementIds.each( function( i, item ){
+		dataElementIds += "dataElementIds=" + item.value;
+		dataElementIds += ( i < listDataElementIds.length - 1 ) ? "&" : "";
+	});
+	
+	return searchingValues + dataElementIds
+				+ "&programStageId=" + getFieldValue('programStageId')
+				+ "&startDate=" + getFieldValue('startDate')
+				+ "&endDate=" + getFieldValue('endDate');
+}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm	2012-03-04 15:54:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/menu.vm	2012-03-05 04:22:57 +0000
@@ -14,8 +14,13 @@
 <h2>$i18n.getString( "reports" )&nbsp;</h2>
 <ul>
     <li><a href="reportSelect.action">$i18n.getString( "program_summary" )&nbsp;</a></li> 
-	<li><a href="showSingleEventReportForm.action"> $i18n.getString( "anonymous_event_reports" )&nbsp;</a></li>
-	<li><a href="visitplan.action">$i18n.getString( "visit_plan" )&nbsp;</a></li>
+	<li><a href="showSingleEventReportForm.action"> $i18n.getString( "anonymous_event_report" )&nbsp;</a></li> 	    
+	<li><a href="tabularReportSelect.action"> $i18n.getString( "tabular_report" )&nbsp;</a></li> 
+</ul>
+
+<h2>$i18n.getString( "activity_planning" )&nbsp;</h2>
+<ul>
+    <li><a href="visitplan.action">$i18n.getString( "visit_plan" )&nbsp;</a></li>     
 </ul>
 
 <h2>$i18n.getString( "case_aggregation" )&nbsp;</h2>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm	2012-02-17 17:11:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm	2012-03-05 04:22:57 +0000
@@ -1,6 +1,7 @@
 
+#if( $patient )
 <table> 
-    <tr>            
+	<tr>            
         <td>
             <span class='bold'>$i18n.getString( "full_name" ):</span>
 		</td>
@@ -13,7 +14,7 @@
             <span class='bold'>$i18n.getString( "gender" ):</span>
 		</td>
 		<td>
-			$i18n.getString( $patient.gender )
+			$i18n.getString( "$patient.gender" )
 		</td>
 	</tr>
 	<tr>
@@ -32,6 +33,7 @@
 		</td>
 	</tr>
 </table>
+#end
 
 <table>    
    <tr>
@@ -71,7 +73,7 @@
 </table>
 
 </form>
-
+<p></p>
 #parse( "dhis-web-commons/loader/loader.vm" )
 <div id='dataEntryFormDiv' name='dataEntryFormDiv'>
 	#parse( "dhis-web-caseentry/dataEntryForm.vm" )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportsMenu.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportsMenu.vm	2012-01-15 16:13:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportsMenu.vm	2012-03-05 04:22:57 +0000
@@ -4,7 +4,8 @@
 <a href="index.action"><h2>$i18n.getString( "reports" )&nbsp;</h2></a>
 <ul>
     <li><a href="reportSelect.action">$i18n.getString( "program_summary" )&nbsp;</a></li>
-	<li><a href="showSingleEventReportForm.action"> $i18n.getString( "anonymous_event_reports" )&nbsp;</a></li> 
+	<li><a href="showSingleEventReportForm.action"> $i18n.getString( "anonymous_event_report" )&nbsp;</a></li> 
+	<li><a href="tabularReportSelect.action"> $i18n.getString( "tabular_report" )&nbsp;</a></li> 
 </ul>
 
 <br>

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm	2012-03-05 04:22:57 +0000
@@ -0,0 +1,9 @@
+#set( $size = $psDataElements.size() )
+{ "dataElements": [
+#foreach( $psDataElement in $psDataElements )
+  {
+    "id": $!{psDataElement.dataElement.id},
+    "name": "$encoder.xmlEncode(${psDataElement.dataElement.name} )"
+  }#if( $velocityCount < $size ),#end
+	#end]
+}

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTabularReportResult.vm	2012-03-05 04:22:57 +0000
@@ -0,0 +1,22 @@
+
+	#set( $mark = false )
+	#set( $i = 1 )
+	#foreach( $row in $grid.getVisibleRows() )
+		<tr id="tr${i}">
+			<td>
+				#set( $nr = ( ( $paging.getCurrentPage() - 1  ) * $paging.pageSize ) + $velocityCount )
+				$nr
+			</td>
+			#set($programStageId='')
+			#foreach( $col in $row )
+				#set( $index = ( $velocityCount - 1 ) )
+				#if( $grid.VisibleHeaders().get( $index ).meta )
+					<td style="text-align:left">$!encoder.htmlEncode( $col )</td>
+				#else
+					<td>$col</td>
+				#end
+			#end
+		</tr>
+		#set( $mark = !$mark)
+		#set( $i = $i + 1 )
+	#end

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/report.css'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/report.css	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/report.css	2012-03-05 04:22:57 +0000
@@ -0,0 +1,19 @@
+/*----------------------------------------------------------------------------*/
+/* For GRID form                                                              */
+/*----------------------------------------------------------------------------*/
+
+.grid tr {
+  background-color:#eee;
+  }
+  
+.grid th, .grid td
+{
+  text-align: center;
+  width: 150px;
+  line-height: 170%;
+  border:1px solid #fff;
+}
+
+.small-button {
+	font-size: .8em !important;
+}
\ No newline at end of file

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportResult.vm	2012-03-05 04:22:57 +0000
@@ -0,0 +1,48 @@
+<script>
+	$(document).ready(function() {
+		entryFormContainerOnReady();
+	});
+</script>
+
+<h3>$!encoder.htmlEncode( $grid.title )</h3>
+
+<div style="margin-bottom:15px">
+<input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportTabularReport( 'xls' )" style="width:140px">
+<input type="button" value="$i18n.getString( 'get_report_as_pdf' )" onclick="exportTabularReport( 'pdf' )" style="width:140px">
+</div>
+
+<h5>$!encoder.htmlEncode( $grid.subtitle )</h5>
+
+<table class="listTable grid" id='gridTable'>
+	<tr>
+		<th>#</th>
+		#foreach( $dataElement in $dataElements )
+			<th>
+				$!encoder.htmlEncode( $dataElement.name )
+			</th>
+		#end
+	</tr>
+	<tr>
+		<td></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' style='width:75%' #end />
+			</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

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm	2012-03-05 04:22:57 +0000
@@ -0,0 +1,92 @@
+<script>
+	jQuery(document).ready(	function(){
+		validation( 'reportForm', function(form){
+			loadGeneratedReport();
+		}); 
+	});		
+</script>
+
+<h3>$i18n.getString( "tabular_report" )</h3>
+<form id="reportForm" name="reportForm" method="post">
+<p><input type="button" style="width:120px" value="$i18n.getString('data')" onclick="showCriteria();" ></p>
+
+<div class="inputCriteria" id='criteriaDiv' style="width:530px;height:300px;margin-bottom:20px;">
+
+<table>	
+    <tr>
+	  <td><label>$i18n.getString( "reporting_unit" )</label></td>
+	  <td><input type="text" readonly="readonly" id='orgunitname' name='orgunitname' #if($!orgunit) value="$!orgunit.name" #else value="[$i18n.getString( "select" )]" #end style="min-width:350px"></td>
+    </tr>
+    
+    <tr>
+        <td><label for="programId">$i18n.getString( "program" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td>
+            <select id="programId" name="programId" #if($!programs) #else disabled #end style="width:350px" class="{validate:{required:true}}" onchange='loadProgramStages();'>
+				<option value=''>[$i18n.getString('please_select')]</option>
+				#foreach( $program in $programs )
+				<option value='$program.id'>$program.name</option>
+				#end
+			</select>
+        </td>
+    </tr>
+        
+    <tr>
+        <td><label>$i18n.getString( "start_date" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td>
+            <input type="text" id="startDate" name="startDate" class="{validate:{required:true}}" />
+			<script type="text/javascript">
+				datePicker('startDate');
+            </script>  	
+        </td>
+    </tr>
+    
+    <tr>
+        <td><label>$i18n.getString( "end_date" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td>
+            <input type="text" id="endDate" name="endDate" class="{validate:{required:true}}" />
+            <script type="text/javascript">
+				datePicker('endDate');
+            </script> 				
+        </td>      
+    </tr>
+	<tr>
+        <td><label>$i18n.getString( "data_elements" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td>
+			<select id="programStageId" name="programStageId" style="width:350px" class="{validate:{required:true}}" onchange='loadDataElements();'></select>
+        </td>      
+    </tr>
+	<tr>
+		<td></td>
+        <td>
+			<select id="dataElementIds" name="dataElementIds" multiple size='6' style="width:350px"  class="{validate:{required:true}}" ></select>
+        </td>      
+    </tr>
+    
+    <tr>
+    	<td></td>
+    	<td><input type="submit" id='generateBtn' name='generateBtn' #if($!programs) #else disabled #end value="$i18n.getString( 'generate' )" style="width:10em" />
+    		<input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='index.action'" style="width:10em"/>
+    	</td>
+    </tr>	                		
+</table>
+
+</div>
+
+</form>
+
+<span id="message"></span>
+
+<div id="contentDiv">
+	#parse( "dhis-web-commons/loader/loader.vm" )
+</div>
+
+<script type="text/javascript">   
+    var i18n_report_generation_failed = '$encoder.jsEscape( $i18n.getString( "report_generation_failed" ), "'")';    
+	var i18n_please_select_a_program = '[' + '$encoder.jsEscape( $i18n.getString( "please_select_a_program" ), "'")' + ']'; 
+	var i18n_reports = '$encoder.jsEscape( $i18n.getString( "reports" ), "'")';    	
+	var i18n_patient_profile = '$encoder.jsEscape( $i18n.getString( "patient_profile" ), "'")';    	
+	var i18n_please_select = "[" + '$encoder.jsEscape( $i18n.getString( "please_select" ) , "'" )' + "]";
+	var i18n_show_all_items = "[" + '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'" )' + "]";
+	var i18n_complete_confirm_message = '$encoder.jsEscape( $i18n.getString( "complete_confirm_message" ) , "'")';
+	var i18n_syntax_error_in_search_value = '$encoder.jsEscape( $i18n.getString( "syntax_error_in_search_value" ) , "'")';
+</script>   

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-02-23 11:12:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-03-05 04:22:57 +0000
@@ -249,3 +249,4 @@
 suggested_values=Suggested values
 back_to_main_menu = Back to main menu
 add_all_values = Add all values
+display_provided_other_facility_column = Display provided other facility column
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm	2012-02-13 02:41:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programList.vm	2012-03-05 04:22:57 +0000
@@ -50,7 +50,7 @@
 				<p><label class="bold">$i18n.getString( "description" ):</label><br><span id="descriptionField"></span></p>				
 				<p><label class="bold">$i18n.getString( "single_event" ):</label><br><span id="singleEventField"></span></p>				
 				<p><label class="bold">$i18n.getString( "anonymous" ):</label><br><span id="anonymousField"></span></p>
-				<p><label class="bold">$i18n.getString( "display_provided_other_facility" ):</label><br><span id="displayProvidedOtherFacilityField"></span></p>
+				<p><label class="bold">$i18n.getString( "display_provided_other_facility_column" ):</label><br><span id="displayProvidedOtherFacilityField"></span></p>
 				<p><label class="bold">$i18n.getString( "date_of_enrollment_description" ):</label><br><span id="dateOfEnrollmentDescriptionField"></span></p>				
 				<p><label class="bold">$i18n.getString( "date_of_incident_description" ):</label><br><span id="dateOfIncidentDescriptionField"></span></p>				
 				<p><label class="bold">$i18n.getString( "stage_in_program" ):</label><br><span id="programStageCountField"></span></p>