← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16643: Validation rules, custom forms, getting data elements from data set instead of parsing custom for...

 

------------------------------------------------------------
revno: 16643
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-09-07 22:02:09 -0400
message:
  Validation rules, custom forms, getting data elements from data set instead of parsing custom form in data entry validation
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.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-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2014-09-08 02:02:09 +0000
@@ -53,8 +53,6 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
-import org.hisp.dhis.dataelement.DataElementOperand;
-import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.expression.ExpressionService;
@@ -112,13 +110,6 @@
         this.expressionService = expressionService;
     }
 
-    private DataEntryFormService dataEntryFormService;
-
-    public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
-    {
-        this.dataEntryFormService = dataEntryFormService;
-    }
-
     private PeriodService periodService;
 
     public void setPeriodService( PeriodService periodService )
@@ -242,17 +233,8 @@
         Collection<Period> periods = new ArrayList<>();
         periods.add( period );
 
-        Collection<ValidationRule> rules = null;
-        
-        if ( DataSet.TYPE_CUSTOM.equals( dataSet.getDataSetType() ) )
-        {
-            rules = getRulesForDataSet( dataSet );
-        }
-        else
-        {
-            rules = getValidationTypeRulesForDataElements( dataSet.getDataElements() );
-        }
-        
+        Collection<ValidationRule> rules = getValidationTypeRulesForDataElements( dataSet.getDataElements() );
+                
         log.info( "Using validation rules: " + rules.size() );
         
         Collection<OrganisationUnit> sources = new HashSet<>();
@@ -597,39 +579,6 @@
 
         return rulesForDataElements;
     }
-
-    /**
-     * Returns all validation rules which have data elements assigned to them
-     * which are members of the given data set.
-     * 
-     * @param dataSet the data set
-     * @return all validation rules which have data elements assigned to them
-     *         which are members of the given data set
-     */
-    private Collection<ValidationRule> getRulesForDataSet( DataSet dataSet )
-    {
-        Set<ValidationRule> rulesForDataSet = new HashSet<>();
-
-        Set<DataElementOperand> operands = dataEntryFormService.getOperandsInDataEntryForm( dataSet );
-
-        Set<DataElementOperand> validationRuleOperands = new HashSet<>();
-
-        for ( ValidationRule rule : getAllValidationRules() )
-        {
-            validationRuleOperands.clear();
-            validationRuleOperands.addAll( expressionService.getOperandsInExpression(
-                rule.getLeftSide().getExpression() ) );
-            validationRuleOperands.addAll( expressionService.getOperandsInExpression(
-                rule.getRightSide().getExpression() ) );
-
-            if ( operands.containsAll( validationRuleOperands ) )
-            {
-                rulesForDataSet.add( rule );
-            }
-        }
-
-        return rulesForDataSet;
-    }
     
     /**
      * Formats and sets name on the period of each result.

=== 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	2014-08-29 13:03:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-09-08 02:02:09 +0000
@@ -515,7 +515,6 @@
     <property name="validationRuleStore" ref="org.hisp.dhis.validation.ValidationRuleStore" />
     <property name="validationRuleGroupStore" ref="org.hisp.dhis.validation.ValidationRuleGroupStore" />
     <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
-    <property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
     <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
     <property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
     <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />

=== 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	2014-08-06 19:15:50 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2014-09-08 02:02:09 +0000
@@ -56,7 +56,7 @@
         
         if ( isDefined( formula ) )
         {        
-	        var expression = generateExpression( formula );
+	        var expression = dhis2.de.generateExpression( formula );
 	
 	        if ( expression )
 	        {
@@ -118,7 +118,7 @@
  * Parses the expression and substitutes the operand identifiers with the value
  * of the corresponding input entry field.
  */
-function generateExpression( expression )
+dhis2.de.generateExpression = function( expression )
 {
     var matcher = expression.match( FORMULA_PATTERN );
 
@@ -187,35 +187,35 @@
         {
             if ( value.length > 255 )
             {
-                return alertField( fieldId, i18n_value_too_long + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_too_long + '\n\n' + dataElementName );
             }
             if ( type == 'int' && !dhis2.validation.isInt( value ) )
             {
-                return alertField( fieldId, i18n_value_must_integer + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_must_integer + '\n\n' + dataElementName );
             }
             if ( type == 'number' && !dhis2.validation.isNumber( value ) )
             {
-                return alertField( fieldId, i18n_value_must_number + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_must_number + '\n\n' + dataElementName );
             }
             if ( type == 'posInt' && !dhis2.validation.isPositiveInt( value ) )
             {
-                return alertField( fieldId, i18n_value_must_positive_integer + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_must_positive_integer + '\n\n' + dataElementName );
             }
             if ( type == 'negInt' && !dhis2.validation.isNegativeInt( value ) )
             {
-                return alertField( fieldId, i18n_value_must_negative_integer + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_must_negative_integer + '\n\n' + dataElementName );
             }
             if ( type == 'zeroPositiveInt' && !dhis2.validation.isZeroOrPositiveInt( value ) )
             {
-                return alertField( fieldId, i18n_value_must_zero_or_positive_integer + '\n\n' + dataElementName );
+                return dhis2.de.alertField( fieldId, i18n_value_must_zero_or_positive_integer + '\n\n' + dataElementName );
             }
             if ( type == 'unitInterval' && !dhis2.validation.isUnitInterval( value ) )
             {
-            	return alertField( fieldId, i18n_value_must_unit_interval + '\n\n' + dataElementName );
+            	return dhis2.de.alertField( fieldId, i18n_value_must_unit_interval + '\n\n' + dataElementName );
             }
             if ( type == 'percentage' && !dhis2.validation.isPercentage( value ) )
             {
-            	return alertField( fieldId, i18n_value_must_percentage + '\n\n' + dataElementName );
+            	return dhis2.de.alertField( fieldId, i18n_value_must_percentage + '\n\n' + dataElementName );
             }
             if ( !existing && dhis2.validation.isValidZeroNumber( value ) )
             {
@@ -298,7 +298,7 @@
 /**
  * Supportive method.
  */
-function alertField( fieldId, alertMessage )
+dhis2.de.alertField = function( fieldId, alertMessage )
 {
     var $field = $( fieldId );
     $field.css( 'background-color', COLOR_YELLOW );