use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfBirth.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfBirth() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
// milliseconds are not serialized into the database. they will be ignored in the test
cDate.set(Calendar.MILLISECOND, 0);
Patient preferred = patientService.getPatient(999);
preferred.setBirthdate(cDate.getTime());
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
Assert.assertEquals("prior date of birth was not audited", cDate.getTime(), audit.getPersonMergeLogData().getPriorDateOfBirth());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldNotSetThePreferredNameAddressAndIdentifierIfTheyAlreadyExist.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldNotSetThePreferredNameAddressAndIdentifierIfTheyAlreadyExist() throws Exception {
Patient patient = new Patient();
patient.setGender("M");
PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(5), locationService.getLocation(1));
PatientIdentifier preferredIdentifier = new PatientIdentifier("QWERTY2", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
preferredIdentifier.setPreferred(true);
patient.addIdentifier(identifier);
patient.addIdentifier(preferredIdentifier);
PersonName name = new PersonName("givenName", "middleName", "familyName");
PersonName preferredName = new PersonName("givenName", "middleName", "familyName");
preferredName.setPreferred(true);
patient.addName(name);
patient.addName(preferredName);
PersonAddress address = new PersonAddress();
address.setAddress1("some address");
PersonAddress preferredAddress = new PersonAddress();
preferredAddress.setAddress1("another address");
preferredAddress.setPreferred(true);
patient.addAddress(address);
patient.addAddress(preferredAddress);
patientService.savePatient(patient);
Assert.assertTrue(preferredIdentifier.getPreferred());
Assert.assertTrue(preferredName.getPreferred());
Assert.assertTrue(preferredAddress.getPreferred());
Assert.assertFalse(identifier.getPreferred());
Assert.assertFalse(name.getPreferred());
Assert.assertFalse(address.getPreferred());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method getCountOfPatients_shouldReturnTheRightCountWhenAPatientHasMultipleMatchingPersonNames.
/**
* @see PatientService#getCountOfPatients(String)
*/
@Test
public void getCountOfPatients_shouldReturnTheRightCountWhenAPatientHasMultipleMatchingPersonNames() throws Exception {
// TODO H2 cannot execute the generated SQL because it requires all
// fetched columns to be included in the group by clause
Patient patient = patientService.getPatient(2);
// sanity check
Assert.assertTrue(patient.getPersonName().getGivenName().startsWith("Horati"));
// add a name that will match the search phrase
patient.addName(new PersonName("Horatio", "Test", "name"));
Context.getPatientService().savePatient(patient);
Assert.assertEquals(1, Context.getPatientService().getCountOfPatients("Hor").intValue());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfDeath.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfDeath() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
// milliseconds are not serialized into the database. they will be ignored in the test
cDate.set(Calendar.MILLISECOND, 0);
Patient preferred = patientService.getPatient(999);
preferred.setDeathDate(cDate.getTime());
preferred.setDead(true);
preferred.setCauseOfDeath(Context.getConceptService().getConcept(3));
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
Assert.assertEquals("prior date of death was not audited", cDate.getTime(), audit.getPersonMergeLogData().getPriorDateOfDeath());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorGender.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorGender() throws Exception {
// retrieve preferred patient and set gender
Patient preferred = patientService.getPatient(999);
preferred.setGender("M");
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
// merge with not preferred
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
Assert.assertEquals("prior gender was not audited", "M", audit.getPersonMergeLogData().getPriorGender());
}
Aggregations