=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationService.java	2010-05-12 02:15:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationService.java	2010-10-06 16:31:39 +0000
@@ -55,4 +55,6 @@
     Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations( ProgramStageDataElement element );
 
     Collection<ProgramStageDataElementValidation> getAllProgramStageDataElementValidations();
+    
+    Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations( ProgramStage programStage );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationStore.java	2010-05-12 02:15:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementValidationStore.java	2010-10-06 16:31:29 +0000
@@ -47,5 +47,6 @@
     Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations( Program program );
 
     Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations( ProgramStageDataElement element );
-
+    
+    Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations( ProgramStage programStage );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java	2010-09-23 15:16:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java	2010-10-05 07:06:33 +0000
@@ -40,7 +40,6 @@
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.dataelement.CalculatedDataElement;
 import org.hisp.dhis.dataelement.DataElement;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java	2010-02-22 09:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierTypeService.java	2010-10-04 17:52:29 +0000
@@ -56,8 +56,7 @@
 
     public void deletePatientIdentifierType( PatientIdentifierType patientIdentifierType )
     {
-        patientIdentifierTypeStore.save( patientIdentifierType );
-
+        patientIdentifierTypeStore.delete( patientIdentifierType );
     }
 
     public Collection<PatientIdentifierType> getAllPatientIdentifierTypes()

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java	2010-10-04 08:47:42 +0000
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient;
+
+import java.util.Collection;
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version PatientDeletionHandler.java Oct 1, 2010 12:10:21 AM
+ */
+public class PatientDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PatientService patientService;
+
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return Patient.class.getSimpleName();
+    }
+
+    public void deletePatientAttribute( PatientAttribute patientAttribute )
+    {
+        Collection<Patient> patients = patientService.getAllPatients();
+
+        for ( Patient patient : patients )
+        {
+            if ( patient.getAttributes()!= null && patient.getAttributes().contains( patientAttribute ) )
+            {
+                patient.getAttributes().remove( patientAttribute );
+                patientService.updatePatient( patient );
+            }
+        }
+
+    }
+    
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientIdentifierDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientIdentifierDeletionHandler.java	2010-04-23 13:37:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientIdentifierDeletionHandler.java	2010-10-04 18:31:31 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.system.deletion.DeletionHandler;
@@ -68,15 +70,30 @@
             patientIdentifierService.deletePatientIdentifier( patientIdentifier );
         }
     }
-    
+
     @Override
     public void deletePatient( Patient patient )
     {
-        PatientIdentifier patientIdentifier = patientIdentifierService.getPatientIdentifier( patient );
-
-        if ( patientIdentifier != null )
-        {
-            patientIdentifierService.deletePatientIdentifier( patientIdentifier );
+        Collection<PatientIdentifier> patientIdentifiers = patientIdentifierService.getPatientIdentifiers( patient );
+
+        if ( patientIdentifiers.size() > 0 )
+        {
+            for ( PatientIdentifier identifier : patientIdentifiers )
+            {
+                patientIdentifierService.deletePatientIdentifier( identifier );
+            }
+        }
+    }
+
+    @Override
+    public void deletePatientIdentifierType( PatientIdentifierType patientIdentifierType )
+    {
+        Collection<PatientIdentifier> identifiers = patientIdentifierService
+            .getPatientIdentifiersByType( patientIdentifierType );
+
+        for ( PatientIdentifier identifier : identifiers )
+        {
+            patientIdentifierService.deletePatientIdentifier( identifier );
         }
     }
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueDeletionHandler.java	2010-10-04 10:22:36 +0000
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patientattributevalue;
+
+import java.util.Collection;
+
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version PatientAttributeValueDeletionHandler.java Sep 30, 2010 1:34:28 PM
+ */
+public class PatientAttributeValueDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PatientAttributeValueService patientAttributeValueService;
+
+    public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
+    {
+        this.patientAttributeValueService = patientAttributeValueService;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return PatientAttributeValue.class.getSimpleName();
+    }
+
+    @Override
+    public void deletePatient( Patient patient )
+    {
+        Collection<PatientAttributeValue> attributeValues = patientAttributeValueService
+            .getPatientAttributeValues( patient );
+
+        for ( PatientAttributeValue attributeValue : attributeValues )
+        {
+            patientAttributeValueService.deletePatientAttributeValue( attributeValue );
+        }
+    }
+
+    public void deletePatientAttribute( PatientAttribute patientAttribute )
+    {
+        Collection<PatientAttributeValue> attributeValues = patientAttributeValueService
+            .getPatientAttributeValues( patientAttribute );
+
+        if ( attributeValues != null && attributeValues.size() > 0 )
+        {
+            for ( PatientAttributeValue attributeValue : attributeValues )
+            {
+                patientAttributeValueService.deletePatientAttributeValue( attributeValue );
+            }
+        }
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2010-09-22 06:44:36 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/hibernate/HibernatePatientAttributeValueStore.java	2010-10-02 15:12:13 +0000
@@ -55,14 +55,14 @@
 
     public int deleteByAttribute( PatientAttribute patientAttribute )
     {
-        Query query = getQuery( "delete PatientAttributeValue where patientAttribute = :patientAttribute" );
+        Query query = getQuery( "delete from PatientAttributeValue where patientAttribute = :patientAttribute" );
         query.setEntity( "patientAttribute", patientAttribute );
         return query.executeUpdate();
     }
 
     public int deleteByPatient( Patient patient )
     {
-        Query query = getQuery( "delete PatientAttributeValue where patient = :patient" );
+        Query query = getQuery( "delete from PatientAttributeValue where patient = :patient" );
         query.setEntity( "patient", patient );
         return query.executeUpdate();
     }
@@ -100,7 +100,7 @@
 
     public int delete( DataElementCategoryOptionCombo optionCombo )
     {
-        Query query = getQuery( "delete PatientDataValue where optionCombo = :optionCombo" );
+        Query query = getQuery( "delete from PatientDataValue where optionCombo = :optionCombo" );
         query.setEntity( "optionCombo", optionCombo );
         return query.executeUpdate();
     }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2009-10-28 19:47:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/hibernate/HibernatePatientDataValueStore.java	2010-10-03 16:59:10 +0000
@@ -54,21 +54,21 @@
 
     public int delete( ProgramStageInstance programStageInstance )
     {
-        Query query = getQuery( "delete PatientDataValue where programStageInstance = :programStageInstance" );
+        Query query = getQuery( "delete from PatientDataValue where programStageInstance = :programStageInstance" );
         query.setEntity( "programStageInstance", programStageInstance );
         return query.executeUpdate();
     }
 
     public int delete( DataElement dataElement )
     {
-        Query query = getQuery( "delete PatientDataValue where dataElement = :dataElement" );
+        Query query = getQuery( "delete from PatientDataValue where dataElement = :dataElement" );
         query.setEntity( "dataElement", dataElement );
         return query.executeUpdate();
     }
 
     public int delete( DataElementCategoryOptionCombo optionCombo )
     {
-        Query query = getQuery( "delete PatientDataValue where optionCombo = :optionCombo" );
+        Query query = getQuery( "delete from PatientDataValue where optionCombo = :optionCombo" );
         query.setEntity( "optionCombo", optionCombo );
         return query.executeUpdate();
     }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageDataElementValidationService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageDataElementValidationService.java	2010-05-12 02:15:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageDataElementValidationService.java	2010-10-06 16:32:28 +0000
@@ -92,4 +92,10 @@
         return validationStore.getProgramStageDataElementValidations( element );
     }
 
+    public Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations(
+        ProgramStage programStage )
+    {
+        return validationStore.getProgramStageDataElementValidations( programStage );
+    }
+
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java	2010-10-06 17:26:11 +0000
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.validation.ValidationCriteria;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ProgramDeleteHandler.java Sep 30, 2010 1:39:15 PM
+ */
+public class ProgramDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PatientService patientService;
+
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    // -------------------------------------------------------------------------
+
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return Program.class.getSimpleName();
+    }
+
+    @Override
+    public void deletePatient( Patient patient )
+    {
+        Set<Program> programs = patient.getPrograms();
+
+        if ( programs != null )
+        {
+            patient.setPrograms( null );
+
+            patientService.updatePatient( patient );
+        }
+    }
+
+    @Override
+    public void deleteValidationCriteria( ValidationCriteria validationCriteria )
+    {
+        Collection<Program> programs = programService.getPrograms( validationCriteria );
+        
+        for(Program program : programs){
+            program.getPatientValidationCriteria().remove( validationCriteria );
+            programService.updateProgram( program );
+        }
+        
+    }
+}

=== removed file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeleteHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeleteHandler.java	2010-05-10 17:50:39 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeleteHandler.java	1970-01-01 00:00:00 +0000
@@ -1,69 +0,0 @@
-package org.hisp.dhis.program;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.system.deletion.DeletionHandler;
-
-/**
- * @author Quang Nguyen
- * @version $Id$
- */
-public class ProgramInstanceDeleteHandler
-    extends DeletionHandler
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private ProgramInstanceService programInstanceService;
-
-    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
-    {
-        this.programInstanceService = programInstanceService;
-    }
-
-    // -------------------------------------------------------------------------
-    // DeletionHandler implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public String getClassName()
-    {
-        return ProgramInstance.class.getSimpleName();
-    }
-
-    @Override
-    public void deletePatient( Patient patient )
-    {
-        for(ProgramInstance programInstance : programInstanceService.getProgramInstances( patient ))
-        {
-            programInstanceService.deleteProgramInstance( programInstance );
-        }
-    }
-}

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java	2010-10-06 15:23:43 +0000
@@ -0,0 +1,160 @@
+package org.hisp.dhis.program;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Quang Nguyen
+ * @version $Id$
+ */
+public class ProgramInstanceDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ProgramInstanceService programInstanceService;
+
+    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+    {
+        this.programInstanceService = programInstanceService;
+    }
+
+    private PatientDataValueService patientDataValueService;
+
+    public void setPatientDataValueService( PatientDataValueService patientDataValueService )
+    {
+        this.patientDataValueService = patientDataValueService;
+    }
+
+    ProgramStageDataElementService programStageDEService;
+
+    public void setProgramStageDEService( ProgramStageDataElementService programStageDEService )
+    {
+        this.programStageDEService = programStageDEService;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return ProgramInstance.class.getSimpleName();
+    }
+
+    @Override
+    public void deletePatient( Patient patient )
+    {
+        Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( patient );
+
+        // ---------------------------------------------------------------------
+        // Delete Patient data values
+        // ---------------------------------------------------------------------
+
+        Set<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
+
+        for ( ProgramInstance programInstance : programInstances )
+        {
+            dataValues.addAll( patientDataValueService
+                .getPatientDataValues( programInstance.getProgramStageInstances() ) );
+        }
+
+        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 );
+            }
+        }
+    }
+
+    @Override
+    public void deleteProgram( 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 );
+            }
+        }
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java	2010-10-06 17:32:40 +0000
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ProgramStageDataElementDeletionHandler.java Oct 5, 2010 11:06:03 PM
+ */
+public class ProgramStageDataElementDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    ProgramStageDataElementService programStageDEService;
+
+    public void setProgramStageDEService( ProgramStageDataElementService programStageDEService )
+    {
+        this.programStageDEService = programStageDEService;
+    }
+
+    ProgramStageDataElementValidationService programStageDEValidationService;
+
+    public void setProgramStageDEValidationService(
+        ProgramStageDataElementValidationService programStageDEValidationService )
+    {
+        this.programStageDEValidationService = programStageDEValidationService;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return ProgramInstance.class.getSimpleName();
+    }
+
+    @Override
+    public void deleteProgram( Program program )
+    {
+        // ---------------------------------------------------------------------
+        // Delete Program Stage data element validations
+        // ---------------------------------------------------------------------
+
+        Collection<ProgramStageDataElementValidation> validations = programStageDEValidationService
+            .getProgramStageDataElementValidations( program );
+
+        for ( ProgramStageDataElementValidation validation : validations )
+        {
+            programStageDEValidationService.deleteProgramStageDataElementValidation( validation );
+        }
+
+        // ---------------------------------------------------------------------
+        // Delete Program Stage data elements
+        // ---------------------------------------------------------------------
+
+        Set<ProgramStage> programStages = program.getProgramStages();
+
+        for ( ProgramStage programStage : programStages )
+        {
+            Collection<ProgramStageDataElement> dataElements = programStageDEService.get( programStage );
+            if ( dataElements != null && dataElements.size() > 0 )
+            {
+                for ( ProgramStageDataElement dataElement : dataElements )
+                {
+                    programStageDEService.deleteProgramStageDataElement( dataElement );
+                }
+
+            }
+        }
+    }
+
+    @Override
+    public void deleteProgramStage( ProgramStage programStage )
+    {
+        // ---------------------------------------------------------------------
+        // Delete Program Stage data element validations
+        // ---------------------------------------------------------------------
+
+        Collection<ProgramStageDataElementValidation> validations = programStageDEValidationService
+            .getProgramStageDataElementValidations( programStage );
+
+        for ( ProgramStageDataElementValidation validation : validations )
+        {
+            programStageDEValidationService.deleteProgramStageDataElementValidation( validation );
+        }
+
+        // ---------------------------------------------------------------------
+        // Delete Program Stage data elements
+        // ---------------------------------------------------------------------
+
+        Collection<ProgramStageDataElement> dataElements = programStageDEService.get( programStage );
+        if ( dataElements != null && dataElements.size() > 0 )
+        {
+            for ( ProgramStageDataElement dataElement : dataElements )
+            {
+                programStageDEService.deleteProgramStageDataElement( dataElement );
+            }
+
+        }
+
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementValidationStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementValidationStore.java	2010-05-12 02:15:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementValidationStore.java	2010-10-06 16:35:21 +0000
@@ -33,6 +33,7 @@
 import org.hibernate.Session;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramStageDataElementValidation;
 import org.hisp.dhis.program.ProgramStageDataElementValidationStore;
@@ -81,4 +82,19 @@
         return query.list();
     }
 
+    @SuppressWarnings( "unchecked" )
+    public Collection<ProgramStageDataElementValidation> getProgramStageDataElementValidations(
+        ProgramStage programStage )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session
+            .createQuery( "from ProgramStageDataElementValidation c where "
+                + "c.leftProgramStageDataElement.programStage.id = :programStageId or "
+                + "c.rightProgramStageDataElement.programStage.id = :programStageId" );
+
+        query.setInteger( "programStageId", programStage.getId() );
+
+        return query.list();
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/relationship/RelationshipDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/relationship/RelationshipDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/relationship/RelationshipDeletionHandler.java	2010-10-04 18:43:05 +0000
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.relationship;
+
+import java.util.Collection;
+
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version RelationshipDeletionHandler.java Sep 30, 2010 1:20:23 PM
+ */
+public class RelationshipDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private RelationshipService relationshipSevice;
+
+    public void setRelationshipSevice( RelationshipService relationshipSevice )
+    {
+        this.relationshipSevice = relationshipSevice;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return Relationship.class.getSimpleName();
+    }
+
+    @Override
+    public void deletePatient( Patient patient )
+    {
+        Collection<Relationship> relationships = relationshipSevice.getRelationshipsForPatient( patient );
+
+        if ( relationships != null )
+        {
+            for ( Relationship relationship : relationships )
+            {
+                relationshipSevice.deleteRelationship( relationship );
+            }
+        }
+    }
+
+    @Override
+    public void deleteRelationshipType( RelationshipType relationshipType )
+    {
+        Collection<Relationship> relationships = relationshipSevice
+            .getRelationshipsByRelationshipType( relationshipType );
+        
+        for ( Relationship relationship : relationships )
+        {
+            relationshipSevice.deleteRelationship( relationship );
+        }
+    }
+
+}

=== 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	2010-05-27 08:42:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2010-10-06 17:37:19 +0000
@@ -1,8 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
-	xsi:schemaLocation="
-http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
 
 	<!-- Store definitions -->
 	
@@ -228,23 +230,115 @@
 		<property name="patientIdentifierService" ref="org.hisp.dhis.patient.PatientIdentifierService"/>
 	</bean>
 
-	<bean id="org.hisp.dhis.program.ProgramInstanceDeleteHandler" 
-		class="org.hisp.dhis.program.ProgramInstanceDeleteHandler">
+	<bean id="org.hisp.dhis.program.ProgramInstanceDeletionHandler" 
+		class="org.hisp.dhis.program.ProgramInstanceDeletionHandler">
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService"/>
-	</bean>
-
+		<property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService"/>
+		<property name="programStageDEService" ref="org.hisp.dhis.program.ProgramStageDataElementService"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.relationship.RelationshipDeletionHandler" 
+		class="org.hisp.dhis.relationship.RelationshipDeletionHandler">
+		<property name="relationshipSevice" ref="org.hisp.dhis.relationship.RelationshipService"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.patientattributevalue.PatientAttributeValueDeletionHandler" 
+		class="org.hisp.dhis.patientattributevalue.PatientAttributeValueDeletionHandler">
+		<property name="patientAttributeValueService" ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramDeletionHandler" 
+		class="org.hisp.dhis.program.ProgramDeletionHandler">
+		<property name="patientService" ref="org.hisp.dhis.patient.PatientService"/>
+		<property name="programService" ref="org.hisp.dhis.program.ProgramService"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.patient.PatientDeletionHandler" 
+		class="org.hisp.dhis.patient.PatientDeletionHandler">
+		<property name="patientService" ref="org.hisp.dhis.patient.PatientService"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler" 
+		class="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler">
+		<property name="programStageDEService" ref="org.hisp.dhis.program.ProgramStageDataElementService"/>
+		<property name="programStageDEValidationService" ref="org.hisp.dhis.program.ProgramStageDataElementValidationService"/>
+	</bean>
+	
 	<!-- DeletionManager -->
   
   	<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-		<property name="targetObject" ref="deletionManager"/>
-		<property name="targetMethod" value="addDeletionHandlers"/>
-		<property name="arguments">
+    	<property name="targetObject" ref="deletionManager"/>
+    	<property name="targetMethod" value="addDeletionHandlers"/>
+    	<property name="arguments">
 		  <list>
 			<list>
+			  <ref local="org.hisp.dhis.patient.PatientDeletionHandler"/>
+			  <ref local="org.hisp.dhis.patientattributevalue.PatientAttributeValueDeletionHandler"/>
 			  <ref local="org.hisp.dhis.patient.PatientIdentifierDeletionHandler"/>
-			  <ref local="org.hisp.dhis.program.ProgramInstanceDeleteHandler"/>
+			  <ref local="org.hisp.dhis.relationship.RelationshipDeletionHandler"/>
+			  
+			  <ref local="org.hisp.dhis.program.ProgramDeletionHandler"/>
+			  <ref local="org.hisp.dhis.program.ProgramInstanceDeletionHandler"/>
+			  <ref local="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler"/>
 			</list>
 		  </list>
 		</property>
 	</bean>
+	
+	<!-- AOP definitions -->
+  
+  	<aop:config>
+  	
+	    <aop:aspect ref="deletionInterceptor">
+	       
+	      <aop:before 
+		      pointcut="execution( * org.hisp.dhis.patient.PatientService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+	      	pointcut="execution( * org.hisp.dhis.patientattributevalue.PatientAttributeValueService.delete*(..) )" 
+	      	method="intercept"/>
+	      <aop:before
+		      pointcut="execution( * org.hisp.dhis.patient.PatientAttributeService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.patient.PatientIdentifierService.delete*(..) )" 
+		      method="intercept"/>
+		   <aop:before 
+		      pointcut="execution( * org.hisp.dhis.patient.PatientIdentifierTypeService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.relationship.RelationshipService.delete*(..) )" 
+		      method="intercept"/>
+		   <aop:before 
+		      pointcut="execution( * org.hisp.dhis.relationship.RelationshipTypeService.delete*(..) )" 
+		      method="intercept"/>
+		 
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramInstanceService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramStageService.delete*(..) )" 
+		      method="intercept"/>
+	      <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramStageInstanceService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramStageDataElementService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.program.ProgramStageInstanceService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.patientdatavalue.PatientDataValueService.delete*(..) )" 
+		      method="intercept"/>
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.validation.ValidationCriteriaService.delete*(..) )" 
+		      method="intercept"/>
+	    </aop:aspect>
+      
+  	</aop:config>
+  
 </beans>

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2010-09-17 12:11:18 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2010-10-01 11:13:23 +0000
@@ -38,7 +38,6 @@
 import org.hisp.dhis.common.DeleteNotAllowedException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.source.Source;
-import org.springframework.stereotype.Component;
 
 /**
  * @author Lars Helge Overland
@@ -71,7 +70,6 @@
     @SuppressWarnings( "unchecked" )
     public void execute( Object object )
     {
-
         Class clazz = object.getClass();
 
         if ( object instanceof OrganisationUnit )
@@ -92,11 +90,11 @@
         try
         {
             Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[] { clazz }  );
-            
+
             for ( DeletionHandler handler : handlers )
             {   
                 currentHandler = handler.getClass().getSimpleName();
-                
+
                 boolean allow = (Boolean) allowMethod.invoke( handler, object );
                 
                 if ( !allow )
@@ -127,7 +125,7 @@
         try
         {
             Method deleteMethod = DeletionHandler.class.getMethod( deleteMethodName, new Class[] { clazz } );
-        
+
             for ( DeletionHandler handler : handlers )
             {
                 currentHandler = handler.getClass().getSimpleName();

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2010-09-04 07:26:32 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2010-10-06 17:22:50 +0000
@@ -63,7 +63,20 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeGroup;
+import org.hisp.dhis.patient.PatientIdentifier;
+import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.relationship.Relationship;
+import org.hisp.dhis.relationship.RelationshipType;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.source.Source;
@@ -71,6 +84,7 @@
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserSetting;
+import org.hisp.dhis.validation.ValidationCriteria;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleGroup;
 
@@ -99,27 +113,27 @@
     // -------------------------------------------------------------------------
 
     public void deleteChart( Chart chart )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteChart( Chart chart )
     {
         return true;
     }
-    
+
     public void deleteDataDictionary( DataDictionary dataDictionary )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteDataDictionary( DataDictionary dataDictionary )
     {
         return true;
     }
-    
+
     public void deleteDataElement( DataElement dataElement )
     {
     }
-    
+
     public boolean allowDeleteDataElement( DataElement dataElement )
     {
         return true;
@@ -128,12 +142,12 @@
     public void deleteCalculatedDataElement( CalculatedDataElement dataElement )
     {
     }
-    
+
     public boolean allowDeleteCalculatedDataElement( CalculatedDataElement dataElement )
     {
         return true;
     }
-    
+
     public void deleteDataElementGroup( DataElementGroup dataElementGroup )
     {
     }
@@ -142,16 +156,16 @@
     {
         return true;
     }
-    
+
     public void deleteDataElementGroupSet( DataElementGroupSet dataElementGroupSet )
     {
     }
-    
+
     public boolean allowDeleteDataElementGroupSet( DataElementGroupSet dataElementGroupSet )
     {
         return true;
     }
-    
+
     public void deleteDataElementCategory( DataElementCategory category )
     {
     }
@@ -160,7 +174,7 @@
     {
         return true;
     }
-    
+
     public void deleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
     {
     }
@@ -169,7 +183,7 @@
     {
         return true;
     }
-    
+
     public void deleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
     {
     }
@@ -178,7 +192,7 @@
     {
         return true;
     }
-    
+
     public void deleteDataElementCategoryOptionCombo( DataElementCategoryOptionCombo categoryOptionCombo )
     {
     }
@@ -186,8 +200,8 @@
     public boolean allowDeleteDataElementCategoryOptionCombo( DataElementCategoryOptionCombo categoryOptionCombo )
     {
         return true;
-    }    
-    
+    }
+
     public void deleteDataSet( DataSet dataSet )
     {
     }
@@ -196,25 +210,25 @@
     {
         return true;
     }
-    
+
     public void deleteSection( Section section )
-    {   
+    {
     }
 
     public boolean allowDeleteSection( Section section )
     {
         return true;
     }
-    
+
     public void deleteCompleteDataSetRegistration( CompleteDataSetRegistration registration )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteCompleteDataSetRegistration( CompleteDataSetRegistration registration )
     {
         return true;
     }
-    
+
     public void deleteDataValue( DataValue dataValue )
     {
     }
@@ -223,7 +237,7 @@
     {
         return true;
     }
-    
+
     public void deleteExpression( Expression expression )
     {
     }
@@ -232,16 +246,16 @@
     {
         return true;
     }
-    
+
     public void deleteMinMaxDataElement( MinMaxDataElement minMaxDataElement )
-    {   
+    {
     }
 
     public boolean allowDeleteMinMaxDataElement( MinMaxDataElement minMaxDataElement )
     {
         return true;
     }
-    
+
     public void deleteIndicator( Indicator indicator )
     {
     }
@@ -250,7 +264,7 @@
     {
         return true;
     }
-    
+
     public void deleteIndicatorGroup( IndicatorGroup indicatorGroup )
     {
     }
@@ -259,9 +273,9 @@
     {
         return true;
     }
-    
+
     public void deleteIndicatorType( IndicatorType indicatorType )
-    {   
+    {
     }
 
     public boolean allowDeleteIndicatorType( IndicatorType indicatorType )
@@ -272,12 +286,12 @@
     public void deleteIndicatorGroupSet( IndicatorGroupSet indicatorGroupSet )
     {
     }
-    
+
     public boolean allowDeleteIndicatorGroupSet( IndicatorGroupSet indicatorGroupSet )
     {
         return true;
     }
-    
+
     public void deletePeriod( Period period )
     {
     }
@@ -286,7 +300,7 @@
     {
         return true;
     }
-    
+
     public void deleteSource( Source source )
     {
     }
@@ -295,7 +309,7 @@
     {
         return true;
     }
-    
+
     public void deleteValidationRule( ValidationRule validationRule )
     {
     }
@@ -304,43 +318,43 @@
     {
         return true;
     }
-    
+
     public void deleteValidationRuleGroup( ValidationRuleGroup validationRuleGroup )
-    {   
+    {
     }
 
     public boolean allowDeleteValidationRuleGroup( ValidationRuleGroup validationRuleGroup )
     {
         return true;
     }
-    
+
     public void deleteFrequencyOverrideAssociation( FrequencyOverrideAssociation association )
-    {   
+    {
     }
 
     public boolean allowDeleteFrequencyOverrideAssociation( FrequencyOverrideAssociation association )
     {
         return true;
     }
-    
+
     public void deleteDataEntryForm( DataEntryForm form )
-    {   
+    {
     }
 
     public boolean allowDeleteDataEntryForm( DataEntryForm form )
     {
         return true;
     }
-    
+
     public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
-    {   
+    {
     }
 
     public boolean allowDeleteOrganisationUnitGroup( OrganisationUnitGroup group )
     {
         return true;
     }
-    
+
     public void deleteOrganisationUnitGroupSet( OrganisationUnitGroupSet groupSet )
     {
     }
@@ -349,156 +363,147 @@
     {
         return true;
     }
-    
+
     public void deleteOrganisationUnitLevel( OrganisationUnitLevel level )
-    {   
+    {
     }
 
     public boolean allowDeleteOrganisationUnitLevel( OrganisationUnitLevel level )
     {
         return true;
     }
-    
+
     public void deleteReport( Report report )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteReport( Report report )
     {
         return true;
     }
-    
+
     public void deleteReportTable( ReportTable reportTable )
-    {   
+    {
     }
 
     public boolean allowDeleteReportTable( ReportTable reportTable )
     {
         return true;
     }
-    
+
     public void deleteUser( User user )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteUser( User user )
     {
         return true;
     }
-    
+
     public void deleteUserCredentials( UserCredentials credentials )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteUserCredentials( UserCredentials credentials )
     {
         return true;
     }
-    
+
     public void deleteUserAuthorityGroup( UserAuthorityGroup authorityGroup )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteUserAuthorityGroup( UserAuthorityGroup authorityGroup )
     {
         return true;
     }
-    
+
     public void deleteUserSetting( UserSetting userSetting )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteUserSetting( UserSetting userSetting )
     {
         return true;
     }
-    
+
     public void deleteDataMartExport( DataMartExport dataMartExport )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteDataMartExport( DataMartExport dataMartExport )
     {
         return true;
     }
-    
+
     public void deleteOlapURL( OlapURL olapURL )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteOlapURL( OlapURL olapURL )
     {
         return true;
     }
-    
+
     public void deleteDocument( Document document )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteDocument( Document document )
     {
         return true;
     }
-    
+
     public void deleteMap( Map map )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteMap( Map map )
     {
         return true;
     }
-    
+
     public void deleteMapLegend( MapLegend mapLegend )
     {
     }
-    
+
     public boolean allowDeleteMapLegend( MapLegend mapLegend )
     {
         return true;
     }
-    
+
     public void deleteMapLegendSet( MapLegendSet mapLegendSet )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteMapLegendSet( MapLegendSet mapLegendSet )
     {
         return true;
     }
-    
+
     public void deleteMapOrganisationUnitRelation( MapOrganisationUnitRelation mapOrganisationUnitRelation )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteMapOrganisationUnitRelation( MapOrganisationUnitRelation mapOrganisationUnitRelation )
     {
         return true;
     }
-    
+
     public void deleteMapView( MapView mapView )
-    {   
+    {
     }
-    
+
     public boolean allowDeleteMapView( MapView mapView )
     {
         return true;
     }
 
-    public void deletePatient( Patient patient )
-    {
-    }
-
-    public boolean allowDeletePatient( Patient patient )
-    {
-        return true;
-    }
-    
     public boolean allowDeleteLegend( Legend legend )
     {
         return true;
     }
-    
+
     public void deleteConcept( Concept concept )
     {
     }
@@ -507,4 +512,141 @@
     {
         return true;
     }
+
+    public boolean allowDeletePatient( Patient patient )
+    {
+        return true;
+    }
+
+    public void deletePatient( Patient patient )
+    {
+    }
+
+    public boolean allowDeletePatientAttribute( PatientAttribute patientAttribute )
+    {
+        return true;
+    }
+
+    public void deletePatientAttribute( PatientAttribute patientAttribute )
+    {
+
+    }
+
+    public boolean allowDeletePatientAttributeValue( PatientAttributeValue patientAttributeValue )
+    {
+        return true;
+    }
+
+    public void deletePatientAttributeValue( PatientAttributeValue patientAttributeValue )
+    {
+    }
+
+    public boolean allowDeletePatientAttributeGroup( PatientAttributeGroup patientAttributeGroup )
+    {
+        return true;
+    }
+
+    public void deletePatientAttributeGroup( PatientAttributeGroup patientAttributeGroup )
+    {
+    }
+
+    public boolean allowDeletePatientIdentifier( PatientIdentifier patientIdentifier )
+    {
+        return true;
+    }
+
+    public void deletePatientIdentifier( PatientIdentifier patientIdentifier )
+    {
+    }
+
+    public boolean allowDeletePatientIdentifierType( PatientIdentifierType patientIdentifierType )
+    {
+        return true;
+    }
+
+    public void deletePatientIdentifierType( PatientIdentifierType patientIdentifierType )
+    {
+    }
+
+    public boolean allowDeleteRelationship( Relationship relationship )
+    {
+        return true;
+    }
+
+    public void deleteRelationship( Relationship relationship )
+    {
+    }
+
+    public boolean allowDeleteRelationshipType( RelationshipType relationshipType )
+    {
+        return true;
+    }
+
+    public void deleteRelationshipType( RelationshipType relationshipType )
+    {
+    }
+    
+    public boolean allowDeleteProgram( Program program )
+    {
+        return true;
+    }
+
+    public void deleteProgram( Program program )
+    {
+    }
+
+    public boolean allowDeleteProgramInstance( ProgramInstance programInstance )
+    {
+        return true;
+    }
+
+    public void deleteProgramInstance( ProgramInstance programInstance )
+    {
+    }
+    
+    public boolean allowDeleteProgramStage( ProgramStage programStage )
+    {
+        return true;
+    }
+
+    public void deleteProgramStage( ProgramStage programStage )
+    {
+    }
+    
+    public boolean allowDeleteProgramStageInstance( ProgramStageInstance programStageInstance )
+    {
+        return true;
+    }
+
+    public void deleteProgramStageInstance( ProgramStageInstance programStageInstance )
+    {
+    }
+    
+    public boolean allowDeleteProgramStageDataElement( ProgramStageDataElement programStageDataElement )
+    {
+        return true;
+    }
+
+    public void deleteProgramStageDataElement( ProgramStageDataElement programStageDataElement )
+    {
+    }
+    
+    
+    public boolean allowDeletePatientDataValue( PatientDataValue patientDataValue )
+    {
+        return true;
+    }
+
+    public void deletePatientDataValue( PatientDataValue patientDataValue )
+    {
+    }
+    
+    public boolean allowDeleteValidationCriteria( ValidationCriteria validationCriteria )
+    {
+        return true;
+    }
+
+    public void deleteValidationCriteria( ValidationCriteria validationCriteria )
+    {
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2010-09-28 04:02:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2010-09-28 07:40:59 +0000
@@ -84,7 +84,6 @@
 			<result name="success" type="velocity">/main.vm</result>
 			<param name="page">/dhis-web-maintenance-datadictionary/addDataElementForm.vm</param>
 			<param name="javascripts">javascript/shortName.js,javascript/dataElement.js</param>
-			<param name="stylesheets">style/dhis-web-maintenance-datadictionary.css</param>
 			<param name="requiredAuthorities">F_DATAELEMENT_ADD</param>
 		</action>
 
@@ -100,7 +99,6 @@
 			<result name="success" type="velocity">/main.vm</result>
 			<param name="page">/dhis-web-maintenance-datadictionary/updateDataElementForm.vm</param>
 			<param name="javascripts">javascript/shortName.js,javascript/dataElement.js,javascript/updateLoad.js</param>
-			<param name="stylesheets">style/dhis-web-maintenance-datadictionary.css</param>
 			<param name="requiredAuthorities">F_DATAELEMENT_UPDATE</param>
 		</action>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/RemovePatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/RemovePatientAction.java	2009-11-24 16:26:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/RemovePatientAction.java	2010-10-01 11:04:11 +0000
@@ -27,7 +27,8 @@
 
 package org.hisp.dhis.patient.action.patient;
 
-import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.patient.PatientService;
 
 import com.opensymphony.xwork2.Action;
@@ -61,16 +62,39 @@
         this.id = id;
     }
 
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
     public String execute()
-        throws Exception
     {
-        Patient patient = patientService.getPatient( id );
+        try
+        {
+            patientService.deletePatient( patientService.getPatient( id ) );
+        }
+        catch ( DeleteNotAllowedException ex )
+        {
+            if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+            {
+                message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getClassName();
 
-        patientService.deletePatient( patient );
+                return ERROR;
+            }
+        }
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java	2009-10-22 07:41:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java	2010-10-04 17:50:24 +0000
@@ -27,6 +27,8 @@
 
 package org.hisp.dhis.patient.action.patientattribute;
 
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientAttributeService;
 
@@ -60,13 +62,42 @@
     {
         this.id = id;
     }
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Implementation Action
+    // -------------------------------------------------------------------------
 
     public String execute()
-        throws Exception
     {
-        PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( id );
-
-        patientAttributeService.deletePatientAttribute( patientAttribute );
+        try
+        {
+            PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( id );
+
+            patientAttributeService.deletePatientAttribute( patientAttribute );
+
+        }
+        catch ( DeleteNotAllowedException ex )
+        {
+            if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+            {
+                message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getClassName();
+
+                return ERROR;
+            }
+        }
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/RemovePatientIdentifierTypeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/RemovePatientIdentifierTypeAction.java	2010-02-22 09:19:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/RemovePatientIdentifierTypeAction.java	2010-10-04 17:51:08 +0000
@@ -27,6 +27,7 @@
 
 package org.hisp.dhis.patient.action.patientidentifiertype;
 
+import org.hisp.dhis.common.DeleteNotAllowedException;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
@@ -51,43 +52,55 @@
     // -------------------------------------------------------------------------
 
     private Integer id;
-    
+
     private String message;
-    
+
     private I18n i18n;
-    
+
     // -------------------------------------------------------------------------
     // Action
     // -------------------------------------------------------------------------
 
     public String execute()
-        throws Exception
     {
-        
-        if( id == null ){
-            message = i18n.getString("can_not_find_patient_identifier_type_with_id_null") ;
-            return ERROR;
-        }
-        
-        PatientIdentifierType patientIdentifierType = patientIdentifierTypeService.getPatientIdentifierType( id );
-        
-        if( patientIdentifierType != null ){
-            patientIdentifierTypeService.deletePatientIdentifierType( patientIdentifierType );
-            message = i18n.getString("delete_successfull") + patientIdentifierType.getName();
-            return SUCCESS;
-        }
-        else {
-            message = i18n.getString("can_not_find_patient_identifier_type_with_id") + id.toString();
-            return ERROR;
-        }
-
+        try
+        {
+            if ( id == null )
+            {
+                message = i18n.getString( "can_not_find_patient_identifier_type_with_id_null" );
+                return ERROR;
+            }
+
+            PatientIdentifierType patientIdentifierType = patientIdentifierTypeService.getPatientIdentifierType( id );
+
+            if ( patientIdentifierType != null )
+            {
+                patientIdentifierTypeService.deletePatientIdentifierType( patientIdentifierType );
+                message = i18n.getString( "delete_successfull" ) + patientIdentifierType.getName();
+                return SUCCESS;
+            }
+            else
+            {
+                message = i18n.getString( "can_not_find_patient_identifier_type_with_id" ) + id.toString();
+                return ERROR;
+            }
+        }
+        catch ( DeleteNotAllowedException ex )
+        {
+            if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+            {
+                message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getClassName();
+
+                return ERROR;
+            }
+        }
+
+        return ERROR;
     }
-    
-    
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
-    
 
     public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
     {
@@ -98,7 +111,7 @@
     {
         this.id = id;
     }
-    
+
     public String getMessage()
     {
         return message;

