← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4131: Data entry: completed separate loading of forms and datavalues/minmax-values. Forms are now only ...

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4131 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-07-13 19:24:42 +0200
message:
  Data entry: completed separate loading of forms and datavalues/minmax-values. Forms are now only loaded when user changes data sets. Only datavalues/minmax-values are loaded when user changes period or orgunit. This will greatly reduce total bandwith use during data entry.
removed:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMinMaxGeneration.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm


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

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2011-07-11 10:22:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2011-07-13 13:48:02 +0000
@@ -29,13 +29,10 @@
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 import java.util.regex.Pattern;
 
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.minmax.MinMaxDataElement;
 
 /**
  * @author Bharath Kumar
@@ -138,8 +135,7 @@
      * @param dataSet the data set associated with this form.
      * @return HTML code for the form.
      */
-    String prepareDataEntryFormForEntry( String htmlCode,
-        Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet );
+    String prepareDataEntryFormForEntry( String htmlCode, String disabled, I18n i18n, DataSet dataSet );
     
     Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds );
     

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2011-07-12 17:45:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2011-07-13 15:09:37 +0000
@@ -29,8 +29,6 @@
 
 import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
 import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
-import static org.hisp.dhis.datavalue.DataValue.FALSE;
-import static org.hisp.dhis.datavalue.DataValue.TRUE;
 
 import java.util.Collection;
 import java.util.HashMap;
@@ -43,11 +41,9 @@
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
-import org.hisp.dhis.minmax.MinMaxDataElement;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
@@ -230,8 +226,7 @@
         return sb.toString();
     }
 
-    public String prepareDataEntryFormForEntry( String htmlCode,
-        Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet )
+    public String prepareDataEntryFormForEntry( String htmlCode, String disabled, I18n i18n, DataSet dataSet )
     {
         // ---------------------------------------------------------------------
         // Inline javascript/html to add to HTML before output
@@ -245,9 +240,9 @@
         final String historyCode = " ondblclick='javascript:viewHist( $DATAELEMENTID, $OPTIONCOMBOID )' ";
         
         final String metaDataCode = "<span id=\"$DATAELEMENTID-dataelement\" style=\"display:none\">$DATAELEMENTNAME</span>"
-            + "<span id=\"$DATAELEMENTID-type\" style=\"display:none\">$DATAELEMENTTYPE</span>"
-            + "<div id=\"$DATAELEMENTID-$OPTIONCOMBOID-min\" style=\"display:none\"></div>"
-            + "<div id=\"$DATAELEMENTID-$OPTIONCOMBOID-max\" style=\"display:none\"></div>";
+            + "<span id=\"$DATAELEMENTID-type\" class=\"hidden\">$DATAELEMENTTYPE</span>"
+            + "<span id=\"$DATAELEMENTID-$OPTIONCOMBOID-min\" name=\"min\" class=\"hidden\"></span>"
+            + "<span id=\"$DATAELEMENTID-$OPTIONCOMBOID-max\" name=\"max\" class=\"hidden\"></span>";
 
         StringBuffer sb = new StringBuffer();
 
@@ -286,8 +281,6 @@
 
                 String dataElementValueType = dataElement.getDetailedNumberType();
 
-                String dataElementValue = getValue( dataValues, dataElementId, optionComboId );
-
                 // -------------------------------------------------------------
                 // Insert data value for data element in output code for boolean
                 // -------------------------------------------------------------
@@ -302,22 +295,11 @@
                 // Insert title info
                 // -------------------------------------------------------------
 
-                MinMaxDataElement minMaxDataElement = minMaxMap.get( dataElement.getId() + ":" + optionComboId );
-                String minValue = minMaxDataElement != null ? String.valueOf( minMaxDataElement.getMin() ) : "-";
-                String maxValue = minMaxDataElement != null ? String.valueOf( minMaxDataElement.getMax() ) : "-";
-
                 StringBuilder title = new StringBuilder( "title=\"Name: " ).append( dataElement.getName() ).append( " " ).
-                    append( categoryOptionCombo.getName() ).append( " Type: " ).append( dataElement.getType() ).
-                    append( " Min: " ).append( minValue ).append( " Max: " ).append( maxValue ).append( "\"" );
+                    append( categoryOptionCombo.getName() ).append( " Type: " ).append( dataElement.getType() ).append( "\"" );
                 
                 inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, title ) : inputHtml + " " + title;
 
-                // -------------------------------------------------------------
-                // Append Javascript code and meta data (type/min/max) for
-                // persisting to output code, and insert value and type for
-                // fields
-                // -------------------------------------------------------------
-                
                 String backgroundColor = "style=\"";
                 
                 String appendCode = "";
@@ -327,25 +309,8 @@
                     appendCode += jsCodeForSelectLists + "tabindex=\"" + i++ + "\">";
 
                     appendCode += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
-
-                    if ( dataElementValue.equals( TRUE ) )
-                    {
-                        appendCode += "<option value=\"true\" selected>" + i18n.getString( "yes" ) + "</option>";
-                    }
-                    else
-                    {
-                        appendCode += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
-                    }
-
-                    if ( dataElementValue.equals( FALSE ) )
-                    {
-                        appendCode += "<option value=\"false\" selected>" + i18n.getString( "no" ) + "</option>";
-                    }
-                    else
-                    {
-                        appendCode += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
-                    }
-
+                    appendCode += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
+                    appendCode += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
                     appendCode += "</select>";
                 }
                 else
@@ -355,16 +320,6 @@
                     if ( dataElement.getType().equals( VALUE_TYPE_INT ) )
                     {
                         appendCode += historyCode;
-                        
-                        if ( minMaxDataElement != null && !dataElementValue.equals( EMPTY ) )
-                        {
-                            double value = Double.parseDouble( dataElementValue );
-                            
-                            if ( value < minMaxDataElement.getMin() || value > minMaxDataElement.getMax() )
-                            {
-                                backgroundColor = "style=\"background-color:#ff6600;";
-                            }
-                        }
                     }
 
                     appendCode += TAG_CLOSE;
@@ -427,24 +382,6 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Returns the value of the DataValue in the Collection of DataValues with
-     * the given data element identifier and category option combo id.
-     */
-    private String getValue( Collection<DataValue> dataValues, int dataElementId, int categoryOptionComboId )
-    {
-        for ( DataValue dataValue : dataValues )
-        {
-            if ( dataValue.getDataElement().getId() == dataElementId
-                && dataValue.getOptionCombo().getId() == categoryOptionComboId )
-            {
-                return dataValue.getValue();
-            }
-        }
-
-        return EMPTY;
-    }
-
-    /**
      * Returns a Map of all DataElements in the given DataSet where the key is
      * the DataElement identifier and the value is the DataElement.
      */

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2011-07-12 17:20:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java	2011-07-13 15:09:37 +0000
@@ -72,6 +72,17 @@
     }
 
     // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer selectedPeriodIndex;
+
+    public void setSelectedPeriodIndex( Integer selectedPeriodIndex )
+    {
+        this.selectedPeriodIndex = selectedPeriodIndex;
+    }
+
+    // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
@@ -95,6 +106,11 @@
 
     public String execute()
     {
+        if ( selectedPeriodIndex != null )
+        {
+            selectedStateManager.setSelectedPeriodIndex( selectedPeriodIndex );
+        }
+        
         Period period = selectedStateManager.getSelectedPeriod();
         DataSet dataSet = selectedStateManager.getSelectedDataSet();
         OrganisationUnit unit = selectedStateManager.getSelectedOrganisationUnit();

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java	2011-06-27 10:39:01 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java	2011-07-13 15:09:37 +0000
@@ -57,11 +57,8 @@
 import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.dataset.comparator.SectionOrderComparator;
 import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.de.state.SelectedStateManager;
 import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.minmax.MinMaxDataElement;
-import org.hisp.dhis.minmax.MinMaxDataElementService;
 import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
@@ -118,20 +115,6 @@
         this.registrationService = registrationService;
     }
 
-    private DataValueService dataValueService;
-
-    public void setDataValueService( DataValueService dataValueService )
-    {
-        this.dataValueService = dataValueService;
-    }
-
-    private MinMaxDataElementService minMaxDataElementService;
-
-    public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService )
-    {
-        this.minMaxDataElementService = minMaxDataElementService;
-    }
-
     private DataElementCategoryService categoryService;
 
     public void setCategoryService( DataElementCategoryService categoryService )
@@ -168,6 +151,10 @@
         this.displayPropertyHandler = displayPropertyHandler;
     }
 
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
     private Map<DataElementCategoryCombo, List<DataElement>> orderedDataElements = new HashMap<DataElementCategoryCombo, List<DataElement>>();
 
     public Map<DataElementCategoryCombo, List<DataElement>> getOrderedDataElements()
@@ -198,10 +185,6 @@
         return this.customDataEntryFormCode;
     }
 
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
     private String displayMode;
 
     public void setDisplayMode( String displayMode )
@@ -209,10 +192,6 @@
         this.displayMode = displayMode;
     }
 
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
     private OrganisationUnit organisationUnit;
 
     public OrganisationUnit getOrganisationUnit()
@@ -276,14 +255,7 @@
         return dataElementValueTypeMap;
     }
 
-    private Map<String, MinMaxDataElement> minMaxMap;
-
-    public Map<String, MinMaxDataElement> getMinMaxMap()
-    {
-        return minMaxMap;
-    }
-
-    private Integer integer = 0;
+    private Integer integer = 0; // TODO wtf
 
     public Integer getInteger()
     {
@@ -487,21 +459,6 @@
         // Get the min/max values
         // ---------------------------------------------------------------------
 
-        Collection<MinMaxDataElement> minMaxDataElements = minMaxDataElementService.getMinMaxDataElements(
-            organisationUnit, dataElements );
-
-        minMaxMap = new HashMap<String, MinMaxDataElement>( minMaxDataElements.size() );
-
-        for ( MinMaxDataElement minMaxDataElement : minMaxDataElements )
-        {
-            minMaxMap.put( minMaxDataElement.getDataElement().getId() + ":"
-                + minMaxDataElement.getOptionCombo().getId(), minMaxDataElement );
-        }
-
-        // ---------------------------------------------------------------------
-        // Get the min/max values
-        // ---------------------------------------------------------------------
-
         orderedDataElements = dataElementService.getGroupedDataElementsByCategoryCombo( dataElements );
 
         orderedCategoryCombos = dataElementService.getDataElementCategoryCombos( dataElements );
@@ -569,23 +526,6 @@
         }
 
         // ---------------------------------------------------------------------
-        // Get the DataValues and create a map
-        // ---------------------------------------------------------------------
-
-        Collection<DataValue> dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements,
-            allOptionCombos );
-
-        dataValueMap = new HashMap<String, DataValue>( dataValues.size() );
-
-        for ( DataValue dataValue : dataValues )
-        {
-            Integer deId = dataValue.getDataElement().getId();
-            Integer ocId = dataValue.getOptionCombo().getId();
-
-            dataValueMap.put( deId.toString() + ':' + ocId.toString(), dataValue );
-        }
-
-        // ---------------------------------------------------------------------
         // Make the DataElement types available
         // ---------------------------------------------------------------------
 
@@ -599,13 +539,13 @@
         // Get data entry form
         // ---------------------------------------------------------------------
 
-        if( displayMode.equals( SECTION_FORM ) )
+        if ( displayMode.equals( SECTION_FORM ) )
         {
             getSectionForm( dataElements, selectedDataSet );
         }
         else
         {
-            getOtherDataEntryForm( dataElements, selectedDataSet, dataValues );
+            getOtherDataEntryForm( dataElements, selectedDataSet );
         }
 
         return displayMode;
@@ -656,8 +596,7 @@
 
     }
 
-    private void getOtherDataEntryForm( List<DataElement> dataElements, DataSet dataSet,
-        Collection<DataValue> dataValues )
+    private void getOtherDataEntryForm( List<DataElement> dataElements, DataSet dataSet )
     {
         DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period );
 
@@ -676,8 +615,8 @@
 
         if ( cdeFormExists )
         {
-            customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry( dataEntryForm.getHtmlCode(),
-                dataValues, minMaxMap, disabled, i18n, dataSet );
+            customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry( 
+                dataEntryForm.getHtmlCode(), disabled, i18n, dataSet );
         }
 
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-07-12 17:20:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-07-13 13:48:02 +0000
@@ -59,8 +59,6 @@
     <property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
     <property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
     <property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
-    <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
-    <property name="minMaxDataElementService" ref="org.hisp.dhis.minmax.MinMaxDataElementService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
   </bean>
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm	2010-11-24 20:34:35 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm	2011-07-13 15:09:37 +0000
@@ -1,9 +1,3 @@
-
-<input type="hidden" value="$organisationUnit.id" id="organisationUnitId"/>
-
-#foreach( $optionCombo in $allOptionCombos )
-<td><span id="value[option$optionCombo.id].name" style="display:none">$optionCombo.name</span></td>       
-#end
 $customDataEntryFormCode
 
 #parse( "/dhis-web-dataentry/completeRegistration.vm" )
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-07-12 17:30:07 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-07-13 15:09:37 +0000
@@ -1,5 +1,3 @@
-<input type="hidden" value="$organisationUnit.id" id="organisationUnitId"/>
-
 #set( $tabIndex = 1 )
 #foreach( $categoryCombo in $orderedCategoryCombos )
 <table style="border:1px solid #c0c0c0; padding:10px;">
@@ -41,29 +39,18 @@
       <span id="${dataElement.id}-dataelement" title="$!encoder.htmlEncode( $dataElement.description )">${encoder.htmlEncode( $dataElement.name )}</span>
       <span id="${dataElement.id}-type" class="hidden">$dataElement.getDetailedNumberType()</span>
     </td>
-
     #foreach( $optionCombo in $optionCombos )
-	    #set( $minMax = false )
-	    #set( $minMax = $minMaxMap.get( "$dataElement.id:$optionCombo.id" ) )
-	    #set( $dataValue = false )
-	    #set( $dataValue = $dataValueMap.get( "$dataElement.id:$optionCombo.id" ) )
 	    #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )
-	    #set( $minMaxError = false )
-	    #if( $dataElement.type == "int" && $dataValue && $minMax )
-	      #if( $integer.parseInt( $dataValue.value ) < $minMax.min || $integer.parseInt( $dataValue.value ) > $minMax.max )
-	      	#set( $minMaxError = true )
-	      #end
-	    #end
-	    <span id="${dataElement.id}-${optionCombo.id}-min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" class="hidden"></span>
+	    <span id="${dataElement.id}-${optionCombo.id}-min" name="min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" name="max" class="hidden"></span>
 	    <td>
 	    #if( $dataElement.type == "bool" )
 		    <select name="entryselect" id="$dataEntryId" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) ) onchange="saveBoolean($dataElement.id,$optionCombo.id )"  #else disabled="disabled" #end style="width:100%" tabindex="$tabIndex" #if( $locked ) disabled="disabled"#end>
 		      <option value="">[$i18n.getString( "no_value" )]</option>
-		      <option value="true" #if( $dataValue.value == "true" ) selected="selected" #end>$i18n.getString( "yes" )</option>
-		      <option value="false" #if( $dataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
+		      <option value="true">$i18n.getString( "yes" )</option>
+		      <option value="false">$i18n.getString( "no" )</option>
 		    </select>
 	    #else
-		    <input name="entryfield" id="$dataEntryId" type="text" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue") ) onchange="saveVal(${dataElement.id},${optionCombo.id})" ondblclick="viewHist(${dataElement.id},${optionCombo.id})" #else disabled="disabled"#end onkeyup="return keyPress(event,this)" class="entryField #if( $minMaxError ) minmax#end" tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
+		    <input name="entryfield" id="$dataEntryId" type="text" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue") ) onchange="saveVal(${dataElement.id},${optionCombo.id})" ondblclick="viewHist(${dataElement.id},${optionCombo.id})" #else disabled="disabled"#end onkeyup="return keyPress(event,this)" class="entryField" tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
 	    #end
 	    </td>
 	    #set( $tabIndex = $tabIndex + 1 )

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-07-12 13:59:10 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-07-13 15:09:37 +0000
@@ -1,5 +1,7 @@
 
 /**
+ * This file depends on form.js.
+ * 
  * Format for the span/input identifiers for selectors:
  * 
  * {dataelementid}-{optioncomboid}-val // data value
@@ -14,11 +16,6 @@
 // Save
 // -----------------------------------------------------------------------------
 
-var COLOR_GREEN = '#b9ffb9';
-var COLOR_YELLOW = '#fffe8c';
-var COLOR_RED = '#ff8a8a';
-var COLOR_ORANGE = '#ff6600';
-
 var FORMULA_PATTERN = /\[.+?\]/g;
 var SEPARATOR = '.';
 
@@ -99,7 +96,6 @@
     var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
     var value =$( fieldId ).val();
     var type = $( '#' + dataElementId + '-type' ).html();
-    var organisationUnitId = $( '#organisationUnitId' ).val();
 
     $( fieldId ).css( 'background-color', COLOR_YELLOW );
 
@@ -140,7 +136,7 @@
             var minString = $( '#' + dataElementId + '-' + optionComboId + '-min' ).html();
             var maxString = $( '#' + dataElementId + '-' + optionComboId + '-max' ).html();
 
-            if ( minString && maxString )
+            if ( minString && maxString ) // TODO if only one exists?
             {
                 var valueNo = new Number( value );
                 var min = new Number( minString );
@@ -148,7 +144,7 @@
 
                 if ( valueNo < min )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_ORANGE );
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, value, COLOR_ORANGE );
                     valueSaver.save();
 
                     window.alert( i18n_value_of_data_element_less + ': ' + min + '\n\n' + dataElementName );
@@ -157,7 +153,7 @@
 
                 if ( valueNo > max )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_ORANGE );
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, value, COLOR_ORANGE );
                     valueSaver.save();
 
                     window.alert( i18n_value_of_data_element_greater + ': ' + max + '\n\n' + dataElementName );
@@ -167,7 +163,7 @@
         }
     }
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, value, COLOR_GREEN );
     valueSaver.save();
     
     updateIndicators(); // Update indicators in case of custom form
@@ -177,11 +173,10 @@
 {
     var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
     var value = $( fieldId + ' option:selected' ).val();
-    var organisationUnitId = $( '#organisationUnitId' ).val();
 
     $( fieldId ).css( 'background-color', COLOR_YELLOW );
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, value, COLOR_GREEN );
     valueSaver.save();
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-07-12 17:26:24 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-07-13 16:16:49 +0000
@@ -1,7 +1,20 @@
-var significantZeros = []; // Identifiers for which zero values are
-// insignificant, also used in entry.js
-var indicatorFormulas = []; // Associative array with [indicator id, expression]
-// for indicators in form, also used in entry.js
+// Identifiers for which zero values are, insignificant, also used in entry.js
+var significantZeros = [];
+
+// Associative array with [indicator id, expression] for indicators in form, also used in entry.js
+var indicatorFormulas = [];
+
+// Indicates whether any data entry form has been loaded
+var dataEntryFormIsLoaded = false;
+
+// Currently selected organisation unit identifier
+var currentOrganisationUnitId = null;
+
+var COLOR_GREEN = '#b9ffb9';
+var COLOR_YELLOW = '#fffe8c';
+var COLOR_RED = '#ff8a8a';
+var COLOR_ORANGE = '#ff6600';
+var COLOR_WHITE = '#ffffff';
 
 function addEventListeners()
 {
@@ -18,6 +31,8 @@
 function clearEntryForm()
 {
     $( '#contentDiv' ).html( '' );
+    
+    dataEntryFormIsLoaded = false;
 }
 
 // -----------------------------------------------------------------------------
@@ -26,6 +41,8 @@
 
 function organisationUnitSelected( orgUnits )
 {
+	currentOrganisationUnitId = orgUnits[0];
+	
     $( '#selectedDataSetId' ).removeAttr( 'disabled' );
 
     var dataSetId = $( '#selectedDataSetId' ).val();
@@ -50,12 +67,13 @@
         {
             $( '#selectedDataSetId' ).val( dataSetId );
 
-            if ( json.periodValid )
+            if ( json.periodValid && dataEntryFormIsLoaded )
             {
                 showLoader();
-                $( '#contentDiv' ).load( 'select.action', loadDataValues );
+                loadDataValues();
             }
-        } else
+        } 
+        else
         {
             clearPeriod();
         }
@@ -147,7 +165,8 @@
                 showLoader();
                 $( '#selectedPeriodIndex' ).val( periodIndex );
                 $( '#contentDiv' ).load( 'select.action', loadDataValuesAndDisplayModes );
-            } else
+            } 
+            else
             {
                 clearEntryForm();
             }
@@ -183,8 +202,17 @@
     if ( periodIndex && periodIndex != -1 )
     {
         showLoader();
-        var url = 'select.action?selectedPeriodIndex=' + periodIndex;
-        $( '#contentDiv' ).load( url, loadDataValuesAndDisplayModes );
+        
+        if ( dataEntryFormIsLoaded )
+        {
+        	loadDataValuesAndDisplayModes();
+        }
+        else
+        {
+        	var url = 'select.action?selectedPeriodIndex=' + periodIndex;
+        	
+        	$( '#contentDiv' ).load( url, loadDataValuesAndDisplayModes );
+        }
     }
 }
 
@@ -207,13 +235,24 @@
 
 function insertDataValues()
 {
-	// Clear existing values
+	var valueMap = new Array();
+	
+	var periodIndex = $( '#selectedPeriodIndex' ).val();
+	
+	// Clear existing values and colors
 	
 	$( '[name="entryfield"]' ).val( '' );
-	
-	$.getJSON( 'getDataValues.action', function( json ) 
+	$( '[name="entryselect"]' ).val( '' );
+	
+	$( '[name="entryfield"]' ).css( 'background-color', COLOR_WHITE );
+	$( '[name="entryselect"]' ).css( 'background-color', COLOR_WHITE );
+	
+	$( '[name="min"]' ).html( '' );
+	$( '[name="max"]' ).html( '' );
+	
+	$.getJSON( 'getDataValues.action', { selectedPeriodIndex:periodIndex }, function( json ) 
 	{
-		// Set data values
+		// Set data values, works for select lists too as data value = select value
 	
 		$.each( json.dataValues, function( i, value )
 		{
@@ -223,14 +262,17 @@
 			{
 				$( fieldId ).val( value.val );
 			}
+			
+			valueMap[value.id] = value.val;
 		} );
 		
-		// Set min-max values
+		// Set min-max values and colorize violation fields
 		
 		$.each( json.minMaxDataElements, function( i, value )
 		{
 			var minFieldId = '#' + value.id + '-min';
 			var maxFieldId = '#' + value.id + '-max';
+			var valFieldId = '#' + value.id + '-val';
 			
 			if ( $( minFieldId ) )
 			{
@@ -241,6 +283,14 @@
 			{
 				$( maxFieldId ).html( value.max );
 			}
+			
+			var dataValue = valueMap[value.id];
+			
+			if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( value.min ) ) 
+				|| ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) )
+			{
+				$( valFieldId ).css( 'background-color', COLOR_ORANGE );
+			}
 		} );
 	} );
 }
@@ -284,9 +334,10 @@
 function displayEntryFormCompleted()
 {
     addEventListeners();
-    hideLoader();
     enable( 'validationButton' );
     updateIndicators();
+    dataEntryFormIsLoaded = true;
+    hideLoader();
 }
 
 function valueFocus( e )
@@ -328,7 +379,8 @@
         if ( field.is( ':disabled' ) || field.is( ':hidden' ) )
         {
             field = $( 'input[name="entryfield"][tabindex="' + ( ++index ) + '"]' );
-        } else
+        } 
+        else
         {
             return field;
         }
@@ -346,7 +398,8 @@
         if ( field.is( ':disabled' ) || field.is( ':hidden' ) )
         {
             field = $( 'input[name="entryfield"][tabindex="' + ( --index ) + '"]' );
-        } else
+        } 
+        else
         {
             return field;
         }
@@ -389,7 +442,8 @@
 
             alert( i18n_no_response_from_server );
         } );
-    } else
+    } 
+    else
     {
         window.open( 'validate.action', '_blank', 'width=800, height=400, scrollbars=yes, resizable=yes' );
     }

=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMinMaxGeneration.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMinMaxGeneration.vm	2009-03-09 19:32:51 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMinMaxGeneration.vm	1970-01-01 00:00:00 +0000
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<minmax>
-	#foreach( $minMaxDataElement in $minMaxDataElements )
-    	<dataelement>
-    		<dataelementId>$encoder.xmlEncode( $minMaxDataElement.dataElement.id )</dataelementId>
-    		<optionComboId>$encoder.xmlEncode( $minMaxDataElement.optionCombo.id )</optionComboId>
-    		<minLimit>$encoder.xmlEncode( $minMaxDataElement.min )</minLimit>
-    		<maxLimit>$encoder.xmlEncode( $minMaxDataElement.max )</maxLimit>
-    	</dataelement>
-	#end
-</minmax>

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-07-12 17:30:07 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-07-13 15:09:37 +0000
@@ -1,5 +1,3 @@
-<input type="hidden" value="$organisationUnit.id" id="organisationUnitId"/>
-
 #set( $marker = 0 )
 #set( $tabIndex = 1 )
 
@@ -58,29 +56,19 @@
           <span id="${dataElement.id}-dataelement" title="$!{encoder.htmlEncode( $dataElement.description )}">${encoder.htmlEncode( $dataElement.name )}</span><span id="${dataElement.id}-type" class="hidden">$dataElement.getDetailedNumberType()</span>
         </td>
         #foreach( $optionCombo in $optionCombos )
-        #set( $minMax = false )
-        #set( $minMax = $minMaxMap.get( "$dataElement.id:$optionCombo.id" ) )
-        #set( $dataValue = false )
-        #set( $dataValue = $dataValueMap.get( "$dataElement.id:$optionCombo.id" ) )
         #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )
         #set( $greyedField = false )
-        #set( $greyedField = $greyedFields.get( "$dataElement.id:$optionCombo.id" ) )        
-        #set( $minMaxError = false )
-        #if( $dataElement.type == "int" && $dataValue && $minMax )
-          #if( $integer.parseInt( $dataValue.value ) < $minMax.min || $integer.parseInt( $dataValue.value ) > $minMax.max )
-          #set( $minMaxError = true )
-          #end
-        #end
-        <span id="${dataElement.id}-${optionCombo.id}-min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" class="hidden"></span>
+        #set( $greyedField = $greyedFields.get( "$dataElement.id:$optionCombo.id" ) )
+        <span id="${dataElement.id}-${optionCombo.id}-min" name="min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" name="max" class="hidden"></span>
         <td>
         #if( $dataElement.type == "bool" )
         <select name="entryselect" id="$dataEntryId" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) ) onchange="saveBoolean($dataElement.id,$optionCombo.id )"  #else disabled="disabled" #end style="width:100%" tabindex="$tabIndex" #if( $locked ) disabled="disabled"#end #if( $greyedField ) disabled="disabled"#end>
 	      <option value="">[$i18n.getString( "no_value" )]</option>
-          <option value="true" #if( $dataValue.value == "true" ) selected="selected" #end>$i18n.getString( "yes" )</option>
-          <option value="false" #if( $dataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
+          <option value="true">$i18n.getString( "yes" )</option>
+          <option value="false">$i18n.getString( "no" )</option>
         </select>
         #else
-        <input name="entryfield" id="$dataEntryId" type="text" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue") ) onchange="saveVal(${dataElement.id},${optionCombo.id})" ondblclick="viewHist(${dataElement.id},${optionCombo.id})" #else disabled="disabled"#end onkeyup="return keyPress(event,this)" class="entryField #if( $minMaxError ) minmax#elseif( $locked || $greyedField ) grey#end" tabindex="$tabIndex" #if( $locked || $greyedField )disabled="disabled"#end>
+        <input name="entryfield" id="$dataEntryId" type="text" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue") ) onchange="saveVal(${dataElement.id},${optionCombo.id})" ondblclick="viewHist(${dataElement.id},${optionCombo.id})" #else disabled="disabled"#end onkeyup="return keyPress(event,this)" class="entryField #if( $locked || $greyedField ) grey#end" tabindex="$tabIndex" #if( $locked || $greyedField )disabled="disabled"#end>
         #end
       </td>
       #set( $tabIndex = $tabIndex + 1 )