← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7228: (patient) Changed dataentry UI.

 

------------------------------------------------------------
revno: 7228
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-06-07 11:23:40 +0700
message:
  (patient) Changed dataentry UI.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageInstanceDueDateComparator.java
renamed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStagesAction.java => dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseProgramStages.vm => dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm
modified:
  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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.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/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.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/dataRecordingSelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  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/multiDataEntry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/report.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/dataEntry.css
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/patient.css
  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/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2012-06-04 10:03:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2012-06-07 04:23:40 +0000
@@ -43,13 +43,10 @@
      */
     private static final long serialVersionUID = 6239130884678145713L;
 
-    public static final String COLOR_RED = "#fb4754";
-
-    public static final String COLOR_YELLOW = "#f9f95a";
-
-    public static final String COLOR_GREEN = "#8ffe8f";
-
-    public static final String COLOR_LIGHTRED = "#fb6bfb";
+    public static final int COMPLETED_STATUS = 1;
+    public static final int VISITED_STATUS = 2;
+    public static final int FUTURE_VISIT_STATUS = 3;
+    public static final int LATE_VISIT_STATUS = 4;
 
     private int id;
 

=== 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-05-28 09:46:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-06-07 04:23:40 +0000
@@ -72,7 +72,7 @@
 
     Collection<ProgramStageInstance> getAllProgramStageInstances();
 
-    Map<Integer, String> colorProgramStageInstances( Collection<ProgramStageInstance> programStageInstances );
+    Map<Integer, Integer> statusProgramStageInstances( Collection<ProgramStageInstance> programStageInstances );
 
     /**
      * Get all {@link ProgramStageInstance program stage instances} for unit,

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageInstanceDueDateComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageInstanceDueDateComparator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageInstanceDueDateComparator.java	2012-06-07 04:23:40 +0000
@@ -0,0 +1,55 @@
+/*
+ * 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.program.comparator;
+
+import java.util.Comparator;
+
+import org.hisp.dhis.program.ProgramStageInstance;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ProgramStageInstanceDueDateComparator.java Jun 7, 2012 9:49:25 AM$
+ */
+public class ProgramStageInstanceDueDateComparator
+    implements Comparator<ProgramStageInstance>
+{
+    public int compare( ProgramStageInstance programStageInstance1, ProgramStageInstance programStageInstance2 )
+    {
+        if ( programStageInstance1.getDueDate().before( programStageInstance2.getDueDate() ) )
+        {
+            return -1;
+        }
+        else if ( programStageInstance1.getDueDate().after( programStageInstance2.getDueDate() ) )
+        {
+            return 1;
+        }
+        return 0;
+    }
+
+}

=== 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-05-28 09:46:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-06-07 04:23:40 +0000
@@ -122,19 +122,19 @@
         programStageInstanceStore.update( programStageInstance );
     }
 
-    public Map<Integer, String> colorProgramStageInstances( Collection<ProgramStageInstance> programStageInstances )
+    public Map<Integer, Integer> statusProgramStageInstances( Collection<ProgramStageInstance> programStageInstances )
     {
-        Map<Integer, String> colorMap = new HashMap<Integer, String>();
+        Map<Integer, Integer> colorMap = new HashMap<Integer, Integer>();
 
         for ( ProgramStageInstance programStageInstance : programStageInstances )
         {
             if ( programStageInstance.isCompleted() )
             {
-                colorMap.put( programStageInstance.getId(), ProgramStageInstance.COLOR_GREEN );
+                colorMap.put( programStageInstance.getId(), ProgramStageInstance.COMPLETED_STATUS );
             }
             else if ( programStageInstance.getExecutionDate() != null )
             {
-                colorMap.put( programStageInstance.getId(), ProgramStageInstance.COLOR_LIGHTRED );
+                colorMap.put( programStageInstance.getId(), ProgramStageInstance.VISITED_STATUS );
             }
             else
             {
@@ -150,11 +150,11 @@
 
                 if ( dueDateCalendar.getTime().before( new Date() ) )
                 {
-                    colorMap.put( programStageInstance.getId(), ProgramStageInstance.COLOR_RED );
+                    colorMap.put( programStageInstance.getId(), ProgramStageInstance.LATE_VISIT_STATUS );
                 }
                 else
                 {
-                    colorMap.put( programStageInstance.getId(), ProgramStageInstance.COLOR_YELLOW );
+                    colorMap.put( programStageInstance.getId(), ProgramStageInstance.FUTURE_VISIT_STATUS );
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java	2012-06-04 10:03:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CreateAnonymousEncounterAction.java	2012-06-07 04:23:40 +0000
@@ -125,7 +125,6 @@
 
         if ( date != null )
         {
-
             ProgramInstance programInstance = programInstanceService.getProgramInstance( programInstanceId );
 
             ProgramStageInstance programStageInstance = new ProgramStageInstance();
@@ -139,9 +138,9 @@
             programStageInstance.setExecutionDate( date );
             programStageInstance.setOrganisationUnit( selectedStateManager.getSelectedOrganisationUnit() );
 
-            programStageInstanceService.addProgramStageInstance( programStageInstance );
+            int id = programStageInstanceService.addProgramStageInstance( programStageInstance );
             
-            message = programStageInstance.getId() + "";
+            message = id + "";
             
             return SUCCESS;
         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2011-09-23 18:54:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2012-06-07 04:23:40 +0000
@@ -156,11 +156,11 @@
         return programStageInstanceMap;
     }
 
-    private Map<Integer, String> colorMap = new HashMap<Integer, String>();
+    private Map<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
 
-    public Map<Integer, String> getColorMap()
+    public Map<Integer, Integer> getStatusMap()
     {
-        return colorMap;
+        return statusMap;
     }
 
     private Map<Patient, ProgramInstance> programInstanceMap = new HashMap<Patient, ProgramInstance>();
@@ -257,7 +257,7 @@
             }
         }
 
-        colorMap = programStageInstanceService.colorProgramStageInstances( programStageInstances );
+        statusMap = programStageInstanceService.statusProgramStageInstances( programStageInstances );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2012-05-23 15:02:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java	2012-06-07 04:23:40 +0000
@@ -42,12 +42,9 @@
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramDataEntryService;
-import org.hisp.dhis.program.ProgramInstance;
-import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.program.comparator.ProgramStageDataElementSortOrderComparator;
 
 import com.opensymphony.xwork2.Action;
@@ -64,8 +61,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private ProgramStageService programStageService;
-
     private ProgramDataEntryService programDataEntryService;
 
     private PatientDataValueService patientDataValueService;
@@ -78,7 +73,7 @@
     // Input && Output
     // -------------------------------------------------------------------------
 
-    private Integer programStageId;
+    private Integer programStageInstanceId;
 
     private ProgramStageInstance programStageInstance;
 
@@ -103,16 +98,16 @@
         this.programStageInstanceService = programStageInstanceService;
     }
 
+    public void setProgramStageInstanceId( Integer programStageInstanceId )
+    {
+        this.programStageInstanceId = programStageInstanceId;
+    }
+
     public Program getProgram()
     {
         return program;
     }
 
-    public void setProgramStageService( ProgramStageService programStageService )
-    {
-        this.programStageService = programStageService;
-    }
-
     public void setSelectedStateManager( SelectedStateManager selectedStateManager )
     {
         this.selectedStateManager = selectedStateManager;
@@ -143,11 +138,6 @@
         this.i18n = i18n;
     }
 
-    public void setProgramStageId( Integer programStageId )
-    {
-        this.programStageId = programStageId;
-    }
-
     public String getCustomDataEntryFormCode()
     {
         return customDataEntryFormCode;
@@ -176,58 +166,49 @@
         // Get program-stage-instance
         // ---------------------------------------------------------------------
 
-        ProgramStage programStage = programStageService.getProgramStage( programStageId );
-
-        program = programStage.getProgram();
-
-        ProgramInstance programInstance = selectedStateManager.getSelectedProgramInstance();
-
-        if ( programInstance != null )
+        programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId );
+        program = programStageInstance.getProgramStage().getProgram();
+
+        if ( programStageInstance != null )
         {
-            programStageInstance = programStageInstanceService.getProgramStageInstance( programInstance, programStage );
-
-            if ( programStageInstance != null )
-            {
-                if ( program.getType() == Program.SINGLE_EVENT_WITHOUT_REGISTRATION
-                    && programStageInstance.isCompleted() )
-                {
-                    return SUCCESS;
-                }
-
-                selectedStateManager.setSelectedProgramStageInstance( programStageInstance );
-
-                // ---------------------------------------------------------------------
-                // Get data values
-                // ---------------------------------------------------------------------
-
-                programStageDataElements = new ArrayList<ProgramStageDataElement>( programStage
-                    .getProgramStageDataElements() );
-
-                Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() );
-
-                Collection<PatientDataValue> patientDataValues = patientDataValueService
-                    .getPatientDataValues( programStageInstance );
-
-                patientDataValueMap = new HashMap<Integer, PatientDataValue>( patientDataValues.size() );
-
-                for ( PatientDataValue patientDataValue : patientDataValues )
-                {
-                    int key = patientDataValue.getDataElement().getId();
-                    patientDataValueMap.put( key, patientDataValue );
-                }
-
-                // ---------------------------------------------------------------------
-                // Get data-entry-form
-                // ---------------------------------------------------------------------
-
-                DataEntryForm dataEntryForm = programStage.getDataEntryForm();
-
-                if ( dataEntryForm != null )
-                {
-                    customDataEntryFormCode = programDataEntryService.prepareDataEntryFormForEntry( dataEntryForm
-                        .getHtmlCode(), patientDataValues, program.getDisplayProvidedOtherFacility().toString(), i18n,
-                        programStage, programStageInstance, organisationUnit );
-                }
+            if ( program.getType() == Program.SINGLE_EVENT_WITHOUT_REGISTRATION && programStageInstance.isCompleted() )
+            {
+                return SUCCESS;
+            }
+
+            selectedStateManager.setSelectedProgramStageInstance( programStageInstance );
+
+            // ---------------------------------------------------------------------
+            // Get data values
+            // ---------------------------------------------------------------------
+
+            programStageDataElements = new ArrayList<ProgramStageDataElement>( programStageInstance.getProgramStage()
+                .getProgramStageDataElements() );
+
+            Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() );
+
+            Collection<PatientDataValue> patientDataValues = patientDataValueService
+                .getPatientDataValues( programStageInstance );
+
+            patientDataValueMap = new HashMap<Integer, PatientDataValue>( patientDataValues.size() );
+
+            for ( PatientDataValue patientDataValue : patientDataValues )
+            {
+                int key = patientDataValue.getDataElement().getId();
+                patientDataValueMap.put( key, patientDataValue );
+            }
+
+            // ---------------------------------------------------------------------
+            // Get data-entry-form
+            // ---------------------------------------------------------------------
+
+            DataEntryForm dataEntryForm = programStageInstance.getProgramStage().getDataEntryForm();
+
+            if ( dataEntryForm != null )
+            {
+                customDataEntryFormCode = programDataEntryService.prepareDataEntryFormForEntry( dataEntryForm
+                    .getHtmlCode(), patientDataValues, program.getDisplayProvidedOtherFacility().toString(), i18n,
+                    programStageInstance.getProgramStage(), programStageInstance, organisationUnit );
             }
         }
 

=== renamed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStagesAction.java' => 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStagesAction.java	2012-05-23 15:02:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2012-06-07 04:23:40 +0000
@@ -28,11 +28,10 @@
 package org.hisp.dhis.caseentry.action.caseentry;
 
 import java.util.ArrayList;
+import java.util.Collections;
 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.patient.Patient;
@@ -40,17 +39,18 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 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.comparator.ProgramStageInstanceDueDateComparator;
 
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Chau Thu Tran
- * @version $ LoadProgramStagesAction.java May 7, 2011 2:31:47 PM $
+ * @version $ LoadProgramStageInstancesAction.java May 7, 2011 2:31:47 PM $
  * 
  */
-public class LoadProgramStagesAction
+public class LoadProgramStageInstancesAction
     implements Action
 {
     // -------------------------------------------------------------------------
@@ -96,25 +96,18 @@
         this.programId = programId;
     }
 
-    private ProgramInstance programInstance;
-
-    public ProgramInstance getProgramInstance()
-    {
-        return programInstance;
-    }
-
-    private Set<ProgramStage> programStages = new HashSet<ProgramStage>();
-
-    public Set<ProgramStage> getProgramStages()
-    {
-        return programStages;
-    }
-
-    private Map<Integer, String> colorMap = new HashMap<Integer, String>();
-
-    public Map<Integer, String> getColorMap()
-    {
-        return colorMap;
+    private Map<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
+
+    public Map<Integer, Integer> getStatusMap()
+    {
+        return statusMap;
+    }
+
+    private List<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
+
+    public List<ProgramStageInstance> getProgramStageInstances()
+    {
+        return programStageInstances;
     }
 
     private Program program;
@@ -131,19 +124,12 @@
     public String execute()
         throws Exception
     {
-        if ( programId == null )
-        {
-            return SUCCESS;
-        }
-
         selectedStateManager.clearSelectedProgramInstance();
         selectedStateManager.clearSelectedProgramStageInstance();
 
         Patient patient = selectedStateManager.getSelectedPatient();
 
-        program = programService.getProgram( programId );
-
-        programStages = program.getProgramStages();
+        Program program = programService.getProgram( programId );
 
         List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
 
@@ -160,13 +146,16 @@
 
         if ( programInstances != null && programInstances.size() > 0 )
         {
-            programInstance = programInstances.iterator().next();
+            ProgramInstance programInstance = programInstances.iterator().next();
 
             selectedStateManager.setSelectedProgramInstance( programInstance );
 
             if ( programInstance.getProgramStageInstances() != null )
             {
-                colorMap = programStageInstanceService.colorProgramStageInstances( programInstance
+                programStageInstances.addAll( programInstance.getProgramStageInstances() );
+                Collections.sort( programStageInstances, new ProgramStageInstanceDueDateComparator() );
+
+                statusMap = programStageInstanceService.statusProgramStageInstances( programInstance
                     .getProgramStageInstances() );
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java	2012-05-26 12:31:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RegisterIrregularEncounterAction.java	2012-06-07 04:23:40 +0000
@@ -78,6 +78,13 @@
         this.dueDate = dueDate;
     }
 
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -94,7 +101,9 @@
         programStageInstance.setStageInProgram( currentStageInstance.getStageInProgram() );
         programStageInstance.setDueDate( format.parseDate( dueDate ) );
 
-        programStageInstanceService.addProgramStageInstance( programStageInstance );
+        int id = programStageInstanceService.addProgramStageInstance( programStageInstance );
+        message = id + "";
+
         selectedStateManager.setSelectedProgramStageInstance( programStageInstance );
 
         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-06-04 10:03:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java	2012-06-07 04:23:40 +0000
@@ -31,7 +31,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -76,13 +75,6 @@
         this.patientDataValueService = patientDataValueService;
     }
 
-    private SelectedStateManager selectedStateManager;
-
-    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
-    {
-        this.selectedStateManager = selectedStateManager;
-    }
-
     private Boolean providedElsewhere;
 
     public void setProvidedElsewhere( Boolean providedElsewhere )
@@ -136,14 +128,8 @@
     public String execute()
         throws Exception
     {
-        if ( programStageInstanceId == null )
-        {
-            programStageInstance = selectedStateManager.getSelectedProgramStageInstance();
-        }
-        else
-        {
-            programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId );
-        }
+
+        programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId );
 
         DataElement dataElement = dataElementService.getDataElement( dataElementId );
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2011-12-21 07:16:29 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java	2012-06-07 04:23:40 +0000
@@ -122,18 +122,18 @@
         return organisationUnit;
     }
 
-    Collection<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
+    private Collection<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
 
     public Collection<ProgramInstance> getProgramInstances()
     {
         return programInstances;
     }
 
-    private Map<Integer, String> colorMap = new HashMap<Integer, String>();
+    private Map<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
 
-    public Map<Integer, String> getColorMap()
+    public Map<Integer, Integer> getStatusMap()
     {
-        return colorMap;
+        return statusMap;
     }
 
     private Program program;
@@ -176,7 +176,7 @@
             programStageInstances.addAll( programInstance.getProgramStageInstances() );
         }
 
-        colorMap = programStageInstanceService.colorProgramStageInstances( programStageInstances );
+        statusMap = programStageInstanceService.statusProgramStageInstances( programStageInstances );
 
         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-06-04 10:03:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-06-07 04:23:40 +0000
@@ -80,8 +80,6 @@
 			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 		<property name="patientDataValueService"
 			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
-		<property name="selectedStateManager"
-			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 	</bean>
 
 	<bean
@@ -97,8 +95,8 @@
 	</bean>
 
 	<bean
-		id="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStagesAction"
-		class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStagesAction"
+		id="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction"
+		class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction"
 		scope="prototype">
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
@@ -111,7 +109,6 @@
 	<bean id="org.hisp.dhis.caseentry.action.caseentry.LoadDataEntryAction"
 		class="org.hisp.dhis.caseentry.action.caseentry.LoadDataEntryAction"
 		scope="prototype">
-		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
 		<property name="programDataEntryService"
 			ref="org.hisp.dhis.program.ProgramDataEntryService" />
 		<property name="patientDataValueService"

=== 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-06-01 04:31:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-06-07 04:23:40 +0000
@@ -353,4 +353,5 @@
 before = Before
 after = After
 on = On
-clear_filter = Clear filter
\ No newline at end of file
+clear_filter = Clear filter
+events = Events
\ 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-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-06-07 04:23:40 +0000
@@ -65,10 +65,10 @@
 			<param name="stylesheets">style/patient.css</param>
 		</action>
 
-		<action name="loadProgramStages"
-			class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStagesAction">
+		<action name="loadProgramStageInstances"
+			class="org.hisp.dhis.caseentry.action.caseentry.LoadProgramStageInstancesAction">
 			<result name="success" type="velocity-json">
-				/dhis-web-caseentry/responseProgramStages.vm</result>
+				/dhis-web-caseentry/jsonProgramStageInstances.vm</result>
 		</action>
 
 		<action name="dataentryform"

=== 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-06-04 10:03:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-06-07 04:23:40 +0000
@@ -6,29 +6,17 @@
 		#elseif( $programStageInstance )
 			setFieldValue( 'dueDate', "$!format.formatDate( $programStageInstance.dueDate )" );
 			setFieldValue( 'executionDate', "$!format.formatDate( $programStageInstance.executionDate )" );
-		#elseif( $program.type == "2" )
-		{
-			disable("dueDate");
-		}
 		#end
 		
 		$('#executionDate').change(function() {
 				saveExecutionDate( getFieldValue('programStageId'), getFieldValue('executionDate') );
 			});
-			
-		if( getFieldValue('programStageId') == 0 )
-		{
-			disable('executionDate');
-		}
-		else
-		{
-			enable('executionDate');
-		}
 		
 		entryFormContainerOnReady();
 	});
 </script>
 
+
 <div id='entryFormContainer'>
 
 <input type='hidden' id='incidentDate' value='$!format.formatDate($programStageInstance.programInstance.dateOfIncident)'>
@@ -115,6 +103,11 @@
 	#end
 </div>
 
+<div id='inputCriteriaDiv' class="page inputCriteria" style="display:none;width:480px;height:29px;">	
+	<input type="button" class='button' id="completeInBelowBtn" value="$i18n.getString('complete')" onClick="doComplete()" disabled="disabled">
+	<input type="button" class='button' id="validationInBelowBtn" value="$i18n.getString('run_validation')" onClick="javascript: runValidation();" >
+</div>
+
 </div>
 
 <div id='validateProgramDiv'></div>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm	2012-06-05 08:55:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataRecordingSelect.vm	2012-06-07 04:23:40 +0000
@@ -34,54 +34,51 @@
 	<input type="button" class='button' value="$i18n.getString( 'back_to_search' )" id='backBtnFromEntry' onclick="javascript:showSearchForm();" >
 </div>
 		
-<div class="inputCriteria" style="width:480px;height:130px;">
-
-	<table> 
-		<tr>
+<div id='inputCriteria' class="page inputCriteria" style="width:480px;height:29px;">	
+	<input type='hidden' id='programStageId' name='programStageId'>
+	<table>
+	   <tr id='programIdTR'>
+			<td class='text-column'><label for="programId">$i18n.getString( "program" )</label></td>
 			<td>
-				<table>
-				   <tr id='programIdTR'>
-						<td class='text-column'><label for="programId">$i18n.getString( "program" )</label></td>
-						<td>
-							<select id="programId" name="programId" class="criteria" onchange="loadProgramStages();" #if( $programs.size() == 0 ) disabled="disabled" #end>
-								<option value="0">[$i18n.getString( "select" )]</option>
-								#foreach( $program in $programs )
-									<option value="$program.id" type="$program.type" #if( $programId && $program.id == $programId ) selected="selected" #end>$encoder.htmlEncode( $program.name )</option>
-								#end
-							</select>
-						</td>
-					</tr>
-					<tr id='programStageIdTR' >
-						<td class='text-column'><label for="programStageId">$i18n.getString( "program_stage" )</label></td>
-						<td>
-							<select id="programStageId" name="programStageId" class="criteria" onchange="javascript:loadDataEntry();" >
-							</select>
-						</td>
-					</tr>
-					
-					<tr>
-						<td class='text-column'><label for="executionDate">$i18n.getString( "report_date" ) </label></td>
-						<td><input type="text" id="executionDate" name="executionDate" class="criteria" style="width:320px" value="$!format.formatDate( $programStageInstance.executionDate )" >
-							<script type="text/javascript">
-							   datePickerValid( 'executionDate', false );
-							   disable('executionDate');
-							</script>
-					</tr>
-					
-					<tr id='dueDateTR'>
-						<td class='text-column'><label for="dueDate">$i18n.getString( "due_date" ) </label></td>
-						<td><input type="text" id="dueDate" name="dueDate" class="criteria" value="$!format.formatDate( $programStageInstance.dueDate )" readonly> </td>
-					</tr>
-				</table>
+				<select id="programId" name="programId" class="criteria" onchange="loadProgramStages();" #if( $programs.size() == 0 ) disabled="disabled" #end>
+					<option value="0">[$i18n.getString( "select" )]</option>
+					#foreach( $program in $programs )
+						<option value="$program.id" type="$program.type" #if( $programId && $program.id == $programId ) selected="selected" #end>$encoder.htmlEncode( $program.name )</option>
+					#end
+				</select>
 			</td>
-			
-			
-		</tr>
-	</table>
+		</tr>
+	</table>
+</div>
+
+<div id='programInstanceDiv' class='hidden '>
+	<div id='programInstanceFlowDiv' style="width:500px;height:81px;overflow-x:auto;">
+		<table>
+			<tr id='programStageIdTR'></tr>
+		</table>
+	</div>
+	
+	<br>
+	
+	<table>
+		<tr>
+			<th class='text-column'><label for="executionDate">$i18n.getString( "report_date" ) </label></th>
+			<th><input type="text" id="executionDate" name="executionDate" class='criteria' value="$!format.formatDate( $programStageInstance.executionDate )" >
+				<script type="text/javascript">
+				   datePickerValid( 'executionDate', false );
+				</script>
+			</th>
+			<th class='text-column'><label for="dueDate">$i18n.getString( "due_date" ) </label></th>
+			<th><input type="text" id="dueDate" name="dueDate" class='criteria' value="$!format.formatDate( $programStageInstance.dueDate )" readonly > </th>
+		</tr>
+	</table>
+	
 </div>
 
 </form>
 
+<p></p>
+	
 <div id='createNewEncounterDiv' class='hidden'>
 	<table>
 		<tr>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataentryRecords.vm	2012-06-07 04:23:40 +0000
@@ -17,7 +17,11 @@
 								</td>
 								
 								<td width='100px;'>
-									<input type='button' class='stage-object' style='border-color:$colorMap.get( $programStageInstance.id );' value='$programStageInstance.programStage.name $format.formatDate( $programStageInstance.dueDate )' onclick='javascript:viewPrgramStageRecords( $programStageInstance.id );'>
+									<input type='button' id='ps_$programStageInstance.id' name='programStageBtn' class='stage-object' value='$programStageInstance.programStage.name $format.formatDate( $programStageInstance.dueDate )' onclick='javascript:viewPrgramStageRecords( $programStageInstance.id );'>
+									<script>	
+										var status = $statusMap.get( $programStageInstance.id );
+										setEventColorStatus( 'ps_' + $programStageInstance.id ,status);
+									</script>
 								</td>
 							#end
 						</tr>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2012-06-05 06:33:23 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2012-06-07 04:23:40 +0000
@@ -263,3 +263,39 @@
 	var url = "getPatientHistory.action?patientId=" + patientId + "&type=" + type;
 	window.location.href = url;
 }
+
+var prefixStageId = 'ps_';
+var COLOR_RED = "#fb4754";
+var COLOR_GREEN = "#8ffe8f";
+var COLOR_YELLOW = "#f9f95a";
+var COLOR_LIGHTRED = "#fb6bfb";
+var COLOR_LIGHT_RED = "#ff7676";
+var COLOR_LIGHT_YELLOW = "#ffff99";
+var COLOR_LIGHT_GREEN = "#ccffcc";
+var COLOR_LIGHT_LIGHTRED = "#ff99ff";
+
+function setEventColorStatus( elementId, status )
+{
+	status = eval(status);
+	switch(status)
+	{
+		case 1:
+			jQuery('#' + elementId ).css('border-color', COLOR_GREEN);
+			jQuery('#' + elementId ).css('background-color', COLOR_LIGHT_GREEN);
+			return;
+		case 2:
+		  jQuery('#' + elementId ).css('border-color', COLOR_LIGHTRED);
+			jQuery('#' + elementId ).css('background-color', COLOR_LIGHT_LIGHTRED);
+			return;
+		case 3:
+			jQuery('#' + elementId ).css('border-color', COLOR_YELLOW);
+			jQuery('#' + elementId ).css('background-color', COLOR_LIGHT_YELLOW);
+			return;
+		case 4:
+			jQuery('#' + elementId ).css('border-color', COLOR_RED);
+			jQuery('#' + elementId ).css('background-color', COLOR_LIGHT_RED);
+			return;
+		default:
+		  return;
+	}
+}
\ No newline at end of file

=== 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-06-05 08:55:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-06-07 04:23:40 +0000
@@ -1,3 +1,13 @@
+var prefixId = 'ps_';
+
+var COLOR_RED = "#fb4754";
+var COLOR_GREEN = "#8ffe8f";
+var COLOR_YELLOW = "#f9f95a";
+var COLOR_LIGHTRED = "#fb6bfb";
+var COLOR_LIGHT_RED = "#ff7676";
+var COLOR_LIGHT_YELLOW = "#ffff99";
+var COLOR_LIGHT_GREEN = "#ccffcc";
+var COLOR_LIGHT_LIGHTRED = "#ff99ff";
 
 //--------------------------------------------------------------------------------------------
 // Load program-stages by the selected program
@@ -7,120 +17,104 @@
 {
 	jQuery('#createNewEncounterDiv').dialog('close');
 	hideById('dataEntryFormDiv');
-	clearListById('programStageId');
 	setFieldValue('executionDate','');
 	setFieldValue('dueDate','');
 	disable('completeBtn');
 	disable('completeInBelowBtn');
 	disable('validationBtn');
+	disable('validationInBelowBtn');
 	disable('newEncounterBtn');
 	hideById('inputCriteriaDiv');
-		
+	$('#programStageIdTR').html('');
+	hideById('programInstanceDiv');
+	
 	var programId = jQuery('#dataRecordingSelectDiv [name=programId]').val();
 	if ( programId == 0 )
 	{
-		hideById('historyPlanLink');
 		return;
 	}
-	jQuery.getJSON( "loadProgramStages.action",
+	
+	jQuery.getJSON( "loadProgramStageInstances.action",
 		{
 			programId: programId
 		},  
 		function( json ) 
 		{    
-			addOptionById( 'programStageId', "0", i18n_select );
-			for ( i in json.programStages ) 
-			{
-				$('#programStageId').append("<option value='" + json.programStages[i].id + "' standardInterval='" + json.programStages[i].standardInterval + "' >" + json.programStages[i].name +  '</option>');
-			} 
+			showById('programInstanceDiv');
 			
 			var type = jQuery('#dataRecordingSelectDiv [name=programId] option:selected').attr('type');
+			if( type == 1 && json.programStageInstances.length > 1 )
+			{
+				for ( i in json.programStageInstances ) 
+				{
+					if( i!= 0 )
+					{
+						$('#programStageIdTR').append('<td><img src="images/rightarrow.png"></td>');
+					}
+
+					var status =json.programStageInstances[i].status;
+					var programStageInstanceId = json.programStageInstances[i].id;
+					var programStageId = json.programStageInstances[i].programStageId;
+					var programStageName= json.programStageInstances[i].programStageName;
+					var elementId = prefixId + programStageInstanceId;
+					
+					$('#programStageIdTR').append('<td><input name="programStageBtn" '
+						+ 'id="' + elementId + '"' 
+						+ 'type="button" class="stage-object" '
+						+ 'psid="' + programStageId + '"' 
+						+ 'psname="' + programStageName + '" '
+						+ 'dueDate="' + json.programStageInstances[i].dueDate + '"'
+						+ 'value="'+ programStageName + ' ' + json.programStageInstances[i].dueDate + '" '
+						+ 'onclick="javascript:loadDataEntry(' + programStageInstanceId + ')"></td>');
+					setEventColorStatus( elementId, status );
+				}
 				
-			// Single-event program or normal program with only one program-stage
-			if( type=='2' || type=='3' || json.programStages.length == 1)
+				disable('completeBtn');
+				disable('completeInBelowBtn');
+				disable('validationBtn');
+				disable('validationInBelowBtn');
+				showById('programStageIdTR');
+				showById('programInstanceFlowDiv');
+			}
+			// Load entry form for Single-event program or normal program with only one program-stage
+			else
 			{
-				byId('programStageId').selectedIndex = 1;
-				jQuery('#programStageIdTR').attr('class','hidden');
 				jQuery('#dueDateTR').attr('class','hidden');
 				enable('completeBtn');
 				enable('completeInBelowBtn');
 				hideById('historyPlanLink');
-				loadDataEntry();
-			}
-			else
-			{
-				// show history / plan
-				setInnerHTML( 'currentSelection', '' ); 
-				var history = '<table class="history">';
-				history += '<tr>';
-				history += '<td class="bold row">' + i18n_program_stage + '</td>';
-				history += '<td class="bold row">' + i18n_scheduled_for + '</td>';
-				history += '</tr>';
-				for ( i in json.programStageInstances ) 
-				{
-					history += '<tr bgcolor=' + json.programStageInstances[i].colorMap + '>';
-					history += '<td>';
-					history += '<span>' + json.programStageInstances[i].name + '</span>';
-					history += '</td>';
-					history += '<td class="cent">';
-					history += json.programStageInstances[i].infor;
-					history += '</td>';
-					history += '</tr>';
-				}
-				history += '</table>';
-				setInnerHTML( 'currentSelection', history );
-				showById('historyPlanLink');
-				
-				disable('completeBtn');
-				disable('completeInBelowBtn');
-				
-				jQuery('#programStageIdTR').removeAttr('class');
-				jQuery('#dueDateTR').removeAttr('class');
-			}
-			
+				hideById('programStageIdTR');
+				hideById('programInstanceFlowDiv');
+				loadDataEntry( json.programStageInstances[0].id );
+			}
 	});
 }
 
-function showHistoryPlan()
-{
-	$('#currentSelection' ).dialog({
-        title: i18n_program_stages_history_plan,
-		maximize: true, 
-		closable: true,
-		modal:false,
-		overlay:{background:'#000000', opacity:0.1},
-		width: 400,
-        height: 400
-    });
-}
-
 //--------------------------------------------------------------------------------------------
 // Load data-entry-form
 //--------------------------------------------------------------------------------------------
 
-function loadDataEntry()
+function loadDataEntry( programStageInstanceId )
 {
 	setInnerHTML('dataEntryFormDiv', '');
 	showById('dataEntryFormDiv');
 	setFieldValue( 'dueDate', '' );
 	setFieldValue( 'executionDate', '' );
 	disable('validationBtn');
+	disable('validationInBelowBtn');
 	disable('completeBtn');
 	disable('completeInBelowBtn');
 	disable('newEncounterBtn');
-		
-	if( getFieldValue('programStageId') == null
-		|| getFieldValue('programStageId') == 0 )
-	{
-		enable('newEncounterBtn');
-		return;
-	}
-	
-	showLoader();
-	
+	
+	jQuery(".stage-object-selected").removeClass('stage-object-selected');
+	var selectedProgramStageInstance = jQuery( '#' + prefixId + programStageInstanceId );
+	selectedProgramStageInstance.addClass('stage-object-selected');
+	setFieldValue( 'programStageId', selectedProgramStageInstance.attr('psid') );
+	
+	showLoader();	
 	$( '#dataEntryFormDiv' ).load( "dataentryform.action", 
 		{ 
-			programStageId:getFieldValue('programStageId')
+			programStageInstanceId: programStageInstanceId
 		},function( )
 		{
 			var executionDate = jQuery('#dataRecordingSelectDiv input[id=executionDate]').val();
@@ -128,8 +122,13 @@
 			var irregular = jQuery('#entryFormContainer input[id=irregular]').val();
 			showById('inputCriteriaDiv');
 			enable('validationBtn');
-			
-			if( executionDate != '' && completed == 'false' )
+			enable('validationInBelowBtn');
+			if(  executionDate == '' )
+			{
+				disable('validationBtn');
+				disable('validationInBelowBtn');
+			}
+			else if( executionDate != '' && completed == 'false' )
 			{
 				enable('completeBtn');
 				enable('completeInBelowBtn');
@@ -395,8 +394,13 @@
     this.save = function()
     {
 		var params  = 'dataElementId=' + dataElementId;
-			params += '&value=';
-			params += '&providedElsewhere=' + byId( providedElsewhereId ).checked;
+			params += '&programStageInstanceId=' + getFieldValue('programStageInstanceId');
+		
+		params += '&providedElsewhere=';
+		if( byId( providedElsewhereId ) != null )
+			params += byId( providedElsewhereId ).checked;
+		
+		params += '&value=';
 		if( value != '')
 			params += htmlEncode(value);
 		
@@ -533,6 +537,16 @@
 			   data: params,
 			   dataType: "xml",
 			   success: function(result){
+					var selectedProgramStageInstance = jQuery( '#' + prefixId + getFieldValue('programStageInstanceId') );
+					jQuery(".stage-object-selected").css('border-color', COLOR_LIGHTRED);
+					jQuery(".stage-object-selected").css('background-color', COLOR_LIGHT_LIGHTRED);
+					enable('completeBtn');
+					enable('completeInBelowBtn');
+					enable('validationBtn');
+					enable('validationInBelowBtn');
+					disable('newEncounterBtn');
+					setFieldValue( 'programStageId', selectedProgramStageInstance.attr('psid') );
+					
 					handleResponse (result);
 			   },
 			   error: function(request,status,errorThrown) {
@@ -550,8 +564,9 @@
             markValue( resultColor );
 			if( getFieldValue('programStageInstanceId' )=='' )
 			{
-				setFieldValue('programStageInstanceId',rootElement.firstChild.nodeValue);
-				loadDataEntry();
+				var programStageInstanceId = rootElement.firstChild.nodeValue;
+				setFieldValue('programStageInstanceId', programStageInstanceId);
+				loadDataEntry( getFieldValue('programStageId') );
 			}
 			else
 			{
@@ -631,8 +646,12 @@
 				},
 				function (data)
 				{
+					jQuery(".stage-object-selected").css('border-color', COLOR_GREEN);
+					jQuery(".stage-object-selected").css('background-color', COLOR_LIGHT_GREEN);
+
 					disable('completeBtn');
 					disable('completeInBelowBtn');
+					enable('newEncounterBtn');
 					var irregular = jQuery('#entryFormContainer [name=irregular]').val();
 					if( irregular == 'true' )
 					{
@@ -664,7 +683,6 @@
 					
 					enable('createEventBtn');
 					selection.enable();
-		
 					hideLoader();
 					hideById('contentDiv');
 				});
@@ -759,8 +777,36 @@
 	jQuery.postJSON( "registerIrregularEncounter.action",{ dueDate: dueDate }, 
 		function( json ) 
 		{   
+			var programStageInstanceId = json.message;
 			jQuery('#createNewEncounterDiv').dialog('close');
-			loadDataEntry();
+			enable('completeBtn');
+			enable('completeInBelowBtn');
+			disable('newEncounterBtn');
+			
+			var programStageName = jQuery(".stage-object-selected").attr('psname');
+			var flag = false;
+			jQuery("#programStageIdTR input[name='programStageBtn']").each(function(i,item){
+				var element = jQuery(item);
+				var dueDateInStage = element.attr('dueDate');
+				
+				if( dueDate < dueDateInStage && !flag)
+				{	
+					var elementId = prefixId + programStageInstanceId;
+					jQuery('<td><input name="programStageBtn" '
+						+ 'id="' + elementId + '" ' 
+						+ 'psid="' + programStageInstanceId + '" '
+						+ 'psname="' + programStageName + '" '
+						+ 'dueDate="' + dueDate + '" '
+						+ 'value="'+ programStageName + ' ' + dueDate + '" '
+						+ 'onclick="javascript:loadDataEntry(' + programStageInstanceId + ')" '
+						+ 'type="button" class="stage-object" '
+						+ '></td>'
+						+ '<td><img src="images/rightarrow.png"></td>')
+					.insertBefore(element.parent());
+					setEventColorStatus( elementId, 3 );
+					flag = true;
+				}
+			});
 		});
 }
 
@@ -830,3 +876,9 @@
 			input.focus();
 		});
 }
+
+/* function hexToR(h) {
+	return parseInt((cutHex(h)).substring(0,2),16) + 
+	parseInt((cutHex(h)).substring(2,4),16);
+	parseInt((cutHex(h)).substring(2,4),16);
+} */

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/multiDataEntry.js	2012-06-07 04:23:40 +0000
@@ -62,6 +62,11 @@
 }
 function viewPrgramStageRecords( programStageInstanceId ) 
 {
+	jQuery("#patientList input[name='programStageBtn']").each(function(i,item){
+		jQuery(item).removeClass('stage-object-selected');
+	});
+	jQuery( '#' + prefixStageId + programStageInstanceId ).addClass('stage-object-selected');
+	
 	$('#contentDataRecord').dialog('destroy').remove();
     $('<div id="contentDataRecord">' ).load("viewProgramStageRecords.action",
 		{

=== renamed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseProgramStages.vm' => 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseProgramStages.vm	2012-05-23 16:19:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstances.vm	2012-06-07 04:23:40 +0000
@@ -1,26 +1,13 @@
-#set( $size = $programStages.size() )
+#set( $size = $programStageInstances.size() )
 { 
-"programStages": [
-	#foreach( $programStage in $programStages )
+"programStageInstances": [
+	#foreach( $programStageInstance in $programStageInstances )
 	  {
-		"id":  ${programStage.id} ,
-		"name": "$!encoder.jsonEncode( ${programStage.name} )",
-		"irregular": "${programStage.irregular}",
-		"standardInterval": "$!programStage.standardInterval"
+		"id": "$programStageInstance.id",
+		"programStageId": "$programStageInstance.programStage.id",
+		"programStageName": "$programStageInstance.programStage.name",
+		"dueDate": "$format.formatDate( $programStageInstance.dueDate )",
+		"status": "$statusMap.get( $programStageInstance.id )"
 	  }#if( $velocityCount < $size ),#end
-	#end],
-	
-#set( $size = $programStages.size() )
-"programStageInstances": [
-	#foreach( $programStageInstance in $programInstance.programStageInstances )
-	  {
-		"name": "$programStageInstance.programStage.name",
-		"colorMap": "$colorMap.get( $programStageInstance.id )",
-		"infor": #if( $programStageInstance.completed )
-					"$format.formatDate( $programStageInstance.executionDate )"
-				#else
-					"$format.formatDate( $programStageInstance.dueDate )"
-				#end
-	  }#if( $velocityCount < $programInstance.programStageInstances.size() ),#end
 	#end]
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/report.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/report.vm	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/report.vm	2012-06-07 04:23:40 +0000
@@ -17,7 +17,11 @@
 							<img src='images/rightarrow.png'>
 						</td>
 						<td width='100px;'>
-							<input type='button' class='stage-object' style='border-color:$colorMap.get( $programStageInstance.id );' value='$programStageInstance.programStage.name $format.formatDate( $programStageInstance.dueDate )' onclick='javascript:viewRecords( $programStageInstance.id )'>
+							<input type='button' class='stage-object' id='ps_$programStageInstance.id' value='$programStageInstance.programStage.name $format.formatDate( $programStageInstance.dueDate )' onclick='javascript:viewRecords( $programStageInstance.id )'>
+							<script>	
+								var status = $statusMap.get( $programStageInstance.id );
+								setEventColorStatus( 'ps_' + $programStageInstance.id ,status);
+							</script>
 						</td>
                     #end
                 </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-06-05 08:55:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-06-07 04:23:40 +0000
@@ -58,11 +58,6 @@
 <div id='dataRecordingSelectDiv'></div>
 <div id='dataEntryFormDiv'></div>
 
-<div id='inputCriteriaDiv' class="page inputCriteria" style="display:none;width:480px;height:29px;">	
-	<input type="button" class='button' id="completeInBelowBtn" value="$i18n.getString('complete')" onClick="doComplete()" disabled="disabled">
-	<input type="button" class='button' id="validationBtn" value="$i18n.getString('run_validation')" onClick="javascript: runValidation();" >
-</div>
-
 #parse( "dhis-web-commons/loader/loader.vm" )
 
 <script type="text/javascript">
@@ -92,6 +87,7 @@
 	var i18n_create_new_encounter = '$encoder.jsEscape( $i18n.getString( "create_new_encounter" ) , "'")';
 	var i18n_yes = '$encoder.jsEscape( $i18n.getString( "yes" ) , "'")';
 	var i18n_no = '$encoder.jsEscape( $i18n.getString( "no" ) , "'")';
+	var i18n_events = '$encoder.jsEscape( $i18n.getString( "events" ) , "'")';
 	
 	selection.setListenerFunction( organisationUnitSelected );
 	

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/dataEntry.css'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/dataEntry.css	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/dataEntry.css	2012-06-07 04:23:40 +0000
@@ -81,12 +81,17 @@
 	padding-right:5px;
 }
 
-.criteria
+select.criteria
 {
 	width:350px;
-	padding-left:5px;
+	margin-right: 5px
 }
 
+input.criteria
+{
+	width:150px;
+	margin-right: 5px;
+}
 .inputWidth
 {
 	width:350px;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/patient.css'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/patient.css	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/patient.css	2012-06-07 04:23:40 +0000
@@ -75,15 +75,26 @@
 	border: 1px solid #3f5d8e;
 }
 
-
 .stage-object
 {
 	width: 100px;
 	height: 40px;
     white-space: normal;
 	border:2px solid; 
-	background-color:#ffffff;
 	cursor:pointer;
+	opacity: 0.75;
+}
+
+.stage-object:hover
+{
+	opacity: 1.0;
+}
+
+.stage-object-selected 
+{
+	width: 120px;
+	height: 50px;
+    opacity: 1.0;
 }
 
 .patient-object
@@ -96,4 +107,3 @@
 	background-color:#cccccc
 	cursor:pointer;
 }
-

=== modified 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	2012-06-05 08:47:35 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/style/report.css	2012-06-07 04:23:40 +0000
@@ -63,17 +63,22 @@
 	width: 100px;
 	height: 40px;
     white-space: normal;
-	border:2px solid; 
+	border:4px solid; 
 	background-color:#ffffff;
 	cursor:pointer;
 }
 
+.stage-object:hover
+{
+	background-color:#6699FF;
+}
+
 .patient-object
 {
 	width: 100px;
 	height: 40px;
     white-space: normal;
-	border:2px solid; 
+	border:4px solid; 
 	border-color:#bbbbbb;
 	background-color:#cccccc
 	cursor:pointer;