use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375.
/**
* Regression test for ticket #1375: org.hibernate.NonUniqueObjectException caused by
* PatientIdentifierValidator Manually construct a patient with a correctly-matching patientId
* and patient identifier with validator. Calling PatientService.savePatient on that patient
* leads to a call to PatientIdentifierValidator.validateIdentifier which used to load the
* Patient for that identifier into the hibernate session, leading to a NonUniqueObjectException
* when the calling saveOrUpdate on the manually constructed Patient.
*
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375() {
Patient patient = new Patient();
patient.setGender("M");
patient.setPatientId(2);
patient.addName(new PersonName("This", "Isa", "Test"));
PatientIdentifier patientIdentifier = new PatientIdentifier("101-6", new PatientIdentifierType(1), new Location(1));
patientIdentifier.setPreferred(true);
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldNotGetNewPatientByWrongIdentifierStartMatch.
@Test
public void getPatients_shouldNotGetNewPatientByWrongIdentifierStartMatch() {
String oldPropertyValue = globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START);
Patient patient = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("OM292", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
updateSearchIndex();
List<Patient> patients = dao.getPatients("OM78", false, 0, null);
Assert.assertEquals(0, patients.size());
if (oldPropertyValue != null) {
globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, oldPropertyValue);
} else {
globalPropertiesTestHelper.purgeGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE);
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldEscapeUnderscoreCharacterInIdentifierPhrase.
/**
* @throws SQLException
* @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
*/
@Test
public void getPatients_shouldEscapeUnderscoreCharacterInIdentifierPhrase() throws SQLException {
deleteAllData();
baseSetupWithStandardDataAndAuthentication();
Patient patient2 = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("_567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient2.addIdentifier(patientIdentifier);
patientService.savePatient(patient2);
// add closely matching identifier to a different patient
Patient patient6 = patientService.getPatient(6);
PatientIdentifier patientIdentifier6 = new PatientIdentifier("4567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patientIdentifier6.setPreferred(true);
patient6.addIdentifier(patientIdentifier6);
patientService.savePatient(patient6);
updateSearchIndex();
// we expect only one matching patient
int actualSize = dao.getPatients("_567", 0, null).size();
Assert.assertEquals(1, actualSize);
// if actually the search returned the matching patient
Patient actualPatient = dao.getPatients("_567", 0, null).get(0);
Assert.assertEquals(patient2, actualPatient);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers() throws Exception {
List<Location> locations = Context.getLocationService().getAllLocations();
Assert.assertTrue(CollectionUtils.isNotEmpty(locations));
// check if we have patient identifiers already
PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierType(5);
Assert.assertNotNull(patientIdentifierType);
// retrieve preferred patient and set gender
Patient preferred = patientService.getPatient(999);
// create new identifier for the preferred patient
PatientIdentifier preferredIdentifier = new PatientIdentifier();
preferredIdentifier.setIdentifier("9999-4");
preferredIdentifier.setIdentifierType(patientIdentifierType);
preferredIdentifier.setLocation(locations.get(0));
preferred.addIdentifier(preferredIdentifier);
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
// merge with not preferred
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
// create identifier with the same values for the non preferred patient
PatientIdentifier nonPreferredIdentifier = new PatientIdentifier();
nonPreferredIdentifier.setIdentifier("9999-4");
nonPreferredIdentifier.setIdentifierType(patientIdentifierType);
nonPreferredIdentifier.setLocation(locations.get(0));
notPreferred.addIdentifier(nonPreferredIdentifier);
patientService.savePatient(notPreferred);
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// should not copy the duplicate identifier to the winner
Assert.assertEquals(notPreferred.getIdentifiers().size() - 1, audit.getPersonMergeLogData().getCreatedIdentifiers().size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldIgnoreVoidedPatientIdentifier.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test
public void checkPatientIdentifiers_shouldIgnoreVoidedPatientIdentifier() throws Exception {
Patient patient = new Patient();
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setVoided(true);
patientIdentifier.setVoidedBy(Context.getAuthenticatedUser());
patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
patient.addIdentifier(patientIdentifier);
// add a non-voided identifier so that the initial
// "at least one nonvoided identifier" check passes
patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("a non empty string");
patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setVoided(false);
patientIdentifier.setVoidedBy(Context.getAuthenticatedUser());
patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
patient.addIdentifier(patientIdentifier);
// If the identifier is ignored, it won't throw a
// BlankIdentifierException as it should
Context.getPatientService().checkPatientIdentifiers(patient);
}
Aggregations