=== 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 2014-01-13 01:42:00 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2014-01-13 15:30:27 +0000 @@ -106,7 +106,7 @@ @Autowired private StatementBuilder statementBuilder; - + // ------------------------------------------------------------------------- // Action Implementation // ------------------------------------------------------------------------- @@ -296,7 +296,7 @@ executeSql( "UPDATE patientattribute SET displayInListNoProgram=false WHERE displayInListNoProgram is null" ); executeSql( "UPDATE patientidentifiertype SET displayInListNoProgram=false WHERE displayInListNoProgram is null" ); - + updateProgramAttributes(); } @@ -307,28 +307,24 @@ private void updateProgramAttributes() { String autoIncrVal = statementBuilder.getAutoIncrementValue(); - + String attributeSql = "INSERT INTO program_attributes (programattributeid, attributeid, sort_order, displayinlist, programid) " - + "SELECT " - + autoIncrVal - + ", pp.patientattributeid, pp.sort_order, false, pp.programid " - + "FROM program_patientattributes pp"; + + "SELECT " + autoIncrVal + ", pp.patientattributeid, pp.sort_order, false, pp.programid " + + "FROM program_patientattributes pp"; executeSql( attributeSql ); String identifierSql = "INSERT INTO program_identifiertypes (programidentifiertypeid, identifiertypeid, sort_order, displayinlist, programid) " - + "SELECT " - + autoIncrVal - + ", pp.patientidentifiertypeid, pp.sort_order, false, pp.programid " - + "FROM program_patientidentifiertypes pp"; + + "SELECT " + autoIncrVal + ", pp.patientidentifiertypeid, pp.sort_order, false, pp.programid " + + "FROM program_patientidentifiertypes pp"; executeSql( identifierSql ); - + executeSql( "DROP TABLE program_patientattributes" ); executeSql( "DROP TABLE program_patientidentifiertypes" ); executeSql( "ALTER TABLE patientattribute DROP COLUMN displayedInList" ); executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN personDisplayName" ); } - + private void updateUid() { updateUidColumn( "patientattribute" ); @@ -500,7 +496,7 @@ ResultSet resultSet = statement.executeQuery( "SELECT gender FROM patient" ); // Only execute once - if ( resultSet.next() ) + if ( !resultSet.next() ) { Integer max = jdbcTemplate.queryForObject( "select max(patientattributeid) from patientattribute", Integer.class ); @@ -548,7 +544,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "gender", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='gender' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='gender' " ); // --------------------------------------------------------------------- // Death date @@ -569,7 +567,9 @@ // Update custom entry form && Validation criteria removeFixedAttributeInCustomRegistrationForm( "deathDate", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='deathDate' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='deathDate' " ); // --------------------------------------------------------------------- // registrationDate @@ -591,8 +591,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "registrationDate", uid ); - - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='registrationDate' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='registrationDate' " ); // --------------------------------------------------------------------- // isDead @@ -613,7 +614,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "isDead", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='isDead' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='isDead' " ); // --------------------------------------------------------------------- // underAge @@ -630,10 +633,13 @@ + "','Is under age', 'Is under age','" + PatientAttribute.TYPE_TRACKER_ASSOCIATE + "', false, false, false)" ); executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid," - + max + ",underage from patient where underAge=true" ); + + max + ",isDead from patient where underAge=true" ); // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "underAge", uid ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='underAge' " ); // --------------------------------------------------------------------- // DobType @@ -678,7 +684,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "dobType", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='dobType' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='dobType' " ); // ------------------------------------------------------------- // Birthdate @@ -699,7 +707,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "birthDate", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='birthdate' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='birthDate' " ); // ------------------------------------------------------------- // Age @@ -720,7 +730,9 @@ // Update custom entry form && validation criteria removeFixedAttributeInCustomRegistrationForm( "age", uid ); - executeSql( "UPDATE validationcriteria SET property='" + uid + "' WHERE property='age' " ); + executeSql( "UPDATE validationcriteria SET property='" + resultSet.getInt( "property" ) + + "' WHERE validationcriteriaid=" + resultSet.getInt( "validationcriteriaid" ) + + " and property='age' " ); // ------------------------------------------------------------- // Phone number @@ -795,7 +807,7 @@ executeSql( "ALTER TABLE patient DROP COLUMN gender" ); executeSql( "ALTER TABLE patient DROP COLUMN deathDate" ); - executeSql( "ALTER TABLE patient DROP COLUMN registrationdate" ); + executeSql( "ALTER TABLE patient DROP COLUMN registrationDate" ); executeSql( "ALTER TABLE patient DROP COLUMN isDead" ); executeSql( "ALTER TABLE patient DROP COLUMN underAge" ); executeSql( "ALTER TABLE patient DROP COLUMN dobType" ); === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientAttribute.hbm.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientAttribute.hbm.xml 2014-01-13 03:25:30 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientAttribute.hbm.xml 2014-01-13 15:30:27 +0000 @@ -11,7 +11,7 @@ + column="attributeid" foreign-key="fk_program_attributeid" /> === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientIdentifierType.hbm.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientIdentifierType.hbm.xml 2014-01-13 03:25:30 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramPatientIdentifierType.hbm.xml 2014-01-13 15:30:27 +0000 @@ -11,7 +11,7 @@ + column="identifiertypeid" foreign-key="fk_program_identifiertypeid" />