=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java 2013-09-17 06:08:16 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierService.java 2013-09-23 04:29:22 +0000 @@ -78,5 +78,5 @@ Patient patient ); boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier, - OrganisationUnit orgunit, Program program, PeriodType periodType ); + Integer patientId, OrganisationUnit orgunit, Program program, PeriodType periodType ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java 2013-09-17 06:08:16 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierStore.java 2013-09-23 04:29:22 +0000 @@ -75,6 +75,6 @@ Collection get( Collection identifierTypes, Patient patient ); boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier, - OrganisationUnit orgunit, Program program, PeriodType periodType ); + Integer patientId, OrganisationUnit orgunit, Program program, PeriodType periodType ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java 2013-09-17 06:08:16 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientIdentifierType.java 2013-09-23 04:29:22 +0000 @@ -66,13 +66,13 @@ private String type; - private Boolean personDisplayName; + private Boolean personDisplayName = false;; // For Local ID type - private Boolean orgunitScope; + private Boolean orgunitScope = false; - private Boolean programScope; + private Boolean programScope = false;; private PeriodType periodType; === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java 2013-09-17 06:08:16 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientIdentifierService.java 2013-09-23 04:29:22 +0000 @@ -146,8 +146,9 @@ @Override public boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier, - OrganisationUnit orgunit, Program program, PeriodType periodType ) + Integer patientId, OrganisationUnit orgunit, Program program, PeriodType periodType ) { - return patientIdentifierStore.checkDuplicateIdentifier( patientIdentifierType, identifier, orgunit, program, periodType ); + return patientIdentifierStore.checkDuplicateIdentifier( patientIdentifierType, identifier, patientId, orgunit, + program, periodType ); } } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java 2013-09-17 18:07:42 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientIdentifierStore.java 2013-09-23 04:29:22 +0000 @@ -152,27 +152,33 @@ @SuppressWarnings( "deprecation" ) public boolean checkDuplicateIdentifier( PatientIdentifierType patientIdentifierType, String identifier, - OrganisationUnit orgunit, Program program, PeriodType periodType ) + Integer patientId, OrganisationUnit orgunit, Program program, PeriodType periodType ) { String sql = "select count(*) from patientidentifier pi inner join patient p on pi.patientid=p.patientid " + "inner join programinstance pis on pis.patientid=pi.patientid where pi.patientidentifiertypeid=" + patientIdentifierType.getId() + " and pi.identifier='" + identifier + "' "; - if ( orgunit != null ) + + if ( patientId != null ) + { + sql += " and pi.patientid!=" + patientId; + } + + if ( patientIdentifierType.getType().equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) && orgunit != null ) { sql += " and p.organisationunitid=" + orgunit.getId(); } - if ( program != null ) + if ( patientIdentifierType.getType().equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) && program != null ) { sql += " and pis.programid=" + program.getId(); } - if ( periodType != null ) + if ( patientIdentifierType.getType().equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) && periodType != null ) { Date currentDate = new Date(); Period period = periodType.createPeriod( currentDate ); sql += " and pis.enrollmentdate >='" + period.getStartDateString() + "' and pis.enrollmentdate <='" - + DateUtils.getMediumDateString( period.getEndDate() ) + "'"; + + DateUtils.getMediumDateString( period.getEndDate() ) + "'"; } return jdbcTemplate.queryForInt( sql ) == 0 ? false : true; === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2013-09-19 08:26:17 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2013-09-23 04:29:22 +0000 @@ -245,6 +245,9 @@ executeSql( "update programstage set openAfterEnrollment=false where openAfterEnrollment is null" ); executeSql( "update programstage set reportDateToUse=false where reportDateToUse is null" ); + + executeSql( "update patientidentifiertype set orgunitScope=false where orgunitScope is null" ); + executeSql( "update patientidentifiertype set programScope=false where programScope is null" ); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java 2013-09-17 06:08:16 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientAction.java 2013-09-23 04:29:22 +0000 @@ -199,24 +199,12 @@ { boolean isDuplicate = false; - if ( idType.getType().equals( PatientIdentifierType.VALUE_TYPE_LOCAL_ID ) ) - { - OrganisationUnit orgunit = (idType.getOrgunitScope()) ? selectionManager - .getSelectedOrganisationUnit() : null; + OrganisationUnit orgunit = (idType.getOrgunitScope()) ? selectionManager + .getSelectedOrganisationUnit() : null; + Program program = (idType.getProgramScope()) ? programService.getProgram( programId ) : null; - Program program = (idType.getProgramScope()) ? programService.getProgram( programId ) - : null; - isDuplicate = patientIdentifierService.checkDuplicateIdentifier( idType, value, orgunit, - program, idType.getPeriodType() ); - } - else - { - PatientIdentifier identifier = patientIdentifierService.get( idType, value ); - if ( identifier != null && (id == null || identifier.getPatient().getId() != id) ) - { - idDuplicate += idType.getName() + ", "; - } - } + isDuplicate = patientIdentifierService.checkDuplicateIdentifier( idType, value, id, + orgunit, program, idType.getPeriodType() ); if ( isDuplicate ) { === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientIdentifierAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientIdentifierAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ValidatePatientIdentifierAction.java 2013-09-23 04:29:22 +0000 @@ -0,0 +1,201 @@ +package org.hisp.dhis.caseentry.action.patient; + +/* + * Copyright (c) 2004-2013, 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. + */ + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; +import org.hisp.dhis.patient.PatientIdentifier; +import org.hisp.dhis.patient.PatientIdentifierService; +import org.hisp.dhis.patient.PatientIdentifierType; +import org.hisp.dhis.patient.PatientIdentifierTypeService; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Abyot Asalefew Gizaw + */ +public class ValidatePatientIdentifierAction + implements Action +{ + public static final String PATIENT_DUPLICATE = "duplicate"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private PatientIdentifierService patientIdentifierService; + + private PatientIdentifierTypeService identifierTypeService; + + private ProgramService programService; + + private OrganisationUnitSelectionManager selectionManager; + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer programId; + + private Integer patientId; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private String message; + + private I18n i18n; + + private Map patientAttributeValueMap = new HashMap(); + + private PatientIdentifier patientIdentifier; + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + HttpServletRequest request = ServletActionContext.getRequest(); + + Collection identifiers = identifierTypeService.getAllPatientIdentifierTypes(); + + if ( identifiers != null && identifiers.size() > 0 ) + { + String value = null; + String idDuplicate = ""; + + for ( PatientIdentifierType idType : identifiers ) + { + + value = request.getParameter( AddPatientAction.PREFIX_IDENTIFIER + idType.getId() ); + + if ( StringUtils.isNotBlank( value ) ) + { + boolean isDuplicate = false; + + OrganisationUnit orgunit = (idType.getOrgunitScope()) ? selectionManager + .getSelectedOrganisationUnit() : null; + + Program program = (idType.getProgramScope()) ? programService.getProgram( programId ) : null; + isDuplicate = patientIdentifierService.checkDuplicateIdentifier( idType, value, patientId, orgunit, + program, idType.getPeriodType() ); + + if ( isDuplicate ) + { + idDuplicate += idType.getName() + ", "; + } + } + + } + + if ( StringUtils.isNotBlank( idDuplicate ) ) + { + idDuplicate = StringUtils.substringBeforeLast( idDuplicate, "," ); + message = i18n.getString( "identifier_duplicate" ) + ": " + idDuplicate; + return INPUT; + } + } + + // --------------------------------------------------------------------- + // Validation success + // --------------------------------------------------------------------- + + message = i18n.getString( "everything_is_ok" ); + + return SUCCESS; + } + + // ------------------------------------------------------------------------- + // Getter/Setter + // ------------------------------------------------------------------------- + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + + public void setPatientId( Integer patientId ) + { + this.patientId = patientId; + } + + public void setProgramId( Integer programId ) + { + this.programId = programId; + } + + public void setIdentifierTypeService( PatientIdentifierTypeService identifierTypeService ) + { + this.identifierTypeService = identifierTypeService; + } + + public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService ) + { + this.patientIdentifierService = patientIdentifierService; + } + + public void setSelectionManager( OrganisationUnitSelectionManager selectionManager ) + { + this.selectionManager = selectionManager; + } + + public String getMessage() + { + return message; + } + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + public Map getPatientAttributeValueMap() + { + return patientAttributeValueMap; + } + + public PatientIdentifier getPatientIdentifier() + { + return patientIdentifier; + } + +} === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-09-18 06:54:48 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-09-23 04:29:22 +0000 @@ -617,6 +617,22 @@ ref="org.hisp.dhis.oust.manager.SelectionTreeManager" /> + + + + + + + + + + + + - + @@ -1042,7 +1058,7 @@ - + - + - - + - + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2013-09-11 16:02:06 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2013-09-23 04:29:22 +0000 @@ -729,6 +729,18 @@ F_PROGRAM_ENROLLMENT + + + /dhis-web-commons/ajax/jsonResponseSuccess.vm + + + /dhis-web-commons/ajax/jsonResponseInput.vm + + plainTextError + + + F_ACCESS_PATIENT_ATTRIBUTES - + /dhis-web-commons/ajax/jsonResponseSuccess.vm F_ALLOW_EDIT_PATIENT_PROPERTIES - + /dhis-web-commons/ajax/jsonResponseSuccess.vm F_ALLOW_EDIT_PATIENT_ATTRIBUTES - + /dhis-web-commons/ajax/jsonResponseSuccess.vm === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js 2013-09-17 07:53:28 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js 2013-09-23 04:29:22 +0000 @@ -1400,7 +1400,7 @@ jQuery('#activeTB' ).append(activedRow); jQuery('#enrollmentDiv').dialog("close"); - saveIdentifierAndAttribute( patientId, programId,'identifierAndAttributeDiv' ); + validateIdentifier( patientId, programId,'identifierAndAttributeDiv' ); loadActiveProgramStageRecords( programInstanceId ); showSuccessMessage(i18n_enrol_success); }); @@ -1611,12 +1611,30 @@ // Identifiers && Attributes for selected program // ---------------------------------------------------------------- -function saveIdentifierAndAttribute( patientId, programId, paramsDiv) +function validateIdentifier( patientId, programId, paramsDiv) { var params = getParamsForDiv(paramsDiv); params += "&patientId=" + patientId; params +="&programId=" + programId; $.ajax({ + type: "POST", + url: 'validatePatientIdentifier.action', + data: params, + success: function(json) + { + if( json.response=='success'){ + saveIdentifierAndAttribute( params); + } + else{ + showErrorMessage( json.message ); + } + } + }); +} + +function saveIdentifierAndAttribute(params) +{ + $.ajax({ type: "POST", url: 'savePatientIdentifierAndAttribute.action', data: params, === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm 2013-09-17 09:14:41 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm 2013-09-23 04:29:22 +0000 @@ -64,7 +64,7 @@ #foreach ($identifierType in $identifierTypes) #set( $identifier = '') #set( $identifier = $identiferMap.get( $identifierType.id ) ) - + @@ -75,35 +75,35 @@ #foreach($attribute in $patientAttributes ) - #set( $attributeValue = '') - #set( $attributeValue = $!patientAttributeValueMap.get( $attribute.id ) ) - - - - #if( $attribute.valueType == "bool" ) - - #elseif( $attribute.valueType == "date" ) - - - #elseif( $attribute.valueType == "combo" ) - - #else - - #end - - - #set( $mark = !$mark ) + #set( $attributeValue = '') + #set( $attributeValue = $!patientAttributeValueMap.get( $attribute.id ) ) + + #set($mandatory = $attribute.mandatory ) + + + #if( $attribute.valueType == "bool" ) + + #elseif( $attribute.valueType == "date" ) + + + #elseif( $attribute.valueType == "combo" ) + + #else + + #end + + #end   @@ -141,7 +141,7 @@