← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5513: DeletionHandler for program.

 

------------------------------------------------------------
revno: 5513
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-12-21 11:23:59 +0700
message:
  DeletionHandler for program.
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/HibernatePatientStore.java
  dhis-2/dhis-services/dhis-service-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-api/src/main/java/org/hisp/dhis/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-05-26 03:43:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2011-12-21 04:23:59 +0000
@@ -221,4 +221,6 @@
     
     Object getObjectValue( String property, String value, I18nFormat format );
     
+    void removeErollmentPrograms( Program program );
+    
 }

=== 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	2011-05-26 03:43:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2011-12-21 04:23:59 +0000
@@ -68,4 +68,6 @@
     int countGetPatientsByName( String name );
     
     int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program );
+
+    void removeErollmentPrograms( Program program );
 }

=== 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-09-28 07:00:14 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2011-12-21 04:23:59 +0000
@@ -330,7 +330,8 @@
     @Override
     public Collection<Patient> sortPatientsByAttribute( Collection<Patient> patients, PatientAttribute patientAttribute )
     {
-//        List<PatientAttributeValue> patientsSortedByAttribute = new ArrayList<PatientAttributeValue>();
+        // List<PatientAttributeValue> patientsSortedByAttribute = new
+        // ArrayList<PatientAttributeValue>();
 
         Collection<Patient> sortedPatients = new ArrayList<Patient>();
 
@@ -341,7 +342,7 @@
 
         Collection<PatientAttributeValue> patientAttributeValues = patientAttributeValueService
             .getPatientAttributeValues( patients );
-        
+
         if ( patientAttributeValues != null )
         {
             for ( PatientAttributeValue patientAttributeValue : patientAttributeValues )
@@ -360,7 +361,7 @@
         // ---------------------------------------------------------------------
 
         sortedPatients.addAll( patients );
-        
+
         return sortedPatients;
     }
 
@@ -502,4 +503,9 @@
     {
         return patientStore.getRepresentatives( patient );
     }
+
+    public void removeErollmentPrograms( Program program )
+    {
+        patientStore.removeErollmentPrograms( program );
+    }
 }

=== 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-09-29 07:41:04 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java	2011-12-21 04:23:59 +0000
@@ -30,6 +30,7 @@
 import java.util.Collection;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.Program;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 public class PatientDeletionHandler
@@ -77,4 +78,10 @@
             patientService.deletePatient( patient );
         }
     }
+    
+    @Override
+    public void deleteProgram( Program program )
+    {
+        patientService.removeErollmentPrograms( program );
+    }
 }

=== 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-08-30 09:00:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2011-12-21 04:23:59 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientStore;
 import org.hisp.dhis.program.Program;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -78,6 +79,13 @@
         this.statementManager = statementManager;
     }
 
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -101,7 +109,7 @@
     }
 
     public Collection<Patient> getByNames( String name )
-    {   
+    {
         String sql = statementBuilder.getPatientsByFullName( name );
 
         StatementHolder holder = statementManager.getHolder();
@@ -131,9 +139,9 @@
 
         return patients;
     }
-    
+
     public Collection<Patient> getByNames( String name, int min, int max )
-    {   
+    {
         String sql = statementBuilder.getPatientsByFullName( name, min, max );
 
         StatementHolder holder = statementManager.getHolder();
@@ -179,7 +187,7 @@
 
         if ( StringUtils.isNotBlank( lastName ) )
             con.add( Restrictions.ilike( "lastName", lastName ) );
-        
+
         con.add( Restrictions.eq( "gender", gender ) );
         con.add( Restrictions.eq( "birthDate", birthdate ) );
 
@@ -265,11 +273,18 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public Collection<Patient> getRepresentatives( Patient patient )
     {
         String hql = "select distinct p from Patient p where p.representative = :representative order by p.id DESC";
 
         return getQuery( hql ).setEntity( "representative", patient ).list();
     }
+
+    public void removeErollmentPrograms( Program program )
+    {
+        String sql = "delete from patient_programs where programid='" + program.getId() + "'";
+        
+        jdbcTemplate.execute( sql );
+    }
 }

=== 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-12-14 07:33:18 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-12-21 04:23:59 +0000
@@ -66,6 +66,7 @@
 		<property name="sessionFactory" ref="sessionFactory" />
 		<property name="statementManager" ref="statementManager"/>
 		<property name="statementBuilder" ref="statementBuilder"/>
+		<property name="jdbcTemplate" ref="jdbcTemplate"/>
 	</bean>
 
 	<bean id="org.hisp.dhis.patient.PatientIdentifierStore"