← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1373: Improved dataentry validation gui.

 

------------------------------------------------------------
revno: 1373
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-01-29 14:22:17 +0100
message:
  Improved dataentry validation gui.
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java
  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/resources/META-INF/dhis/beans.xml
  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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2010-01-20 10:06:43 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2010-01-29 13:22:17 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -94,4 +95,22 @@
         
         return duplicates;
     }
+    
+    /**
+     * Returns a Collection with the given items.
+     * 
+     * @param items the items which should be included in the Collection.
+     * @return a Collection.
+     */
+    public static <T> Collection<T> getCollection( T... items )
+    {
+        List<T> list = new ArrayList<T>();
+        
+        for ( T item : items )
+        {
+            list.add( item );
+        }
+        
+        return list;
+    }
 }

=== 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	2009-12-09 08:57:51 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java	2010-01-29 13:22:17 +0000
@@ -28,19 +28,22 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataanalysis.DataAnalysisService;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
 import org.hisp.dhis.de.state.SelectedStateManager;
-import org.hisp.dhis.expression.Expression;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
+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;
@@ -56,6 +59,8 @@
 {
     private static final Log log = LogFactory.getLog( ValidationAction.class );
 
+    private static final double STD_DEV = 2.0;
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -87,6 +92,13 @@
     {
         this.periodService = periodService;
     }
+    
+    private DataAnalysisService stdDevOutlierAnalysisService;
+
+    public void setStdDevOutlierAnalysisService( DataAnalysisService stdDevOutlierAnalysisService )
+    {
+        this.stdDevOutlierAnalysisService = stdDevOutlierAnalysisService;
+    }
 
     // -------------------------------------------------------------------------
     // Output
@@ -99,20 +111,6 @@
         return results;
     }
 
-    private Map<Integer, Expression> leftsideMap;
-
-    public Map<Integer, Expression> getLeftsideMap()
-    {
-        return leftsideMap;
-    }
-
-    private Map<Integer, Expression> rightsideMap;
-
-    public Map<Integer, Expression> getRightsideMap()
-    {
-        return rightsideMap;
-    }
-
     private Map<Integer, String> leftsideFormulaMap;
 
     public Map<Integer, String> getLeftsideFormulaMap()
@@ -127,6 +125,13 @@
         return rightsideFormulaMap;
     }
 
+    private Collection<DeflatedDataValue> dataValues;
+
+    public Collection<DeflatedDataValue> getDataValues()
+    {
+        return dataValues;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -145,36 +150,30 @@
 
         results = new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, orgUnit ) );
 
-        log.info( "Numer of validation violations: " + results.size() );
-
+        log.info( "Number of validation violations: " + results.size() );
+        
         if ( results.size() == 0 )
         {
             return NONE;
         }
         else
         {
-            leftsideMap = new HashMap<Integer, Expression>( results.size() );
-            rightsideMap = new HashMap<Integer, Expression>( results.size() );
-
             leftsideFormulaMap = new HashMap<Integer, String>( results.size() );
             rightsideFormulaMap = new HashMap<Integer, String>( results.size() );
 
             for ( ValidationResult result : results )
             {
                 ValidationRule rule = result.getValidationRule();
-                int id = rule.getId();
-
-                Expression leftside = rule.getLeftSide();
-                Expression rightside = rule.getRightSide();
-
-                leftsideMap.put( id, leftside );
-                rightsideMap.put( id, rightside );
-
-                leftsideFormulaMap.put( id, expressionService.getExpressionDescription( leftside.getExpression() ) );
-                rightsideFormulaMap.put( id, expressionService.getExpressionDescription( rightside.getExpression() ) );
+
+                leftsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule.getLeftSide().getExpression() ) );
+                rightsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule.getRightSide().getExpression() ) );
             }
         }
+        
+        dataValues = stdDevOutlierAnalysisService.analyse( orgUnit, dataSet.getDataElements(), ListUtils.getCollection( period ), STD_DEV );
 
+        log.info( "Number of outlier values: " + dataValues.size() );
+        
         return SUCCESS;
     }
 }

=== 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	2010-01-28 23:08:44 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2010-01-29 13:22:17 +0000
@@ -293,6 +293,7 @@
 		</property>
 		<property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
 		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+		<property name="stdDevOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.StdDevOutlierAnalysisService"/>
 	</bean>
 	
 	<bean id="org.hisp.dhis.de.action.MarkForFollowupAction" class="org.hisp.dhis.de.action.MarkForFollowupAction">

=== 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	2010-01-29 09:39:22 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/validationResult.vm	2010-01-29 13:22:17 +0000
@@ -1,41 +1,40 @@
 <h3>$encoder.htmlEncode( $i18n.getString( "validation_result" ) )</h3>
 
 #if( $results.size() == 0)
-	<p><b>$encoder.htmlEncode( $i18n.getString( "successful_validation" ) )</b></p>
+    <p><b>$encoder.htmlEncode( $i18n.getString( "successful_validation" ) )</b></p>
 #else
-	<p><b>$encoder.htmlEncode( $i18n.getString( "unsuccessful_validation" ) )</b></p>
-	<table width="100%">
-		<thead>
-			<tr>
-				<th style="width:110px">$encoder.htmlEncode( $i18n.getString( "validation_rule" ) )</th>				
-				<th>$encoder.htmlEncode( $i18n.getString( "expression" ) )</th>
-				<th>$encoder.htmlEncode( $i18n.getString( "description" ) )</th>
-    			<th>$encoder.htmlEncode( $i18n.getString( "value" ) )</th>
-    			<th>$encoder.htmlEncode( $i18n.getString( "operator" ) )</th>
-    			<th>$encoder.htmlEncode( $i18n.getString( "value" ) )</th>
-				<th>$encoder.htmlEncode( $i18n.getString( "description" ) )</th>
-			</tr>
-		</thead>
-		
-		<tbody>		
-		#foreach( $result in $results )
-			#set ( $id = $result.validationRule.id )
-			#set ( $leftside = $leftsideMap.get( $id ) )
-			#set ( $rightside = $rightsideMap.get( $id ) )
-			#set ( $leftFormula = $leftsideFormulaMap.get( $id ) )
-			#set ( $rightFormula = $rightsideFormulaMap.get( $id ) )
-			<tr>
-				<td>$encoder.htmlEncode( $result.validationRule.name )</td>
-				<td>$leftFormula $result.validationRule.operator $rightFormula</td>
-				<td>$!encoder.htmlEncode( $leftside.description )</td>
-    			<td>$result.leftsideValue</td>
-    			<td>$encoder.htmlEncode( $i18n.getString( $result.validationRule.operator ) )</td>
-    			<td>$result.rightsideValue</td>
-				<td>$!encoder.htmlEncode( $rightside.description )</td>
-			</tr>
-		#end
-		</tbody>
-	</table>			
+    <p><b>$encoder.htmlEncode( $i18n.getString( "unsuccessful_validation" ) )</b></p>
+    <table class="listTable" width="100%">
+        <tr>
+            <th style="width:110px">$encoder.htmlEncode( $i18n.getString( "validation_rule" ) )</th>                
+            <th>$encoder.htmlEncode( $i18n.getString( "expression" ) )</th>
+            <th>$encoder.htmlEncode( $i18n.getString( "description" ) )</th>
+            <th>$encoder.htmlEncode( $i18n.getString( "value" ) )</th>
+            <th>$encoder.htmlEncode( $i18n.getString( "operator" ) )</th>
+            <th>$encoder.htmlEncode( $i18n.getString( "value" ) )</th>
+            <th>$encoder.htmlEncode( $i18n.getString( "description" ) )</th>
+        </tr>
+        #set( $mark = false )   
+        #foreach( $result in $results )
+            #set ( $id = $result.validationRule.id )
+            #set ( $leftFormula = $leftsideFormulaMap.get( $id ) )
+            #set ( $rightFormula = $rightsideFormulaMap.get( $id ) )
+            <tr>
+                <td#alternate( $mark )>$encoder.htmlEncode( $result.validationRule.name )</td>
+                <td#alternate( $mark )>$leftFormula $result.validationRule.operator $rightFormula</td>
+                <td#alternate( $mark )>$!encoder.htmlEncode( $result.validationRule.leftSide.description )</td>
+                <td#alternate( $mark )>$result.leftsideValue</td>
+                <td#alternate( $mark )>$encoder.htmlEncode( $i18n.getString( $result.validationRule.operator ) )</td>
+                <td#alternate( $mark )>$result.rightsideValue</td>
+                <td#alternate( $mark )>$!encoder.htmlEncode( $result.validationRule.rightSide.description )</td>
+            </tr>
+        #if( $mark )
+            #set( $mark = false )
+        #else
+            #set( $mark = true )
+        #end
+        #end
+    </table>            
 #end
 
 <p><input type="button" value="$encoder.htmlEncode( $i18n.getString( "close" ) )" style="width:10em" onclick="window.close()"></p>