dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14725
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5087: Deletionhandler ( Aggregation Query Builder ).
------------------------------------------------------------
revno: 5087
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-11-03 09:20:41 +0700
message:
Deletionhandler ( Aggregation Query Builder ).
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.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/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2011-10-05 09:19:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2011-11-03 02:20:41 +0000
@@ -33,8 +33,10 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.program.Program;
/**
* @author Chau Thu Tran
@@ -68,5 +70,9 @@
Collection<DataElementCategoryOptionCombo> getOptionCombosInCondition( String aggregationExpression );
+ Collection<Program> getProgramsInCondition( String aggregationExpression );
+
+ Collection<PatientAttribute> getPatientAttributesInCondition( String aggregationExpression );
+
String getConditionDescription( String condition );
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java 2011-09-29 07:41:04 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java 2011-11-03 02:20:41 +0000
@@ -32,6 +32,8 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.program.Program;
import org.hisp.dhis.system.deletion.DeletionHandler;
/**
@@ -117,4 +119,44 @@
return null;
}
+ @Override
+ public String allowDeleteProgram( Program program )
+ {
+ Collection<CaseAggregationCondition> conditions = aggregationConditionService
+ .getAllCaseAggregationCondition();
+
+ for ( CaseAggregationCondition condition : conditions )
+ {
+ Collection<Program> programs = aggregationConditionService.getProgramsInCondition( condition
+ .getAggregationExpression() );
+
+ if ( programs != null && programs.contains( program ) )
+ {
+ return condition.getDescription();
+ }
+ }
+
+ return null;
+ }
+
+
+ @Override
+ public String allowDeletePatientAttribute( PatientAttribute patientAttribute )
+ {
+ Collection<CaseAggregationCondition> conditions = aggregationConditionService
+ .getAllCaseAggregationCondition();
+
+ for ( CaseAggregationCondition condition : conditions )
+ {
+ Collection<PatientAttribute> patientAttributes = aggregationConditionService.getPatientAttributesInCondition( condition
+ .getAggregationExpression() );
+
+ if ( patientAttributes != null && patientAttributes.contains( patientAttribute ) )
+ {
+ return condition.getDescription();
+ }
+ }
+
+ return null;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-11-02 07:04:50 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-11-03 02:20:41 +0000
@@ -410,7 +410,68 @@
return optionCombos;
}
-
+
+ public Collection<Program> getProgramsInCondition( String aggregationExpression )
+ {
+ String regExp = "\\[" + OBJECT_PROGRAM + SEPARATOR_OBJECT + "[0-9]+\\]";
+
+ Collection<Program> programs = new HashSet<Program>();
+
+ // ---------------------------------------------------------------------
+ // parse expressions
+ // ---------------------------------------------------------------------
+
+ Pattern pattern = Pattern.compile( regExp );
+
+ Matcher matcher = pattern.matcher( aggregationExpression );
+
+ while ( matcher.find() )
+ {
+ String match = matcher.group();
+ match = match.replaceAll( "[\\[\\]]", "" );
+
+ String[] info = match.split( SEPARATOR_OBJECT );
+
+ int programId = Integer.parseInt( info[1] );
+
+ Program program = programService.getProgram( programId );
+
+ programs.add( program );
+ }
+
+ return programs;
+ }
+
+ public Collection<PatientAttribute> getPatientAttributesInCondition( String aggregationExpression )
+ {
+ String regExp = "\\[" + OBJECT_PATIENT_ATTRIBUTE + SEPARATOR_OBJECT + "[0-9]+\\]";
+
+ Collection<PatientAttribute> patientAttributes = new HashSet<PatientAttribute>();
+
+ // ---------------------------------------------------------------------
+ // parse expressions
+ // ---------------------------------------------------------------------
+
+ Pattern pattern = Pattern.compile( regExp );
+
+ Matcher matcher = pattern.matcher( aggregationExpression );
+
+ while ( matcher.find() )
+ {
+ String match = matcher.group();
+ match = match.replaceAll( "[\\[\\]]", "" );
+
+ String[] info = match.split( SEPARATOR_OBJECT );
+
+ int patientAttributeId = Integer.parseInt( info[1] );
+ PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( patientAttributeId );
+
+ patientAttributes.add( patientAttribute );
+ }
+
+ return patientAttributes;
+ }
+
// -------------------------------------------------------------------------
// Support Methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java 2011-09-29 07:41:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/RemovePatientAttributeAction.java 2011-11-03 02:20:41 +0000
@@ -87,16 +87,15 @@
PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( id );
patientAttributeService.deletePatientAttribute( patientAttribute );
-
}
catch ( DeleteNotAllowedException ex )
{
if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
{
message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getMessage();
-
- return ERROR;
}
+
+ return ERROR;
}
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAction.java 2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAction.java 2011-11-03 02:20:41 +0000
@@ -27,6 +27,8 @@
package org.hisp.dhis.patient.action.program;
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
@@ -61,6 +63,24 @@
this.id = id;
}
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -68,10 +88,21 @@
public String execute()
throws Exception
{
- Program program = programService.getProgram( id );
-
- programService.deleteProgram( program );
-
+ try
+ {
+ Program program = programService.getProgram( id );
+
+ programService.deleteProgram( program );
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getMessage();
+
+ return ERROR;
+ }
+ }
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2011-10-27 03:12:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2011-11-03 02:20:41 +0000
@@ -116,6 +116,8 @@
class="org.hisp.dhis.patient.action.patientattribute.RemovePatientAttributeAction">
<result name="success" type="velocity-json">
/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <result name="error" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseError.vm</result>
<param name="requiredAuthorities">F_PATIENTATTRIBUTE_DELETE</param>
</action>
@@ -211,6 +213,8 @@
class="org.hisp.dhis.patient.action.program.RemoveProgramAction">
<result name="success" type="velocity-json">
/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <result name="error" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseError.vm</result>
<param name="requiredAuthorities">F_PROGRAM_DELETE</param>
</action>