dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08888
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2236: Add DeleteHandler with ProgramAttributeValue object for Patient module.
------------------------------------------------------------
revno: 2236
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2010-11-30 15:39:40 +0700
message:
Add DeleteHandler with ProgramAttributeValue object for Patient module.
added:
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java
modified:
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/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java
--
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-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 2010-10-22 06:43:14 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2010-11-30 08:39:40 +0000
@@ -34,6 +34,8 @@
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.programattributevalue.ProgramAttributeValue;
+import org.hisp.dhis.programattributevalue.ProgramAttributeValueService;
import org.hisp.dhis.system.deletion.DeletionHandler;
/**
@@ -61,13 +63,20 @@
this.patientDataValueService = patientDataValueService;
}
- ProgramStageDataElementService programStageDEService;
+ public ProgramStageDataElementService programStageDEService;
public void setProgramStageDEService( ProgramStageDataElementService programStageDEService )
{
this.programStageDEService = programStageDEService;
}
+
+ private ProgramAttributeValueService programAttributeValueService;
+ public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService )
+ {
+ this.programAttributeValueService = programAttributeValueService;
+ }
+
// -------------------------------------------------------------------------
// DeletionHandler implementation
// -------------------------------------------------------------------------
@@ -86,7 +95,7 @@
// ---------------------------------------------------------------------
// Delete Patient data values
// ---------------------------------------------------------------------
-
+
Set<PatientDataValue> dataValues = new HashSet<PatientDataValue>();
for ( ProgramInstance programInstance : programInstances )
@@ -102,11 +111,27 @@
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 Instances
// ---------------------------------------------------------------------
-
+System.out.println("\n\n Delete Program Instances ");
if ( programInstances != null && programInstances.size() > 0 )
{
for ( ProgramInstance programInstance : programInstances )
@@ -114,6 +139,7 @@
programInstanceService.deleteProgramInstance( programInstance );
}
}
+
}
@Override
@@ -130,12 +156,12 @@
for ( ProgramInstance programInstance : programInstances )
{
Collection<ProgramStageInstance> stageInstances = programInstance.getProgramStageInstances();
- if ( stageInstances != null && stageInstances.size() > 0)
+ if ( stageInstances != null && stageInstances.size() > 0 )
{
dataValues.addAll( patientDataValueService.getPatientDataValues( stageInstances ) );
}
}
-
+
if ( dataValues != null && dataValues.size() > 0 )
{
for ( PatientDataValue dataValue : dataValues )
@@ -145,6 +171,22 @@
}
// ---------------------------------------------------------------------
+ // Delete Program attribute values
+ // ---------------------------------------------------------------------
+
+ for ( ProgramInstance programInstance : programInstances )
+ {
+ Collection<ProgramAttributeValue> attributeValues = programAttributeValueService
+ .getProgramAttributeValues( programInstance );
+
+ for ( ProgramAttributeValue attributeValue : attributeValues )
+ {
+ programAttributeValueService.deleteProgramAttributeValue( attributeValue );
+ }
+
+ }
+
+ // ---------------------------------------------------------------------
// Delete Program Instances
// ---------------------------------------------------------------------
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java 2010-11-30 08:39:40 +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.programattributevalue;
+
+import java.util.Collection;
+
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramAttribute;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * @version $Id ProgramAttributeValueDeletionHandler.java 2010-11-30 14:06:12Z $
+ */
+
+public class ProgramAttributeValueDeletionHandler
+ extends DeletionHandler
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ProgramAttributeValueService programAttributeValueService;
+
+ public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService )
+ {
+ this.programAttributeValueService = programAttributeValueService;
+ }
+
+ private ProgramInstanceService programInstanceService;
+
+ public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+ {
+ this.programInstanceService = programInstanceService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DeletionHandler implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String getClassName()
+ {
+ return ProgramAttributeValue.class.getSimpleName();
+ }
+
+ @Override
+ public void deleteProgram( Program program )
+ {
+ Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( program );
+
+ for ( ProgramInstance programInstance : programInstances )
+ {
+ programAttributeValueService.deleteProgramAttributeValues( programInstance );
+ }
+ }
+
+ public void deleteProgramAttribute( ProgramAttribute programAttribute )
+ {
+ Collection<ProgramAttributeValue> attributeValues = programAttributeValueService
+ .getProgramAttributeValues( programAttribute );
+
+ if ( attributeValues != null && attributeValues.size() > 0 )
+ {
+ for ( ProgramAttributeValue attributeValue : attributeValues )
+ {
+ programAttributeValueService.deleteProgramAttributeValue( attributeValue );
+ }
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java 2010-11-10 13:49:29 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java 2010-11-30 08:39:40 +0000
@@ -74,9 +74,9 @@
}
@SuppressWarnings("unchecked")
- public Collection<ProgramAttributeValue> get( ProgramInstance progranInstance )
+ public Collection<ProgramAttributeValue> get( ProgramInstance programInstance )
{
- return getCriteria( Restrictions.eq( "progranInstance", progranInstance ) ).list();
+ return getCriteria( Restrictions.eq( "programInstance", programInstance ) ).list();
}
@SuppressWarnings("unchecked")
=== 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-11-29 02:04:22 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2010-11-30 08:39:40 +0000
@@ -298,6 +298,7 @@
<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService"/>
<property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService"/>
<property name="programStageDEService" ref="org.hisp.dhis.program.ProgramStageDataElementService"/>
+ <property name="programAttributeValueService" ref="org.hisp.dhis.programattributevalue.ProgramAttributeValueService"/>
</bean>
<bean id="org.hisp.dhis.relationship.RelationshipDeletionHandler"
@@ -316,6 +317,12 @@
<property name="programService" ref="org.hisp.dhis.program.ProgramService"/>
</bean>
+ <bean id="org.hisp.dhis.programattributevalue.ProgramAttributeValueDeletionHandler"
+ class="org.hisp.dhis.programattributevalue.ProgramAttributeValueDeletionHandler">
+ <property name="programAttributeValueService" ref="org.hisp.dhis.programattributevalue.ProgramAttributeValueService"/>
+ <property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService"/>
+ </bean>
+
<bean id="org.hisp.dhis.patient.PatientDeletionHandler"
class="org.hisp.dhis.patient.PatientDeletionHandler">
<property name="patientService" ref="org.hisp.dhis.patient.PatientService"/>
@@ -356,6 +363,7 @@
</list>
</property>
</bean>
+
<!-- DeletionManager -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
@@ -372,6 +380,7 @@
<ref local="org.hisp.dhis.program.ProgramDeletionHandler"/>
<ref local="org.hisp.dhis.program.ProgramInstanceDeletionHandler"/>
<ref local="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler"/>
+ <ref local="org.hisp.dhis.programattributevalue.ProgramAttributeValueDeletionHandler"/>
</list>
</list>
</property>
@@ -412,6 +421,9 @@
pointcut="execution( * org.hisp.dhis.program.ProgramInstanceService.delete*(..) )"
method="intercept"/>
<aop:before
+ pointcut="execution( * org.hisp.dhis.programattributevalue.ProgramAttributeValueService.delete*(..) )"
+ method="intercept"/>
+ <aop:before
pointcut="execution( * org.hisp.dhis.program.ProgramStageService.delete*(..) )"
method="intercept"/>
<aop:before
=== 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-11-15 16:26:51 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java 2010-11-30 08:39:40 +0000
@@ -73,6 +73,7 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.programattributevalue.ProgramAttributeValue;
import org.hisp.dhis.relationship.Relationship;
import org.hisp.dhis.relationship.RelationshipType;
import org.hisp.dhis.report.Report;
@@ -629,4 +630,13 @@
public void deleteValidationCriteria( ValidationCriteria validationCriteria )
{
}
+
+ public boolean allowDeleteProgramAttributeValue( ProgramAttributeValue programAttributeValue )
+ {
+ return true;
+ }
+
+ public void deleteProgramAttributeValue( ProgramAttributeValue programAttributeValue )
+ {
+ }
}