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);
}
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());
}
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);
}
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);
}
}
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());
}
Aggregations