=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java 2013-04-02 08:24:05 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java 2013-04-08 08:33:27 +0000 @@ -27,6 +27,7 @@ package org.hisp.dhis.program; import java.util.Collection; +import java.util.List; /** * @author Abyot Asalefew @@ -50,7 +51,9 @@ ProgramStage getProgramStage( String uid ); - ProgramStage getProgramStageByName( String name ); + List getProgramStageByName( String name ); + + ProgramStage getProgramStageByName( String name, Program program ); Collection getAllProgramStages(); === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageStore.java 2013-04-08 08:33:27 +0000 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004-2012, 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.program; + +import org.hisp.dhis.common.GenericNameableObjectStore; + +/** + * @author Chau Thu Tran + */ +public interface ProgramStageStore + extends GenericNameableObjectStore +{ + ProgramStage getByNameAndProgram( String name, Program program ); +} === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java 2013-04-02 08:24:05 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java 2013-04-08 08:33:27 +0000 @@ -29,11 +29,9 @@ import static org.hisp.dhis.i18n.I18nUtils.i18n; import java.util.Collection; +import java.util.List; -import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.i18n.I18nService; -import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.program.ProgramStageService; import org.springframework.transaction.annotation.Transactional; /** @@ -48,9 +46,9 @@ // Dependencies // ------------------------------------------------------------------------- - private GenericIdentifiableObjectStore programStageStore; + private ProgramStageStore programStageStore; - public void setProgramStageStore( GenericIdentifiableObjectStore programStageStore ) + public void setProgramStageStore( ProgramStageStore programStageStore ) { this.programStageStore = programStageStore; } @@ -86,9 +84,14 @@ return i18n( i18nService, programStageStore.getByUid( uid ) ); } - public ProgramStage getProgramStageByName( String name ) - { - return i18n( i18nService, programStageStore.getByName( name ) ); + public List getProgramStageByName( String name ) + { + return programStageStore.getAllEqName( name ); + } + + public ProgramStage getProgramStageByName( String name, Program program ) + { + return i18n( i18nService, programStageStore.getByNameAndProgram( name, program ) ); } public void updateProgramStage( ProgramStage programStage ) === added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageStore.java 2013-04-08 08:33:27 +0000 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2004-2012, 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.program.hibernate; + +import org.hibernate.criterion.Restrictions; +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramStage; +import org.hisp.dhis.program.ProgramStageStore; + +/** + * @author Chau Thu Tran + * @version $ HibernateProgramStageStore.java Apr 8, 2013 1:30:00 PM $ + */ +public class HibernateProgramStageStore + extends HibernateIdentifiableObjectStore + implements ProgramStageStore +{ + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + public ProgramStage getByNameAndProgram( String name, Program program ) + { + return (ProgramStage) getCriteria( Restrictions.eq( "name", name ), Restrictions.eq( "program", program ) ) + .uniqueResult(); + } + +} === 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 2013-04-03 15:46:23 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-04-08 08:33:27 +0000 @@ -52,7 +52,7 @@ + class="org.hisp.dhis.program.hibernate.HibernateProgramStageStore"> === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2013-03-01 05:14:56 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2013-04-08 08:33:27 +0000 @@ -103,4 +103,5 @@ symbol=Symbol name_code_identifier=Name, code or identifier identifier=Identifier -short_name_in_use=The short name is already in use. Please choose a different short name \ No newline at end of file +short_name_in_use=The short name is already in use. Please choose a different short name +show_all_sections = Show all sections \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java 2013-04-05 08:47:47 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java 2013-04-08 08:33:27 +0000 @@ -42,7 +42,6 @@ import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.program.ProgramStageService; -import org.hisp.dhis.user.CurrentUserService; import com.opensymphony.xwork2.Action; @@ -95,14 +94,7 @@ { this.patientAttributeService = patientAttributeService; } - - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - + // ------------------------------------------------------------------------- // Input/Output // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java 2011-10-03 09:40:38 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageAction.java 2013-04-08 08:33:27 +0000 @@ -28,6 +28,8 @@ */ import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.program.ProgramStageService; @@ -53,10 +55,24 @@ this.programStageService = programStageService; } + private ProgramService programService; + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + // ------------------------------------------------------------------------- // Input/Output // ------------------------------------------------------------------------- + private Integer programStageId; + + public void setProgramStageId( Integer programStageId ) + { + this.programStageId = programStageId; + } + private Integer id; public void setId( Integer id ) @@ -92,11 +108,13 @@ public String execute() throws Exception { - ProgramStage match = programStageService.getProgramStageByName( name ); - - if ( match != null && (id == null || match.getId() != id.intValue()) ) + Program program = programService.getProgram( id ); + + ProgramStage match = programStageService.getProgramStageByName( name, program ); + + if ( match != null && (programStageId == null || match.getId() != programStageId.intValue()) ) { - message = i18n.getString( "duplicate_names" ); + message = i18n.getString( "name_exists" ); return ERROR; } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2013-04-05 07:46:29 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2013-04-08 08:33:27 +0000 @@ -163,7 +163,6 @@ ref="org.hisp.dhis.patient.PatientIdentifierTypeService" /> - + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm 2013-03-14 13:30:46 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm 2013-04-08 08:33:27 +0000 @@ -5,7 +5,7 @@

$program.displayName

- + @@ -174,4 +174,10 @@ var i18n_orgunit_name = '$encoder.jsEscape( $i18n.getString( "orgunit_name" ) , "'")'; var i18n_days_since_due_date = '$encoder.jsEscape( $i18n.getString( "days_since_due_date" ) , "'")'; var i18n_message = '$encoder.jsEscape( $i18n.getString( "message" ) , "'")'; + var i18n_name_exists = '$encoder.jsEscape( $i18n.getString( "name_exists" ) , "'")'; + + var programStageList = new Array(); + #foreach($programStage in $program.programStages) + programStageList.push("$programStage.displayName"); + #end \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addProgramStageForm.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addProgramStageForm.js 2012-11-08 04:13:48 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addProgramStageForm.js 2013-04-08 08:33:27 +0000 @@ -74,5 +74,5 @@ } }); - checkValueIsExist( "name", "validateProgramStage.action"); + checkValueIsExist( "name", "validateProgramStage.action",{id: getFieldValue('programId')}); }); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js 2013-03-01 14:09:05 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js 2013-04-08 08:33:27 +0000 @@ -293,4 +293,25 @@ function removeTemplateMessageForm( rowId ) { jQuery("[name=tr" + rowId + "]").remove(); -} \ No newline at end of file +} + +// ---------------------------------------------------------- +// Validate program stage name +// ---------------------------------------------------------- + +function validateName( name ) +{ + var valid = true; + for( var i=0; i" + i18n_name_exists + "") + .insertAfter( nameField ); + valid = false; + } + } + if(valid) + { + $("span[for=name]").remove(); + } +}