Search in sources :

Example 71 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 72 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 73 with PersonName

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());
}
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 74 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 75 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

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