← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4737: (wip) form validation

 

------------------------------------------------------------
revno: 4737
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-09-28 11:35:12 +0200
message:
  (wip) form validation
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/dataentry/GetSectionFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.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-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/dataentry/GetSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/dataentry/GetSectionFormAction.java	2011-09-27 12:03:32 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/dataentry/GetSectionFormAction.java	2011-09-28 09:35:12 +0000
@@ -27,8 +27,11 @@
 
 package org.hisp.dhis.light.action.dataentry;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -39,7 +42,6 @@
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.datavalue.DeflatedDataValue;
@@ -189,9 +191,9 @@
         return dataValues;
     }
 
-    private Map<String, String> validationErrors = new HashMap<String, String>();
+    private Map<String, DeflatedDataValue> validationErrors = new HashMap<String, DeflatedDataValue>();
 
-    public Map<String, String> getValidationErrors()
+    public Map<String, DeflatedDataValue> getValidationErrors()
     {
         return validationErrors;
     }
@@ -219,6 +221,7 @@
     // Action Implementation
     // -------------------------------------------------------------------------
 
+    @SuppressWarnings( "unchecked" )
     @Override
     public String execute()
     {
@@ -228,69 +231,56 @@
 
         dataSet = dataSetService.getDataSet( dataSetId );
 
-        for ( Section section : dataSet.getSections() )
+        List<DataValue> values = new ArrayList<DataValue>( dataValueService.getDataValues( organisationUnit, period,
+            dataSet.getDataElements() ) );
+
+        for ( DataValue dataValue : values )
         {
-            for ( DataElement dataElement : section.getDataElements() )
-            {
-                for ( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() )
-                {
-                    DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period,
-                        optionCombo );
-
-                    String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() );
-                    String value = "";
-
-                    if ( dataValue != null )
-                    {
-                        value = dataValue.getValue();
-                        validateDataElement( organisationUnit, dataElement, optionCombo, period, value );
-                    }
-
-                    dataValues.put( key, value );
-                }
-            }
+            DataElement dataElement = dataValue.getDataElement();
+            DataElementCategoryOptionCombo optionCombo = dataValue.getOptionCombo();
+
+            String key = String.format( "DE%dOC%d", dataElement.getId(), optionCombo.getId() );
+            String value = dataValue.getValue();
+
+            dataValues.put( key, value );
         }
 
-        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
-            organisationUnit );
-
-        complete = registration != null ? true : false;
-
-        return SUCCESS;
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public void validateDataElement( OrganisationUnit organisationUnit, DataElement dataElement,
-        DataElementCategoryOptionCombo optionCombo, Period period, String value )
-    {
-        Collection<DeflatedDataValue> outliers;
-
-        MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement( organisationUnit,
-            dataElement, optionCombo );
-
-        if ( minMaxDataElement == null )
+        Collection<MinMaxDataElement> minmaxs = minMaxDataElementService.getMinMaxDataElements( organisationUnit,
+            dataSet.getDataElements() );
+
+        Collection<DeflatedDataValue> deflatedDataValues = new HashSet<DeflatedDataValue>();
+
+        if ( minmaxs == null )
         {
             Double factor = (Double) systemSettingManager.getSystemSetting(
                 SystemSettingManager.KEY_FACTOR_OF_DEVIATION, 2.0 );
 
             Collection<DeflatedDataValue> stdDevs = stdDevOutlierAnalysisService.analyse( organisationUnit,
-                ListUtils.getCollection( dataElement ), ListUtils.getCollection( period ), factor );
+                dataSet.getDataElements(), ListUtils.getCollection( period ), factor );
 
             Collection<DeflatedDataValue> minMaxs = minMaxOutlierAnalysisService.analyse( organisationUnit,
-                ListUtils.getCollection( dataElement ), ListUtils.getCollection( period ), null );
+                dataSet.getDataElements(), ListUtils.getCollection( period ), null );
 
-            outliers = CollectionUtils.union( stdDevs, minMaxs );
+            deflatedDataValues = CollectionUtils.union( stdDevs, minMaxs );
         }
         else
         {
-            outliers = minMaxValuesGenerationService.findOutliers( organisationUnit, ListUtils.getCollection( period ),
-                ListUtils.getCollection( minMaxDataElement ) );
+            deflatedDataValues = minMaxValuesGenerationService.findOutliers( organisationUnit,
+                ListUtils.getCollection( period ), minmaxs );
         }
 
-        for ( DeflatedDataValue deflatedDataValue : outliers )
+        for ( DeflatedDataValue deflatedDataValue : deflatedDataValues )
         {
-            System.err.println( "max: " + deflatedDataValue.getMax() );
-            System.err.println( "min: " + deflatedDataValue.getMin() );
+            String key = String.format( "DE%dOC%d", deflatedDataValue.getDataElementId(),
+                deflatedDataValue.getCategoryOptionComboId() );
+            validationErrors.put( key, deflatedDataValue );
         }
+
+        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
+            organisationUnit );
+
+        complete = registration != null ? true : false;
+
+        return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm	2011-09-27 07:49:40 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm	2011-09-28 09:35:12 +0000
@@ -14,8 +14,15 @@
 	<p>
 		#foreach( $dataElement in $section.dataElements)
 			#foreach( $optionCombo in $section.categoryCombo.optionCombos )
-			#set( $key = "DE${dataElement.id}OC${optionCombo.id}" )
-			<label>$dataElement.name $optionCombo.name</label> <input type="number" size="24" name="$key" value="$dataValues.get($key)" /> <br />
+				#set( $key = "DE${dataElement.id}OC${optionCombo.id}" )
+				<label>$dataElement.name $optionCombo.name</label>
+	
+				#if( $validationErrors.get( $key ) )
+				#set( $validationError = $validationErrors.get( $key ) ) 
+				<br /><span style="color: red;">Value is out of bounds [ $validationError.min, $validationError.max ]</span>
+				#end
+				
+				<input type="number" size="24" name="$key" value="$dataValues.get($key)" /> <br />
 			#end
 		#end
 	</p>