=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/DelDataEntryFormAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/DelDataEntryFormAction.java 2011-08-25 05:06:11 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/DelDataEntryFormAction.java 2011-08-25 05:42:18 +0000 @@ -27,8 +27,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; -import java.util.Collections; import java.util.Set; import org.hisp.dhis.dataentryform.DataEntryForm; === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/RemoveProgramStageAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/RemoveProgramStageAction.java 2010-10-20 07:16:54 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/RemoveProgramStageAction.java 2011-08-25 05:42:18 +0000 @@ -27,6 +27,11 @@ package org.hisp.dhis.patient.action.programstage; +import java.util.Set; + +import org.hisp.dhis.dataentryform.DataEntryForm; +import org.hisp.dhis.dataentryform.DataEntryFormService; +import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.program.ProgramStageDataElement; import org.hisp.dhis.program.ProgramStageDataElementService; import org.hisp.dhis.program.ProgramStageService; @@ -44,6 +49,13 @@ // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- + + private DataEntryFormService dataEntryFormService; + + public void setDataEntryFormService( DataEntryFormService dataEntryFormService ) + { + this.dataEntryFormService = dataEntryFormService; + } private ProgramStageService programStageService; @@ -77,11 +89,49 @@ public String execute() throws Exception { - for ( ProgramStageDataElement de : programStageService.getProgramStage( id ).getProgramStageDataElements() ) + ProgramStage programStage = programStageService.getProgramStage( id ); + + for ( ProgramStageDataElement de : programStage.getProgramStageDataElements() ) { programStageDataElementService.deleteProgramStageDataElement( de ); } + // --------------------------------------------------------------------- + // Check dataentry form of the selected programstage in other stages in + // the program + // --------------------------------------------------------------------- + + DataEntryForm dataEntryForm = programStage.getDataEntryForm(); + + boolean flag = false; + + if ( dataEntryForm != null ) + { + Set programStages = programStage.getProgram().getProgramStages(); + + for ( ProgramStage stage : programStages ) + { + if ( !stage.equals( programStage ) && stage.getDataEntryForm() != null ) + { + flag = true; + break; + } + } + + programStage.setDataEntryForm( null ); + + programStageService.updateProgramStage( programStage ); + + if ( !flag ) + { + dataEntryFormService.deleteDataEntryForm( dataEntryForm ); + } + } + + // --------------------------------------------------------------------- + // Delete the selected program stage + // --------------------------------------------------------------------- + programStageService.deleteProgramStage( programStageService.getProgramStage( id ) ); return SUCCESS; === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2011-08-24 08:57:39 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2011-08-25 05:42:18 +0000 @@ -709,6 +709,7 @@ id="org.hisp.dhis.patient.action.programstage.RemoveProgramStageAction" class="org.hisp.dhis.patient.action.programstage.RemoveProgramStageAction" scope="prototype"> +