← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3745: Fix bug: Cannot delete patient.

 

------------------------------------------------------------
revno: 3745
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-05-26 10:43:41 +0700
message:
  Fix bug: Cannot delete patient.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  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/hibernate/HibernatePatientMobileSettingStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.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-api/src/main/java/org/hisp/dhis/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-04-07 08:21:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-05-26 03:43:41 +0000
@@ -191,6 +191,7 @@
      */
     Collection<Patient> getPatientsByNames( String name, int min, int max );
     
+    Collection<Patient> getRepresentatives( Patient patient );
     /**
      * Search Patient base on identifier value and get number of result
      * 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2010-12-27 07:59:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2011-05-26 03:43:41 +0000
@@ -61,6 +61,8 @@
     
     Collection<Patient> getByOrgUnitProgram( OrganisationUnit organisationUnit, Program program, int min, int max );
     
+    Collection<Patient> getRepresentatives( Patient patient );
+    
     int countListPatientByOrgunit(OrganisationUnit organisationUnit);
     
     int countGetPatientsByName( String name );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-04-07 08:21:36 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-05-26 03:43:41 +0000
@@ -512,4 +512,8 @@
         return null;
     }
 
+    public Collection<Patient> getRepresentatives( Patient patient )
+    {
+        return patientStore.getRepresentatives( patient );
+    }
 }

=== modified 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	2011-04-22 21:04:14 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java	2011-05-26 03:43:41 +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.system.deletion.DeletionHandler;
 
@@ -55,6 +57,19 @@
     }
 
     @Override
+    public void deletePatient( Patient patient )
+    {
+        Collection<Patient> representatives = patientService.getRepresentatives(patient);
+        
+        for(Patient representative : representatives )
+        {
+            representative.setRepresentative( null );
+            representative.setUnderAge( false );
+            patientService.updatePatient( representative );
+        }
+    }
+    
+    @Override
     public void deleteOrganisationUnit( OrganisationUnit unit )
     {
         for ( Patient patient : patientService.getPatients( unit ) )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientMobileSettingStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientMobileSettingStore.java	2011-05-10 08:37:38 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientMobileSettingStore.java	2011-05-26 03:43:41 +0000
@@ -30,7 +30,6 @@
 import java.util.Collection;
 
 import org.hibernate.Criteria;
-import org.hibernate.Hibernate;
 import org.hibernate.Session;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.patient.PatientMobileSetting;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2011-04-12 12:15:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2011-05-26 03:43:41 +0000
@@ -265,4 +265,11 @@
         return rs != null ? rs.intValue() : 0;
     }
 
+    @SuppressWarnings("unchecked")
+    public Collection<Patient> getRepresentatives( Patient patient )
+    {
+        String hql = "select distinct p from Patient p where p.representative = :representative order by p.id";
+
+        return getQuery( hql ).setEntity( "representative", patient ).list();
+    }
 }

=== 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	2011-03-31 01:55:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java	2011-05-26 03:43:41 +0000
@@ -69,14 +69,21 @@
     {
         this.programStageDEService = programStageDEService;
     }
-    
+
     private ProgramAttributeValueService programAttributeValueService;
 
     public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService )
     {
         this.programAttributeValueService = programAttributeValueService;
     }
-    
+
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -92,54 +99,67 @@
     {
         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 attribute values
-        // ---------------------------------------------------------------------
-
-        for ( ProgramInstance programInstance : programInstances )
-        {
-            Collection<ProgramAttributeValue> attributeValues = programAttributeValueService
-                .getProgramAttributeValues( programInstance );
+        if ( programInstances != null )
+        {
+            // ---------------------------------------------------------------------
+            // Delete Patient data values
+            // ---------------------------------------------------------------------
+
+            for ( ProgramInstance programInstance : programInstances )
+            {
+                Set<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
+
+                dataValues.addAll( patientDataValueService.getPatientDataValues( programInstance
+                    .getProgramStageInstances() ) );
+
+                if ( dataValues != null )
+                {
+                    for ( PatientDataValue dataValue : dataValues )
+                    {
+                        patientDataValueService.deletePatientDataValue( dataValue );
+                    }
+                }
+            }
+
+            // ---------------------------------------------------------------------
+            // Delete Program attribute values
+            // ---------------------------------------------------------------------
+
+            for ( ProgramInstance programInstance : programInstances )
+            {
+                Collection<ProgramAttributeValue> attributeValues = programAttributeValueService
+                    .getProgramAttributeValues( programInstance );
+
+                for ( ProgramAttributeValue attributeValue : attributeValues )
+                {
+                    programAttributeValueService.deleteProgramAttributeValue( attributeValue );
+                }
+            }
+
+            // ---------------------------------------------------------------------
+            // Delete Program Stage Instances
+            // ---------------------------------------------------------------------
+
+            for ( ProgramInstance programInstance : programInstances )
+            {
+               Set<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
+               
+               for ( ProgramStageInstance programStageInstance : programStageInstances )
+               { 
+                   programStageInstanceService.deleteProgramStageInstance( programStageInstance );
+               }
+            }
             
-            for ( ProgramAttributeValue attributeValue : attributeValues )
-            {
-                programAttributeValueService.deleteProgramAttributeValue( attributeValue );
-            }
-
-        }
-
-        // ---------------------------------------------------------------------
-        // Delete Program Instances
-        // ---------------------------------------------------------------------
-        
-        if ( programInstances != null && programInstances.size() > 0 )
-        {
+            // ---------------------------------------------------------------------
+            // Delete Program Instances
+            // ---------------------------------------------------------------------
+
             for ( ProgramInstance programInstance : programInstances )
             {
-                programInstanceService.deleteProgramInstance( programInstance );
+                 programInstanceService.deleteProgramInstance( programInstance );
             }
         }
-        
+
     }
 
     @Override
@@ -173,7 +193,7 @@
         // ---------------------------------------------------------------------
         // Delete Program attribute values
         // ---------------------------------------------------------------------
-        
+
         for ( ProgramInstance programInstance : programInstances )
         {
             Collection<ProgramAttributeValue> attributeValues = programAttributeValueService
@@ -185,7 +205,7 @@
             }
 
         }
-        
+
         // ---------------------------------------------------------------------
         // Delete Program Instances
         // ---------------------------------------------------------------------

=== 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	2011-05-23 06:10:58 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-05-26 03:43:41 +0000
@@ -318,6 +318,7 @@
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService"/>
 		<property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService"/>
 		<property name="programAttributeValueService" ref="org.hisp.dhis.programattributevalue.ProgramAttributeValueService"/>
+		<property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService"/>
 	</bean>
 	
 	<bean id="org.hisp.dhis.relationship.RelationshipDeletionHandler" 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml	2011-05-06 04:41:35 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml	2011-05-26 03:43:41 +0000
@@ -24,7 +24,7 @@
     <many-to-one name="program" class="org.hisp.dhis.program.Program" column="programid" not-null="true"
       foreign-key="fk_programinstance_programid" />
 
-    <set name="programStageInstances" order-by="stageinprogram" cascade="all">
+    <set name="programStageInstances" order-by="stageinprogram" >
       <key column="programinstanceid" />
       <one-to-many class="org.hisp.dhis.program.ProgramStageInstance" />
     </set>