← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4780: (mobil) validation rule analysis in data entry

 

------------------------------------------------------------
revno: 4780
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-30 12:39:41 +0200
message:
  (mobil) validation rule analysis in data entry
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java
  dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
  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/dataentry/action/GetSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java	2011-09-29 10:23:26 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetSectionFormAction.java	2011-09-30 10:39:41 +0000
@@ -27,7 +27,9 @@
 
 package org.hisp.dhis.light.dataentry.action;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
@@ -147,11 +149,18 @@
         return dataValues;
     }
 
-    private Map<String, DeflatedDataValue> validationErrors = new HashMap<String, DeflatedDataValue>();
-
-    public Map<String, DeflatedDataValue> getValidationErrors()
-    {
-        return validationErrors;
+    private Map<String, DeflatedDataValue> validationViolations = new HashMap<String, DeflatedDataValue>();
+
+    public Map<String, DeflatedDataValue> getValidationViolations()
+    {
+        return validationViolations;
+    }
+
+    private List<String> validationRuleViolations = new ArrayList<String>();
+
+    public List<String> getValidationRuleViolations()
+    {
+        return validationRuleViolations;
     }
 
     private Boolean complete = false;
@@ -188,7 +197,9 @@
 
         dataValues = sectionFormUtils.getDataValueMap( organisationUnit, dataSet, period );
 
-        validationErrors = sectionFormUtils.getValidationErrorMap( organisationUnit, dataSet, period );
+        validationViolations = sectionFormUtils.getValidationErrorMap( organisationUnit, dataSet, period );
+
+        validationRuleViolations = sectionFormUtils.getValidationRuleViolations( organisationUnit, dataSet, period );
 
         CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
             organisationUnit );

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java	2011-09-29 12:27:42 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java	2011-09-30 10:39:41 +0000
@@ -27,8 +27,10 @@
 
 package org.hisp.dhis.light.dataentry.action;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
@@ -188,11 +190,18 @@
         return dataValues;
     }
 
-    private Map<String, DeflatedDataValue> validationErrors = new HashMap<String, DeflatedDataValue>();
-
-    public Map<String, DeflatedDataValue> getValidationErrors()
-    {
-        return validationErrors;
+    private Map<String, DeflatedDataValue> validationViolations = new HashMap<String, DeflatedDataValue>();
+
+    public Map<String, DeflatedDataValue> getValidationViolations()
+    {
+        return validationViolations;
+    }
+
+    private List<String> validationRuleViolations = new ArrayList<String>();
+
+    public List<String> getValidationRuleViolations()
+    {
+        return validationRuleViolations;
     }
 
     private Boolean complete = false;
@@ -263,9 +272,9 @@
 
                 value = value.trim();
 
-                if( dataValue == null )
+                if ( dataValue == null )
                 {
-                    if( value != null && value.length() > 0 )
+                    if ( value != null && value.length() > 0 )
                     {
                         needsValidation = true;
 
@@ -276,7 +285,7 @@
                 }
                 else
                 {
-                    if( !dataValue.getValue().equals( value ) )
+                    if ( !dataValue.getValue().equals( value ) )
                     {
                         needsValidation = true;
 
@@ -310,9 +319,11 @@
 
         dataValues = sectionFormUtils.getDataValueMap( organisationUnit, dataSet, period );
 
-        validationErrors = sectionFormUtils.getValidationErrorMap( organisationUnit, dataSet, period );
-
-        if ( needsValidation && validationErrors.size() > 0 )
+        validationViolations = sectionFormUtils.getValidationErrorMap( organisationUnit, dataSet, period );
+
+        validationRuleViolations = sectionFormUtils.getValidationRuleViolations( organisationUnit, dataSet, period );
+
+        if ( needsValidation && validationViolations.size() > 0 )
         {
             return ERROR;
         }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java	2011-09-29 10:23:26 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/utils/SectionFormUtils.java	2011-09-30 10:39:41 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.datavalue.DeflatedDataValue;
+import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.minmax.MinMaxDataElement;
 import org.hisp.dhis.minmax.MinMaxDataElementService;
 import org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService;
@@ -49,6 +50,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.system.util.ListUtils;
+import org.hisp.dhis.validation.ValidationResult;
+import org.hisp.dhis.validation.ValidationRule;
+import org.hisp.dhis.validation.ValidationRuleService;
 
 /**
  * @author mortenoh
@@ -101,6 +105,20 @@
         this.minMaxDataElementService = minMaxDataElementService;
     }
 
+    private ValidationRuleService validationRuleService;
+
+    public void setValidationRuleService( ValidationRuleService validationRuleService )
+    {
+        this.validationRuleService = validationRuleService;
+    }
+
+    private ExpressionService expressionService;
+
+    public void setExpressionService( ExpressionService expressionService )
+    {
+        this.expressionService = expressionService;
+    }
+
     // -------------------------------------------------------------------------
     // Utils
     // -------------------------------------------------------------------------
@@ -145,6 +163,28 @@
         return validationErrorMap;
     }
 
+    public List<String> getValidationRuleViolations( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+    {
+        List<ValidationResult> validationRuleResults = new ArrayList<ValidationResult>( validationRuleService.validate(
+            dataSet, period, organisationUnit ) );
+
+        List<String> validationRuleViolations = new ArrayList<String>( validationRuleResults.size() );
+
+        for ( ValidationResult result : validationRuleResults )
+        {
+            ValidationRule rule = result.getValidationRule();
+
+            StringBuffer sb = new StringBuffer();
+            sb.append( expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) );
+            sb.append( " " + rule.getOperator().getMathematicalOperator() + " " );
+            sb.append( expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) );
+
+            validationRuleViolations.add( sb.toString() );
+        }
+
+        return validationRuleViolations;
+    }
+
     public Map<String, String> getDataValueMap( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
     {
         Map<String, String> dataValueMap = new HashMap<String, String>();
@@ -177,12 +217,14 @@
         {
             integerValue = Integer.parseInt( value );
 
-            if(integerValue > max)
+            if ( integerValue > max )
             {
                 return true;
             }
-        } catch ( NumberFormatException e )
-        { }
+        }
+        catch ( NumberFormatException e )
+        {
+        }
 
         return false;
     }
@@ -195,12 +237,14 @@
         {
             integerValue = Integer.parseInt( value );
 
-            if(integerValue < min)
+            if ( integerValue < min )
             {
                 return true;
             }
-        } catch ( NumberFormatException e )
-        { }
+        }
+        catch ( NumberFormatException e )
+        {
+        }
 
         return false;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-09-29 08:14:40 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-09-30 10:39:41 +0000
@@ -14,6 +14,8 @@
     <property name="minMaxValuesGenerationService" ref="org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService" />
     <property name="minMaxDataElementService" ref="org.hisp.dhis.minmax.MinMaxDataElementService" />
     <property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
+    <property name="validationRuleService" ref="org.hisp.dhis.validation.ValidationRuleService" />
+    <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
   </bean>
 
   <bean id="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction" class="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction">

=== 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-29 10:23:26 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntry.vm	2011-09-30 10:39:41 +0000
@@ -3,6 +3,17 @@
 
 <h2>$dataSet.name</h2>
 
+#if( $validationRuleViolations.size() > 0 )
+<div class="header-box" align="center">
+	<h3 style="text-align: left; background-color: #990000; color: white;">Validation Rule Violations</h3>
+	<p style="text-align: left;">
+	#foreach( $validationRuleViolation in $validationRuleViolations )
+		$validationRuleViolation <br />
+	#end
+	</p>
+</div>
+#end
+
 <form action="saveSectionForm.action" method="POST">
 
 <input type="hidden" id="organisationUnitId" name="organisationUnitId" value="$organisationUnitId" />
@@ -19,13 +30,13 @@
 				#set( $key = "DE${dataElement.id}OC${optionCombo.id}" )
 				<label>$dataElement.name $optionCombo.name</label>
 
-				#if( $validationErrors.get( $key ) )
-				#set( $validationError = $validationErrors.get( $key ) )
+				#if( $validationViolations.get( $key ) )
+				#set( $validationViolation = $validationViolations.get( $key ) )
 
-                #if( $sectionFormUtils.valueHigher( $validationError.value, $validationError.max ) )
-                    <br /><span style="color: red;">Too high (max $validationError.max)</span>
-                #elseif( $sectionFormUtils.valueLower( $validationError.value, $validationError.min ) )
-                    <br /><span style="color: red;">Too low (min $validationError.min)</span>
+                #if( $sectionFormUtils.valueHigher( $validationViolation.value, $validationViolation.max ) )
+                    <br /><span style="color: #990000;">Too high (max $validationViolation.max)</span>
+                #elseif( $sectionFormUtils.valueLower( $validationViolation.value, $validationViolation.min ) )
+                    <br /><span style="color: red;">Too low (min $validationViolation.min)</span>
                 #else
                     <br /><span style="color: red;">Not a number</span>
                 #end