← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6193: (patient) Remove statements in TableAlteror which are not used for converting database from 2.7 v...

 

------------------------------------------------------------
revno: 6193
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-03-07 13:26:09 +0700
message:
  (patient) Remove statements in TableAlteror which are not used for converting database from 2.7 version to 2.8
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-03-07 02:40:08 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2012-03-07 06:26:09 +0000
@@ -29,21 +29,12 @@
 
 import java.sql.ResultSet;
 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;
 
@@ -70,27 +61,6 @@
         this.statementManager = statementManager;
     }
 
-    private DataElementCategoryService categoryService;
-
-    public void setCategoryService( DataElementCategoryService categoryService )
-    {
-        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
     // -------------------------------------------------------------------------
@@ -99,278 +69,17 @@
     public void execute()
         throws Exception
     {
-        updatePatientOrgunitAssociation();
-
-        executeSql( "UPDATE patient SET dobType='A' WHERE birthdateestimated=true" );
-
-        executeSql( "ALTER TABLE patient drop column birthdateestimated" );
-
-        executeSql( "DELETE FROM validationcriteria where property='birthdateestimated'" );
-
-        executeSql( "UPDATE patientattribute SET mandatory = false WHERE mandatory is NULL" );
-
-        executeSql( "UPDATE program SET version = 1 WHERE version is NULL" );
-
-        executeSql( "UPDATE patientidentifiertype SET type='" + PatientIdentifierType.VALUE_TYPE_TEXT
-            + "' WHERE type IS NULL" );
-
-        executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN format" );
-
-        executeSql( "ALTER TABLE program DROP COLUMN minDaysAllowedInputData" );
-
-        executeSql( "UPDATE program SET maxDaysAllowedInputData=0 WHERE maxDaysAllowedInputData IS NULL" );
-
-        executeSql( "UPDATE patient SET isdead=false WHERE isdead IS NULL" );
-
-        executeSql( "UPDATE patient SET hasPatients=false WHERE hasPatients IS NULL" );
-
-        executeSql( "UPDATE dataset SET mobile = false WHERE mobile is null" );
-
-        executeSql( "UPDATE dataset SET version = 1 WHERE version is null" );
-
-        executeSql( "UPDATE program SET singleEvent = false WHERE singleevent is null" );
-
-        executeSql( "UPDATE program SET anonymous = false WHERE anonymous is null" );
-
-        executeSql( "UPDATE programstage SET irregular = false WHERE irregular is null" );
-
-        executeSql( "Alter table programinstance modify patientid integer null" );
-
-        updateSingleProgramValidation();
-
-        updateStageInProgram();
-
-        executeSql( "UPDATE programvalidation SET dateType = false WHERE dateType is null" );
-
-        executeSql( "UPDATE programstage_dataelements SET showOnReport = false WHERE showOnReport is null" );
-
-        int categoryOptionId = categoryService.getDefaultDataElementCategoryOptionCombo().getId();
-        executeSql( "UPDATE dataelement SET categoryoptioncomboid = " + categoryOptionId + " WHERE domain='patient'" );
-        executeSql( "ALTER TABLE patientdatavalue DROP COLUMN categoryoptioncomboid" );
-
-        upgradeCaseAggregationFormula();
-
-        upgradeProgramValidationFormula();
-
-        executeSql( "UPDATE program SET displayProvidedOtherFacility = false WHERE displayProvidedOtherFacility is null" );
-
         executeSql( "ALTER TABLE relationshiptype RENAME description TO name" );
 
         updateProgramStageInstanceOrgunit();
-        
-        executeSql("ALTER TABLE programstage_dataelements DROP COLUMN showOnReport"); 
+
+        executeSql( "ALTER TABLE programstage_dataelements DROP COLUMN showOnReport" );
     }
 
     // -------------------------------------------------------------------------
     // Supporting methods
     // -------------------------------------------------------------------------
 
-    private void updatePatientOrgunitAssociation()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet isUpdated = statement
-                .executeQuery( "SELECT organisationunitid FROM patient where organisationunitid is null " );
-
-            if ( isUpdated.next() )
-            {
-                ResultSet resultSet = statement
-                    .executeQuery( "SELECT patientid, organisationunitid FROM patientidentifier" );
-                while ( resultSet.next() )
-                {
-                    executeSql( "UPDATE patient SET organisationunitid=" + resultSet.getInt( 2 ) + " WHERE patientid="
-                        + resultSet.getInt( 1 ) );
-                }
-
-                executeSql( "ALTER TABLE patientidentifier DROP COLUMN organisationunitid" );
-            }
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
-    private void updateSingleProgramValidation()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet isUpdated = statement.executeQuery( "SELECT * FROM INFORMATION_SCHEMA.COLUMNS "
-                + "WHERE TABLE_NAME = 'programstage_dataelement_validation'" );
-
-            if ( isUpdated.next() )
-            {
-                ResultSet rsCount = statement.executeQuery( "SELECT max(programvalidationid) FROM programvalidation" );
-                rsCount.next();
-
-                int max = rsCount.getInt( 1 ) + 1;
-
-                ResultSet resultSet = statement
-                    .executeQuery( "SELECT pdv.description, pdv.leftprogramstageid, pdv.leftdataelementid, "
-                        + "pdv.rightprogramstageid, pdv.rightdataelementid, " + "pdv.operator, ps.programid "
-                        + "FROM programstage_dataelement_validation pdv " + "INNER JOIN programstage_dataelements pd "
-                        + "ON (pdv.leftprogramstageid=pd.dataelementid AND "
-                        + "pdv.leftdataelementid=pd.programstageid) " + "INNER JOIN programstage ps "
-                        + "ON pd.programstageid=ps.programstageid" );
-
-                while ( resultSet.next() )
-                {
-                    max++;
-                    String leftSide = "[" + resultSet.getString( 2 ) + "." + resultSet.getString( 3 ) + "." + "]";
-                    String rightSide = "[" + resultSet.getString( 4 ) + "." + resultSet.getString( 5 ) + "." + "]";
-                    String operator = resultSet.getInt( 6 ) > 0 ? ">" : (resultSet.getInt( 6 ) < 0) ? "<" : "==";
-
-                    String fomular = leftSide + operator + rightSide;
-
-                    executeSql( "INSERT INTO programvalidation (programvalidationid, description,leftSide, rightSide, programid )"
-                        + "VALUES ( "
-                        + max
-                        + ",'"
-                        + resultSet.getString( 1 )
-                        + "', '"
-                        + fomular
-                        + "', '1==1', "
-                        + resultSet.getInt( 7 ) + ")" );
-                }
-
-                executeSql( "DROP TABLE programstage_dataelement_validation" );
-            }
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
-    private void updateStageInProgram()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            Collection<Integer> programIds = getPrograms();
-
-            for ( Integer programId : programIds )
-            {
-                ResultSet resultSet = statement.executeQuery( "SELECT programstageid "
-                    + "FROM programstage WHERE programid = " + programId );
-
-                int index = 1;
-                while ( resultSet.next() )
-                {
-                    executeSql( "UPDATE programstage SET stageinprogram = " + index + " WHERE programstageid = "
-                        + resultSet.getInt( 1 ) );
-                    index++;
-                }
-            }
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
-    private Collection<Integer> getPrograms()
-    {
-        Collection<Integer> result = new HashSet<Integer>();
-
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet rsMax = statement.executeQuery( "SELECT max(stageinprogram), programid "
-                + "FROM programstage GROUP BY programid" );
-
-            while ( rsMax.next() )
-            {
-                if ( rsMax.getInt( 1 ) == 0 )
-                {
-                    result.add( rsMax.getInt( 2 ) );
-                }
-            }
-
-            return result;
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-
-            return null;
-        }
-        finally
-        {
-            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 void updateProgramStageInstanceOrgunit()
     {
         StatementHolder holder = statementManager.getHolder();

=== 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-03-05 04:22:57 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-03-07 06:26:09 +0000
@@ -405,9 +405,6 @@
 		<property name="name" value="PatientTableAlteror" />
 		<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">