From 2efc5956de67447d39fd2b5a72d02945f9226d07 Mon Sep 17 00:00:00 2001 From: common-cold Date: Sun, 24 Mar 2024 04:36:51 +0530 Subject: [PATCH 1/3] Fix Duplicate National Id/Subject No. persistence --- .../rest/PatientManagementRestController.java | 12 +++-- .../patient/service/PatientServiceImpl.java | 53 +++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java index 6e10535baa..0615ceb22b 100644 --- a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java +++ b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java @@ -6,6 +6,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.dataexchange.fhir.exception.FhirPersistanceException; @@ -58,7 +59,7 @@ public class PatientManagementRestController extends BaseRestController { @PostMapping(value = "patient-management", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntryForm.SamplePatientEntry.class) @RequestBody PatientManagementInfo patientInfo ,BindingResult bindingResult) + public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntryForm.SamplePatientEntry.class) @RequestBody PatientManagementInfo patientInfo , BindingResult bindingResult, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{ if (StringUtils.isNotBlank(patientInfo.getPatientPK())) { @@ -90,6 +91,7 @@ public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntr } request.setAttribute(ALLOW_EDITS_KEY, "false"); + response.setStatus(400); } catch (FhirTransformationException | FhirPersistanceException e) { LogEvent.logError(e); @@ -101,10 +103,10 @@ public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntr private void preparePatientData(Errors errors ,HttpServletRequest request, PatientManagementInfo patientInfo, Patient patient) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - validatePatientInfo(errors, patientInfo); - if (errors.hasErrors()) { - return; - } +// validatePatientInfo(errors, patientInfo); +// if (errors.hasErrors()) { +// return; +// } initMembers(patient); patientInfo.setPatientIdentities(new ArrayList()); diff --git a/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java b/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java index 2d39a32c0c..00954eb844 100644 --- a/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java +++ b/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java @@ -14,9 +14,12 @@ import org.openelisglobal.address.valueholder.PersonAddress; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; +import org.openelisglobal.common.provider.query.PatientSearchResults; import org.openelisglobal.common.service.AuditableBaseObjectServiceImpl; +import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.common.util.validator.GenericValidator; +import org.openelisglobal.common.validator.BaseErrors; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; import org.openelisglobal.gender.service.GenderService; import org.openelisglobal.gender.valueholder.Gender; @@ -36,9 +39,11 @@ import org.openelisglobal.patienttype.valueholder.PatientPatientType; import org.openelisglobal.person.service.PersonService; import org.openelisglobal.person.valueholder.Person; +import org.openelisglobal.search.service.SearchResultsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.Errors; @Service public class PatientServiceImpl extends AuditableBaseObjectServiceImpl implements PatientService { @@ -97,6 +102,9 @@ public class PatientServiceImpl extends AuditableBaseObjectServiceImpl getPatientIdentityBySampleStatusIdAndProject(List i public void persistPatientData(PatientManagementInfo patientInfo, Patient patient, String sysUserId) throws LIMSRuntimeException { if (patientInfo.getPatientUpdateStatus() == PatientUpdateStatus.ADD) { + Errors errors = validatePatientInfo(patientInfo); + if(errors.hasErrors()){ + throw new LIMSRuntimeException("This Id already exists"); + } personService.insert(patient.getPerson()); } else if (patientInfo.getPatientUpdateStatus() == PatientUpdateStatus.UPDATE) { personService.update(patient.getPerson()); @@ -832,4 +844,45 @@ public Patient getByExternalId(String id) { return baseObjectDAO.getByExternalId(id); } + + private Errors validatePatientInfo(PatientManagementInfo patientInfo) { + Errors errors = new BaseErrors(); + boolean disallowDuplicateSubjectNumbers = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false"); + boolean disallowDuplicateNationalIds = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "false"); + if (disallowDuplicateSubjectNumbers || disallowDuplicateNationalIds) { + String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) ? null + : patientInfo.getSTnumber(); + String newSubjectNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSubjectNumber()) ? null + : patientInfo.getSubjectNumber(); + String newNationalId = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getNationalId()) ? null + : patientInfo.getNationalId(); + + List results = search.getSearchResults(null, null, newSTNumber, newSubjectNumber, + newNationalId, null, null, null, null, null); + + if (!results.isEmpty()) { + + for (PatientSearchResults result : results) { + if (!result.getPatientID().equals(patientInfo.getPatientPK())) { + if (disallowDuplicateSubjectNumbers && newSTNumber != null + && newSTNumber.equals(result.getSTNumber())) { + errors.reject("error.duplicate.STNumber", null, null); + } + if (disallowDuplicateSubjectNumbers && newSubjectNumber != null + && newSubjectNumber.equals(result.getSubjectNumber())) { + errors.reject("error.duplicate.subjectNumber", null, null); + } + if (disallowDuplicateNationalIds && newNationalId != null + && newNationalId.equals(result.getNationalId())) { + errors.reject("error.duplicate.nationalId", null, null); + } + } + } + } + } + return errors; + } + } \ No newline at end of file From 6d0bbb24fceb5ea78c02993117e7f7c2241f7997 Mon Sep 17 00:00:00 2001 From: common-cold Date: Fri, 29 Mar 2024 23:52:22 +0530 Subject: [PATCH 2/3] Removed the new validator from PatientServiceImpl.java and placed it into PatientManagementRestController.java --- .../rest/PatientManagementRestController.java | 119 ++++++++++++------ .../patient/service/PatientServiceImpl.java | 53 -------- 2 files changed, 78 insertions(+), 94 deletions(-) diff --git a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java index 0615ceb22b..92b6dede60 100644 --- a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java +++ b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java @@ -6,7 +6,6 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.dataexchange.fhir.exception.FhirPersistanceException; @@ -59,7 +58,7 @@ public class PatientManagementRestController extends BaseRestController { @PostMapping(value = "patient-management", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntryForm.SamplePatientEntry.class) @RequestBody PatientManagementInfo patientInfo , BindingResult bindingResult, HttpServletResponse response) + public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntryForm.SamplePatientEntry.class) @RequestBody PatientManagementInfo patientInfo , BindingResult bindingResult) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{ if (StringUtils.isNotBlank(patientInfo.getPatientPK())) { @@ -91,7 +90,6 @@ public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntr } request.setAttribute(ALLOW_EDITS_KEY, "false"); - response.setStatus(400); } catch (FhirTransformationException | FhirPersistanceException e) { LogEvent.logError(e); @@ -103,10 +101,10 @@ public void savepatient(HttpServletRequest request, @Validated(SamplePatientEntr private void preparePatientData(Errors errors ,HttpServletRequest request, PatientManagementInfo patientInfo, Patient patient) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { -// validatePatientInfo(errors, patientInfo); -// if (errors.hasErrors()) { -// return; -// } + validatePatientInfo(errors, patientInfo); + if (errors.hasErrors()) { + return; + } initMembers(patient); patientInfo.setPatientIdentities(new ArrayList()); @@ -124,40 +122,40 @@ private void preparePatientData(Errors errors ,HttpServletRequest request, Patie } - private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { - if (ConfigurationProperties.getInstance() - .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false")) { - String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) - ? null - : patientInfo.getSTnumber(); - String newSubjectNumber = org.apache.commons.validator.GenericValidator - .isBlankOrNull(patientInfo.getSubjectNumber()) ? null : patientInfo.getSubjectNumber(); - String newNationalId = org.apache.commons.validator.GenericValidator - .isBlankOrNull(patientInfo.getNationalId()) ? null : patientInfo.getNationalId(); - - List results = searchService.getSearchResults(null, null, newSTNumber, - newSubjectNumber, newNationalId, null, null, null, null, null); - - if (!results.isEmpty()) { - for (PatientSearchResults result : results) { - if (!result.getPatientID().equals(patientInfo.getPatientPK())) { - if (newSTNumber != null && newSTNumber.equals(result.getSTNumber())) { - errors.reject("error.duplicate.STNumber", "error.duplicate.STNumber"); - } - if (newSubjectNumber != null && newSubjectNumber.equals(result.getSubjectNumber())) { - errors.reject("error.duplicate.subjectNumber", "error.duplicate.subjectNumber"); - } - if (newNationalId != null && newNationalId.equals(result.getNationalId())) { - errors.reject("error.duplicate.nationalId", "error.duplicate.nationalId"); - } - } - } - } - } - - validateBirthdateFormat(patientInfo, errors); - - } +// private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { +// if (ConfigurationProperties.getInstance() +// .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false")) { +// String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) +// ? null +// : patientInfo.getSTnumber(); +// String newSubjectNumber = org.apache.commons.validator.GenericValidator +// .isBlankOrNull(patientInfo.getSubjectNumber()) ? null : patientInfo.getSubjectNumber(); +// String newNationalId = org.apache.commons.validator.GenericValidator +// .isBlankOrNull(patientInfo.getNationalId()) ? null : patientInfo.getNationalId(); +// +// List results = searchService.getSearchResults(null, null, newSTNumber, +// newSubjectNumber, newNationalId, null, null, null, null, null); +// +// if (!results.isEmpty()) { +// for (PatientSearchResults result : results) { +// if (!result.getPatientID().equals(patientInfo.getPatientPK())) { +// if (newSTNumber != null && newSTNumber.equals(result.getSTNumber())) { +// errors.reject("error.duplicate.STNumber", "error.duplicate.STNumber"); +// } +// if (newSubjectNumber != null && newSubjectNumber.equals(result.getSubjectNumber())) { +// errors.reject("error.duplicate.subjectNumber", "error.duplicate.subjectNumber"); +// } +// if (newNationalId != null && newNationalId.equals(result.getNationalId())) { +// errors.reject("error.duplicate.nationalId", "error.duplicate.nationalId"); +// } +// } +// } +// } +// } +// +// validateBirthdateFormat(patientInfo, errors); +// +// } private void validateBirthdateFormat(PatientManagementInfo patientInfo, Errors errors) { String birthDate = patientInfo.getBirthDateForDisplay(); @@ -218,4 +216,43 @@ private Patient loadForUpdate(PatientManagementInfo patientInfo) { return patient; } + private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { + boolean disallowDuplicateSubjectNumbers = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false"); + boolean disallowDuplicateNationalIds = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "false"); + if (disallowDuplicateSubjectNumbers || disallowDuplicateNationalIds) { + String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) ? null + : patientInfo.getSTnumber(); + String newSubjectNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSubjectNumber()) ? null + : patientInfo.getSubjectNumber(); + String newNationalId = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getNationalId()) ? null + : patientInfo.getNationalId(); + + List results = searchService.getSearchResults(null, null, newSTNumber, newSubjectNumber, + newNationalId, null, null, null, null, null); + + if (!results.isEmpty()) { + + for (PatientSearchResults result : results) { + if (!result.getPatientID().equals(patientInfo.getPatientPK())) { + if (disallowDuplicateSubjectNumbers && newSTNumber != null + && newSTNumber.equals(result.getSTNumber())) { + errors.reject("error.duplicate.STNumber", null, null); + } + if (disallowDuplicateSubjectNumbers && newSubjectNumber != null + && newSubjectNumber.equals(result.getSubjectNumber())) { + errors.reject("error.duplicate.subjectNumber", null, null); + } + if (disallowDuplicateNationalIds && newNationalId != null + && newNationalId.equals(result.getNationalId())) { + errors.reject("error.duplicate.nationalId", null, null); + } + } + } + } + } + validateBirthdateFormat(patientInfo, errors); + } + } diff --git a/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java b/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java index 00954eb844..2d39a32c0c 100644 --- a/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java +++ b/src/main/java/org/openelisglobal/patient/service/PatientServiceImpl.java @@ -14,12 +14,9 @@ import org.openelisglobal.address.valueholder.PersonAddress; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.provider.query.PatientSearchResults; import org.openelisglobal.common.service.AuditableBaseObjectServiceImpl; -import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.common.util.validator.GenericValidator; -import org.openelisglobal.common.validator.BaseErrors; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; import org.openelisglobal.gender.service.GenderService; import org.openelisglobal.gender.valueholder.Gender; @@ -39,11 +36,9 @@ import org.openelisglobal.patienttype.valueholder.PatientPatientType; import org.openelisglobal.person.service.PersonService; import org.openelisglobal.person.valueholder.Person; -import org.openelisglobal.search.service.SearchResultsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.Errors; @Service public class PatientServiceImpl extends AuditableBaseObjectServiceImpl implements PatientService { @@ -102,9 +97,6 @@ public class PatientServiceImpl extends AuditableBaseObjectServiceImpl getPatientIdentityBySampleStatusIdAndProject(List i public void persistPatientData(PatientManagementInfo patientInfo, Patient patient, String sysUserId) throws LIMSRuntimeException { if (patientInfo.getPatientUpdateStatus() == PatientUpdateStatus.ADD) { - Errors errors = validatePatientInfo(patientInfo); - if(errors.hasErrors()){ - throw new LIMSRuntimeException("This Id already exists"); - } personService.insert(patient.getPerson()); } else if (patientInfo.getPatientUpdateStatus() == PatientUpdateStatus.UPDATE) { personService.update(patient.getPerson()); @@ -844,45 +832,4 @@ public Patient getByExternalId(String id) { return baseObjectDAO.getByExternalId(id); } - - private Errors validatePatientInfo(PatientManagementInfo patientInfo) { - Errors errors = new BaseErrors(); - boolean disallowDuplicateSubjectNumbers = ConfigurationProperties.getInstance() - .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false"); - boolean disallowDuplicateNationalIds = ConfigurationProperties.getInstance() - .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "false"); - if (disallowDuplicateSubjectNumbers || disallowDuplicateNationalIds) { - String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) ? null - : patientInfo.getSTnumber(); - String newSubjectNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSubjectNumber()) ? null - : patientInfo.getSubjectNumber(); - String newNationalId = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getNationalId()) ? null - : patientInfo.getNationalId(); - - List results = search.getSearchResults(null, null, newSTNumber, newSubjectNumber, - newNationalId, null, null, null, null, null); - - if (!results.isEmpty()) { - - for (PatientSearchResults result : results) { - if (!result.getPatientID().equals(patientInfo.getPatientPK())) { - if (disallowDuplicateSubjectNumbers && newSTNumber != null - && newSTNumber.equals(result.getSTNumber())) { - errors.reject("error.duplicate.STNumber", null, null); - } - if (disallowDuplicateSubjectNumbers && newSubjectNumber != null - && newSubjectNumber.equals(result.getSubjectNumber())) { - errors.reject("error.duplicate.subjectNumber", null, null); - } - if (disallowDuplicateNationalIds && newNationalId != null - && newNationalId.equals(result.getNationalId())) { - errors.reject("error.duplicate.nationalId", null, null); - } - } - } - } - } - return errors; - } - } \ No newline at end of file From 58ff312d57b8e9667856ac02fd62db6dc4911a94 Mon Sep 17 00:00:00 2001 From: common-cold Date: Fri, 12 Apr 2024 17:06:19 +0530 Subject: [PATCH 3/3] Removed the commented validator --- .../rest/PatientManagementRestController.java | 112 ++++++------------ 1 file changed, 38 insertions(+), 74 deletions(-) diff --git a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java index 92b6dede60..90fc2e028e 100644 --- a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java +++ b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java @@ -122,40 +122,44 @@ private void preparePatientData(Errors errors ,HttpServletRequest request, Patie } -// private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { -// if (ConfigurationProperties.getInstance() -// .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false")) { -// String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) -// ? null -// : patientInfo.getSTnumber(); -// String newSubjectNumber = org.apache.commons.validator.GenericValidator -// .isBlankOrNull(patientInfo.getSubjectNumber()) ? null : patientInfo.getSubjectNumber(); -// String newNationalId = org.apache.commons.validator.GenericValidator -// .isBlankOrNull(patientInfo.getNationalId()) ? null : patientInfo.getNationalId(); -// -// List results = searchService.getSearchResults(null, null, newSTNumber, -// newSubjectNumber, newNationalId, null, null, null, null, null); -// -// if (!results.isEmpty()) { -// for (PatientSearchResults result : results) { -// if (!result.getPatientID().equals(patientInfo.getPatientPK())) { -// if (newSTNumber != null && newSTNumber.equals(result.getSTNumber())) { -// errors.reject("error.duplicate.STNumber", "error.duplicate.STNumber"); -// } -// if (newSubjectNumber != null && newSubjectNumber.equals(result.getSubjectNumber())) { -// errors.reject("error.duplicate.subjectNumber", "error.duplicate.subjectNumber"); -// } -// if (newNationalId != null && newNationalId.equals(result.getNationalId())) { -// errors.reject("error.duplicate.nationalId", "error.duplicate.nationalId"); -// } -// } -// } -// } -// } -// -// validateBirthdateFormat(patientInfo, errors); -// -// } + private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { + boolean disallowDuplicateSubjectNumbers = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false"); + boolean disallowDuplicateNationalIds = ConfigurationProperties.getInstance() + .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "false"); + if (disallowDuplicateSubjectNumbers || disallowDuplicateNationalIds) { + String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) ? null + : patientInfo.getSTnumber(); + String newSubjectNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSubjectNumber()) ? null + : patientInfo.getSubjectNumber(); + String newNationalId = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getNationalId()) ? null + : patientInfo.getNationalId(); + + List results = searchService.getSearchResults(null, null, newSTNumber, newSubjectNumber, + newNationalId, null, null, null, null, null); + + if (!results.isEmpty()) { + + for (PatientSearchResults result : results) { + if (!result.getPatientID().equals(patientInfo.getPatientPK())) { + if (disallowDuplicateSubjectNumbers && newSTNumber != null + && newSTNumber.equals(result.getSTNumber())) { + errors.reject("error.duplicate.STNumber", null, null); + } + if (disallowDuplicateSubjectNumbers && newSubjectNumber != null + && newSubjectNumber.equals(result.getSubjectNumber())) { + errors.reject("error.duplicate.subjectNumber", null, null); + } + if (disallowDuplicateNationalIds && newNationalId != null + && newNationalId.equals(result.getNationalId())) { + errors.reject("error.duplicate.nationalId", null, null); + } + } + } + } + } + validateBirthdateFormat(patientInfo, errors); + } private void validateBirthdateFormat(PatientManagementInfo patientInfo, Errors errors) { String birthDate = patientInfo.getBirthDateForDisplay(); @@ -215,44 +219,4 @@ private Patient loadForUpdate(PatientManagementInfo patientInfo) { patientInfo.setPatientIdentities(patientIdentityService.getPatientIdentitiesForPatient(patient.getId())); return patient; } - - private void validatePatientInfo(Errors errors, PatientManagementInfo patientInfo) { - boolean disallowDuplicateSubjectNumbers = ConfigurationProperties.getInstance() - .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_SUBJECT_NUMBERS, "false"); - boolean disallowDuplicateNationalIds = ConfigurationProperties.getInstance() - .isPropertyValueEqual(ConfigurationProperties.Property.ALLOW_DUPLICATE_NATIONAL_IDS, "false"); - if (disallowDuplicateSubjectNumbers || disallowDuplicateNationalIds) { - String newSTNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSTnumber()) ? null - : patientInfo.getSTnumber(); - String newSubjectNumber = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getSubjectNumber()) ? null - : patientInfo.getSubjectNumber(); - String newNationalId = org.apache.commons.validator.GenericValidator.isBlankOrNull(patientInfo.getNationalId()) ? null - : patientInfo.getNationalId(); - - List results = searchService.getSearchResults(null, null, newSTNumber, newSubjectNumber, - newNationalId, null, null, null, null, null); - - if (!results.isEmpty()) { - - for (PatientSearchResults result : results) { - if (!result.getPatientID().equals(patientInfo.getPatientPK())) { - if (disallowDuplicateSubjectNumbers && newSTNumber != null - && newSTNumber.equals(result.getSTNumber())) { - errors.reject("error.duplicate.STNumber", null, null); - } - if (disallowDuplicateSubjectNumbers && newSubjectNumber != null - && newSubjectNumber.equals(result.getSubjectNumber())) { - errors.reject("error.duplicate.subjectNumber", null, null); - } - if (disallowDuplicateNationalIds && newNationalId != null - && newNationalId.equals(result.getNationalId())) { - errors.reject("error.duplicate.nationalId", null, null); - } - } - } - } - } - validateBirthdateFormat(patientInfo, errors); - } - }