← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5917: (patient) update case-aggregation-fomular and program-validation formula after remove option-comb...

 

------------------------------------------------------------
revno: 5917
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-02-11 21:51:09 +0700
message:
  (patient) update case-aggregation-fomular and program-validation formula after remove option-combo from patient-data-value.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2012-02-11 14:51:09 +0000
@@ -31,13 +31,19 @@
 import java.sql.Statement;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.amplecode.quick.StatementHolder;
 import org.amplecode.quick.StatementManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
+import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.program.ProgramValidation;
+import org.hisp.dhis.program.ProgramValidationService;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -47,10 +53,11 @@
  * @version TableAlteror.java Sep 9, 2010 10:22:29 PM
  */
 public class TableAlteror
-    extends AbstractStartupRoutine
-{
+    extends AbstractStartupRoutine{
     private static final Log log = LogFactory.getLog( TableAlteror.class );
 
+    Pattern IDENTIFIER_PATTERN = Pattern.compile( "DE:(\\d+)\\.(\\d+)\\.(\\d+)" );
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -69,10 +76,24 @@
         this.categoryService = categoryService;
     }
     
+    private CaseAggregationConditionService aggregationConditionService;
+    
+    public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
+    {
+        this.aggregationConditionService = aggregationConditionService;
+    }  
+    
+    private ProgramValidationService programValidationService;
+
+    public void setProgramValidationService( ProgramValidationService programValidationService )
+    {
+        this.programValidationService = programValidationService;
+    }
+  
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
-
+  
     @Transactional
     public void execute()
         throws Exception
@@ -124,6 +145,10 @@
         
         int categoryOptionId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
         executeSql( "UPDATE dataelement SET categoryoptioncomboid = " + categoryOptionId + " WHERE domain='patient'");
+        
+        upgradeCaseAggregationFormula();
+        
+        upgradeProgramValidationFormula();
     }
 
     // -------------------------------------------------------------------------
@@ -291,6 +316,50 @@
             holder.close();
         }
     }
+    
+    private void upgradeCaseAggregationFormula()
+    {
+        Collection<CaseAggregationCondition> conditions = aggregationConditionService.getAllCaseAggregationCondition();
+        
+        for ( CaseAggregationCondition condition : conditions )
+        {
+            String formula = upgradeFormula( condition.getAggregationExpression() );
+            condition.setAggregationExpression( formula );
+            aggregationConditionService.updateCaseAggregationCondition( condition );
+        }
+    }
+    
+    private void upgradeProgramValidationFormula()
+    {
+        Collection<ProgramValidation> programValidations = programValidationService.getAllProgramValidation();
+        
+        for ( ProgramValidation programValidation : programValidations )
+        {
+            String leftSide = upgradeFormula( programValidation.getLeftSide() );
+            String rightSide = upgradeFormula( programValidation.getRightSide() );
+            programValidation.setLeftSide( leftSide );
+            programValidation.setRightSide( rightSide );
+            programValidationService.updateProgramValidation( programValidation );
+        }
+    }
+    
+    private String upgradeFormula( String formula )
+    {
+        Matcher matcher = IDENTIFIER_PATTERN.matcher( formula );
+
+        StringBuffer out = new StringBuffer();
+
+        while ( matcher.find() )
+        {
+            String upgradedId = "DE:" + matcher.group( 1 ) + "." + matcher.group( 2 );
+
+            matcher.appendReplacement( out, upgradedId );
+        }
+
+        matcher.appendTail( out );
+        
+        return out.toString();
+    }
 
     private int executeSql( String sql )
     {

=== 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-02-11 13:58:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-02-11 14:51:09 +0000
@@ -404,6 +404,8 @@
 		<property name="runlevel" value="4" />
 		<property name="skipInTests" value="true" />
 		<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+		<property name="aggregationConditionService" ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
+		<property name="programValidationService" ref="org.hisp.dhis.program.ProgramValidationService" />
 	</bean>
 	
 	<bean id="org.hisp.dhis.patient.startup.ProgramAttributePopulator" class="org.hisp.dhis.patient.startup.ProgramAttributePopulator">