← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4142: Upgraded the format used for identifiers of input fields in data entry module ( Patient module ).

 

------------------------------------------------------------
revno: 4142
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-07-14 16:31:24 +0700
message:
  Upgraded the format used for identifiers of input fields in data entry module ( Patient module ).
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramDataEntryStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  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/program/DefaultProgramDataEntryService.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/caseentry/ProgramStageCustomDataEntryAction.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/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dataEntry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js


--
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/ProgramDataEntryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2011-05-30 04:34:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2011-07-14 09:31:24 +0000
@@ -30,6 +30,7 @@
 import java.util.Collection;
 import java.util.regex.Pattern;
 
+import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -42,16 +43,16 @@
 public interface ProgramDataEntryService
 {
     final Pattern INPUT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
-    final Pattern SELECT_PATTERN = Pattern.compile( "(<select.*?)[/]?</select>", Pattern.DOTALL );
-    final Pattern IDENTIFIER_PATTERN_TEXTBOX = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value\"" );
-    final Pattern IDENTIFIER_PATTERN_BOOLEAN = Pattern.compile( "value\\[(.*)\\].boolean:value\\[(.*)\\].boolean" );
-    final Pattern IDENTIFIER_PATTERN_COMBO = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].combo:value\\[([\\p{Digit}.]*)\\].combo\"" );
-    final Pattern IDENTIFIER_PATTERN_DATE = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].date:value\\[([\\p{Digit}.]*)\\].date\"" );
-
+    
+    final Pattern IDENTIFIER_PATTERN_TEXTBOX = Pattern.compile( "id=\"(\\d+)-(\\d+)-(\\d+)-val\"" );
+    final Pattern IDENTIFIER_PATTERN_OTHERS = Pattern.compile( "id=\"(\\d+)-(\\d+)-val\"" );
+    
     //--------------------------------------------------------------------------
     // ProgramDataEntryService
     //--------------------------------------------------------------------------
     
+    Collection<DataEntryForm> getProgramDataEntryForms();
+    
     String prepareDataEntryFormForEntry( String htmlCode, Collection<PatientDataValue> dataValues, String disabled,
         I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
         OrganisationUnit organisationUnit );

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java	2011-07-14 09:31:24 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004-2009, 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;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataentryform.DataEntryForm;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ ProgramDataEntryService.java May 26, 2011 3:56:03 PM $
+ * 
+ */
+public interface ProgramDataEntryStore
+{
+    Collection<DataEntryForm> get();
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java	2011-07-11 10:22:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java	2011-07-14 09:31:24 +0000
@@ -1,61 +1,196 @@
 package org.hisp.dhis.dataentryform;
 
+import java.util.Collection;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.program.ProgramDataEntryService;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
- * Upgrades the format of the input field identifiers from the legacy "value[12].value:value[34].value"
- * to the new "12-34-val"
+ * Upgrades the format of the input field identifiers from the legacy
+ * "value[12].value:value[34].value" to the new "12-34-val"
  */
 public class DataEntryFormUpgrader
     extends AbstractStartupRoutine
 {
     private static final Log log = LogFactory.getLog( DataEntryFormUpgrader.class );
-    
+
     private final static String ID_EXPRESSION = "id=\"value\\[(\\d+)\\]\\.value:value\\[(\\d+)\\]\\.value\"";
+
     private final static Pattern ID_PATTERN = Pattern.compile( ID_EXPRESSION );
-    
+
+    private final Pattern SELECT_PATTERN = Pattern.compile( "(<select.*?)[/]?</select>", Pattern.DOTALL );
+
+    private final Pattern ID_PROGRAM_ENTRY_TEXTBOX = Pattern
+        .compile( "id=\"value\\[(\\d+)\\].value:value\\[(\\d+)\\].value:value\\[(\\d+)\\].value\"" );
+
+    private final Pattern ID_PROGRAM_ENTRY_OPTION = Pattern
+        .compile( "id=\"value\\[(\\d+)\\].(combo|boolean){1}:value\\[(\\d+)\\].(combo|boolean){1}\"" );
+
+    private final Pattern ID_PROGRAM_ENTRY_DATE = Pattern
+        .compile( "id=\"value\\[(\\d+)\\].date:value\\[(\\d+)\\].date\"" );
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
     private DataEntryFormService dataEntryFormService;
 
     public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
     {
         this.dataEntryFormService = dataEntryFormService;
     }
-    
+
+    private ProgramDataEntryService programDataEntryService;
+
+    public void setProgramDataEntryService( ProgramDataEntryService programDataEntryService )
+    {
+        this.programDataEntryService = programDataEntryService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation method
+    // -------------------------------------------------------------------------
+
     @Transactional
     @Override
     public void execute()
     {
+        Collection<DataEntryForm> dataEntryForms = dataEntryFormService.getAllDataEntryForms();
+
+        Collection<DataEntryForm> programDataEntryForms = programDataEntryService.getProgramDataEntryForms();
+
+        dataEntryForms.removeAll( programDataEntryForms );
+
+        upgradeDataEntryForm( dataEntryForms );
+
+        upgradeProgramDataEntryForm( programDataEntryForms );
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private void upgradeDataEntryForm( Collection<DataEntryForm> dataEntryForms )
+    {
         int i = 0;
-        
+
         for ( DataEntryForm form : dataEntryFormService.getAllDataEntryForms() )
         {
-            Matcher matcher = ID_PATTERN.matcher( form.getHtmlCode() ); 
+            Matcher matcher = ID_PATTERN.matcher( form.getHtmlCode() );
 
             StringBuffer out = new StringBuffer();
-            
+
             while ( matcher.find() )
             {
-                String upgradedId = "id=\"" + matcher.group(1) + "-" + matcher.group(2) + "-val\"";
-                
+                String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-val\"";
+
                 matcher.appendReplacement( out, upgradedId );
-                
+
                 i++;
             }
 
             matcher.appendTail( out );
-                        
+
             form.setHtmlCode( out.toString() );
             form.setHtmlCode( form.getHtmlCode().replaceAll( "view=\"@@deshortname@@\"", "" ) );
-            
+
             dataEntryFormService.updateDataEntryForm( form );
         }
-        
+
         log.info( "Upgraded custom data entry form identifiers: " + i );
     }
-}
+
+    private void upgradeProgramDataEntryForm( Collection<DataEntryForm> programDataEntryForms )
+    {
+        int i = 0;
+
+        for ( DataEntryForm programDataEntryForm : programDataEntryForms )
+        {
+            String customForm = upgradeProgramDataEntryFormForTextBox( programDataEntryForm.getHtmlCode() );
+
+            customForm = upgradeProgramDataEntryFormForDate( customForm );
+
+            customForm = upgradeProgramDataEntryFormForOption( customForm );
+            
+            programDataEntryForm.setHtmlCode( customForm );
+
+            dataEntryFormService.updateDataEntryForm( programDataEntryForm );
+
+            i++;
+        }
+
+        log.info( "Upgraded custom case entry form identifiers: " + i );
+    }
+
+    private String upgradeProgramDataEntryFormForTextBox( String htmlCode )
+    {
+        int i = 0;
+
+        Matcher matcher = ID_PROGRAM_ENTRY_TEXTBOX.matcher( htmlCode );
+
+        StringBuffer out = new StringBuffer();
+
+        while ( matcher.find() )
+        {
+            String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-" + matcher.group( 3 )
+                + "-val\"";
+
+            matcher.appendReplacement( out, upgradedId );
+
+            i++;
+        }
+
+        matcher.appendTail( out );
+
+        return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" );
+    }
+
+    private String upgradeProgramDataEntryFormForOption( String htmlCode )
+    {
+        StringBuffer out = new StringBuffer();
+        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
+        
+        while ( inputMatcher.find() )
+        {
+            String inputHtml = inputMatcher.group();
+
+            Matcher matcher = ID_PROGRAM_ENTRY_OPTION.matcher( inputHtml );
+
+            if ( matcher.find() )
+            {
+                String upgradedId = matcher.group( 1 ) + "-" + matcher.group( 3 ) + "-val";
+                
+                inputHtml = "<input name=\"entryselect\" id=\"" + upgradedId + "\" >";
+            }
+
+            inputMatcher.appendReplacement( out, inputHtml );
+        }
+
+        inputMatcher.appendTail( out );
+
+        return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" );
+    }
+
+    private String upgradeProgramDataEntryFormForDate( String htmlCode )
+    {
+        Matcher matcher = ID_PROGRAM_ENTRY_DATE.matcher( htmlCode );
+
+        StringBuffer out = new StringBuffer();
+
+        while ( matcher.find() )
+        {
+            String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-val\" ";
+
+            matcher.appendReplacement( out, upgradedId );
+        }
+
+        matcher.appendTail( out );
+
+        return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" );
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-07-11 10:22:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-07-14 09:31:24 +0000
@@ -997,6 +997,7 @@
   
   <bean id="org.hisp.dhis.dataentryform.DataEntryFormUpgrader" class="org.hisp.dhis.dataentryform.DataEntryFormUpgrader">
 	<property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService"/>
+	<property name="programDataEntryService" ref="org.hisp.dhis.program.ProgramDataEntryService"/>
     <property name="runlevel" value="5" />
     <property name="skipInTests" value="true" />
   </bean>

=== 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	2011-07-13 02:28:39 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-07-14 09:31:24 +0000
@@ -439,7 +439,7 @@
                 {
                     condition = getConditionForProgramProperty( orgunitId, startDate, endDate ) + info[1];
                 }
-				else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) )
+                else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) )
                 {
                     condition = getConditionForProgram( info[1], orgunitId, startDate, endDate );
                 }

=== 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	2011-07-06 08:04:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2011-07-14 09:31:24 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
@@ -67,6 +68,13 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    private ProgramDataEntryStore programDataEntryStore;
+
+    public void setProgramDataEntryStore( ProgramDataEntryStore programDataEntryStore )
+    {
+        this.programDataEntryStore = programDataEntryStore;
+    }
+
     private PatientDataValueService patientDataValueService;
 
     public void setPatientDataValueService( PatientDataValueService patientDataValueService )
@@ -114,6 +122,12 @@
     // -------------------------------------------------------------------------
 
     @Override
+    public Collection<DataEntryForm> getProgramDataEntryForms()
+    {
+        return programDataEntryStore.get();
+    }
+
+    @Override
     public String prepareDataEntryFormForEntry( String htmlCode, Collection<PatientDataValue> dataValues,
         String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
         OrganisationUnit organisationUnit )
@@ -125,13 +139,13 @@
         result = populateCustomDataEntryForTextBox( htmlCode, dataValues, disabled, i18n, programStage,
             programStageInstance, organisationUnit, mapDataValue );
 
+        result = populateCustomDataEntryForDate( result, dataValues, disabled, i18n, programStage,
+            programStageInstance, organisationUnit, mapDataValue );
+
         result = populateCustomDataEntryForBoolean( result, dataValues, disabled, i18n, programStage,
             programStageInstance, organisationUnit, mapDataValue );
 
-        result = populateCustomDataEntryForMutiDimentionalString( result, dataValues, disabled, i18n, programStage,
-            programStageInstance, organisationUnit, mapDataValue );
-
-        result = populateCustomDataEntryForDate( result, dataValues, disabled, i18n, programStage,
+        result = populateCustomDataEntryForCombo( result, dataValues, disabled, i18n, programStage,
             programStageInstance, organisationUnit, mapDataValue );
 
         result = populateI18nStrings( result, i18n );
@@ -143,12 +157,10 @@
     {
         String result = populateCustomDataEntryForTextBox( htmlCode );
 
-        result = populateCustomDataEntryForCombo( result );
-
-        result = populateCustomDataEntryForBoolean( result );
-
         result = populateCustomDataEntryForDate( result );
 
+        result = populateCustomDataEntryForOption( result );
+
         return result;
     }
 
@@ -207,139 +219,77 @@
                 inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
                     : inputHTML + " " + displayValue;
 
-                String displayTitle = (dataElement == null || optionCombo == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\""
-                    : "title=\"-- ID:" + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - "
-                        + optionComboId + " - " + optionCombo.getName() + " - Type:" + dataElement.getType() + "\"";
-                inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
-                    : inputHTML + " " + displayTitle;
-
-                inputHTML = inputHTML + ">";
-                
-                inputMatcher.appendReplacement( sb, inputHTML );
-            }
-        }
-
-        inputMatcher.appendTail( sb );
-
-        return (sb.toString().isEmpty()) ? htmlCode : sb.toString();
-    }
-
-    private String populateCustomDataEntryForBoolean( String htmlCode )
-    {
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
-
-        StringBuffer sb = new StringBuffer();
-
-        // ---------------------------------------------------------------------
-        // Pattern to match data elements in the HTML code
-        // ---------------------------------------------------------------------
-
-        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
-
-        // ---------------------------------------------------------------------
-        // Iterate through all matching data element fields
-        // ---------------------------------------------------------------------
-
-        while ( inputMatcher.find() )
-        {
-            String inputHTML = inputMatcher.group();
-            inputHTML = inputHTML.replace( ">", "" );
-            
-            // -----------------------------------------------------------------
-            // Get HTML input field code
-            // -----------------------------------------------------------------
-
-            String dataElementCode = inputMatcher.group( 1 );
-
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode );
-
-            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
-            {
-                // -------------------------------------------------------------
-                // Get data element ID of data element
-                // -------------------------------------------------------------
-
-                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() + " ]\"";
-                inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
-                    : inputHTML + " " + displayValue;
-
-                String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"-- ID:"
-                    + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - Type:"
-                    + dataElement.getType() + "\"";
-                inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
-                    : inputHTML + " " + displayTitle;
-
-                inputHTML = inputHTML + ">";
-                
-                inputMatcher.appendReplacement( sb, inputHTML );
-            }
-        }
-
-        inputMatcher.appendTail( sb );
-
-        return (sb.toString().isEmpty()) ? htmlCode : sb.toString();
-    }
-
-    private String populateCustomDataEntryForCombo( String htmlCode )
-    {
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
-
-        StringBuffer sb = new StringBuffer();
-
-        // ---------------------------------------------------------------------
-        // Pattern to match data elements in the HTML code
-        // ---------------------------------------------------------------------
-
-        Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode );
-
-        // ---------------------------------------------------------------------
-        // Iterate through all matching data element fields
-        // ---------------------------------------------------------------------
-
-        while ( inputMatcher.find() )
-        {
-            String inputHTML = inputMatcher.group();
-            
-            inputHTML = inputHTML.replace( ">", "" );
-            
-            // -----------------------------------------------------------------
-            // Get HTML input field code
-            // -----------------------------------------------------------------
-
-            String dataElementCode = inputMatcher.group( 1 );
-
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_COMBO.matcher( dataElementCode );
-
-            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
-            {
-                // -------------------------------------------------------------
-                // Get data element ID of data element
-                // -------------------------------------------------------------
-
-                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() + " ]\"";
-                inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
-                    : inputHTML + " " + displayValue;
-
-                String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"-- ID:"
-                    + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - Type:"
-                    + dataElement.getType() + "\"";
-                inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
-                    : inputHTML + " " + displayTitle;
-
-                inputHTML = inputHTML + ">";
-                
+                String displayTitle = (dataElement == null || optionCombo == null) ? "title=\""
+                    + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"" + dataElement.getId() + "."
+                    + dataElement.getName() + "-" + optionComboId + "." + optionCombo.getName() + "-"
+                    + dataElement.getDetailedNumberType() + "\" ";
+                inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
+                    : inputHTML + " " + displayTitle;
+
+                inputHTML = inputHTML + ">";
+
+                inputMatcher.appendReplacement( sb, inputHTML );
+            }
+        }
+
+        inputMatcher.appendTail( sb );
+
+        return (sb.toString().isEmpty()) ? htmlCode : sb.toString();
+    }
+
+    private String populateCustomDataEntryForOption( String htmlCode )
+    {
+        // ---------------------------------------------------------------------
+        // Metadata code to add to HTML before outputting
+        // ---------------------------------------------------------------------
+
+        StringBuffer sb = new StringBuffer();
+
+        // ---------------------------------------------------------------------
+        // Pattern to match data elements in the HTML code
+        // ---------------------------------------------------------------------
+
+        Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
+
+        // ---------------------------------------------------------------------
+        // Iterate through all matching data element fields
+        // ---------------------------------------------------------------------
+
+        while ( inputMatcher.find() )
+        {
+            String inputHTML = inputMatcher.group();
+            inputHTML = inputHTML.replace( ">", "" );
+
+            // -----------------------------------------------------------------
+            // Get HTML input field code
+            // -----------------------------------------------------------------
+
+            String dataElementCode = inputMatcher.group( 1 );
+
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
+
+            if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+            {
+                // -------------------------------------------------------------
+                // Get data element ID of data element
+                // -------------------------------------------------------------
+
+                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() + " ]\"";
+                inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
+                    : inputHTML + " " + displayValue;
+
+                String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\""
+                    : "title=\"" + dataElement.getId() + "." + dataElement.getName() + "-"
+                        + dataElement.getDetailedNumberType() + "\" ";
+                inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
+                    : inputHTML + " " + displayTitle;
+
+                inputHTML = inputHTML + ">";
+
                 inputMatcher.appendReplacement( sb, inputHTML );
             }
         }
@@ -370,16 +320,16 @@
         while ( inputMatcher.find() )
         {
             String inputHTML = inputMatcher.group();
-            
+
             inputHTML = inputHTML.replace( ">", "" );
-            
+
             // -----------------------------------------------------------------
             // Get HTML input field code
             // -----------------------------------------------------------------
 
             String dataElementCode = inputMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_DATE.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
@@ -395,14 +345,14 @@
                 inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue )
                     : inputHTML + " " + displayValue;
 
-                String displayTitle = (dataElement == null ) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\""
-                    : "title=\"-- ID:" + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - "
-                       + " - Type:" + dataElement.getType() + "\"";
+                String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\""
+                    : "title=\"" + dataElement.getId() + "." + dataElement.getName() + "-"
+                        + dataElement.getDetailedNumberType() + "\" ";
                 inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle )
                     : inputHTML + " " + displayTitle;
-                
+
                 inputHTML = inputHTML + ">";
-                
+
                 inputMatcher.appendReplacement( sb, inputHTML );
             }
         }
@@ -421,11 +371,7 @@
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForInputs = " $DISABLED onchange=\"saveValueCustom( this )\" data=\"{compulsory:$COMPULSORY, optionComboId:$OPTIONCOMBOID, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\"  onkeypress=\"return keyPress(event, this)\"   ";
-
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
+        final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID, $OPTIONCOMBOID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
 
         StringBuffer sb = new StringBuffer();
 
@@ -493,13 +439,13 @@
                 {
                     continue;
                 }
-                
+
                 if ( !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() )
                     && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) )
                 {
                     continue;
                 }
-                
+
                 // -------------------------------------------------------------
                 // Find type of data element
                 // -------------------------------------------------------------
@@ -550,13 +496,25 @@
                 {
                     dataElementCode += "value=\"" + dataElementValue + "\"";
                 }
-
-                // -------------------------------------------------------------
-                // Remove placeholder view attribute from input field
-                // -------------------------------------------------------------
-
-                dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
-
+                
+                // -------------------------------------------------------------
+                // Insert title information - Data element id, name, type, min,
+                // max
+                // -------------------------------------------------------------
+                DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
+                
+                if ( dataElementCode.contains( "title=\"\"" ) )
+                {
+                    dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dataElement.getId()
+                        + "." + dataElement.getName() +"-" 
+                        + optionComboId + optionCombo.getName() + "-" + dataElementType + "\" " );
+                }
+                else
+                {
+                    dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName()
+                        +"-" + optionComboId + optionCombo.getName() + "-" + dataElementType + "\" ";
+                }
+                
                 // -------------------------------------------------------------
                 // Append Javascript code and meta data (type/min/max) for
                 // persisting to output code, and insert value and type for
@@ -568,7 +526,7 @@
                 appendCode += jsCodeForInputs;
 
                 appendCode += " />";
-
+                
                 // -----------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable
@@ -583,7 +541,6 @@
                     // -----------------------------------------------------------
 
                     appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue );
-
                 }
                 else
                 {
@@ -637,21 +594,15 @@
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForBoolean = " name=\"entryselect\" data=\"{compulsory:$COMPULSORY, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\" $DISABLED onchange=\"saveChoiceCustom( $PROGRAMSTAGEID, $DATAELEMENTID,this)\"";
-
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
-
-        final String metaDataCode = "<span id=\"value[$DATAELEMENTID].name\" style=\"display:none\">$DATAELEMENTNAME</span>"
-            + "<span id=\"value[$DATAELEMENTID].type\" style=\"display:none\">$DATAELEMENTTYPE</span>";
+        final String jsCodeForBoolean = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY}\" onchange=\"saveOpt( $DATAELEMENTID )\" style=\"  text-align:center;\" ";
+
         StringBuffer sb = new StringBuffer();
 
         // ---------------------------------------------------------------------
         // Pattern to match data elements in the HTML code
         // ---------------------------------------------------------------------
 
-        Matcher dataElementMatcher = SELECT_PATTERN.matcher( dataEntryFormCode );
+        Matcher dataElementMatcher = INPUT_PATTERN.matcher( dataEntryFormCode );
 
         // ---------------------------------------------------------------------
         // Iterate through all matching data element fields
@@ -667,7 +618,7 @@
 
             String compulsory = "null";
             String dataElementCode = dataElementMatcher.group( 1 );
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
                 // -------------------------------------------------------------
@@ -716,7 +667,7 @@
                 // Find type of data element
                 // -------------------------------------------------------------
 
-                String dataElementType = dataElement.getType();
+                String dataElementType = dataElement.getDetailedNumberType();
 
                 // -------------------------------------------------------------
                 // Find existing value of data element in data set
@@ -754,16 +705,35 @@
                     }
                 }
 
-                String appendCode = dataElementCode;
+                String appendCode = dataElementCode.replaceFirst( "input", "select" );
                 appendCode = appendCode.replace( "name=\"entryselect\"", jsCodeForBoolean );
+               
+                // -------------------------------------------------------------
+                // Add title
+                // -------------------------------------------------------------
 
+                if ( dataElementCode.contains( "title=\"\"" ) )
+                {
+                    appendCode = appendCode.replace( "title=\"\"", "title=\"" + dataElement.getId()
+                        + "." + dataElement.getName() + "-" + dataElementType + "\" " );
+                }
+                else
+                {
+                    appendCode += "title=\"" + dataElement.getId() + "." + dataElement.getName()
+                        + "-" + dataElementType + "\" ";
+                }
+                
+                appendCode += ">";
+                appendCode += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
+                appendCode += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
+                appendCode += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
+                
                 // -------------------------------------------------------------
                 // Insert value of data element in output code
                 // -------------------------------------------------------------
 
                 if ( patientDataValue != null )
                 {
-
                     if ( dataElementValue.equalsIgnoreCase( "true" ) )
                     {
                         appendCode = appendCode.replace( "<option value=\"true\">", "<option value=\""
@@ -775,41 +745,10 @@
                         appendCode = appendCode.replace( "<option value=\"false\">", "<option value=\""
                             + i18n.getString( "false" ) + "\" selected>" );
                     }
-
                 }
-
+                
                 appendCode += "</select>";
 
-                // -------------------------------------------------------------
-                // Remove placeholder view attribute from input field
-                // -------------------------------------------------------------
-
-                dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
-
-                // -------------------------------------------------------------
-                // Insert title information - Data element id, name, type, min,
-                // max
-                // -------------------------------------------------------------
-
-                if ( dataElementCode.contains( "title=\"\"" ) )
-                {
-                    dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- ID:" + dataElement.getId()
-                        + " Name:" + dataElement.getShortName() + " Type:" + dataElement.getType() + "\"" );
-                }
-                else
-                {
-                    dataElementCode += "title=\"-- ID:" + dataElement.getId() + " Name:" + dataElement.getShortName()
-                        + " Type:" + dataElement.getType() + "\"";
-                }
-
-                // -------------------------------------------------------------
-                // Append Javascript code and meta data (type/min/max) for
-                // persisting to output code, and insert value and type for
-                // fields
-                // -------------------------------------------------------------
-
-                appendCode += metaDataCode;
-
                 // -----------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable
@@ -826,6 +765,7 @@
                     // -----------------------------------------------------------
                     // Add ProvidedByOtherFacility checkbox
                     // -----------------------------------------------------------
+                    
                     appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue );
                 }
 
@@ -870,7 +810,7 @@
         return sb.toString();
     }
 
-    private String populateCustomDataEntryForMutiDimentionalString( String dataEntryFormCode,
+    private String populateCustomDataEntryForCombo( String dataEntryFormCode,
         Collection<PatientDataValue> dataValues, String disabled, I18n i18n, ProgramStage programStage,
         ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit,
         Map<Integer, Collection<PatientDataValue>> mapDataValue )
@@ -880,21 +820,15 @@
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForCombo = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\" onchange=\"saveChoiceCustom( $PROGRAMSTAGEID, $DATAELEMENTID,this)\"";
-
-        // ---------------------------------------------------------------------
-        // Metadata code to add to HTML before outputting
-        // ---------------------------------------------------------------------
-
-        final String metaDataCode = "<span id=\"value[$DATAELEMENTID].name\" style=\"display:none\">$DATAELEMENTNAME</span>"
-            + "<span id=\"value[$DATAELEMENTID].type\" style=\"display:none\">$DATAELEMENTTYPE</span>";
+        final String jsCodeForCombo = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY}\" onchange=\"saveOpt( $DATAELEMENTID )\"";
+
         StringBuffer sb = new StringBuffer();
 
         // ---------------------------------------------------------------------
         // Pattern to match data elements in the HTML code
         // ---------------------------------------------------------------------
 
-        Matcher dataElementMatcher = SELECT_PATTERN.matcher( dataEntryFormCode );
+        Matcher dataElementMatcher = INPUT_PATTERN.matcher( dataEntryFormCode );
 
         // ---------------------------------------------------------------------
         // Iterate through all matching data element fields
@@ -910,16 +844,16 @@
 
             String dataElementCode = dataElementMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_COMBO.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
 
             String compulsory = "null";
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
-
                 // -------------------------------------------------------------
                 // Get data element ID of data element
                 // -------------------------------------------------------------
+                
                 int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
                 int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
 
@@ -992,28 +926,28 @@
                     dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue;
                 }
 
-                String appendCode = dataElementCode;
+                String appendCode = dataElementCode.replaceFirst( "input", "select" );;
                 appendCode = appendCode.replace( "name=\"entryselect\"", jsCodeForCombo );
 
+                appendCode += ">";
+                appendCode += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
+                for( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+                {
+                    appendCode += "<option value=\"" + optionCombo.getId() + "\">" + optionCombo.getName() + "</option>";
+                }
+                
                 // -------------------------------------------------------------
                 // Insert value of data element in output code
                 // -------------------------------------------------------------
 
                 if ( patientDataValue != null )
                 {
-                    appendCode = appendCode.replace( "id=\"combo[" + patientDataValue.getOptionCombo().getId()
-                        + "].combo\"", "id=\"combo[" + patientDataValue.getOptionCombo().getId()
-                        + "].combo\" selected=\"selected\"" );
+                    appendCode = appendCode.replace(  "<option value=\"" + patientDataValue.getOptionCombo().getId() + "\">",
+                        "<option value=\"" + patientDataValue.getOptionCombo().getId() + "\" selected=\"selected\">" );
                 }
 
                 appendCode += "</select>";
-
-                // -------------------------------------------------------------
-                // Remove placeholder view attribute from input field
-                // -------------------------------------------------------------
-
-                dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
-
+                
                 // -------------------------------------------------------------
                 // Insert title information - Data element id, name, type, min,
                 // max
@@ -1021,23 +955,15 @@
 
                 if ( dataElementCode.contains( "title=\"\"" ) )
                 {
-                    dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- ID:" + dataElement.getId()
-                        + " Name:" + dataElement.getShortName() + " Type:" + dataElement.getType() + "\"" );
+                    dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dataElement.getId()
+                        + "." + dataElement.getName() + " (" + dataElementType + ")\" " );
                 }
                 else
                 {
-                    dataElementCode += "title=\"-- ID:" + dataElement.getId() + " Name:" + dataElement.getShortName()
-                        + " Type:" + dataElement.getType() + "\"";
+                    dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName()
+                        + " (" + dataElementType + ")\" ";
                 }
 
-                // -------------------------------------------------------------
-                // Append Javascript code and meta data (type/min/max) for
-                // persisting to output code, and insert value and type for
-                // fields
-                // -------------------------------------------------------------
-
-                appendCode += metaDataCode;
-
                 // -----------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable
@@ -1100,23 +1026,20 @@
         String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
         OrganisationUnit organisationUnit, Map<Integer, Collection<PatientDataValue>> mapDataValue )
     {
-
         // ---------------------------------------------------------------------
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForDate = " name=\"entryfield\" $DISABLED onchange=\"saveDateCustom( this )\" data=\"{compulsory:$COMPULSORY, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\"";
+        final String jsCodeForDate = " name=\"entryfield\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME'}\" onchange=\"saveDate( $DATAELEMENTID )\" ";
 
         // ---------------------------------------------------------------------
         // Metadata code to add to HTML before outputting
         // ---------------------------------------------------------------------
 
         final String jQueryCalendar = "<script> "
-            + "datePicker(\"value\\\\\\\\[$PROGRAMSTAGEID\\\\\\\\]\\\\\\\\.date\\\\\\\\:value\\\\\\\\[$DATAELEMENTID\\\\\\\\]\\\\\\\\.date\", false)"
+            + "datePicker(\"$PROGRAMSTAGEID-$DATAELEMENTID-val\", false)"
             + ";</script>";
 
-        final String metaDataCode = "<span id=\"value[$DATAELEMENTID].name\" style=\"display:none\">$DATAELEMENTNAME</span>"
-            + "<span id=\"value[$DATAELEMENTID].type\" style=\"display:none\">$DATAELEMENTTYPE</span>";
         StringBuffer sb = new StringBuffer();
 
         // ---------------------------------------------------------------------
@@ -1145,7 +1068,7 @@
             String compulsory = "null";
             String dataElementCode = dataElementMatcher.group( 1 );
 
-            Matcher identifierMatcher = IDENTIFIER_PATTERN_DATE.matcher( dataElementCode );
+            Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
@@ -1240,11 +1163,21 @@
                 }
 
                 // -------------------------------------------------------------
-                // Remove placeholder view attribute from input field
+                // Insert title information - Data element id, name, type, min,
+                // max
                 // -------------------------------------------------------------
 
-                dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
-
+                if ( dataElementCode.contains( "title=\"\"" ) )
+                {
+                    dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dataElement.getId()
+                        + "." + dataElement.getName() + " (" + dataElementType + ")\" " );
+                }
+                else
+                {
+                    dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName()
+                        + " (" + dataElementType + ")\" ";
+                }
+                
                 // -------------------------------------------------------------
                 // Append Javascript code and meta data (type/min/max) for
                 // persisting to output code, and insert value and type for
@@ -1254,8 +1187,6 @@
                 String appendCode = dataElementCode + "/>";
                 appendCode = appendCode.replace( "name=\"entryfield\"", jsCodeForDate );
 
-                appendCode += metaDataCode;
-
                 // -------------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable
@@ -1391,7 +1322,7 @@
         {
             appendCode += " checked=\"checked\" ";
         }
-        appendCode += "onChange=\"updateProvidingFacilityCustom( $PROGRAMSTAGEID, $DATAELEMENTID, this )\"  >";
+        appendCode += "onChange=\"updateProvidingFacility( $DATAELEMENTID, this )\"  >";
 
         return appendCode;
 

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramDataEntryStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramDataEntryStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramDataEntryStore.java	2011-07-14 09:31:24 +0000
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2004-2009, 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.hibernate;
+
+import java.util.Collection;
+
+import org.hibernate.SessionFactory;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.program.ProgramDataEntryStore;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ HibernateProgramDataEntryStore.java Jul 12, 2011 11:00:04 AM $
+ * 
+ */
+public class HibernateProgramDataEntryStore
+    implements ProgramDataEntryStore
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    protected SessionFactory sessionFactory;
+
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
+        this.sessionFactory = sessionFactory;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation method
+    // -------------------------------------------------------------------------
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Collection<DataEntryForm> get()
+    {
+        String hql = "select DISTINCT( p.dataEntryForm ) from ProgramStage p";
+
+        return sessionFactory.getCurrentSession().createQuery( hql ).list();
+    }
+
+}

=== 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	2011-07-08 05:52:59 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-07-14 09:31:24 +0000
@@ -137,6 +137,10 @@
 		<property name="clazz" value="org.hisp.dhis.patient.PatientMobileSetting"/>
 		<property name="sessionFactory" ref="sessionFactory"/>
 	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramDataEntryStore" class="org.hisp.dhis.program.hibernate.HibernateProgramDataEntryStore">
+		<property name="sessionFactory" ref="sessionFactory"/>
+	</bean>
    
 	<!-- Service definitions -->
 	
@@ -156,6 +160,8 @@
 			ref="org.hisp.dhis.program.ProgramStageDataElementService" />
 		<property name="categoryService"
 			ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+		<property name="programDataEntryStore"
+			ref="org.hisp.dhis.program.ProgramDataEntryStore" />
 	</bean>
 	
 	<bean id="org.hisp.dhis.activityplan.ActivityPlanService"

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageCustomDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageCustomDataEntryAction.java	2011-07-08 08:34:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ProgramStageCustomDataEntryAction.java	2011-07-14 09:31:24 +0000
@@ -32,7 +32,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.hisp.dhis.caseentry.screen.DataEntryScreenManager;
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -45,6 +44,7 @@
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramDataEntryService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageInstance;
@@ -52,7 +52,8 @@
 
 import com.opensymphony.xwork2.Action;
 
-public class ProgramStageCustomDataEntryAction implements Action
+public class ProgramStageCustomDataEntryAction
+    implements Action
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -86,11 +87,11 @@
         this.selectedStateManager = selectedStateManager;
     }
 
-    private DataEntryScreenManager dataEntryScreenManager;
+    private ProgramDataEntryService programDataEntryService;
 
-    public void setDataEntryScreenManager( DataEntryScreenManager dataEntryScreenManager )
+    public void setProgramDataEntryService( ProgramDataEntryService programDataEntryService )
     {
-        this.dataEntryScreenManager = dataEntryScreenManager;
+        this.programDataEntryService = programDataEntryService;
     }
 
     // -------------------------------------------------------------------------
@@ -220,20 +221,21 @@
     {
         this.useDefaultForm = useDefaultForm;
     }
-    
+
     public ProgramStageInstance programStageInstance;
-    
+
     public int getProgramStageInstanceId()
     {
-           return programStageInstance.getId();
+        return programStageInstance.getId();
     }
-    
+
     private Collection<ProgramStageDataElement> programStageDataElements;
 
     public Collection<ProgramStageDataElement> getProgramStageDataElements()
     {
         return programStageDataElements;
     }
+
     // -------------------------------------------------------------------------
     // Implementation Action
     // -------------------------------------------------------------------------
@@ -242,27 +244,27 @@
         throws Exception
     {
         // ---------------------------------------------------------------------
-        // Get Orgunit & Program, ProgramStage 
+        // Get Orgunit & Program, ProgramStage
         // ---------------------------------------------------------------------
-        
+
         organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
 
         programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId );
-        
+
         programStage = programStageInstance.getProgramStage();
-        
+
         programStageDataElements = programStage.getProgramStageDataElements();
-        
+
         program = programStage.getProgram();
-        
+
         patient = programStageInstance.getProgramInstance().getPatient();
 
         patientIdentifier = patientIdentifierService.getPatientIdentifier( patient );
-        
+
         selectedStateManager.setSelectedProgramStageInstance( programStageInstance );
 
-        Collection<PatientDataValue> patientDataValues = patientDataValueService.getPatientDataValues(
-             programStageInstance );
+        Collection<PatientDataValue> patientDataValues = patientDataValueService
+            .getPatientDataValues( programStageInstance );
 
         DataEntryForm dataEntryForm = programStage.getDataEntryForm();
         if ( dataEntryForm == null )
@@ -272,16 +274,15 @@
 
         boolean cdeFormExists = (dataEntryForm != null);
 
-        String disabled = "";
         if ( cdeFormExists )
         {
             customDataEntryFormExists = true;
-            
-            customDataEntryFormCode = dataEntryScreenManager.populateCustomDataEntryScreenForMultiDimensional(
-                dataEntryForm.getHtmlCode(), patientDataValues, disabled,
-                i18n, programStage, programStageInstance, organisationUnit );
+
+            customDataEntryFormCode = programDataEntryService.prepareDataEntryFormForEntry(
+                dataEntryForm.getHtmlCode(), patientDataValues, "", i18n, programStage, programStageInstance,
+                organisationUnit );
         }
-        
+
         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	2011-07-08 08:34:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2011-07-14 09:31:24 +0000
@@ -151,7 +151,7 @@
 
   <bean id="org.hisp.dhis.caseentry.action.caseentry.ProgramStageCustomDataEntryAction" class="org.hisp.dhis.caseentry.action.caseentry.ProgramStageCustomDataEntryAction"
     scope="prototype">
-    <property name="dataEntryScreenManager" ref="org.hisp.dhis.caseentry.screen.DataEntryScreenManager" />
+    <property name="programDataEntryService" ref="org.hisp.dhis.program.ProgramDataEntryService" />
     <property name="selectedStateManager" ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
     <property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
     <property name="patientIdentifierService" ref="org.hisp.dhis.patient.PatientIdentifierService" />

=== 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	2011-07-08 07:22:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2011-07-14 09:31:24 +0000
@@ -84,42 +84,47 @@
 					##type        
 					<td style="display:none"><span id="value[$programStageDataElement.dataElement.id].type" style="display:none">$encoder.htmlEncode( $programStageDataElement.dataElement.type )</span></td>       
 					##entry        
-					<td>        
+					<td>   
+						#set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val' )
 						#if( $programStageDataElement.dataElement.type == "bool" )
-							<select name="entryselect" #if($programStageInstance.completed) disabled="disabled" #end data="{compulsory: $programStageDataElement.compulsory }" id="value[$programStageDataElement.dataElement.id].boolean" onchange="saveChoice( $programStageDataElement.dataElement.id, this )"  tabindex="$tabIndex">              
+							<select name="entryselect" #if($programStageInstance.completed) disabled="disabled" #end data="{compulsory: $programStageDataElement.compulsory }" id="$id" onchange="saveOpt( $programStageDataElement.dataElement.id )"  tabindex="$tabIndex">              
 								<option value="">[$i18n.getString( "select_value" )]</option>
 								<option value="true" #if( $patientDataValue.value == "true" ) selected="selected" #end>$i18n.getString( "yes" )</option>
 								<option value="false" #if( $patientDataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
 							</select>                              
 						#elseif( $programStageDataElement.dataElement.type == "string" && $programStageDataElement.dataElement.isMultiDimensional() )
 							#set( $optionValues = $optionMap.get( $programStageDataElement.dataElement.id ) )
-							<select name="entryselect" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="value[$programStageDataElement.dataElement.id].value" onchange="saveChoice( $programStageDataElement.dataElement.id, this )" tabindex="$tabIndex">              
+							<select name="entryselect" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" onchange="saveOpt( $programStageDataElement.dataElement.id )" tabindex="$tabIndex">              
 								<option value="">[$i18n.getString( "no_value" )]</option>
 								#foreach( $optionValue in $optionValues )
 									<option value="$optionValue.id" #if( $patientDataValue.value == $optionValue.id ) selected="selected" #end>$encoder.htmlEncode( $optionValue.name )</option>
 								#end
 							</select>
 						#elseif( $programStageDataElement.dataElement.type == "date" )
-							<input type="text" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="value[$programStageDataElement.dataElement.id].date" name="entryfield" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveDateValue( $programStageDataElement.dataElement.id, '$encoder.jsEncode( $programStageDataElement.dataElement.name )' )" tabindex="$tabIndex" >
+							<input type="text" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" name="entryfield" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveDate( $programStageDataElement.dataElement.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
 							<script type="text/javascript">
-								datePicker('value\\[$programStageDataElement.dataElement.id\\]\\.date', false);
+								datePicker($programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val', false);
 							</script>                     
 						#else
-							<input name="entryfield" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="value[$programStageDataElement.dataElement.id].value" type="text" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveValue( $programStageDataElement.dataElement.id, '$encoder.jsEncode( $programStageDataElement.dataElement.name )' )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
+							#foreach( $optionCombo in $programStageDataElement.dataElement.categoryCombo.optionCombos )
+								#set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-' + $optionCombo.id + '-val' )
+								<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, $optionCombo.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
+							#end
 						#end
 					</td>   
 					##providedByAnotherFacility                
 					<td>   
+						#set( $id = $programStageDataElement.programStage.id + '_' + $programStageDataElement.dataElement.id + '_facility' )
 						#if ( $patientDataValue.value )        
 							#if( !$patientDataValue.providedByAnotherFacility )
 								$patientDataValue.organisationUnit.name
-								<input  name="providedByAnotherFacility" id="value[$programStageDataElement.dataElement.id].providedByAnotherFacility" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
+								<input  name="providedByAnotherFacility" id="$id" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
 							#else
 								$i18n.getString("other_facility")
-								<input  name="providedByAnotherFacility" id="value[$programStageDataElement.dataElement.id].providedByAnotherFacility" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
+								<input  name="providedByAnotherFacility" id="$id" type="hidden" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
 							#end
 						 #else
-							<input name="providedByAnotherFacility" id="value[$programStageDataElement.dataElement.id].providedByAnotherFacility" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
+							<input name="providedByAnotherFacility" id="$id" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )">
 						 #end                         
 					</td>    
 				</tr>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dataEntry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dataEntry.js	2011-07-08 07:22:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dataEntry.js	2011-07-14 09:31:24 +0000
@@ -25,6 +25,20 @@
 
 selection.setListenerFunction( organisationUnitSelected );
 
+function selectDefaultForm()
+{
+    if( byId('useDefaultForm').checked  )
+	{
+		hideById('customEntryScreenContainer');
+		showById('defaultEntryScreenContainer');
+	}
+	else
+	{
+		hideById('defaultEntryScreenContainer');
+		showById('customEntryScreenContainer');
+	}
+}
+
 //--------------------------------------------------------------------------------------------
 // Show search-form
 //--------------------------------------------------------------------------------------------
@@ -288,389 +302,23 @@
 }
 
 //------------------------------------------------------------------------------
-// Save Execution Date
-//------------------------------------------------------------------------------
-
-function saveExecutionDate( programStageInstanceId, programStageInstanceName )
-{
-    var field = document.getElementById( 'executionDate' );
-	
-    field.style.backgroundColor = '#ffffcc';
-	
-    var executionDateSaver = new ExecutionDateSaver( programStageInstanceId, field.value, '#ccffcc' );
-    executionDateSaver.save();
-	
-    if( !jQuery("#entryForm").is(":visible") )
-    {
-        toggleContentForReportDate(true);
-    }
-}
-
-//-----------------------------------------------------------------------------
-// Date Saver objects
-//-----------------------------------------------------------------------------
-
-function ExecutionDateSaver( programStageInstanceId_, executionDate_, resultColor_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ffcc00';
-	
-    var programStageInstanceId = programStageInstanceId_;
-    var executionDate = executionDate_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-        request.send( 'saveExecutionDate.action?executionDate=' + executionDate );
-    };
-
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-			showById('dataEntryFormDiv');
-			showById('entryForm');
-        }
-        else
-        {
-            if( executionDate != "")
-            {
-                markValue( ERROR );
-                window.alert( i18n_invalid_date );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-			hideById('dataEntryFormDiv');
-        }
-    }
-
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( color )
-    {
-   
-        var element = document.getElementById( 'executionDate' );
-           
-        element.style.backgroundColor = color;
-    }
-}
-
-//------------------------------------------------------------------------------
-//Save Execution Date
-//------------------------------------------------------------------------------
-
-function saveDateValue( dataElementId, dataElementName )
-{
-    var field = document.getElementById( 'value[' + dataElementId + '].date' );
-    var providedByAnotherFacility = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ).checked;
+//Save value
+//------------------------------------------------------------------------------
+
+function saveVal( dataElementId, optionComboId )
+{
+	var programStageId = byId('programStageId').value;
+	var fieldId = programStageId + '-' + dataElementId + '-' + optionComboId + '-val';
+	var data = jQuery( "#" + fieldId ).metadata({
+        type:'attr',
+        name:'data'
+    });
+	var field = byId( fieldId ); 
+	var dataElementName = data.deName; 
+    var type = data.deType;
+    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
  
-    var dateSaver = new DateSaver( dataElementId, field.value, providedByAnotherFacility, '#ccffcc' );
-    dateSaver.save();
-	
-}
-
-//-----------------------------------------------------------------------------
-//Date Saver objects
-//-----------------------------------------------------------------------------
-
-function DateSaver( dataElementId_, value_, providedByAnotherFacility_, resultColor_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ffcc00';
-	
-    var dataElementId = dataElementId_;
-    var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-		var params = 'dataElementId=' + dataElementId 
-			params +=  '&value=' + value 
-			params +=  '&providedByAnotherFacility=' + providedByAnotherFacility;
-			
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-		request.sendAsPost( params );
-        request.send( 'saveDateValue.action' );
-    };
-
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else if(code == 1)
-        {
-            if(value != "")
-            {
-                var validationElement = rootElement.getElementsByTagName( 'validations' )[0];
-                var dataelementList = rootElement.getElementsByTagName( 'validation' );
-                var message = '';
-                for ( var i = 0; i < dataelementList.length; i++ )
-                {
-                    message += "\n - " + dataelementList[i].firstChild.nodeValue;
-                }
-
-                markValue( ERROR );
-                window.alert( i18n_violate_validation + message);
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-		else if(code == 2)
-        {
-			markValue( ERROR );
-            window.alert( i18n_invalid_date + ":\n" + rootElement.getElementsByTagName( 'message' )[0].firstChild.nodeValue );
-		}
-        else
-        {
-            if(value != "")
-            {
-                markValue( ERROR );
-                window.alert( i18n_invalid_date );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-    }
-
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( color )
-    {
-        var element = document.getElementById( 'value[' + dataElementId + '].date' );
-        
-        element.style.backgroundColor = color;
-    }
-}
-
-function DateSaverCustom( programStageId, dataElementId_, value_, providedByAnotherFacility_, resultColor_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ffcc00';
-	
-    var dataElementId = dataElementId_;
-    var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-		var params = 'dataElementId=' + dataElementId 
-			params +=  '&value=' + value 
-			params +=  '&providedByAnotherFacility=' + providedByAnotherFacility;
-		
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-		request.sendAsPost( params );
-        request.send( 'saveDateValue.action');
-    };
-
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else
-        {
-            if(value != "")
-            {
-                markValue( ERROR );
-                window.alert( i18n_invalid_date );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-    }
-
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( color )
-    {
-        var element = document.getElementById( 'value[' + programStageId + '].date.value[' + dataElementId + '].date' );
-        
-        element.style.backgroundColor = color;
-    }
-}
-
-//------------------------------------------------------------------------------
-//Save providing facility
-//------------------------------------------------------------------------------
-
-function updateProvidingFacility( dataElementId, checkedBox )
-{
-    checkedBox.style.backgroundColor = '#ffffcc';
-    var providedByAnotherFacility = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ).checked;
-	
-    var checkBoxSaver = new CheckBoxSaver( dataElementId, providedByAnotherFacility, '#ccffcc' );
-    checkBoxSaver.save();
-    
-}
-
-function updateProvidingFacilityCustom( programStageId, dataElementId, checkedBox )
-{
-    var providedByAnotherFacility = checkedBox.checked;
-    var checkBoxSaver = new CustomCheckBoxSaver( programStageId, dataElementId, providedByAnotherFacility, '#ccffcc' );
-    checkBoxSaver.save();
-    
-}
-
-
-//-----------------------------------------------------------------------------
-//Saver objects - checkbox
-//-----------------------------------------------------------------------------
-
-function CheckBoxSaver( dataElementId_, providedByAnotherFacility_, resultColor_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ccccff';
-	
-    var dataElementId = dataElementId_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponseCheckBox );
-        request.setCallbackError( handleHttpErrorCheckBox );
-        request.setResponseTypeXML( 'status' );
-        request.send( 'saveProvidingFacility.action?dataElementId=' + dataElementId 
-				+ '&providedByAnotherFacility=' + providedByAnotherFacility );
-    };
-
-    function handleResponseCheckBox( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-   
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else
-        {
-            markValue( ERROR );
-            window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
-        }
-    }
-
-    function handleHttpErrorCheckBox( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( color )
-    {
-        var element = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' );
-        element.style.backgroundColor = color; //need to find another option as it is difficult to set background color for checkbox
-    }
-}
-
-function CustomCheckBoxSaver( programStageId, dataElementId_, providedByAnotherFacility_, resultColor_ )
-{
-    var SUCCESS = 'success';
-    var ERROR = '#error';
-	
-    var dataElementId = dataElementId_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponseCheckBox );
-        request.setCallbackError( handleHttpErrorCheckBox );
-        request.setResponseTypeXML( 'status' ); 
-        request.send( 'saveProvidingFacility.action?dataElementId=' + dataElementId 
-					+'&providedByAnotherFacility=' + providedByAnotherFacility );
-    };
-
-    function handleResponseCheckBox( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( SUCCESS );
-        }
-        else
-        {
-            markValue( ERROR );
-            window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
-        }
-    }
-
-    function handleHttpErrorCheckBox( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( result )
-    {
-        if( result == SUCCESS )
-        {
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').toggleClass('checked');
-        }
-        else if( result == ERROR )
-        {
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').removeClass('checked');
-            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').addClass('error');
-        }
-    }
-}
-
-//------------------------------------------------------------------------------
-//Save
-//------------------------------------------------------------------------------
-
-function saveValue( dataElementId, dataElementName )
-{
-    var field = document.getElementById( 'value[' + dataElementId + '].value' );
-    var type = document.getElementById( 'value[' + dataElementId + '].type' ).innerHTML;
-    var providedByAnotherFacility = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ).checked;
-    
-    field.style.backgroundColor = '#ffffcc';
+	field.style.backgroundColor = '#ffffcc';
     
     if( field.value != '' )
     {
@@ -687,7 +335,7 @@
 
                 return;
             }
-			else if (  type == 'number' && !isRealNumber( field.value ))
+			else if ( type == 'number' && !isRealNumber( field.value ) )
             {
                 field.style.backgroundColor = '#ffcc00';
                 window.alert( i18n_value_must_number + '\n\n' + dataElementName );
@@ -696,7 +344,7 @@
 
                 return;
             } 
-			else if (  type == 'positiveNumber' && !isPositiveInt( field.value ))
+			else if ( type == 'positiveNumber' && !isPositiveInt( field.value ) )
             {
                 field.style.backgroundColor = '#ffcc00';
                 window.alert( i18n_value_must_positive_integer + '\n\n' + dataElementName );
@@ -705,7 +353,7 @@
 
                 return;
             } 
-			else if (  type == 'negativeNumber' && !isNegativeInt( field.value ))
+			else if ( type == 'negativeNumber' && !isNegativeInt( field.value ) )
             {
                 field.style.backgroundColor = '#ffcc00';
                 window.alert( i18n_value_must_negative_integer + '\n\n' + dataElementName );
@@ -718,277 +366,92 @@
     	
     }
     
-    var valueSaver = new ValueSaver( dataElementId, field.value, providedByAnotherFacility, '#ccffcc', '' );
+	var valueSaver = new ValueSaver( dataElementId, optionComboId,  field.value, providedByAnotherFacility, type, '#ccffcc'  );
     valueSaver.save();
-    
 }
 
-function saveValueCustom( this_ )
-{
-    var data = jQuery( this_ ).metadata({
+function saveDate( dataElementId )
+{	
+	var programStageId = byId('programStageId').value;
+	var fieldId = programStageId + '-' + dataElementId + '-val';
+	var field = jQuery( "#" + fieldId ); 
+	var fieldValue = field.val();
+	var data = field.metadata({
         type:'attr',
         name:'data'
     });
 	
-    var providedByAnotherFacility = jQuery('input#'+data.programStageId+'_'+data.dataElementId).attr("checked");
-    
-    this_.style.backgroundColor = '#ffffcc';
-    
-    if( this_.value != '' )
-    {
-        if( data.dataElementType == 'int' )
-        {
-            if ( !isInt( this_.value ))
-            {
-                this_.style.backgroundColor = '#ffcc00';
-
-                window.alert( i18n_value_must_integer + '\n\n' + data.dataElementName );
-
-                this_.select();
-                this_.focus();
-
-                return;
-            }
-        }
-    	
-    }
-    
-    var valueSaver = new CustomValueSaver( data.dataElementId, this_.value, providedByAnotherFacility, '#ccffcc', '' );
-    valueSaver.setProgramStageId( data.programStageId );
-    valueSaver.setOptionComboId(data.optionComboId);
-    valueSaver.setType(data.dataElementType);
-    valueSaver.save();
-    
-}
-
-function saveChoice( dataElementId, selectedOption )
-{
-    selectedOption.style.backgroundColor = '#ffffcc';
-	
-    var providedByAnotherFacility = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ).checked;
- 
-    var valueSaver = new ValueSaver( dataElementId, selectedOption.options[selectedOption.selectedIndex].value, providedByAnotherFacility, '#ccffcc', selectedOption );
-    valueSaver.save();
-}
-function saveChoiceCustom( programStageId, dataElementId, selectedOption )
-{
-    selectedOption.style.backgroundColor = '#ffffcc';
-	
-    var providedByAnotherFacility = document.getElementById( programStageId+'_'+dataElementId+'_facility' ).checked;
- 
-    var valueSaver = new CustomValueSaver( dataElementId, selectedOption.options[selectedOption.selectedIndex].value, providedByAnotherFacility, '#ccffcc', selectedOption );
-    valueSaver.setProgramStageId( programStageId );
-    valueSaver.setType(jQuery(selectedOption).metadata({
-        type:"attr",
-        name:"data"
-    }).dataElementType);
-    valueSaver.save();
-}
-
-
-//-----------------------------------------------------------------------------
-//Saver objects
-//-----------------------------------------------------------------------------
-
-function ValueSaver( dataElementId_, value_, providedByAnotherFacility_, resultColor_, selectedOption_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ccccff';
-	
-    var dataElementId = dataElementId_;
-    var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-    var selectedOption = selectedOption_;
-	
-	
-    this.save = function()
-    {
-		var params = 'dataElementId=' + dataElementId;
-			params += '&value=' + value;
-			params += '&providedByAnotherFacility=' + providedByAnotherFacility;
-			
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-		request.sendAsPost( params );
-        request.send( 'saveValue.action');
-    };
- 
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else
-        {
-            if(value!="")
-            {
-                markValue( ERROR );
-                window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-    }
- 
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
- 
-    function markValue( color )
-    {
-		
-        var type = document.getElementById( 'value[' + dataElementId + '].type' ).innerHTML;
-		
-        var element;
-     
-        if ( type == 'bool' )
-        {
-            element = document.getElementById( 'value[' + dataElementId + '].boolean' );
-        }
-        else if( type == 'date' )
-        {
-            element = document.getElementById( 'value[' + dataElementId + '].date' );
-        }
-        else if( selectedOption )
-        {
-            element = selectedOption;
-        }
-        else
-        {
-            element = document.getElementById( 'value[' + dataElementId + '].value' );
-        }
-             
-        element.style.backgroundColor = color;
-    }
-}
-
-function CustomValueSaver( dataElementId_, value_, providedByAnotherFacility_, resultColor_, selectedOption_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ccccff';
-	
-    var dataElementId = dataElementId_;
-    var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-    var selectedOption = selectedOption_;
-    var optionComboId ;
-    var programStageId;
-    var type;
-	
-    this.setType = function( type_ )
-    {
-        type = type_;
-    }
-	
-    this.setOptionComboId =  function( optionComboId_ )
-    {
-        optionComboId = optionComboId_;
-    }
-	
-    this.setProgramStageId = function( programStageId_ )
-    {
-        programStageId = programStageId_;
-    }
-	
-    this.save = function()
-    {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-		
-        if( optionComboId )
-        {
-			var params = 'dataElementId=' + dataElementId;
-				params += '&optionComboId=' + optionComboId;
-				params += '&value=' + value;
-				params += '&providedByAnotherFacility=' + providedByAnotherFacility;
-			
-			request.sendAsPost( params ); 
-			
-			if( type == 'date' ) request.send( 'saveDateValue.action' );
-			else request.send( 'saveValue.action' );
-        }
-        else
-        {	
-			var params = 'dataElementId=' + dataElementId;
-				params += '&value=' + value;
-				params += '&providedByAnotherFacility=' + providedByAnotherFacility;
-				
-			request.sendAsPost( params );
-			if( type == 'date' ) request.send( 'saveDateValue.action' );
-			else request.send( 'saveValue.action' );
-        }
-		
-		
-    };
- 
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else
-        {
-            if(value!="")
-            {
-                markValue( ERROR );
-                window.alert( rootElement.getElementsByTagName( "message" )[0].firstChild.nodeValue );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-    }
- 
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
- 
-    function markValue( color )
-    {
-		
-        var element;
-     
-        if ( type == 'bool' )
-        {
-            element = document.getElementById( 'value[' + programStageId + '].boolean:value[' + dataElementId + '].boolean' );
-        }
-        else if( type == 'date' )
-        {
-            element = document.getElementById( 'value[' + programStageId + '].date:value[' + dataElementId + '].date' );
-        }
-        else if( selectedOption )
-        {
-            element = selectedOption;
-        }
-        else if ( optionComboId )
-        {
-            element = document.getElementById( 'value[' + programStageId + '].value:value[' + dataElementId + '].value:value[' + optionComboId + '].value');
-        }
-        else
-        {
-            element = document.getElementById( 'value[' + programStageId + '].value:value[' + dataElementId + '].value' );
-        }
-             
-        element.style.backgroundColor = color;
+    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
+ 
+	if( fieldValue !="")
+    { 
+		var d2 = new Date( fieldValue );
+        if( d2 == 'Invalid Date' )
+        {
+            field.css({
+                "background-color":"#ffcc00"
+            });
+            window.alert('Incorrect format for date value. The correct format should be ' + dateFormat.replace('yy', 'yyyy') +' \n\n ' + data.deName );
+		  
+            field.focus();
+
+            return;
+        }
+    }
+	
+	var dueDate = new Date( jQuery('#dueDate').val() );
+	var inputtedDate = new Date( fieldValue );
+	if( inputtedDate < dueDate )
+	{
+		field.css({
+                "background-color":"#ffcc00"
+            });
+            window.alert( i18n_date_is_greater_then_or_equals_due_date );
+		  
+            field.focus();
+
+            return;
+	}
+	
+    var dateSaver = new DateSaver( dataElementId, fieldValue, providedByAnotherFacility, '#ccffcc' );
+    dateSaver.save();
+}
+
+function saveOpt( dataElementId )
+{
+	var programStageId = byId('programStageId').value;
+	var field = byId( programStageId + '-' + dataElementId + '-val' );
+	
+	field.style.backgroundColor = '#ffffcc';
+	var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
+ 
+	var valueSaver = new ValueSaver( dataElementId, 0, field.options[field.selectedIndex].value, providedByAnotherFacility, 'bool', '#ccffcc' );
+    valueSaver.save();
+}
+
+function updateProvidingFacility( dataElementId, checkedBox )
+{
+	var programStageId = byId( 'programStageId' ).value;
+    checkedBox.style.backgroundColor = '#ffffcc';
+    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
+ 
+    var facilitySaver = new FacilitySaver( dataElementId, providedByAnotherFacility, '#ccffcc' );
+    facilitySaver.save();
+    
+}
+
+function saveExecutionDate( programStageInstanceId, programStageInstanceName )
+{
+    var field = document.getElementById( 'executionDate' );
+	
+    field.style.backgroundColor = '#ffffcc';
+	
+    var executionDateSaver = new ExecutionDateSaver( programStageInstanceId, field.value, '#ccffcc' );
+    executionDateSaver.save();
+	
+    if( !jQuery("#entryForm").is(":visible") )
+    {
+        toggleContentForReportDate(true);
     }
 }
 
@@ -1111,133 +574,287 @@
     }
 }
 
-//------------------------------------------------------
-// Save value for dataElement of type date in entryscreen
-//------------------------------------------------------
-
-function saveDate( dataElementId , dataElementName )
-{
-    var providedByAnotherFacility ;
-	
-    if( document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ) )
-        providedByAnotherFacility = document.getElementById( 'value[' + dataElementId + '].providedByAnotherFacility' ).checked;
-	
-    var field = document.getElementById('value['+dataElementId+'].date');
-	
-    field.style.backgroundColor = '#ffffcc';
-	
-    if( !isValidDate( field.value ) )
-    {
-        field.style.backgroundColor = '#ffcc00';
-        window.alert('Incorrect format for date value. The correct format should be ' + dateFormat.replace('yy', 'yyyy') + '\n\n '+dataElementName );
-		  
-        field.select();
-        field.focus();
-
-        return;
-    }
-	
-    var valueSaver = new ValueSaver( dataElementId, field.value, providedByAnotherFacility, '#ccffcc', '' );
-    valueSaver.save();
-	
-}
-function saveDateCustom(  this_ )
-{
-    jQuery(this_).css({
-        "background-color":"#ffffcc"
-    });
-
-    var data = jQuery(this_).metadata({
-        type:"attr",
-        name:"data"
-    });
-    var providedByAnotherFacility = document.getElementById( data.programStageId+'_'+data.dataElementId+'_facility' ).checked;
-
-    if(jQuery(this_).val()!="")
-    { 
-		var d2 = new Date(jQuery(this_).val() );
-        if( d2 == 'Invalid Date' )
-        {
-            jQuery(this_).css({
-                "background-color":"#ffcc00"
-            });
-            window.alert('Incorrect format for date value. The correct format should be ' + dateFormat.replace('yy', 'yyyy') +' \n\n ' + data.dataElementName );
-		  
-            jQuery(this_).focus();
-
-            return;
-        }
-    }
-	
-	var dueDate = new Date( jQuery('#dueDate').val() );
-	
-	var inputtedDate = new Date(jQuery(this_).val());
-	if( inputtedDate < dueDate )
-	{
-		jQuery(this_).css({
-                "background-color":"#ffcc00"
-            });
-            window.alert( i18n_date_is_greater_then_or_equals_due_date );
-		  
-            jQuery(this_).focus();
-
-            return;
-	}
-	
-    var valueSaver = new CustomValueSaver( data.dataElementId, jQuery(this_).val(), providedByAnotherFacility, '#ccffcc', '' );
-    valueSaver.setProgramStageId( data.programStageId );
-    valueSaver.setType(data.dataElementType);
-    valueSaver.save();
-	
-}
-
-function selectDefaultForm()
-{
-    if( byId('useDefaultForm').checked  )
-	{
-		hideById('customEntryScreenContainer');
-		showById('defaultEntryScreenContainer');
-	}
-	else
-	{
-		hideById('defaultEntryScreenContainer');
-		showById('customEntryScreenContainer');
-	}
-}
-
-function saveValueWithOptionComboId( this_ )
-{
-    var data = jQuery( this_ ).metadata({
-        type:'attr',
-        name:'data'
-    });
-	
-    var providedByAnotherFacility = document.getElementById( 'value[' + data.programStageId + '].facility:value[' + data.dataElementId + '].facility' ).checked;
-    
-    this_.style.backgroundColor = '#ffffcc';
-    
-    if( this_.value != '' )
-    {
-        if( data.dataElementType == 'int' )
-        {
-            if ( !isInt( this_.value ))
-            {
-                this_.style.backgroundColor = '#ffcc00';
-
-                window.alert( i18n_value_must_integer + '\n\n' + data.dataElementName );
-
-                this_.select();
-                this_.focus();
-
-                return;
-            }
-        }
-    }
-    var valueSaver = new CustomValueSaver( dataElementId, field.value, providedByAnotherFacility, '#ccffcc', '' );
-    valueSaver.setOptionComboId( data.optionComboId );
-    valueSaver.setProgramStageId( data.programStageId );
-    valueSaver.save();
-}
+//-----------------------------------------------------------------
+// Save value for dataElement of type text, number, boolean, combo
+//-----------------------------------------------------------------
+
+function ValueSaver( dataElementId_, selectedOption_, value_, providedByAnotherFacility_, dataElementType_, resultColor_  )
+{
+    var SUCCESS = '#ccffcc';
+    var ERROR = '#ccccff';
+	
+    var dataElementId = dataElementId_;
+    var selectedOption = selectedOption_;
+	var value = value_;
+    var providedByAnotherFacility = providedByAnotherFacility_;
+	var type = dataElementType_;
+    var resultColor = resultColor_;
+	
+    this.save = function()
+    {
+		var params = 'dataElementId=' + dataElementId;
+			params += '&optionComboId=' + selectedOption;
+			params += '&value=' + value;
+			params += '&providedByAnotherFacility=' + providedByAnotherFacility;
+			
+        var request = new Request();
+        request.setCallbackSuccess( handleResponse );
+        request.setCallbackError( handleHttpError );
+        request.setResponseTypeXML( 'status' );
+		request.sendAsPost( params );
+        request.send( 'saveValue.action');
+    };
+ 
+    function handleResponse( rootElement )
+    {
+        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
+        var code = parseInt( codeElement.firstChild.nodeValue );
+        if ( code == 0 )
+        {
+            markValue( resultColor );
+        }
+        else
+        {
+            if(value!="")
+            {
+                markValue( ERROR );
+                window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
+            }
+            else
+            {
+                markValue( resultColor );
+            }
+        }
+    }
+ 
+    function handleHttpError( errorCode )
+    {
+        markValue( ERROR );
+        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+    }
+ 
+    function markValue( color )
+    {
+		var programStageId = getFieldValue('programStageId');
+        var element;
+     
+        if( selectedOption )
+        {
+            element = byId( programStageId + "-" + dataElementId + "-" + selectedOption +'-val' );
+        }
+        else
+        {
+            element = byId( programStageId + "-" + dataElementId + '-val' );
+        }
+             
+        element.style.backgroundColor = color;
+    }
+}
+
+function DateSaver( dataElementId_, value_, providedByAnotherFacility_, resultColor_ )
+{
+    var SUCCESS = '#ccffcc';
+    var ERROR = '#ffcc00';
+	
+    var dataElementId = dataElementId_;
+    var value = value_;
+    var providedByAnotherFacility = providedByAnotherFacility_;
+    var resultColor = resultColor_;
+
+    this.save = function()
+    {
+		var params = 'dataElementId=' + dataElementId 
+			params +=  '&value=' + value 
+			params +=  '&providedByAnotherFacility=' + providedByAnotherFacility;
+			
+        var request = new Request();
+        request.setCallbackSuccess( handleResponse );
+        request.setCallbackError( handleHttpError );
+        request.setResponseTypeXML( 'status' );
+		request.sendAsPost( params );
+        request.send( 'saveDateValue.action' );
+    };
+
+    function handleResponse( rootElement )
+    {
+        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
+        var code = parseInt( codeElement.firstChild.nodeValue );
+        if ( code == 0 )
+        {
+            markValue( resultColor );
+        }
+        else if(code == 1)
+        {
+            if(value != "")
+            {
+                var validationElement = rootElement.getElementsByTagName( 'validations' )[0];
+                var dataelementList = rootElement.getElementsByTagName( 'validation' );
+                var message = '';
+                for ( var i = 0; i < dataelementList.length; i++ )
+                {
+                    message += "\n - " + dataelementList[i].firstChild.nodeValue;
+                }
+
+                markValue( ERROR );
+                window.alert( i18n_violate_validation + message);
+            }
+            else
+            {
+                markValue( resultColor );
+            }
+        }
+		else if(code == 2)
+        {
+			markValue( ERROR );
+            window.alert( i18n_invalid_date + ":\n" + rootElement.getElementsByTagName( 'message' )[0].firstChild.nodeValue );
+		}
+        else
+        {
+            if(value != "")
+            {
+                markValue( ERROR );
+                window.alert( i18n_invalid_date );
+            }
+            else
+            {
+                markValue( resultColor );
+            }
+        }
+    }
+
+    function handleHttpError( errorCode )
+    {
+        markValue( ERROR );
+        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+    }
+
+    function markValue( color )
+    {
+		var programStageId = byId('programStageId').value;
+        var element = byId(  programStageId + "-" + dataElementId + '-val' );
+        
+        element.style.backgroundColor = color;
+    }
+}
+
+function FacilitySaver( dataElementId_, providedByAnotherFacility_, resultColor_ )
+{
+    var SUCCESS = 'success';
+    var ERROR = '#error';
+	
+    var dataElementId = dataElementId_;
+    var providedByAnotherFacility = providedByAnotherFacility_;
+    var resultColor = resultColor_;
+
+    this.save = function()
+    {
+        var request = new Request();
+        request.setCallbackSuccess( handleResponseCheckBox );
+        request.setCallbackError( handleHttpErrorCheckBox );
+        request.setResponseTypeXML( 'status' ); 
+        request.send( 'saveProvidingFacility.action?dataElementId=' + dataElementId 
+					+'&providedByAnotherFacility=' + providedByAnotherFacility );
+    };
+
+    function handleResponseCheckBox( rootElement )
+    {
+        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
+        var code = parseInt( codeElement.firstChild.nodeValue );
+        if ( code == 0 )
+        {
+            markValue( SUCCESS );
+        }
+        else
+        {
+            markValue( ERROR );
+            window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
+        }
+    }
+
+    function handleHttpErrorCheckBox( errorCode )
+    {
+        markValue( ERROR );
+        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+    }
+
+    function markValue( result )
+    {
+		var programStageId = byId( 'programStageId' ).value;
+        if( result == SUCCESS )
+        {
+            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').toggleClass('checked');
+        }
+        else if( result == ERROR )
+        {
+            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').removeClass('checked');
+            jQuery('label[for="'+programStageId+'_'+dataElementId+'_facility"]').addClass('error');
+        }
+    }
+}
+
+function ExecutionDateSaver( programStageInstanceId_, executionDate_, resultColor_ )
+{
+    var SUCCESS = '#ccffcc';
+    var ERROR = '#ffcc00';
+	
+    var programStageInstanceId = programStageInstanceId_;
+    var executionDate = executionDate_;
+    var resultColor = resultColor_;
+
+    this.save = function()
+    {
+        var request = new Request();
+        request.setCallbackSuccess( handleResponse );
+        request.setCallbackError( handleHttpError );
+        request.setResponseTypeXML( 'status' );
+        request.send( 'saveExecutionDate.action?executionDate=' + executionDate );
+    };
+
+    function handleResponse( rootElement )
+    {
+        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
+        var code = parseInt( codeElement.firstChild.nodeValue );
+        if ( code == 0 )
+        {
+            markValue( resultColor );
+			showById('dataEntryFormDiv');
+			showById('entryForm');
+        }
+        else
+        {
+            if( executionDate != "")
+            {
+                markValue( ERROR );
+                window.alert( i18n_invalid_date );
+            }
+            else
+            {
+                markValue( resultColor );
+            }
+			hideById('dataEntryFormDiv');
+        }
+    }
+
+    function handleHttpError( errorCode )
+    {
+        markValue( ERROR );
+        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+    }
+
+    function markValue( color )
+    {
+   
+        var element = document.getElementById( 'executionDate' );
+           
+        element.style.backgroundColor = color;
+    }
+}
+
+//-----------------------------------------------------------------
+//
+//-----------------------------------------------------------------
+
+
 function initCustomCheckboxes()
 {
     jQuery('input[type=checkbox][name="providedByAnotherFacility"]').prettyCheckboxes();
@@ -1369,7 +986,6 @@
 	window.open( 'validateProgram.action' );
 }
 
-
 //------------------------------------------------------
 // Multi Data-entry
 //------------------------------------------------------

=== 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	2011-07-08 08:34:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm	2011-07-14 09:31:24 +0000
@@ -35,7 +35,8 @@
     <tr>
         <td><label for="programStageId">$i18n.getString( "program_stage" )</label></td>
         <td>
-			<input id="programStageId" name="programStageId" type="text" readonly="readonly" value="$encoder.htmlEncode( $programStage.name )" style="min-width:350px">            
+			<input id="programStageId" name="programStageId" type="hidden" value="$programStage.id" style="min-width:350px">            
+			<input type="text" readonly="readonly" value="$encoder.htmlEncode( $programStage.name )" style="min-width:350px">            
         </td>        
         #if( $programStageInstance )
             <td><label for="executionDate">$i18n.getString( "report_date" ) </label></td>
@@ -52,14 +53,14 @@
 		</td>
 		<td>&nbsp;</td>
 		<td>
-			<div id="actions" style="float:left">
+		<!--	<div id="actions" style="float:left">
 				<input type="checkbox" id="useDefaultForm" name="useDefaultForm"
 					#if( $useDefaultForm  ) 
 						checked="checked"
 					#end
 					onchange="selectDefaultForm();">
 				<label>$i18n.getString( "use_default_form" )</label><br>    
-			</div>			
+			</div>			 -->
 		</td>
     </tr>
 </table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2011-06-23 08:44:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2011-07-14 09:31:24 +0000
@@ -197,61 +197,51 @@
 	var dataElementId = dataElement.id;	
 	var dataElementName = dataElement.name;	
 	var dataElementType = dataElement.type;
-	var viewByValue = jQuery( source + ' #viewBySelector' ).val();	
-
-	var strPSDataEntryId   = "value["+ associationId +"].value:value["+ dataElementId +"].value";
-	var comboPSDataEntryId = "value["+ associationId +"].combo:value["+ dataElementId +"].combo";
-	var boolPSDataEntryId  = "value["+ associationId +"].boolean:value["+ dataElementId +"].boolean";
-	var datePSDataEntryId  = "value["+ associationId +"].date:value["+ dataElementId +"].date";
-
-	if(viewByValue == "deid") dispName = "[ " + dataElementId;
-	else if (viewByValue == "deshortname") dispName = "[ " + dataElement.shortName;
-	else dispName = "[ " + dataElementName;
-
-	viewByValue = "@@" + viewByValue + "@@";
-
+	
 	var id = "";
 
-	var selectString = "";
+	var htmlCode = "";
 
 	if( dataElementType == "string" )
 	{
 		if( categoryOptionCombos[0].default == 'true' )
-		{			
-			strPSDataEntryId  = strPSDataEntryId + ":value["+ categoryOptionCombos[0].id +"].value";
-			selectString += "<input name=\"entryfield\" id=\""+strPSDataEntryId+"\" type=\"text\" value=\"\" onkeypress=\"return keyPress(event, this)\" >";			
-			id = strPSDataEntryId;
-		}else{			
-			selectString = "<select name=\"entryselect\" id=\"" + comboPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
-		
-			jQuery.each( categoryOptionCombos, function(i, item ){
-				selectString += "<option value=\""+ item.id +"\" id=\"combo[" + item.id + "].combo\" >(" + item.name + ")</option>";
-			});
-			
-			selectString += "</select>";
-			
-			id = comboPSDataEntryId;
+		{		
+			var titleValue = dataElementId + "." + dataElementName 
+					+ "-" + categoryOptionCombos[0].id + "." + categoryOptionCombos[0].id 
+					+ " "+dataElementType+"\"";
+			var displayName = dataElementName + "-" + optionComboName + " ]";
+			id  = associationId + "-" + dataElementId + "-" + categoryOptionCombos[0].id +"-val";
+			htmlCode += "<input name=\"entryfield\" id=\""+ id + "\" value=\"" + displayName + "\" title=\"" + displayName + "\" onkeypress=\"return keyPress(event, this)\" >";			
+		}else{	
+			var titleValue = "-- " + dataElementId + "." + dataElementName + " ("+dataElementType+") --";
+			var displayName = dataElementName;
+			id = associationId + "-" + dataElementId + "-val"; 
+			htmlCode = "<input name=\"entryselect\" id=\"" + id + "\" value=\"" + displayName + "\" title=\"" + displayName + "\">";
 		}		
-		
-	} else if (dataElementType == "bool") {
-		selectString = "<select name=\"entryselect\" id=\"" + boolPSDataEntryId + "\" > <option value=\"\">i18n_select_value</option>";
-		selectString += "<option value=\"true\" >i18n_yes</option>";
-		selectString += "<option value=\"false\" >i18n_no</option>";
-		selectString += "</select>";
-		
-		id = boolPSDataEntryId;
-	} else if (dataElementType == "date") {
-		selectString = "<input type=\"text\" id=\"" + datePSDataEntryId + "\" name=\"entryfield\" value=\"\">";	
-		id = datePSDataEntryId;
-	} else if ( dataElementType == "int" ) {
+	} 
+	else if ( dataElementType == "bool" )
+	{
+		var titleValue = "-- " + dataElementId + "." + dataElementName + " ("+dataElementType+") --";
+		var displayName = dataElementName;
+		id = associationId + "-" + dataElementId + "-val" ;
+		htmlCode = "<input name=\"entryselect\" id=\"" + id + "\" value=\"" + displayName + "\" title=\"" + displayName + "\">";
+	} 
+	else if ( dataElementType == "date" )
+	{
+		var titleValue = "-- " + dataElementId + "." + dataElementName + " ("+dataElementType+") --";
+		var displayName = dataElementName;
+		id = associationId + "-" + dataElementId + "-val" ;
+		htmlCode = "<input name=\"entryfield\" id=\"" + id + "\" value=\"" + displayName + "\" title=\"" + displayName + "\">";
+	} 
+	else if ( dataElementType == "int" ) 
+	{
 		jQuery.each( categoryOptionCombos, function(i, item ){
 			optionComboName = item.name;
 			optionComboId = item.id;
-			var titleValue = "-- " + dataElementId + ". " + dataElementName + " " + optionComboId + ". " + optionComboName+" ("+dataElementType+") --";
-			var displayName = dispName + " - " + optionComboName + " ]";
-			var dataEntryId = "value[" + associationId + "].value:value[" + dataElementId + "].value:value[" + optionComboId + "].value";
-			selectString += "<input title=\"" + titleValue + "\" view=\""+viewByValue+"\" value=\"" + displayName + "\" name=\"entryfield\" id=\"" + dataEntryId + "\" style=\"width:10em;text-align:center\"/><br/>";
-			id = dataEntryId;
+			var titleValue = "-- " + dataElementId + "." + dataElementName + "-" + optionComboId + "." + optionComboName+" ("+dataElementType+") --";
+			var displayName = dataElementName + "-" + optionComboName;
+			id = associationId + "-" + dataElementId + "-" + optionComboId + "-val";
+			htmlCode += "<input title=\"" + titleValue + "\" value=\"" + displayName + "\" name=\"entryfield\" id=\"" + id + "\" />";
 		});
 	}
 	
@@ -263,5 +253,5 @@
 		jQuery( source + " #message_").html("");
 	}
 
-	oEditor.insertHtml( selectString );
+	oEditor.insertHtml( htmlCode );
 }