~registry/dhis2-academy/trunk

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/PatientDeletionHandler.java

  • Committer: Abyot Asalefew Gizaw
  • Date: 2012-10-12 00:08:27 UTC
  • Revision ID: abyota@gmail.com-20121012000827-qqmmfllx0s5vtkqi
Updating the acadmy trunk with the main DHIS2 trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package org.hisp.dhis.patient;
2
2
 
3
3
/*
4
 
 * Copyright (c) 2004-2010, University of Oslo
 
4
 * Copyright (c) 2004-2012, University of Oslo
5
5
 * All rights reserved.
6
6
 *
7
7
 * Redistribution and use in source and binary forms, with or without
30
30
import java.util.Collection;
31
31
 
32
32
import org.hisp.dhis.organisationunit.OrganisationUnit;
 
33
import org.hisp.dhis.program.Program;
33
34
import org.hisp.dhis.system.deletion.DeletionHandler;
 
35
import org.springframework.jdbc.core.JdbcTemplate;
34
36
 
35
37
public class PatientDeletionHandler
36
38
    extends DeletionHandler
46
48
        this.patientService = patientService;
47
49
    }
48
50
 
 
51
    private JdbcTemplate jdbcTemplate;
 
52
 
 
53
    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
 
54
    {
 
55
        this.jdbcTemplate = jdbcTemplate;
 
56
    }
 
57
 
49
58
    // -------------------------------------------------------------------------
50
59
    // DeletionHandler implementation
51
60
    // -------------------------------------------------------------------------
59
68
    @Override
60
69
    public void deletePatient( Patient patient )
61
70
    {
62
 
        Collection<Patient> representatives = patientService.getRepresentatives(patient);
63
 
        
 
71
        Collection<Patient> representatives = patientService.getRepresentatives( patient );
 
72
 
64
73
        for ( Patient representative : representatives )
65
74
        {
66
75
            representative.setRepresentative( null );
68
77
            patientService.updatePatient( representative );
69
78
        }
70
79
    }
71
 
    
72
 
    @Override
73
 
    public void deleteOrganisationUnit( OrganisationUnit unit )
74
 
    {
75
 
        for ( Patient patient : patientService.getPatients( unit ) )
76
 
        {
77
 
            patientService.deletePatient( patient );
78
 
        }
 
80
 
 
81
    @Override
 
82
    public void deletePatientAttribute( PatientAttribute patientAttribute )
 
83
    {
 
84
        jdbcTemplate.execute( "delete from patient_attributes where patientattributeid=" +  patientAttribute.getId() );
 
85
    }
 
86
 
 
87
    @Override
 
88
    public String allowDeleteOrganisationUnit( OrganisationUnit unit )
 
89
    {
 
90
        return patientService.getPatients( unit, null, null ).size() == 0 ? null : ERROR;
 
91
    }
 
92
 
 
93
    @Override
 
94
    public void deleteProgram( Program program )
 
95
    {
 
96
        patientService.removeErollmentPrograms( program );
79
97
    }
80
98
}