use of org.openmrs.PersonName 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.PersonName in project openmrs-core by openmrs.
the class ContextTest method becomeUser_shouldChangeLocaleWhenBecomeAnotherUser.
/**
* @see Context#becomeUser(String)
*/
@Test
public void becomeUser_shouldChangeLocaleWhenBecomeAnotherUser() {
UserService userService = Context.getUserService();
User user = new User(new Person());
user.addName(new PersonName("givenName", "middleName", "familyName"));
user.getPerson().setGender("M");
user.setUserProperty(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE, "pt_BR");
userService.createUser(user, "TestPass123");
Context.becomeUser(user.getSystemId());
Locale locale = Context.getLocale();
Assert.assertEquals("pt", locale.getLanguage());
Assert.assertEquals("BR", locale.getCountry());
Context.logout();
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldNotMatchVoidedPatientNames.
/**
* @see PatientDAO#getPatients(String, String, java.util.List, boolean, Integer,
* Integer, boolean)
*/
@Test
public void getPatients_shouldNotMatchVoidedPatientNames() {
List<Patient> patients = dao.getPatients("Oloo", 0, 11);
Assert.assertEquals(1, patients.size());
Patient patient = patients.get(0);
Set<PersonName> names = patient.getNames();
for (PersonName name : names) {
name.setVoided(true);
}
updateSearchIndex();
dao.savePatient(patient);
patients = dao.getPatients("Oloo", 0, 11);
Assert.assertEquals(0, patients.size());
}
use of org.openmrs.PersonName 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.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method createBasicPatient.
/**
* Convenience method to have a Patient object with all required values filled in
*
* @return a mock Patient object that can be saved
*/
private Patient createBasicPatient() {
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
// patient.removeAddress(pAddress);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept());
patient.setGender("male");
patient.setDeathdateEstimated(true);
return patient;
}
Aggregations