Search in sources :

Example 51 with PersonName

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

the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient.

/**
 * Regression test for http://dev.openmrs.org/ticket/1375
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setPatientId(2);
    // patient.setCreator(new User(1));
    // patient.setDateCreated date_created="2005-09-22 00:00:00.0"
    // changed_by="1" date_changed="2008-08-18 12:29:59.0"
    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);
    Context.getPatientService().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 52 with PersonName

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

the class PatientDAOTest method getPatients_shouldNotMatchVoidedPatientNames_SignatureNo1.

/**
 * @see HibernatePatientDAO#getPatients(String, String, java.util.List, boolean, Integer, Integer, boolean)
 */
@Test
public void getPatients_shouldNotMatchVoidedPatientNames_SignatureNo1() {
    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);
    }
    dao.savePatient(patient);
    updateSearchIndex();
    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 53 with PersonName

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

the class PatientDAOTest method getPatients_shouldEscapeUnderscoreCharacterInNamePhrase.

/**
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapeUnderscoreCharacterInNamePhrase() {
    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 54 with PersonName

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

the class UserDAOTest method getUsers_shouldEscapeSqlWildcardsInSearchPhrase.

@Test
public void getUsers_shouldEscapeSqlWildcardsInSearchPhrase() {
    User u = new User();
    u.setPerson(new Person());
    u.getPerson().setGender("M");
    // we used to also test %, but UserValidator actually doesn't allow that in usernames. TODO: remove the loop
    String[] wildcards = new String[] { "_" };
    // with the wildcards and carry out a search for that user
    for (String wildcard : wildcards) {
        PersonName name = new PersonName(wildcard + "cats", wildcard + "and", wildcard + "dogs");
        name.setDateCreated(new Date());
        u.addName(name);
        u.setUsername(wildcard + "test" + wildcard);
        Context.getUserService().createUser(u, "Openmr5xy");
        // we expect only one matching name or or systemId  to be returned
        int size = dao.getUsers(wildcard + "ca", null, false, null, null).size();
        assertEquals(1, size);
        // if actually the search returned the matching name or system id
        String userName = (dao.getUsers(wildcard + "ca", null, false, null, null).get(0).getUsername());
        assertEquals("Test failed since no user containing the character " + wildcard + " was found, ", wildcard + "test" + wildcard, userName);
    }
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with PersonName

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

the class ProviderServiceTest method getCountOfProviders_shouldFetchNumberOfProviderMatchingGivenQuery.

/**
 * @see ProviderService#getCountOfProviders(String,null)
 */
@Test
public void getCountOfProviders_shouldFetchNumberOfProviderMatchingGivenQuery() {
    assertEquals(1, service.getCountOfProviders("Hippo").intValue());
    Person person = Context.getPersonService().getPerson(502);
    Set<PersonName> names = person.getNames();
    for (PersonName name : names) {
        name.setVoided(true);
    }
    PersonName personName = new PersonName("Hippot", "A", "B");
    personName.setPreferred(true);
    person.addName(personName);
    Context.getPersonService().savePerson(person);
    assertEquals(1, service.getCountOfProviders("Hippo").intValue());
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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