← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8956: Improve program validation rule (WIP).

 

------------------------------------------------------------
revno: 8956
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-11-09 10:14:42 +0700
message:
  Improve program validation rule (WIP).
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java	2012-11-08 16:07:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java	2012-11-09 03:14:42 +0000
@@ -133,14 +133,12 @@
             
             if ( (leftSideValue != null && rightSideValue.equals( NOT_NULL_VALUE_IN_EXPRESSION ) && rightSideValue == null)
                 || ( !(leftSideValue != null && rightSideValue != null 
-                    && ((operator.equals( "==" ) && leftSideValue.equals( rightSideValue ))
-                    || (operator.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0)
-                    || (operator.equals( "<=" ) && (leftSideValue.equals( rightSideValue ) || leftSideValue
-                        .compareTo( rightSideValue ) < 0))
+                    && ( (operator.equals( "==" ) && leftSideValue.compareTo( rightSideValue )==0 )
+                    || (operator.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0 )
+                    || (operator.equals( "<=" ) && (leftSideValue.compareTo( rightSideValue ) <= 0))
                     || (operator.equals( ">" ) && leftSideValue.compareTo( rightSideValue ) > 0)
-                    || (operator.equals( ">=" ) && (leftSideValue.equals( rightSideValue ) || leftSideValue
-                        .compareTo( rightSideValue ) > 0)) || (operator.equals( "!=" ) && !leftSideValue
-                    .equals( rightSideValue ))))) )
+                    || (operator.equals( ">=" ) && leftSideValue.compareTo( rightSideValue ) >= 0)) 
+                    || (operator.equals( "!=" ) && leftSideValue.compareTo( rightSideValue ) ==0  ))) )
             {
                 return new ProgramValidationResult( programStageInstance, validation, leftSideValue, rightSideValue );
             }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java	2012-11-08 16:07:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ValidateProgramInstanceAction.java	2012-11-09 03:14:42 +0000
@@ -34,8 +34,8 @@
 import java.util.Map;
 
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
-import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.program.ProgramExpressionService;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramValidation;
 import org.hisp.dhis.program.ProgramValidationResult;
@@ -58,6 +58,8 @@
 
     private ProgramValidationService programValidationService;
 
+    private ProgramExpressionService programExpressionService;
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -70,14 +72,19 @@
 
     private List<ProgramValidationResult> programValidationResults;
 
-    private Map<Integer, String> leftsideFormulaMap;
+    private Map<Integer, String> leftsideFormulaMap = new HashMap<Integer, String>();
 
-    private Map<Integer, String> rightsideFormulaMap;
+    private Map<Integer, String> rightsideFormulaMap = new HashMap<Integer, String>();
 
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
 
+    public void setProgramExpressionService( ProgramExpressionService programExpressionService )
+    {
+        this.programExpressionService = programExpressionService;
+    }
+
     public void setSelectedStateManager( SelectedStateManager selectedStateManager )
     {
         this.selectedStateManager = selectedStateManager;
@@ -123,7 +130,7 @@
         // ---------------------------------------------------------------------
 
         ProgramStageInstance programStageInstance = selectedStateManager.getSelectedProgramStageInstance();
-        
+
         // ---------------------------------------------------------------------
         // Check validations for dataelement into multi-stages
         // ---------------------------------------------------------------------
@@ -145,11 +152,22 @@
         {
             for ( ProgramValidation validation : validations )
             {
-                ProgramValidationResult validationResult = programValidationService.validate( validation, programStageInstance, format );
+                ProgramValidationResult validationResult = programValidationService.validate( validation,
+                    programStageInstance, format );
 
                 if ( validationResult != null )
                 {
                     programValidationResults.add( validationResult );
+                    
+                    leftsideFormulaMap.put(
+                        validationResult.getProgramValidation().getId(),
+                        programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
+                            .getLeftSide().getExpression() ) );
+                    
+                    rightsideFormulaMap.put(
+                        validationResult.getProgramValidation().getId(),
+                        programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
+                            .getRightSide().getExpression() ) );
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-11-08 02:58:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-11-09 03:14:42 +0000
@@ -323,6 +323,8 @@
 			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 		<property name="programValidationService"
 			ref="org.hisp.dhis.program.ProgramValidationService" />
+		<property name="programExpressionService"
+			ref="org.hisp.dhis.program.ProgramExpressionService" />
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-11-08 18:59:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-11-09 03:14:42 +0000
@@ -59,7 +59,7 @@
 					<input type="text" id='endDate' name='endDate' style="width:90px;">
 				</td>
 				<td>
-					<input type="button" class='large-button' id='listBtn' value="$i18n.getString( 'search' )" onclick='validateSearchEvents( true );'>
+					<input type="button" class='large-button' id='listBtn' value="$i18n.getString( 'update' )" onclick='validateSearchEvents( true );'>
 				</td>
 				<td>
 					<input type="button" class='large-button' id='advancedBtn' value='$i18n.getString( "add_filter" )' onclick="filterDivToogle();" isShown="false" style="width:140px;">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-11-08 18:59:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-11-09 03:14:42 +0000
@@ -605,7 +605,6 @@
 			$.ajax({
 				url: "getOptions.action?id=" + dataElementId + "&query=" + input.val(),
 				dataType: "json",
-				cache: true,
 				success: function(data) {
 					response($.map(data.options, function(item) {
 						return {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/validationResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/validationResult.vm	2012-11-08 16:07:27 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/validationResult.vm	2012-11-09 03:14:42 +0000
@@ -32,12 +32,17 @@
 						#set ( $leftFormula = $leftsideFormulaMap.get( $id ) )
 						#set ( $rightFormula = $rightsideFormulaMap.get( $id ) )
 						<tr>
+							#set($leftsideValue = "NULL")
+							#if($result.leftsideValue) #set($leftsideValue = $result.leftsideValue) #end
+							#set($rightsideValue = "NULL")
+							#if($result.rightsideValue) #set($rightsideValue = $result.rightsideValue ) #end
+							
 							<td style="height:32px">$encoder.htmlEncode( $result.programValidation.description )</td>
 							<td>$!encoder.htmlEncode( $leftFormula ) $encoder.htmlEncode( $i18n.getString( $result.programValidation.operator.mathematicalOperator ) ) $!encoder.htmlEncode( $rightFormula )</td>
 							<td>$!encoder.htmlEncode( $result.programValidation.leftSide.description )</td>
-							<td>$result.leftsideValue</td>
+							<td>$leftsideValue</td>
 							<td>$encoder.htmlEncode( $i18n.getString( $result.programValidation.operator.mathematicalOperator ) )</td>
-							<td>$result.rightsideValue</td>
+							<td>$rightsideValue</td>
 							<td>$!encoder.htmlEncode( $result.programValidation.rightSide.description )</td>
 						</tr>
 					#set( $mark = !$mark )