Search in sources :

Example 81 with PersonName

use of org.openmrs.PersonName in project openmrs-core by openmrs.

the class PatientServiceTest method mergePatients_shouldMaintainSimilarButDifferentNames.

@Test
public void mergePatients_shouldMaintainSimilarButDifferentNames() throws Exception {
    executeDataSet(PATIENT_MERGE_XML);
    Patient preferredPatient = patientService.getPatient(10000);
    Patient nonPreferredPatient = patientService.getPatient(10001);
    patientService.mergePatients(preferredPatient, nonPreferredPatient);
    Set<PersonName> names = preferredPatient.getNames();
    if ((PersonName.getFormat()).equals(OpenmrsConstants.PERSON_NAME_FORMAT_LONG)) {
        assertThat(names, containsFullName("President John Fitzgerald Kennedy Esq."));
    } else {
        assertThat(names, containsFullName("John Fitzgerald Kennedy"));
    }
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 82 with PersonName

use of org.openmrs.PersonName in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldEscapePercentageCharacterInNamePhrase.

/**
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapePercentageCharacterInNamePhrase() {
    Patient patient2 = patientService.getPatient(2);
    PersonName name = new PersonName("%cats", "and", "dogs");
    patient2.addName(name);
    patientService.savePatient(patient2);
    // add a new closely matching identifier to another patient
    Patient patient6 = patientService.getPatient(6);
    PersonName name6 = new PersonName("acats", "and", "dogs");
    patient6.addName(name6);
    patient6.getPatientIdentifier().setPreferred(true);
    patientService.savePatient(patient6);
    updateSearchIndex();
    // we expect only one matching patient
    int actualSize = dao.getPatients("%ca", 0, null).size();
    Assert.assertEquals(1, actualSize);
    Patient actualPatient = dao.getPatients("%ca", 0, null).get(0);
    // if actually the search returned the matching patient
    Assert.assertEquals(patient2, actualPatient);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 83 with PersonName

use of org.openmrs.PersonName in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldEscapeAnAsterixCharacterInNamePhrase.

/**
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapeAnAsterixCharacterInNamePhrase() {
    Patient patient2 = patientService.getPatient(2);
    PersonName name = new PersonName("*cats", "and", "dogs");
    patient2.addName(name);
    patientService.savePatient(patient2);
    // add a new closely matching name to another patient
    Patient patient6 = patientService.getPatient(6);
    PersonName name6 = new PersonName("acats", "and", "dogs");
    patient6.addName(name6);
    patient6.getPatientIdentifier().setPreferred(true);
    patientService.savePatient(patient6);
    updateSearchIndex();
    // we expect only one matching patient
    int actualSize = dao.getPatients("*ca", 0, null).size();
    Assert.assertEquals(1, actualSize);
    // if actually the search returned the matching patient
    Patient actualPatient = dao.getPatients("*ca", 0, null).get(0);
    Assert.assertEquals(patient2, actualPatient);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 84 with PersonName

use of org.openmrs.PersonName in project openmrs-core by openmrs.

the class UserDAOTest method runBeforeEachTest.

/**
 * Run this before each unit test in this class. The "@Before" method in
 * {@link BaseContextSensitiveTest} is run right before this method.
 *
 * @throws Exception
 */
@Before
public void runBeforeEachTest() {
    PersonName name = new PersonName("Joe", "J", "Doe");
    name.setDateCreated(new Date());
    Person person = new Person();
    person.setDateCreated(new Date());
    person.setPersonDateCreated(person.getDateCreated());
    person.setGender("M");
    userJoe = new User();
    userJoe.setSystemId("100-30");
    userJoe.setPerson(person);
    userJoe.addName(name);
    userJoe.setUsername("juser");
    userJoe.setDateCreated(new Date());
    if (dao == null) {
        // fetch the dao from the spring application context
        // this bean name matches the name in /metadata/spring/applicationContext-service.xml
        dao = (UserDAO) applicationContext.getBean("userDAO");
    }
    dao.saveUser(userJoe, null);
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person) Date(java.util.Date) Before(org.junit.Before)

Example 85 with PersonName

use of org.openmrs.PersonName in project openmrs-core by openmrs.

the class AuditableInterceptorTest method createPersonWithNameAndAddress.

private Person createPersonWithNameAndAddress() {
    Person person = new Person();
    person.setGender("M");
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    person.addName(name);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    person.addAddress(address);
    return person;
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person)

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