← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8948: Exception thrown if to move a data element from Available tab to Selected tab in tabular report.

 

------------------------------------------------------------
revno: 8948
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-11-08 20:09:31 +0700
message:
  Exception thrown if to move a data element from Available tab to Selected tab in tabular report.
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationDescriptionAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java
  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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramValidation.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddProgramValidationAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateProgramValidationAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml


--
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-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2012-01-15 14:53:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2012-11-08 13:09:31 +0000
@@ -29,6 +29,8 @@
 
 import java.io.Serializable;
 
+import org.hisp.dhis.expression.Operator;
+
 /**
  * @author Chau Thu Tran
  * @version $ ProgramValidation.java Apr 28, 2011 10:27:29 AM $
@@ -66,6 +68,9 @@
     public static final int AFTER_OR_EQUALS_TO_DUE_DATE = -4;
     
     public static final int BEFORE_DUE_DATE_PLUS_OR_MINUS_MAX_DAYS = -5;
+    
+
+    public static final String NOT_NULL_VALUE_IN_EXPRESSION = "{NOT-NULL-VALUE}";
 
     // -------------------------------------------------------------------------
     // Fields
@@ -75,9 +80,11 @@
 
     private String description;
 
-    private String leftSide;
+    private ProgramExpression leftSide;
+    
+    private Operator operator;
 
-    private String rightSide;
+    private ProgramExpression rightSide;
 
     private Program program;
 
@@ -92,7 +99,7 @@
 
     }
 
-    public ProgramValidation( String description, String leftSide, String rightSide, Program program )
+    public ProgramValidation( String description, ProgramExpression leftSide, ProgramExpression rightSide, Program program )
     {
         this.description = description;
         this.leftSide = leftSide;
@@ -100,7 +107,7 @@
         this.program = program;
     }
 
-    public ProgramValidation( String description, String leftSide, String rightSide, Program program, Boolean dateType )
+    public ProgramValidation( String description, ProgramExpression leftSide, ProgramExpression rightSide, Program program, Boolean dateType )
     {
         this.description = description;
         this.leftSide = leftSide;
@@ -207,22 +214,22 @@
         this.description = description;
     }
 
-    public String getLeftSide()
+    public ProgramExpression getLeftSide()
     {
         return leftSide;
     }
 
-    public void setLeftSide( String leftSide )
+    public void setLeftSide( ProgramExpression leftSide )
     {
         this.leftSide = leftSide;
     }
 
-    public String getRightSide()
+    public ProgramExpression getRightSide()
     {
         return rightSide;
     }
 
-    public void setRightSide( String rightSide )
+    public void setRightSide( ProgramExpression rightSide )
     {
         this.rightSide = rightSide;
     }
@@ -246,4 +253,14 @@
     {
         this.dateType = dateType;
     }
+
+    public Operator getOperator()
+    {
+        return operator;
+    }
+
+    public void setOperator( Operator operator )
+    {
+        this.operator = operator;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java	2012-11-06 07:09:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidationService.java	2012-11-08 13:09:31 +0000
@@ -57,8 +57,6 @@
 
     Collection<ProgramValidation> getProgramValidation( ProgramStageDataElement psdataElement );
 
-    ProgramValidationResult runValidation( ProgramValidation validation,
+    ProgramValidationResult validate( ProgramValidation validation,
         ProgramStageInstance programStageInstance, I18nFormat format );
-
-    String getValidationDescription( String condition );
 }

=== 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-06 15:55:46 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java	2012-11-08 13:09:31 +0000
@@ -27,21 +27,12 @@
 
 package org.hisp.dhis.program;
 
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_ID;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
-import static org.hisp.dhis.program.ProgramValidation.AFTER_CURRENT_DATE;
-import static org.hisp.dhis.program.ProgramValidation.AFTER_DUE_DATE;
-import static org.hisp.dhis.program.ProgramValidation.AFTER_OR_EQUALS_TO_CURRENT_DATE;
-import static org.hisp.dhis.program.ProgramValidation.AFTER_OR_EQUALS_TO_DUE_DATE;
-import static org.hisp.dhis.program.ProgramValidation.BEFORE_CURRENT_DATE;
-import static org.hisp.dhis.program.ProgramValidation.BEFORE_DUE_DATE;
-import static org.hisp.dhis.program.ProgramValidation.BEFORE_DUE_DATE_PLUS_OR_MINUS_MAX_DAYS;
-import static org.hisp.dhis.program.ProgramValidation.BEFORE_OR_EQUALS_TO_CURRENT_DATE;
-import static org.hisp.dhis.program.ProgramValidation.BEFORE_OR_EQUALS_TO_DUE_DATE;
+import static org.hisp.dhis.program.ProgramExpression.NOT_NULL_VALUE_IN_EXPRESSION;
+import static org.hisp.dhis.program.ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT;
+import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_ID;
+import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_OBJECT;
 
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.regex.Matcher;
@@ -50,9 +41,6 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
-import org.hisp.dhis.patientdatavalue.PatientDataValueService;
-import org.nfunk.jep.JEP;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -65,20 +53,14 @@
 {
     private final String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+["
         + SEPARATOR_ID + "[0-9]*]*)" + "\\]";
-
-    private final String regExpComparator = "(<=|>=|==|!=|<|>|>)+";
-
-    private final String SEPARATE_SIDE_VALUE = "&&";
-
-    private final String INVALID_CONDITION = "Invalid condition";
-
+    
     private ProgramValidationStore validationStore;
 
     private ProgramStageService programStageService;
 
     private DataElementService dataElementService;
 
-    private PatientDataValueService valueService;
+    private ProgramExpressionService expressionService;
 
     // -------------------------------------------------------------------------
     // Setters
@@ -89,6 +71,11 @@
         this.validationStore = validationStore;
     }
 
+    public void setExpressionService( ProgramExpressionService expressionService )
+    {
+        this.expressionService = expressionService;
+    }
+
     public void setProgramStageService( ProgramStageService programStageService )
     {
         this.programStageService = programStageService;
@@ -99,11 +86,6 @@
         this.dataElementService = dataElementService;
     }
 
-    public void setValueService( PatientDataValueService valueService )
-    {
-        this.valueService = valueService;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -138,29 +120,31 @@
     }
 
     @Override
-    public ProgramValidationResult runValidation( ProgramValidation validation,
-        ProgramStageInstance programStageInstance, I18nFormat format )
+    public ProgramValidationResult validate( ProgramValidation validation, ProgramStageInstance programStageInstance,
+        I18nFormat format )
     {
-        if ( validation.getDateType() )
-        {
-            return runDateExpression( validation, programStageInstance, format );
-        }
-        else
-        {
-            String resultLeft = runExpression( validation.getLeftSide(), programStageInstance );
-            String resultRight = runExpression( validation.getRightSide(), programStageInstance );
-            if ( resultLeft != null && resultRight != null )
+        if ( !validation.getDateType() )
+        {
+            String leftSideValue = expressionService.getProgramExpressionValue( validation.getLeftSide(),
+                programStageInstance );
+            String rightSideValue = expressionService.getProgramExpressionValue( validation.getRightSide(),
+                programStageInstance );
+            String operator = validation.getOperator().getMathematicalOperator();
+
+            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.equals( rightSideValue ) || leftSideValue
+                        .compareTo( rightSideValue ) > 0)) || (operator.equals( "!=" ) && !leftSideValue
+                    .equals( rightSideValue ))))) )
             {
-                boolean validLeftSide = Boolean.parseBoolean( resultLeft.split( SEPARATE_SIDE_VALUE )[0] );
-                boolean validRightSide = Boolean.parseBoolean( resultRight.split( SEPARATE_SIDE_VALUE )[0] );
-                if ( validLeftSide != validRightSide )
-                {
-                    return new ProgramValidationResult( programStageInstance, validation,
-                        resultLeft.split( SEPARATE_SIDE_VALUE )[1], resultRight.split( SEPARATE_SIDE_VALUE )[1] );
-                }
+                return new ProgramValidationResult( programStageInstance, validation, leftSideValue, rightSideValue );
             }
         }
-
         return null;
     }
 
@@ -196,105 +180,6 @@
         return result;
     }
 
-    private ProgramValidationResult runDateExpression( ProgramValidation programValidation,
-        ProgramStageInstance programStageInstance, I18nFormat format )
-    {
-        boolean valid = true;
-
-        Pattern pattern = Pattern.compile( regExp );
-        Matcher matcher = pattern.matcher( programValidation.getLeftSide() );
-
-        if ( matcher.find() )
-        {
-            String match = matcher.group();
-
-            PatientDataValue dataValue = getPatientDataValue( match, programStageInstance );
-
-            if ( dataValue != null )
-            {
-
-                String rightSide = programValidation.getRightSide();
-                Date dueDate = dataValue.getProgramStageInstance().getDueDate();
-                Date currentDate = dataValue.getTimestamp();
-                Date value = format.parseDate( dataValue.getValue() );
-                String operator = "";
-                int daysValue = 0;
-
-                int index = rightSide.indexOf( 'D' );
-                if ( index < 0 )
-                {
-                    int rightValidation = Integer.parseInt( rightSide );
-
-                    switch ( rightValidation )
-                    {
-                    case BEFORE_CURRENT_DATE:
-                        operator = "<";
-                        valid = value.before( currentDate );
-                        break;
-                    case BEFORE_OR_EQUALS_TO_CURRENT_DATE:
-                        operator = "<=";
-                        valid = (value.before( currentDate ) || value.equals( currentDate ));
-                        break;
-                    case AFTER_CURRENT_DATE:
-                        operator = ">";
-                        valid = value.after( currentDate );
-                        break;
-                    case AFTER_OR_EQUALS_TO_CURRENT_DATE:
-                        operator = ">=";
-                        valid = (value.after( currentDate ) || value.equals( currentDate ));
-                        break;
-                    case BEFORE_DUE_DATE:
-                        operator = "<";
-                        currentDate = dueDate;
-                        valid = value.before( dueDate );
-                        break;
-                    case BEFORE_OR_EQUALS_TO_DUE_DATE:
-                        operator = "<=";
-                        currentDate = dueDate;
-                        valid = (value.before( dueDate ) || value.equals( dueDate ));
-                    case AFTER_DUE_DATE:
-                        operator = ">";
-                        currentDate = dueDate;
-                        valid = value.after( dueDate );
-                        break;
-                    case AFTER_OR_EQUALS_TO_DUE_DATE:
-                        operator = ">=";
-                        currentDate = dueDate;
-                        valid = (value.after( dueDate ) || value.equals( dueDate ));
-                        break;
-                    default:
-                        break;
-                    }
-                }
-                else
-                {
-                    int rightValidation = Integer.parseInt( rightSide.substring( 0, index ) );
-                    daysValue = Integer.parseInt( rightSide.substring( index + 1, rightSide.length() ) );
-                    if ( rightValidation == BEFORE_DUE_DATE_PLUS_OR_MINUS_MAX_DAYS )
-                    {
-                        long maxDays = dueDate.getTime() / 86400000 + daysValue;
-                        long minDays = dueDate.getTime() / 86400000 - daysValue;
-                        long valueDays = value.getTime() / 86400000;
-                        valid = (valueDays <= maxDays && valueDays >= minDays);
-                        operator = "=";
-                    }
-                }
-                
-                if ( !valid )
-                {
-                    String result = dataValue.getValue() + " " + operator + " " + format.formatDate( currentDate );
-                    if( daysValue!=0 )
-                    {
-                        result += " +/- " + daysValue;
-                    }
-                    return new ProgramValidationResult( programStageInstance, programValidation, result, null );
-                }
-            }
-        }
-
-        return null;
-    }
-
     public Collection<ProgramValidation> getProgramValidation( ProgramStage programStage )
     {
         Collection<ProgramValidation> programValidation = getProgramValidation( programStage.getProgram() );
@@ -336,150 +221,11 @@
 
         return programValidation;
     }
-
-    public String getValidationDescription( String condition )
-    {
-        StringBuffer description = new StringBuffer();
-
-        Pattern patternCondition = Pattern.compile( regExp );
-
-        Matcher matcher = patternCondition.matcher( condition );
-
-        while ( matcher.find() )
-        {
-            String match = matcher.group();
-            match = match.replaceAll( "[\\[\\]]", "" );
-
-            String[] info = match.split( SEPARATOR_OBJECT );
-            String[] ids = info[1].split( SEPARATOR_ID );
-
-            String programStageId = ids[0];
-            ProgramStage programStage = programStageService.getProgramStage( Integer.parseInt( programStageId ) );
-
-            int dataElementId = Integer.parseInt( ids[1] );
-            DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
-            if ( programStage == null || dataElement == null )
-            {
-                return INVALID_CONDITION;
-            }
-
-            matcher.appendReplacement( description, programStage.getName() + SEPARATOR_ID + dataElement.getName() );
-
-        }
-
-        matcher.appendTail( description );
-
-        return description.toString();
-    }
-
+    
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
-
-    private String SUM_OPERATOR_IN_EXPRESSION = "+";
-
-    private String NOT_NULL_VALUE_IN_EXPRESSION = "{NOT-NULL-VALUE}";
-
-    private String runExpression( String expression, ProgramStageInstance programStageInstance )
-    {
-        boolean valid = true;
-        String comparetor = "";
-        Pattern pattern = Pattern.compile( regExpComparator );
-        Matcher matcher = pattern.matcher( expression );
-        if ( matcher.find() )
-        {
-            comparetor = matcher.group();
-        }
-
-        String[] sides = expression.split( regExpComparator );
-        String leftSideValue = getOneSideExpressionValue( sides[0].trim(), programStageInstance );
-        String rightSideValue = getOneSideExpressionValue( sides[1].trim(), programStageInstance );
-
-        if ( leftSideValue == null && rightSideValue == null )
-        {
-            return "true&&null";
-        }
-        else if ( expression.indexOf( SUM_OPERATOR_IN_EXPRESSION ) != -1 )
-        {
-            if ( leftSideValue != null && rightSideValue != null )
-            {
-                String result = leftSideValue + comparetor + rightSideValue;
-                final JEP parser = new JEP();
-                parser.parseExpression( result );
-                valid = (parser.getValue() == 1.0);
-            }
-        }
-        else
-        {
-            if ( rightSideValue != null && rightSideValue.equals( NOT_NULL_VALUE_IN_EXPRESSION ) )
-            {
-                valid = !(leftSideValue == null);
-            }
-            else if ( leftSideValue != null
-                && rightSideValue != null
-                && ((comparetor.equals( "==" ) && leftSideValue.equals( rightSideValue ))
-                    || (comparetor.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0)
-                    || (comparetor.equals( "<=" ) && (leftSideValue.equals( rightSideValue ) || leftSideValue
-                        .compareTo( rightSideValue ) < 0))
-                    || (comparetor.equals( ">" ) && leftSideValue.compareTo( rightSideValue ) > 0)
-                    || (comparetor.equals( ">=" ) && (leftSideValue.equals( rightSideValue ) || leftSideValue
-                        .compareTo( rightSideValue ) > 0)) || (comparetor.equals( "!=" ) && !leftSideValue
-                    .equals( rightSideValue ))) )
-            {
-                valid = true;
-            }
-            else
-            {
-                valid = false;
-            }
-        }
-
-        return valid + SEPARATE_SIDE_VALUE + leftSideValue + " " + comparetor + " " + rightSideValue;
-    }
-
-    private String getOneSideExpressionValue( String expression, ProgramStageInstance programStageInstance )
-    {
-        StringBuffer description = new StringBuffer();
-
-        Pattern pattern = Pattern.compile( regExp );
-
-        Matcher matcher = pattern.matcher( expression );
-
-        while ( matcher.find() )
-        {
-            String match = matcher.group();
-
-            PatientDataValue dataValue = getPatientDataValue( match, programStageInstance );
-
-            if ( dataValue == null )
-            {
-                return null;
-            }
-
-            matcher.appendReplacement( description, dataValue.getValue() );
-        }
-
-        matcher.appendTail( description );
-
-        return description.toString();
-    }
-
-    private PatientDataValue getPatientDataValue( String match, ProgramStageInstance programStageInstance )
-    {
-        match = match.replaceAll( "[\\[\\]]", "" );
-
-        String[] info = match.split( SEPARATOR_OBJECT );
-        String[] ids = info[1].split( SEPARATOR_ID );
-
-        int dataElementId = Integer.parseInt( ids[1] );
-        DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
-        PatientDataValue dataValue = valueService.getPatientDataValue( programStageInstance, dataElement );
-
-        return dataValue;
-    }
-
+    
     private Collection<DataElement> getDataElementInExpression( ProgramValidation programValidation )
     {
         Collection<DataElement> dataElements = new HashSet<DataElement>();

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-10-25 13:31:14 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-11-08 13:09:31 +0000
@@ -61,6 +61,11 @@
 		<property name="clazz" value="org.hisp.dhis.program.ProgramValidation" />
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramExpressionStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+		<property name="clazz" value="org.hisp.dhis.program.ProgramExpression" />
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientStore" class="org.hisp.dhis.patient.hibernate.HibernatePatientStore">
 		<property name="clazz" value="org.hisp.dhis.patient.Patient" />
@@ -214,8 +219,13 @@
 		<property name="validationStore" ref="org.hisp.dhis.program.ProgramValidationStore" />
 		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="valueService"
-			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramExpressionService" class="org.hisp.dhis.program.DefaultProgramExpressionService">
+		<property name="programExpressionStore" ref="org.hisp.dhis.program.ProgramExpressionStore" />
+		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
+		<property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientService" class="org.hisp.dhis.patient.DefaultPatientService">

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramValidation.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramValidation.hbm.xml	2012-01-13 02:14:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramValidation.hbm.xml	2012-11-08 13:09:31 +0000
@@ -4,8 +4,7 @@
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
 
 <hibernate-mapping>
-	<class name="org.hisp.dhis.program.ProgramValidation"
-		table="programvalidation">
+	<class name="org.hisp.dhis.program.ProgramValidation" table="programvalidation">
 
 		<id name="id" column="programvalidationid">
 			<generator class="native" />
@@ -13,13 +12,21 @@
 
 		<property name="description" type="text" />
 
-		<property name="leftSide" />
-
-		<property name="rightSide" type="text" not-null="true" />
+		<many-to-one name="leftSide" column="leftprogramexpressionid"
+			class="org.hisp.dhis.expression.Expression" cascade="all"
+			foreign-key="fk_programvalidation_leftprogramexpressionid" />
+
+		<property name="operator" type="org.hisp.dhis.expression.OperatorUserType">
+			<column name="operator" unique="false" />
+		</property>
+
+		<many-to-one name="rightSide" column="rightprogramexpressionid"
+			class="org.hisp.dhis.expression.Expression" cascade="all"
+			foreign-key="fk_programvalidation_rightprogramexpressionid" />
 
 		<many-to-one name="program" class="org.hisp.dhis.program.Program"
 			column="programid" not-null="true" foreign-key="fk_programvalidation_programid" />
-			
+
 		<property name="dateType" />
 
 	</class>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-11-08 06:20:53 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-11-08 13:09:31 +0000
@@ -470,4 +470,6 @@
 left_value = Left value
 right_value = Right value
 validation_rule = Validation rule
-add_filter = Add filter
\ No newline at end of file
+add_filter = Add filter
+edit_left_side = Edit left side
+edit_right_side = Edit right side
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2012-11-08 04:13:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2012-11-08 13:09:31 +0000
@@ -213,7 +213,7 @@
                     var array = [];
                     Ext.Array.each(selected, function(item) {
 						var data = a.store.findExact('id', item);
-                        array.push({id: item, name: a.store.getAt(data).data.name, compulsory: a.store.getAt(data).data.compulsory, valueType: a.store.getAt(data).data.valueType, displayInReports:r.data.displayInReports});
+                        array.push({id: item, name: a.store.getAt(data).data.name, compulsory: a.store.getAt(data).data.compulsory, valueType: a.store.getAt(data).data.valueType});
                     });
                     s.store.add(array);
                 }
@@ -226,7 +226,7 @@
 				{
 					if( elements[i].style.display != 'none' )
 					{
-						array.push({id: a.store.getAt(i).data.id, name: a.store.getAt(i).data.name, compulsory: a.store.getAt(i).data.compulsory, valueType: a.store.getAt(i).data.valueType, displayInReports:r.data.displayInReports});
+						array.push({id: a.store.getAt(i).data.id, name: a.store.getAt(i).data.name, compulsory: a.store.getAt(i).data.compulsory, valueType: a.store.getAt(i).data.valueType});
 					}
 				}
 				s.store.add(array);
@@ -594,7 +594,7 @@
 		}),
 		dataelement: {
             available: Ext.create('Ext.data.Store', {
-                fields: ['id', 'name', 'compulsory', 'valueType', 'displayInReports'],
+                fields: ['id', 'name', 'compulsory', 'valueType'],
                 proxy: {
                     type: 'ajax',
                     url: TR.conf.finals.ajax.path_commons + TR.conf.finals.ajax.dataelements_get,
@@ -608,15 +608,6 @@
                 listeners: {
 					load: function(s) {
 						this.isloaded = true;
-						// Get displayedInList-Data elements
-						var array = [];
-						TR.cmp.params.dataelement.available.store.each( function(r) {
-							if( r.data.displayInReports=="true" )
-							{
-								array.push({id: r.data.id, name: r.data.name, compulsory: r.data.compulsory, valueType: r.data.valueType, displayInReports:r.data.displayInReports });
-							}
-						});
-						TR.cmp.params.dataelement.selected.store.add(array);
                         TR.util.store.addToStorage(s);
                         TR.util.multiselect.filterAvailable(TR.cmp.params.dataelement.available, TR.cmp.params.dataelement.selected);
                     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddProgramValidationAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddProgramValidationAction.java	2012-01-13 02:14:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/AddProgramValidationAction.java	2012-11-08 13:09:31 +0000
@@ -27,7 +27,9 @@
 
 package org.hisp.dhis.patient.action.validation;
 
+import org.hisp.dhis.expression.Operator;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramExpression;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramValidation;
 import org.hisp.dhis.program.ProgramValidationService;
@@ -47,67 +49,73 @@
 
     private ProgramValidationService programValidationService;
 
+    public void setProgramValidationService( ProgramValidationService programValidationService )
+    {
+        this.programValidationService = programValidationService;
+    }
+
     private ProgramService programService;
 
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
 
     private String description;
 
-    private String leftSide;
-
-    private String rightSide;
-
-    private Integer programId;
-
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    private String operator;
+
+    public void setOperator( String operator )
+    {
+        this.operator = operator;
+    }
+
+    private String leftSideExpression;
+
+    public void setLeftSideExpression( String leftSideExpression )
+    {
+        this.leftSideExpression = leftSideExpression;
+    }
+
+    private String leftSideDescription;
+
+    public void setLeftSideDescription( String leftSideDescription )
+    {
+        this.leftSideDescription = leftSideDescription;
+    }
+
+    private String rightSideExpression;
+
+    public void setRightSideExpression( String rightSideExpression )
+    {
+        this.rightSideExpression = rightSideExpression;
+    }
+    
+    private String rightSideDescription;
+
+    public void setRightSideDescription( String rightSideDescription )
+    {
+        this.rightSideDescription = rightSideDescription;
+    }
+    
+    
     private Boolean dateType;
 
-    private String message;
-
-    // -------------------------------------------------------------------------
-    // Setters
-    // -------------------------------------------------------------------------
-
-    public void setProgramService( ProgramService programService )
-    {
-        this.programService = programService;
-    }
-
     public void setDateType( Boolean dateType )
     {
         this.dateType = dateType;
     }
 
-    public void setProgramValidationService( ProgramValidationService programValidationService )
-    {
-        this.programValidationService = programValidationService;
-    }
-
-    public void setDescription( String description )
-    {
-        this.description = description;
-    }
-
-    public void setLeftSide( String leftSide )
-    {
-        this.leftSide = leftSide;
-    }
-
-    public String getMessage()
-    {
-        return message;
-    }
-
-    public void setRightSide( String rightSide )
-    {
-        this.rightSide = rightSide;
-    }
-
-    public Integer getProgramId()
-    {
-        return programId;
-    }
+    private Integer programId;
 
     public void setProgramId( Integer programId )
     {
@@ -122,17 +130,20 @@
     public String execute()
         throws Exception
     {
+        ProgramExpression leftExpression = new ProgramExpression( leftSideExpression, leftSideDescription );
+        ProgramExpression rightExpression = new ProgramExpression( rightSideExpression, rightSideDescription );
+        
         ProgramValidation validation = new ProgramValidation();
-
         validation.setDescription( description.trim() );
-        validation.setLeftSide( leftSide.trim() );
-        validation.setRightSide( rightSide.trim() );
+        validation.setOperator( Operator.valueOf(operator)  );
+        validation.setLeftSide( leftExpression );
+        validation.setRightSide( rightExpression );
         validation.setDateType( dateType );
 
         Program program = programService.getProgram( programId );
         validation.setProgram( program );
-
-        message = programValidationService.addProgramValidation( validation ) + "";
+        
+        programValidationService.addProgramValidation( validation );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationAction.java	2012-07-30 10:10:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationAction.java	2012-11-08 13:09:31 +0000
@@ -44,43 +44,25 @@
     // -------------------------------------------------------------------------
 
     private ProgramValidationService programValidationService;
-    
+
+    public void setProgramValidationService( ProgramValidationService programValidationService )
+    {
+        this.programValidationService = programValidationService;
+    }
+
     // -------------------------------------------------------------------------
     // Input && Output
     // -------------------------------------------------------------------------
 
     private Integer validationId;
 
-    private ProgramValidation validation;
-
-    private String leftDescription;
-
-    public String getLeftDescription()
-    {
-        return leftDescription;
-    }
-
-    private String rightDescription;
-
-    public String getRightDescription()
-    {
-        return rightDescription;
-    }
-
-    // -------------------------------------------------------------------------
-    // Getter && Setter
-    // -------------------------------------------------------------------------
-
-    public void setProgramValidationService( ProgramValidationService programValidationService )
-    {
-        this.programValidationService = programValidationService;
-    }
-
     public void setValidationId( Integer validationId )
     {
         this.validationId = validationId;
     }
 
+    private ProgramValidation validation;
+
     public ProgramValidation getValidation()
     {
         return validation;
@@ -96,9 +78,6 @@
     {
         validation = programValidationService.getProgramValidation( validationId );
 
-        leftDescription = programValidationService.getValidationDescription( validation.getLeftSide() );
-        rightDescription = programValidationService.getValidationDescription( validation.getRightSide() );
-
         return SUCCESS;
     }
 

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationDescriptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationDescriptionAction.java	2012-07-30 10:10:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/GetProgramValidationDescriptionAction.java	1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2004-2012, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.hisp.dhis.patient.action.validation;
-
-import org.hisp.dhis.program.ProgramValidationService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Chau Thu Tran
- * @version $ID : GetAggConditionDescriptionAction.java Jan 11, 2011 9:14:19 PM
- *          $
- */
-public class GetProgramValidationDescriptionAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependency
-    // -------------------------------------------------------------------------
-
-    private ProgramValidationService programValidationService;
-
-    // -------------------------------------------------------------------------
-    // Input && Output
-    // -------------------------------------------------------------------------
-
-    private String condition;
-
-    private String description;
-
-    // -------------------------------------------------------------------------
-    // Getters && Setters
-    // -------------------------------------------------------------------------
-
-    public void setProgramValidationService( ProgramValidationService programValidationService )
-    {
-        this.programValidationService = programValidationService;
-    }
-
-    public String getDescription()
-    {
-        return description;
-    }
-
-    public void setCondition( String condition )
-    {
-        this.condition = condition;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public String execute()
-        throws Exception
-    {
-        description = programValidationService.getValidationDescription( condition );
-
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateProgramValidationAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateProgramValidationAction.java	2012-01-11 05:31:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/validation/UpdateProgramValidationAction.java	2012-11-08 13:09:31 +0000
@@ -27,6 +27,8 @@
 
 package org.hisp.dhis.patient.action.validation;
 
+import org.hisp.dhis.expression.Operator;
+import org.hisp.dhis.program.ProgramExpression;
 import org.hisp.dhis.program.ProgramValidation;
 import org.hisp.dhis.program.ProgramValidationService;
 
@@ -45,52 +47,69 @@
 
     private ProgramValidationService programValidationService;
 
+    public void setProgramValidationService( ProgramValidationService programValidationService )
+    {
+        this.programValidationService = programValidationService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
 
     private Integer id;
 
-    private String description;
-
-    private String leftSide;
-
-    private String rightSide;
-
-    private Integer programId;
-
-    // -------------------------------------------------------------------------
-    // Setters
-    // -------------------------------------------------------------------------
-
-    public void setProgramValidationService( ProgramValidationService programValidationService )
-    {
-        this.programValidationService = programValidationService;
-    }
-
-    public Integer getProgramId()
-    {
-        return programId;
-    }
-
     public void setId( Integer id )
     {
         this.id = id;
     }
 
+    private String description;
+
     public void setDescription( String description )
     {
         this.description = description;
     }
 
-    public void setLeftSide( String leftSide )
-    {
-        this.leftSide = leftSide;
-    }
-
-    public void setRightSide( String rightSide )
-    {
-        this.rightSide = rightSide;
+    private String operator;
+
+    public void setOperator( String operator )
+    {
+        this.operator = operator;
+    }
+
+    private String leftSideExpression;
+
+    public void setLeftSideExpression( String leftSideExpression )
+    {
+        this.leftSideExpression = leftSideExpression;
+    }
+
+    private String leftSideDescription;
+
+    public void setLeftSideDescription( String leftSideDescription )
+    {
+        this.leftSideDescription = leftSideDescription;
+    }
+
+    private String rightSideExpression;
+
+    public void setRightSideExpression( String rightSideExpression )
+    {
+        this.rightSideExpression = rightSideExpression;
+    }
+
+    private String rightSideDescription;
+
+    public void setRightSideDescription( String rightSideDescription )
+    {
+        this.rightSideDescription = rightSideDescription;
+    }
+
+    private Boolean dateType;
+
+    public void setDateType( Boolean dateType )
+    {
+        this.dateType = dateType;
     }
 
     // -------------------------------------------------------------------------
@@ -103,12 +122,15 @@
     {
         ProgramValidation validation = programValidationService.getProgramValidation( id );
 
-        programId = validation.getProgram().getId();
+        ProgramExpression leftExpression = new ProgramExpression( leftSideExpression, leftSideDescription );
+        ProgramExpression rightExpression = new ProgramExpression( rightSideExpression, rightSideDescription );
 
         validation.setDescription( description.trim() );
-        validation.setLeftSide( leftSide.trim() );
-        validation.setRightSide( rightSide.trim() );
-        
+        validation.setOperator( Operator.valueOf( operator ) );
+        validation.setLeftSide( leftExpression );
+        validation.setRightSide( rightExpression );
+        validation.setDateType( dateType );
+
         programValidationService.updateProgramValidation( validation );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2012-10-12 07:34:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2012-11-08 13:09:31 +0000
@@ -898,16 +898,16 @@
 		<property name="programValidationService"
 			ref="org.hisp.dhis.program.ProgramValidationService" />
 	</bean>
-
+	
 	<bean
-		id="org.hisp.dhis.patient.action.validation.GetProgramValidationDescriptionAction"
-		class="org.hisp.dhis.patient.action.validation.GetProgramValidationDescriptionAction"
+		id="org.hisp.dhis.patient.action.validation.GetProgramExpressionDescriptionAction"
+		class="org.hisp.dhis.patient.action.validation.GetProgramExpressionDescriptionAction"
 		scope="prototype">
-		<property name="programValidationService">
-			<ref bean="org.hisp.dhis.program.ProgramValidationService" />
-		</property>
+		<property name="programExpressionService"
+			ref="org.hisp.dhis.program.ProgramExpressionService" />
 	</bean>
-
+	
+	
 	<!-- Scheduling -->
 
 	<bean id="org.hisp.dhis.patient.action.schedule.GetScheduleParamsAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-11-08 04:13:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-11-08 13:09:31 +0000
@@ -162,7 +162,7 @@
 validation_criteria_details=Validation criteria details
 program_attribute_details=Program attribute details
 select_program=Select program
-add_single_program_validation_rule=Add single program validation rule
+create_new_program_validation_rule=Create new program validation rule
 add_multi_program_validation_rule=Add multi program validation rule
 program_validation_rule_details=Program validation rule details
 program_validation_rule_management=Program validation rule management

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2012-10-12 07:34:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2012-11-08 13:09:31 +0000
@@ -987,8 +987,8 @@
 			<param name="requiredAuthorities">F_PROGRAM_VALIDATION</param>
 		</action>
 
-		<action name="getProgramValidationDescription"
-			class="org.hisp.dhis.patient.action.validation.GetProgramValidationDescriptionAction">
+		<action name="getProgramExpressionDescription"
+			class="org.hisp.dhis.patient.action.validation.GetProgramExpressionDescriptionAction">
 			<result name="success" type="velocity">
 				/dhis-web-maintenance-patient/responseCaseAggDescription.vm
 			</result>