Search in sources :

Example 76 with PersonName

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);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 77 with PersonName

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();
}
Also used : Locale(java.util.Locale) PersonName(org.openmrs.PersonName) User(org.openmrs.User) UserService(org.openmrs.api.UserService) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 78 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 79 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 80 with PersonName

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;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) Date(java.util.Date)

Aggregations

PersonName (org.openmrs.PersonName)108 Test (org.junit.Test)81 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)57 Patient (org.openmrs.Patient)41 Person (org.openmrs.Person)39 Date (java.util.Date)26 PatientIdentifier (org.openmrs.PatientIdentifier)19 PersonAddress (org.openmrs.PersonAddress)19 User (org.openmrs.User)17 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)17 PatientIdentifierType (org.openmrs.PatientIdentifierType)13 Location (org.openmrs.Location)12 ArrayList (java.util.ArrayList)9 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)9 PersonMergeLog (org.openmrs.person.PersonMergeLog)8 PersonAttribute (org.openmrs.PersonAttribute)7 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)6 Provider (org.openmrs.Provider)5