=== 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 2014-01-02 13:45:23 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2014-01-02 14:21:19 +0000 @@ -123,14 +123,17 @@ patientCommentService.deletePatientComment( patientComment ); } - for ( PatientAttribute patientAttribute : programInstance.getProgram().getPatientAttributes() ) - { - PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( - patient, patientAttribute ); - - if ( patientAttributeValue != null ) + if ( programInstance.getProgram() != null && programInstance.getProgram().getPatientAttributes() != null ) + { + for ( PatientAttribute patientAttribute : programInstance.getProgram().getPatientAttributes() ) { - patientAttributeValueService.deletePatientAttributeValue( patientAttributeValue ); + PatientAttributeValue patientAttributeValue = patientAttributeValueService.getPatientAttributeValue( + patient, patientAttribute ); + + if ( patientAttributeValue != null ) + { + patientAttributeValueService.deletePatientAttributeValue( patientAttributeValue ); + } } }