← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5873: (patient) Aggregate data for anonymous program.

 

------------------------------------------------------------
revno: 5873
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-02-07 15:39:49 +0700
message:
  (patient) Aggregate data for anonymous program.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.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/patientdatavalue/DefaultPatientDataValueService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.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/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2012-02-07 08:39:49 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStageInstance;
 
 /**
  * @author Chau Thu Tran
@@ -66,6 +67,8 @@
     
     Collection<Patient> getPatients( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period );
     
+    Collection<ProgramStageInstance> getProgramStageInstances( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period );
+    
     Collection<DataElement> getDataElementsInCondition( String aggregationExpression );
     
     Collection<DataElementCategoryOptionCombo> getOptionCombosInCondition( String aggregationExpression );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java	2012-01-15 02:14:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueService.java	2012-02-07 08:39:49 +0000
@@ -63,6 +63,8 @@
         DataElementCategoryOptionCombo optionCombo, OrganisationUnit organisationUnit );
 
     Collection<PatientDataValue> getPatientDataValues( ProgramStageInstance programStageInstance );
+    
+    Collection<PatientDataValue> getPatientDataValues( ProgramStageInstance programStageInstance, Collection<DataElement> dataElement );
 
     Collection<PatientDataValue> getPatientDataValues( Collection<ProgramStageInstance> programStageInstances );
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java	2012-01-15 02:14:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueStore.java	2012-02-07 08:39:49 +0000
@@ -61,6 +61,8 @@
         DataElementCategoryOptionCombo optionCombo, OrganisationUnit organisationUnit );
 
     Collection<PatientDataValue> get( ProgramStageInstance programStageInstance );
+    
+    Collection<PatientDataValue> get( ProgramStageInstance programStageInstance, Collection<DataElement> dataElements );
 
     Collection<PatientDataValue> get( Collection<ProgramStageInstance> programStageInstances );
 

=== 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-01-11 05:31:53 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-02-07 08:39:49 +0000
@@ -60,6 +60,8 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.system.util.DateUtils;
 import org.nfunk.jep.JEP;
@@ -107,6 +109,8 @@
 
     private PatientAttributeService patientAttributeService;
 
+    private ProgramStageInstanceService programStageInstanceService;
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
@@ -116,6 +120,11 @@
         this.aggregationConditionStore = aggregationConditionStore;
     }
 
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
     public void setPatientAttributeService( PatientAttributeService patientAttributeService )
     {
         this.patientAttributeService = patientAttributeService;
@@ -204,7 +213,7 @@
         Period period )
     {
         String sql = convertCondition( aggregationCondition, orgunit, period );
-  
+
         Collection<Integer> patientIds = aggregationConditionStore.executeSQL( sql );
 
         if ( patientIds == null )
@@ -253,12 +262,12 @@
     public Collection<Patient> getPatients( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit,
         Period period )
     {
-        // get params
-        int orgunitId = orgunit.getId();
-        String startDate = DateUtils.getMediumDateString( period.getStartDate() );
-        String endDate = DateUtils.getMediumDateString( period.getEndDate() );
-
         Collection<Patient> result = new HashSet<Patient>();
+        
+        // get params
+        int orgunitId = orgunit.getId();
+        String startDate = DateUtils.getMediumDateString( period.getStartDate() );
+        String endDate = DateUtils.getMediumDateString( period.getEndDate() );
 
         String sql = createSQL( aggregationCondition.getAggregationExpression(), aggregationCondition.getOperator(),
             orgunitId, startDate, endDate );
@@ -272,6 +281,30 @@
 
         return result;
     }
+    
+    public Collection<ProgramStageInstance> getProgramStageInstances( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit,
+        Period period )
+    {
+        Collection<ProgramStageInstance> result = new HashSet<ProgramStageInstance>();
+        aggregationCondition.setOperator( AGGRERATION_SUM );
+        
+        // get params
+        int orgunitId = orgunit.getId();
+        String startDate = DateUtils.getMediumDateString( period.getStartDate() );
+        String endDate = DateUtils.getMediumDateString( period.getEndDate() );
+        
+        String sql = createSQL( aggregationCondition.getAggregationExpression(), aggregationCondition.getOperator(),
+            orgunitId, startDate, endDate );
+
+        Collection<Integer> stageInstanceIds = aggregationConditionStore.executeSQL( sql );
+
+        for ( Integer stageInstanceId : stageInstanceIds )
+        {
+            result.add( programStageInstanceService.getProgramStageInstance( stageInstanceId ) );
+        }
+
+        return result;
+    }
 
     public String getConditionDescription( String condition )
     {
@@ -528,7 +561,7 @@
             subSQL.add( sql );
         }
 
-        return getSQL( subSQL, operators );
+        return getSQL( aggregationCondition.getOperator(), subSQL, operators );
     }
 
     private String createSQL( String aggregationExpression, String operator, int orgunitId, String startDate, String endDate )
@@ -626,7 +659,7 @@
 
                 else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_PROPERTY ) )
                 {
-                    condition = getConditionForProgramProperty( orgunitId, operator, startDate, endDate ) + info[1];
+                    condition = getConditionForProgramProperty( operator, startDate, endDate ) + info[1];
                 }
                 else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) )
                 {
@@ -665,51 +698,55 @@
                     subOperators.add( "AND" );
                 }
 
-                condition = getSQL( subConditions, subOperators ) + _subExp;
+                condition = getSQL( operator, subConditions, subOperators ) + _subExp;
             }
 
             conditions.add( condition );
         }
 
-        return getSQL( conditions, operators );
+        return getSQL( operator, conditions, operators );
     }
 
     private String getConditionForNotDataElement( int programStageId, String operator, int dataElementId,
         int optionComboId, int orgunitId, String startDate, String endDate )
     {
         String sql = "SELECT distinct(pi.patientid) ";
-
-        if ( operator.equals( AGGRERATION_SUM ) )
+        String condition = "pi.patientid";
+        
+        if( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT pi.patientid ";
+            sql = "SELECT psi.programstageinstanceid ";
+            condition = "psi.programstageinstanceid";
         }
 
-        return sql + "FROM programstageinstance as psi "
+        sql += "FROM programstageinstance as psi "
             + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid "
             + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid "
             + "LEFT OUTER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid "
             + "WHERE psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
-            + "AND pd.value IS NULL AND pi.patientid NOT IN  ( "
-            + "SELECT distinct(pi.patientid) FROM programstageinstance as psi "
+            + "AND pd.value IS NULL AND " + condition + " NOT IN  ( "
+            + "SELECT distinct(" + condition + ") FROM programstageinstance as psi "
             + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid "
-            + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid "
+            + "INNER JOIN programinstance as pgi ON pi.programinstanceid = psi.programinstanceid "
             + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid "
             + "WHERE pd.organisationunitid = " + orgunitId + " AND ps.programstageid = " + programStageId + " "
             + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
             + "AND pd.dataelementid = " + dataElementId + " " + "AND pd.categoryoptioncomboid = " + optionComboId
             + "  ) ";
+        
+        return sql;
     }
 
     private String getConditionForDataElement( int programStageId, String operator, int dataElementId,
         int optionComboId, int orgunitId, String startDate, String endDate )
     {
         String sql = "SELECT distinct(pi.patientid) ";
-
-        if ( operator.equals( AGGRERATION_SUM ) )
+        
+        if( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT pi.patientid ";
+            sql = "SELECT pi.programstageinstanceid ";
         }
-
+        
         return sql + "FROM programstageinstance as psi "
             + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid "
             + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid "
@@ -726,7 +763,7 @@
 
         if ( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT p.patientid ";
+            sql = "SELECT pi.patientid ";
         }
 
         return sql + "FROM patient as pi "
@@ -737,15 +774,15 @@
 
     private String getConditionForPatient( int orgunitId, String operator, String startDate, String endDate )
     {
-        String sql = "SELECT distinct(p.patientid) ";
+        String sql = "SELECT distinct(pi.patientid) ";
 
         if ( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT p.patientid ";
+            sql = "SELECT pi.patientid ";
         }
 
-        sql += "FROM patient as p WHERE p.organisationunitid = " + orgunitId + " " + "AND p.registrationdate >= '"
-            + startDate + "' AND p.registrationdate <= '" + endDate + "' ";
+        sql += "FROM patient as pi WHERE pi.organisationunitid = " + orgunitId + " " + "AND pi.registrationdate >= '"
+            + startDate + "' AND pi.registrationdate <= '" + endDate + "' ";
 
         return sql;
     }
@@ -753,12 +790,14 @@
     private String getConditionForPatientProperty( String propertyName, String operator,
         String startDate, String endDate )
     {
-        String sql = "SELECT distinct(pi.patientid) FROM patient as pi ";
+        String sql = "SELECT distinct(pi.patientid) ";
 
         if ( operator.equals( AGGRERATION_SUM ) )
         {
             sql = "SELECT pi.patientid ";
         }
+        
+        sql += "FROM patient as pi ";
 
         if ( propertyName.equals( PROPERTY_AGE ) )
         {
@@ -767,45 +806,47 @@
         }
         else
         {
-            sql += "' AND p." + propertyName + " ";
+            sql += "' AND pi." + propertyName + " ";
         }
 
         return sql;
     }
 
-    private String getConditionForProgramProperty( int orgunitId, String operator, String startDate, String endDate )
+    private String getConditionForProgramProperty( String operator, String startDate, String endDate )
     {
         String sql = "SELECT distinct(pi.patientid) ";
 
         if ( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT pi.patientid ";
+            sql = "SELECT psi.programstageinstanceid ";
         }
         
         return sql + "FROM programstageinstance as psi "
-            + "INNER JOIN programinstance as pgi ON psi.programinstanceid = pgi.programinstanceid "
-            + "INNER JOIN patient as pi ON pi.patientid = pgi.patientid WHERE pi.organisationunitid = " + orgunitId + " "
-            + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' AND ";
+            + "INNER JOIN programinstance as pi ON psi.programinstanceid = pi.programinstanceid "
+            + "WHERE psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' AND ";
     }
 
     private String getConditionForProgram( String programId, String operator, int orgunitId, String startDate,
         String endDate )
     {
-        String sql = "SELECT distinct(pi.patientid) ";
-
-        if ( operator.equals( AGGRERATION_SUM ) )
+        if( operator.equals( AGGRERATION_SUM ) )
         {
-            sql = "SELECT pi.patientid ";
+            return "SELECT psi.programstageinstanceid "
+                + "FROM programinstance as pi INNER JOIN programstageinstance psi "
+                + "ON pi.programinstanceid = psi.programinstanceid "
+                + "WHERE pi.programid=" + programId + " "
+                + "AND pi.enrollmentdate >= '" + startDate
+                + "' AND pi.enrollmentdate <= '" + endDate + "' ";
         }
 
-        return sql + "FROM programinstance as pgi "
-                   + "INNER JOIN patient as pi ON pi.patientid = pgi.patientid  " 
-                   + "WHERE pgi.programid=" + programId + " "
-                       + "AND pi.organisationunitid = " + orgunitId + " " + "AND pgi.enrollmentdate >= '" + startDate
-                       + "' AND pgi.enrollmentdate <= '" + endDate + "' ";
+        return "SELECT distinct(p.patientid) FROM programinstance as pi "
+                   + "INNER JOIN patient as p ON pi.patientid = p.patientid  " 
+                   + "WHERE pi.programid=" + programId + " "
+                       + "AND p.organisationunitid = " + orgunitId + " " + "AND pi.enrollmentdate >= '" + startDate
+                       + "' AND pi.enrollmentdate <= '" + endDate + "' ";
     }
 
-    private String getSQL( List<String> conditions, List<String> operators )
+    private String getSQL( String aggregateOperator, List<String> conditions, List<String> operators )
     {
         String sql = conditions.get( 0 );
 
@@ -817,7 +858,14 @@
         {
             if ( operators.get( index ).equalsIgnoreCase( OPERATOR_AND ) )
             {
-                sql += " AND pi.patientid IN ( " + conditions.get( index + 1 );
+                if( aggregateOperator.equals( AGGRERATION_SUM ) )
+                {
+                    sql += " AND psi.programstageinstanceid IN ( " + conditions.get( index + 1 );
+                }
+                else
+                {
+                    sql += " AND pi.patientid IN ( " + conditions.get( index + 1 );
+                }
                 sqlAnd += ")";
             }
             else

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java	2012-01-15 02:14:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/DefaultPatientDataValueService.java	2012-02-07 08:39:49 +0000
@@ -121,6 +121,11 @@
     {
         return patientDataValueStore.get( programStageInstance );
     }
+    
+    public Collection<PatientDataValue> getPatientDataValues( ProgramStageInstance programStageInstance, Collection<DataElement> dataElements )
+    {
+        return patientDataValueStore.get( programStageInstance, dataElements );
+    }
 
     public Collection<PatientDataValue> getPatientDataValues( Collection<ProgramStageInstance> programStageInstances )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2012-01-15 02:14:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2012-02-07 08:39:49 +0000
@@ -89,10 +89,9 @@
     {
         return (PatientDataValue) getCriteria( Restrictions.eq( "programStageInstance", programStageInstance ),
             Restrictions.eq( "dataElement", dataElement ), Restrictions.eq( "optionCombo", optionCombo ),
-            Restrictions.eq( "organisationUnit", organisationUnit ) )
-            .uniqueResult();
+            Restrictions.eq( "organisationUnit", organisationUnit ) ).uniqueResult();
     }
-    
+
     @SuppressWarnings( "unchecked" )
     public Collection<PatientDataValue> get( ProgramStageInstance programStageInstance )
     {
@@ -100,13 +99,24 @@
     }
 
     @SuppressWarnings( "unchecked" )
+    public Collection<PatientDataValue> get( ProgramStageInstance programStageInstance,
+        Collection<DataElement> dataElements )
+    {
+        String hql = "from PatientDataValue pdv where pdv.dataElement in ( :dataElements ) "
+            + "and pdv.programStageInstance = :programStageInstance";
+
+        return getQuery( hql ).setParameterList( "dataElements", dataElements ).setEntity( "programStageInstance",
+            programStageInstance ).list();
+    }
+
+    @SuppressWarnings( "unchecked" )
     public Collection<PatientDataValue> get( Collection<ProgramStageInstance> programStageInstances )
     {
         if ( programStageInstances == null || programStageInstances.isEmpty() )
         {
             return new ArrayList<PatientDataValue>();
         }
-        
+
         return getCriteria( Restrictions.in( "programStageInstance", programStageInstances ) ).list();
     }
 
@@ -205,12 +215,11 @@
         return getQuery( hql ).setParameterList( "dataElements", dataElements ).setEntity( "patient", patient )
             .setDate( "startDate", startDate ).setDate( "endDate", endDate ).list();
     }
-    
+
     public PatientDataValue get( ProgramStageInstance programStageInstance, DataElement dataElement )
     {
         return (PatientDataValue) getCriteria( Restrictions.eq( "programStageInstance", programStageInstance ),
-            Restrictions.eq( "dataElement", dataElement ) )
-            .uniqueResult();
+            Restrictions.eq( "dataElement", dataElement ) ).uniqueResult();
     }
 
 }

=== 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-01-15 02:14:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-02-07 08:39:49 +0000
@@ -183,7 +183,8 @@
         <property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />     	
         <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
         <property name="programService" ref="org.hisp.dhis.program.ProgramService" />
-        <property name="patientAttributeService" ref="org.hisp.dhis.patient.PatientAttributeService" />      	     	
+        <property name="patientAttributeService" ref="org.hisp.dhis.patient.PatientAttributeService" /> 
+        <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />      	     	
     </bean>
     
 	<bean id="org.hisp.dhis.program.nextvisit.NextVisitGenerator"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java	2011-07-15 03:35:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java	2012-02-07 08:39:49 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.program.ProgramStageInstance;
 
 import com.opensymphony.xwork2.Action;
 
@@ -75,6 +76,8 @@
     private Integer periodId;
 
     private Map<Patient, Collection<PatientDataValue>> mapPatients;
+    
+    private Map<ProgramStageInstance, Collection<PatientDataValue>> mapEvents;
 
     // -------------------------------------------------------------------------
     // Getter/Setter
@@ -105,6 +108,11 @@
         return mapPatients;
     }
 
+    public Map<ProgramStageInstance, Collection<PatientDataValue>> getMapEvents()
+    {
+        return mapEvents;
+    }
+
     public void setOrgunitId( Integer orgunitId )
     {
         this.orgunitId = orgunitId;
@@ -128,8 +136,7 @@
     public String execute()
         throws Exception
     {
-        mapPatients = new HashMap<Patient, Collection<PatientDataValue>>();
-
+        
         OrganisationUnit orgunit = organisationUnitService.getOrganisationUnit( orgunitId );
 
         Period period = periodService.getPeriod( periodId );
@@ -137,22 +144,48 @@
         CaseAggregationCondition aggCondition = aggregationConditionService
             .getCaseAggregationCondition( aggregationConditionId );
 
-        Collection<Patient> patients = aggregationConditionService.getPatients( aggCondition, orgunit, period );
-
-        for ( Patient patient : patients )
+        if( aggCondition.getOperator().equals( CaseAggregationCondition.AGGRERATION_SUM ) )
         {
-            Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( aggCondition
-                .getAggregationExpression() );
-
-            Collection<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
-
-            if ( dataElements.size() > 0 )
-            {
-                dataValues = patientDataValueService.getPatientDataValues( patient,
-                    dataElements, period.getStartDate(), period.getEndDate() );
-            }
+            mapEvents = new HashMap<ProgramStageInstance, Collection<PatientDataValue>>();
             
-            mapPatients.put( patient, dataValues );
+            Collection<ProgramStageInstance> programStageInstances = aggregationConditionService.getProgramStageInstances( aggCondition, orgunit, period );
+
+            for ( ProgramStageInstance programStageInstance : programStageInstances )
+            {
+                Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( aggCondition
+                    .getAggregationExpression() );
+
+                Collection<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
+    
+                if ( dataElements.size() > 0 )
+                {
+                    dataValues = patientDataValueService.getPatientDataValues( programStageInstance, dataElements );
+                }
+                
+                mapEvents.put( programStageInstance, dataValues );
+            }
+        }
+        else
+        {
+            mapPatients = new HashMap<Patient, Collection<PatientDataValue>>();
+
+            Collection<Patient> patients = aggregationConditionService.getPatients( aggCondition, orgunit, period );
+    
+            for ( Patient patient : patients )
+            {
+                Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( aggCondition
+                    .getAggregationExpression() );
+    
+                Collection<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
+    
+                if ( dataElements.size() > 0 )
+                {
+                    dataValues = patientDataValueService.getPatientDataValues( patient,
+                        dataElements, period.getStartDate(), period.getEndDate() );
+                }
+                
+                mapPatients.put( patient, dataValues );
+            }
         }
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm	2011-11-25 04:10:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm	2012-02-07 08:39:49 +0000
@@ -1,5 +1,6 @@
 <table class='mainPageTable listTable'>
 	<tbody>
+	#if( $mapPatients )
 		#set($hasDataValue = true )
 		#foreach( $patient in $mapPatients.keySet())
 			#if( $hasDataValue == true)
@@ -35,7 +36,7 @@
 				#foreach( $dataValue in $dataValues )
 				<tr #alternate( $mark )>
 					<td>$dataValue.programStageInstance.programStage.name</td>
-					<td>$dataValue.dataElement.name</td>
+					<td>$dataValue.dataElement.name $dataValue.optionCombo.name</td>
 					<td>$dataValue.value</td>
 					<td>$format.formatDate($dataValue.timestamp)</td>
 				</tr>
@@ -43,5 +44,41 @@
 				#end
 			#end
 		#end
+	
+	#else
+		<tr height='5em'>
+			<th>$i18n.getString('program_stage')</th>
+			<th>$i18n.getString('data_element')</th>
+			<th>$i18n.getString('value')</th>
+			<th>$i18n.getString('date_of_edit')</th>
+		</tr>
+		#foreach( $stageInstance in $mapEvents.keySet() )
+			#set($dataValues = $mapEvents.get($stageInstance) )
+			#if ( $!dataValues.size() == 0 )
+				#set($hasDataValue = false )
+				<tr>
+					<td colspan='4'></td>
+				</tr>
+			#else
+				#set($hasDataValue = true )
+				<tr style='background-color: #cccccc'>
+					<td>$i18n.getString('program_stage')</td>
+					<td>$i18n.getString('data_element')</td>
+					<td>$i18n.getString('value')</td>
+					<td>$i18n.getString('date_of_edit')</td>
+				</tr>
+				#set( $mark = false )
+				#foreach( $dataValue in $dataValues )
+					<tr #alternate( $mark )>
+						<td>$dataValue.programStageInstance.programStage.name</td>
+						<td>$dataValue.dataElement.name $dataValue.optionCombo.name</td>
+						<td>$dataValue.value</td>
+						<td>$format.formatDate($dataValue.timestamp)</td>
+					</tr>
+					#set( $mark = !$mark)
+				#end
+			#end
+		#end
+	#end
 	</tbody>
 </table>
\ No newline at end of file

=== 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-06 02:56:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-07 08:39:49 +0000
@@ -77,7 +77,10 @@
 					##data element name
 					<td class='text-column'>
 						<span id="value[$programStageDataElement.dataElement.id].name" title="$!encoder.htmlEncode( $programStageDataElement.dataElement.description )">
-							$encoder.htmlEncode( $programStageDataElement.dataElement.name ) $optionCombo.name
+							$encoder.htmlEncode( $programStageDataElement.dataElement.name ) 
+							#if( $!programStageDataElement.dataElement.categoryCombo.optionCombos.size() > 1 ) 
+								$encoder.htmlEncode( $optionCombo.name ) 
+							#end
 							#if ( $programStageDataElement.compulsory )
 								<em title="$i18n.getString( "required" )" class="required">*</em>
 							#end