← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10852: Add plus sign for date-expresstion if it not have mathematics symbol in start of expression

 

------------------------------------------------------------
revno: 10852
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-16 10:41:09 +0700
message:
  Add plus sign for date-expresstion if it not have mathematics symbol in start of expression
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/AddProgramIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/UpdateProgramIndicatorAction.java


--
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-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/AddProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/AddProgramIndicatorAction.java	2013-04-17 07:58:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/AddProgramIndicatorAction.java	2013-05-16 03:41:09 +0000
@@ -27,6 +27,9 @@
 
 package org.hisp.dhis.patient.action.programtindicator;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramIndicatorService;
@@ -133,7 +136,18 @@
         throws Exception
     {
         code = (code == null && code.trim().length() == 0) ? null : code;
-        
+        expression = expression.trim();
+
+        if ( valueType.equals( ProgramIndicator.VALUE_TYPE_DATE ) )
+        {
+            Pattern pattern = Pattern.compile( "[(+|-|*|\\)]+" );
+            Matcher matcher = pattern.matcher( expression );
+            if ( matcher.find() && matcher.start() != 0 )
+            {
+                expression = "+" + expression;
+            }
+        }
+
         Program program = programService.getProgram( programId );
         ProgramIndicator programIndicator = new ProgramIndicator( name, description, valueType, expression );
         programIndicator.setShortName( shortName );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/UpdateProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/UpdateProgramIndicatorAction.java	2013-04-17 07:58:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programtindicator/UpdateProgramIndicatorAction.java	2013-05-16 03:41:09 +0000
@@ -27,6 +27,9 @@
 
 package org.hisp.dhis.patient.action.programtindicator;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramIndicatorService;
 
@@ -126,7 +129,18 @@
         throws Exception
     {
         code = (code == null && code.trim().length() == 0) ? null : code;
-        
+        expression = expression.trim();
+
+        if ( valueType.equals( ProgramIndicator.VALUE_TYPE_DATE ) )
+        {
+            Pattern pattern = Pattern.compile( "[(+|-|*|\\)]+" );
+            Matcher matcher = pattern.matcher( expression );
+            if ( matcher.find() && matcher.start() != 0 )
+            {
+                expression = "+" + expression;
+            }
+        }
+
         ProgramIndicator programIndicator = programIndicatorService.getProgramIndicator( id );
 
         programIndicator.setName( name );
@@ -140,7 +154,7 @@
         programIndicatorService.updateProgramIndicator( programIndicator );
 
         programId = programIndicator.getProgram().getId();
-        
+
         return SUCCESS;
     }