dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21569
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10236: implemented proper validation for multi-org units
------------------------------------------------------------
revno: 10236
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-15 11:53:19 +0700
message:
implemented proper validation for multi-org units
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java
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/validationResult.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-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java 2013-03-07 05:40:43 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java 2013-03-15 04:53:19 +0000
@@ -27,16 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.ListUtils.getCollection;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
+import com.opensymphony.xwork2.Action;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
@@ -54,7 +45,14 @@
import org.hisp.dhis.validation.ValidationRule;
import org.hisp.dhis.validation.ValidationRuleService;
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.hisp.dhis.system.util.ListUtils.getCollection;
/**
* @author Margrethe Store
@@ -152,30 +150,30 @@
// Output
// -------------------------------------------------------------------------
- private List<ValidationResult> results;
-
- public List<ValidationResult> getResults()
- {
- return results;
- }
-
- private Map<Integer, String> leftsideFormulaMap;
-
- public Map<Integer, String> getLeftsideFormulaMap()
- {
- return leftsideFormulaMap;
- }
-
- private Map<Integer, String> rightsideFormulaMap;
-
- public Map<Integer, String> getRightsideFormulaMap()
- {
- return rightsideFormulaMap;
- }
-
- private Collection<DeflatedDataValue> dataValues = new HashSet<DeflatedDataValue>();
-
- public Collection<DeflatedDataValue> getDataValues()
+ private Map<OrganisationUnit, List<ValidationResult>> validationResults = new TreeMap<OrganisationUnit, List<ValidationResult>>();
+
+ public Map<OrganisationUnit, List<ValidationResult>> getValidationResults()
+ {
+ return validationResults;
+ }
+
+ private Map<OrganisationUnit, Map<Integer, String>> leftSideFormulaMap = new HashMap<OrganisationUnit, Map<Integer, String>>();
+
+ public Map<OrganisationUnit, Map<Integer, String>> getLeftSideFormulaMap()
+ {
+ return leftSideFormulaMap;
+ }
+
+ private Map<OrganisationUnit, Map<Integer, String>> rightSideFormulaMap = new HashMap<OrganisationUnit, Map<Integer, String>>();
+
+ public Map<OrganisationUnit, Map<Integer, String>> getRightSideFormulaMap()
+ {
+ return rightSideFormulaMap;
+ }
+
+ private Map<OrganisationUnit, List<DeflatedDataValue>> dataValues = new TreeMap<OrganisationUnit, List<DeflatedDataValue>>();
+
+ public Map<OrganisationUnit, List<DeflatedDataValue>> getDataValues()
{
return dataValues;
}
@@ -193,88 +191,89 @@
Period selectedPeriod = PeriodType.createPeriodExternalId( periodId );
- Period period = null;
-
- if ( selectedPeriod != null )
- {
- period = periodService.getPeriod( selectedPeriod.getStartDate(), selectedPeriod.getEndDate(),
- selectedPeriod.getPeriodType() );
-
- if ( validationCheck( orgUnit, dataSet, period ).equals( INPUT ) )
- {
- return INPUT;
- }
- }
-
- if ( multiOrganisationUnit && selectedPeriod != null )
- {
- List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
-
- Collections.sort( children, IdentifiableObjectNameComparator.INSTANCE );
-
- for ( OrganisationUnit child : children )
- {
- if ( validationCheck( child, dataSet, period ).equals( INPUT ) )
- {
- return INPUT;
- }
- }
- }
-
- return dataValues.size() == 0 && results.size() == 0 ? SUCCESS : INPUT;
- }
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private String validationCheck( OrganisationUnit unit, DataSet dataSet, Period period )
- {
- if ( unit != null )
- {
- // ---------------------------------------------------------------------
- // Min-max and outlier analysis
- // ---------------------------------------------------------------------
-
- dataValues = minMaxOutlierAnalysisService.analyse( getCollection( unit ), dataSet.getDataElements(),
- getCollection( period ), null );
-
- log.debug( "Number of outlier values: " + dataValues.size() );
-
- if ( dataValues.size() > 0 )
- {
- return INPUT;
- }
-
- // ---------------------------------------------------------------------
- // Validation rule analysis
- // ---------------------------------------------------------------------
-
- results = new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, unit ) );
-
- log.debug( "Number of validation violations: " + results.size() );
-
- if ( results.size() > 0 )
- {
- leftsideFormulaMap = new HashMap<Integer, String>( results.size() );
- rightsideFormulaMap = new HashMap<Integer, String>( results.size() );
-
- for ( ValidationResult result : results )
- {
- ValidationRule rule = result.getValidationRule();
-
- leftsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule
- .getLeftSide().getExpression() ) );
-
- rightsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule
- .getRightSide().getExpression() ) );
- }
-
- return INPUT;
- }
- }
-
- return NONE;
- }
-
+ if ( selectedPeriod == null || orgUnit == null || (multiOrganisationUnit && !orgUnit.hasChild()) )
+ {
+ return SUCCESS;
+ }
+
+ Period period = periodService.getPeriod( selectedPeriod.getStartDate(), selectedPeriod.getEndDate(),
+ selectedPeriod.getPeriodType() );
+
+ List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
+
+ if ( !multiOrganisationUnit )
+ {
+ organisationUnits.add( orgUnit );
+ }
+ else
+ {
+ organisationUnits.addAll( orgUnit.getChildren() );
+ }
+
+ Collections.sort( organisationUnits, IdentifiableObjectNameComparator.INSTANCE );
+
+ for ( OrganisationUnit organisationUnit : organisationUnits )
+ {
+ List<DeflatedDataValue> values = outlierAnalysis( organisationUnit, dataSet, period );
+
+ if ( !values.isEmpty() )
+ {
+ dataValues.put( organisationUnit, values );
+ }
+
+ List<ValidationResult> results = validationRuleAnalysis( organisationUnit, dataSet, period );
+
+ if ( !results.isEmpty() )
+ {
+ validationResults.put( organisationUnit, results );
+ }
+ }
+
+ return dataValues.size() == 0 && validationResults.size() == 0 ? SUCCESS : INPUT;
+ }
+
+ // ---------------------------------------------------------------------
+ // Min-max and outlier analysis
+ // ---------------------------------------------------------------------
+ private List<DeflatedDataValue> outlierAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+ {
+ List<DeflatedDataValue> deflatedDataValues = new ArrayList<DeflatedDataValue>( minMaxOutlierAnalysisService.analyse( getCollection( organisationUnit ),
+ dataSet.getDataElements(), getCollection( period ), null ) );
+
+ log.debug( "Number of outlier values: " + deflatedDataValues.size() );
+
+ return deflatedDataValues;
+ }
+
+ // ---------------------------------------------------------------------
+ // Validation rule analysis
+ // ---------------------------------------------------------------------
+ private List<ValidationResult> validationRuleAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
+ {
+ List<ValidationResult> validationResults = new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, organisationUnit ) );
+
+ log.debug( "Number of validation violations: " + validationResults.size() );
+
+ if ( validationResults.size() > 0 )
+ {
+ Map<Integer, String> leftSideFormulas = new HashMap<Integer, String>( validationResults.size() );
+ Map<Integer, String> rightSideFormulas = new HashMap<Integer, String>( validationResults.size() );
+
+ for ( ValidationResult validationResult : validationResults )
+ {
+ ValidationRule rule = validationResult.getValidationRule();
+
+ leftSideFormulas.put( rule.getId(), expressionService.getExpressionDescription( rule
+ .getLeftSide().getExpression() ) );
+
+ rightSideFormulas.put( rule.getId(), expressionService.getExpressionDescription( rule
+ .getRightSide().getExpression() ) );
+ }
+
+ leftSideFormulaMap.put( organisationUnit, leftSideFormulas );
+ rightSideFormulaMap.put( organisationUnit, rightSideFormulas );
+ }
+
+ return validationResults;
+ }
}
=== 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 2013-03-06 03:56:21 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-03-15 04:53:19 +0000
@@ -1207,6 +1207,10 @@
{
addEventListeners();
+ $( '#validationButton' ).removeAttr( 'disabled' );
+ $( '#validateButton' ).removeAttr( 'disabled' );
+
+ /*
if ( !multiOrganisationUnit )
{
$( '#validationButton' ).removeAttr( 'disabled' );
@@ -1217,6 +1221,7 @@
$( '#validationButton' ).attr( 'disabled', true );
$( '#validateButton' ).attr( 'disabled', true );
}
+ */
dataEntryFormIsLoaded = true;
hideLoader();
@@ -1465,10 +1470,8 @@
var params = storageManager.getCurrentCompleteDataSetParams();
params['organisationUnitId'] = selection.getSelected();
params['multiOrganisationUnit'] = multiOrganisationUnit;
-
- $( '#validationDiv' ).load( 'validate.action', params,
- function( response, status, xhr )
- {
+
+ $( '#validationDiv' ).load( 'validate.action', params, function( response, status, xhr ) {
var success = null;
if ( status == 'error' && !ignoreSuccessfulValidation )
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm 2012-12-04 17:33:33 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm 2013-03-15 04:53:19 +0000
@@ -2,7 +2,12 @@
<p class="bold">$i18n.getString( "data_entry_screen_has_following_errors" )</p>
-#if( $results.size() > 0)
+#if( !$validationResults.isEmpty() )
+ #foreach( $key in $validationResults.keySet() )
+ #set( $results = $validationResults.get($key))
+
+ <h3>$key.displayName</h3>
+
<table class="listTable" width="100%">
<tr>
<th>$i18n.getString( "validation_rule" )</th>
@@ -12,16 +17,16 @@
<th style="width:65px">$i18n.getString( "right_side" )</th>
</tr>
#set( $mark = false )
- #foreach( $result in $results )
- #set ( $id = $result.validationRule.id )
- #set ( $leftFormula = $leftsideFormulaMap.get( $id ) )
- #set ( $rightFormula = $rightsideFormulaMap.get( $id ) )
+ #foreach( $validationResult in $results )
+ #set ( $id = $validationResult.validationRule.id )
+ #set ( $leftFormula = $leftSideFormulaMap.get( $key ).get( $id ) )
+ #set ( $rightFormula = $rightSideFormulaMap.get( $key ).get( $id ) )
<tr>
- <td style="height:32px"#alternate( $mark )>$encoder.htmlEncode( $result.validationRule.getDescriptionNameFallback() )</td>
- <td#alternate( $mark )>$!encoder.htmlEncode( $leftFormula ) $encoder.htmlEncode( $i18n.getString( $result.validationRule.operator.mathematicalOperator ) ) $!encoder.htmlEncode( $rightFormula )</td>
- <td#alternate( $mark )>$result.leftsideValue</td>
- <td#alternate( $mark )>$encoder.htmlEncode( $i18n.getString( $result.validationRule.operator.mathematicalOperator ) )</td>
- <td#alternate( $mark )>$result.rightsideValue</td>
+ <td style="height:32px"#alternate( $mark )>$encoder.htmlEncode( $validationResult.validationRule.getDescriptionNameFallback() )</td>
+ <td#alternate( $mark )>$!encoder.htmlEncode( $leftFormula ) $encoder.htmlEncode( $i18n.getString( $validationResult.validationRule.operator.mathematicalOperator ) ) $!encoder.htmlEncode( $rightFormula )</td>
+ <td#alternate( $mark )>$validationResult.leftsideValue</td>
+ <td#alternate( $mark )>$encoder.htmlEncode( $i18n.getString( $validationResult.validationRule.operator.mathematicalOperator ) )</td>
+ <td#alternate( $mark )>$validationResult.rightsideValue</td>
</tr>
#if( $mark )
#set( $mark = false )
@@ -30,9 +35,15 @@
#end
#end
</table><br>
+ #end
#end
-#if( $dataValues.size() > 0 )
+#if( !$dataValues.isEmpty() )
+ #foreach( $key in $dataValues.keySet() )
+ #set( $results = $dataValues.get( $key ))
+
+ <h3>$key.displayName</h3>
+
<p class="bold">$encoder.htmlEncode( $i18n.getString( "the_following_values_are_outliers" ) )</p>
<table class="listTable" style="width:100%">
<tr>
@@ -42,7 +53,7 @@
<th style="text-align:center">$i18n.getString( "max" )</th>
</tr>
#set( $mark = false )
- #foreach( $value in $dataValues )
+ #foreach( $value in $results )
<tr>
<td style="height:32px"#alternate( $mark )>$value.dataElementName $value.categoryOptionComboNameParsed</td>
<td style="text-align:center"#alternate( $mark )>$value.min</td>
@@ -56,4 +67,5 @@
#end
#end
</table>
+ #end
#end