=== 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-03-24 03:34:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2011-06-24 07:55:22 +0000 @@ -54,6 +54,8 @@ Collection getAllCaseAggregationCondition( ); CaseAggregationCondition getCaseAggregationCondition( DataElement dataElement, DataElementCategoryOptionCombo optionCombo); + + Collection getCaseAggregationCondition( DataElement dataElement ); double parseConditition( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java 2010-11-25 22:22:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java 2011-06-24 07:55:22 +0000 @@ -44,6 +44,8 @@ String ID = CaseAggregationConditionStore.class.getName(); CaseAggregationCondition get( DataElement dataElement, DataElementCategoryOptionCombo optionCombo); - + + Collection get( DataElement dataElement ); + Collection executeSQL( String sql ); } === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java 2011-06-24 07:55:22 +0000 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004-2009, 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.caseaggregation; + +import java.util.Collection; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.system.deletion.DeletionHandler; + +/** + * @author Chau Thu Tran + * @version $ CaseAggregationConditionDeletionHandler.java Jun 24, 2011 1:52:01 + * PM $ + * + */ +public class CaseAggregationConditionDeletionHandler + extends DeletionHandler +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CaseAggregationConditionService aggregationConditionService; + + public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService ) + { + this.aggregationConditionService = aggregationConditionService; + } + + // ------------------------------------------------------------------------- + // DeletionHandler implementation + // ------------------------------------------------------------------------- + + @Override + protected String getClassName() + { + return CaseAggregationCondition.class.getSimpleName(); + } + + @Override + public boolean allowDeleteDataElement( DataElement dataElement ) + { + Collection conditions = aggregationConditionService + .getCaseAggregationCondition( dataElement ); + + if ( conditions != null && conditions.size() > 0 ) + { + return false; + } + + conditions = aggregationConditionService.getAllCaseAggregationCondition(); + + for( CaseAggregationCondition condition : conditions ) + { + Collection dataElements = aggregationConditionService.getDataElementsInCondition( condition.getAggregationExpression() ); + + if ( dataElements != null && dataElements.contains( dataElement ) ) + { + return false; + } + } + + return true; + } + +} === 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-06-16 08:52:01 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-06-24 07:55:22 +0000 @@ -167,6 +167,12 @@ { return aggregationConditionStore.get( dataElement, optionCombo ); } + + @Override + public Collection getCaseAggregationCondition( DataElement dataElement ) + { + return aggregationConditionStore.get( dataElement ); + } @Override public double parseConditition( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java 2011-03-31 01:55:06 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java 2011-06-24 07:55:22 +0000 @@ -109,4 +109,12 @@ return (CaseAggregationCondition) getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ), Restrictions.eq( "optionCombo", optionCombo ) ).uniqueResult(); } + + @SuppressWarnings( "unchecked" ) + @Override + public Collection get( DataElement dataElement ) + { + return getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ) ) + .list(); + } } === added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java 2011-06-24 07:55:22 +0000 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004-2009, 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.patientdatavalue; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.system.deletion.DeletionHandler; +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * @author Chau Thu Tran + * @version $ PatientDataValueDeletionHandler.java Jun 24, 2011 1:10:46 PM $ + * + */ +public class PatientDataValueDeletionHandler + extends DeletionHandler +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private JdbcTemplate jdbcTemplate; + + public void setJdbcTemplate( JdbcTemplate jdbcTemplate ) + { + this.jdbcTemplate = jdbcTemplate; + } + + // ------------------------------------------------------------------------- + // DeletionHandler implementation + // ------------------------------------------------------------------------- + + @Override + protected String getClassName() + { + return PatientDataValue.class.getSimpleName(); + } + + @Override + public boolean allowDeleteDataElement( DataElement dataElement ) + { + String sql = "SELECT COUNT(*) FROM patientdatavalue where dataelementid=" + dataElement.getId(); + + return jdbcTemplate.queryForInt( sql ) == 0; + } +} === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java 2011-04-29 07:41:04 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java 2011-06-24 07:55:22 +0000 @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.Set; +import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.system.deletion.DeletionHandler; /** @@ -58,7 +59,7 @@ @Override public String getClassName() { - return ProgramInstance.class.getSimpleName(); + return ProgramStageDataElement.class.getSimpleName(); } @Override @@ -101,5 +102,22 @@ } } + + @Override + public boolean allowDeleteDataElement ( DataElement dataElement ) + { + Collection psDataElements = programStageDEService.getAllProgramStageDataElements(); + for ( ProgramStageDataElement psDataElement : psDataElements ) + { + Collection dataElements = programStageDEService.getListDataElement( psDataElement.getProgramStage() ); + + if ( dataElements.contains( dataElement ) ) + { + return false; + } + } + + return true; + } } === 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-06-14 19:24:18 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2011-06-24 07:55:22 +0000 @@ -371,6 +371,14 @@ + + + + + + + + @@ -414,11 +422,14 @@ + + + @@ -479,6 +490,10 @@ + +