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