← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4435: Cannot delete a program stage if it has dataentry form.

 

------------------------------------------------------------
revno: 4435
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-08-25 12:42:18 +0700
message:
  Cannot delete a program stage if it has dataentry form.
modified:
  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/programstage/RemoveProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-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-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<ProgramStage> 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">
+		<property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
 		<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
 		<property name="programStageDataElementService"
 			ref="org.hisp.dhis.program.ProgramStageDataElementService" />