dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19286
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8340: DeletionHandler for program.
------------------------------------------------------------
revno: 8340
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-02 15:22:33 +0700
message:
DeletionHandler for program.
modified:
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2012-05-23 19:48:53 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2012-10-02 08:22:33 +0000
@@ -118,63 +118,29 @@
for ( ProgramInstance programInstance : programInstances )
{
- Set<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
-
- for ( ProgramStageInstance programStageInstance : programStageInstances )
- {
- programStageInstanceService.deleteProgramStageInstance( programStageInstance );
- }
+ Set<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
+
+ for ( ProgramStageInstance programStageInstance : programStageInstances )
+ {
+ programStageInstanceService.deleteProgramStageInstance( programStageInstance );
+ }
}
-
+
// ---------------------------------------------------------------------
// Delete Program Instances
// ---------------------------------------------------------------------
for ( ProgramInstance programInstance : programInstances )
{
- programInstanceService.deleteProgramInstance( programInstance );
+ programInstanceService.deleteProgramInstance( programInstance );
}
}
}
@Override
- public void deleteProgram( Program program )
+ public String allowDeleteProgram( Program program )
{
- // ---------------------------------------------------------------------
- // Delete Patient data values
- // ---------------------------------------------------------------------
-
Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( program );
-
- Set<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
-
- for ( ProgramInstance programInstance : programInstances )
- {
- Collection<ProgramStageInstance> stageInstances = programInstance.getProgramStageInstances();
- if ( stageInstances != null && stageInstances.size() > 0 )
- {
- dataValues.addAll( patientDataValueService.getPatientDataValues( stageInstances ) );
- }
- }
-
- if ( dataValues != null && dataValues.size() > 0 )
- {
- for ( PatientDataValue dataValue : dataValues )
- {
- patientDataValueService.deletePatientDataValue( dataValue );
- }
- }
-
- // ---------------------------------------------------------------------
- // Delete Program Instances
- // ---------------------------------------------------------------------
-
- if ( programInstances != null && programInstances.size() > 0 )
- {
- for ( ProgramInstance programInstance : programInstances )
- {
- programInstanceService.deleteProgramInstance( programInstance );
- }
- }
+ return (programInstances != null && programInstances.size() > 0) ? null : ERROR;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2012-10-01 09:28:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2012-10-02 08:22:33 +0000
@@ -63,17 +63,24 @@
@Override
public String allowDeleteProgramStage( ProgramStage programStage )
{
- String sql = "SELECT COUNT(*) " + "FROM programstageinstance " + "WHERE programstageid=" + programStage.getId();
-
- return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
- }
-
- @Override
- public void deleteProgramInstance( ProgramInstance programInstance )
- {
- String sql = "DELETE FROM programstageinstance " +
- "WHERE programinstanceid = " + programInstance.getId();
-
- jdbcTemplate.execute( sql );
+ String sql = "SELECT COUNT(*) FROM programstageinstance WHERE programstageid=" + programStage.getId();
+
+ return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
+ }
+
+ @Override
+ public String allowDeleteProgramInstance( ProgramInstance programInstance )
+ {
+ String sql = "SELECT COUNT(*) FROM programstageinstance WHERE programinstanceid=" + programInstance.getId();
+
+ return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
+ }
+
+ @Override
+ public String allowDeleteProgram( Program program )
+ {
+ String sql = "SELECT COUNT(*) FROM programstageinstance psi join programinstance pi on pi.programinstanceid=psi.programinstanceid where pi.programid = " + program.getId();
+
+ return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
}
}