/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatientIdentifiers() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(2); PatientIdentifier patientIdentifier = new PatientIdentifier("ABC123", pit, null); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierDoesNotContainAPatientAndAPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("7TU-8", pit, null); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierDoesNotContainAPatientAndNoPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierContainsAPatientAndAnotherPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("7TU-8", pit, null); patientIdentifier.setPatient(patientService.getPatient(2)); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null); patientIdentifier.setPatient(patientService.getPatient(2)); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsNull() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); Assert.assertNull(idType.getUniquenessBehavior()); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.UNIQUE); patientService.savePatientIdentifierType(idType); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseForALocationAndIdTypeUniquenessIsSetToLocation() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.LOCATION); patientService.savePatientIdentifierType(idType); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * Regression test for http://dev.openmrs.org/ticket/790 * * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatients() throws Exception { { // patient 999 should be voided and have a non-voided identifier of // XYZ Patient p = patientService.getPatient(999); Assert.assertNotNull(p); Assert.assertTrue(p.getVoided()); boolean found = false; for (PatientIdentifier id : p.getIdentifiers()) { if (id.getIdentifier().equals("XYZ") && id.getIdentifierType().getId() == 2) { found = true; break; } } Assert.assertTrue(found); } PatientIdentifierType pit = patientService.getPatientIdentifierType(2); PatientIdentifier patientIdentifier = new PatientIdentifier("XYZ", pit, null); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.LOCATION); patientService.savePatientIdentifierType(idType); Location idLocation = locationService.getLocation(2); Assert.assertNotSame(idLocation, duplicateId.getLocation());//sanity check PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi)); }
&& Context.getPatientService().isIdentifierInUseByAnotherPatient(pi)) {
private void validateIdentifier(Integer identifierType, String identifier, Patient patient) { if (identifierType != null && identifier != null) { try { PatientIdentifier pi = new PatientIdentifier(); pi.setPatient(patient); pi.setIdentifier(identifier); pi.setIdentifierType(getIdentifierType(identifierType.toString())); // note that this is a bit of a hack; we can't call the PatientIdentifierValidator.validateIdentifier(identifier) method // because it (as of 1.8) also tests to make sure that an identifier has a location associated with it; when validating an // individual identifier widget, there will be no location because the location is collected in another widget PatientIdentifierValidator.validateIdentifier(pi.getIdentifier(), pi.getIdentifierType()); if (Context.getPatientService().isIdentifierInUseByAnotherPatient(pi)) { throw new IdentifierNotUniqueException(Context.getMessageSourceService().getMessage( "PatientIdentifier.error.notUniqueWithParameter", new Object[] { pi.getIdentifier() }, Context.getLocale())); } } catch (Exception e) { throw new ValidationException(e.getMessage()); } } }