use of org.openmrs.Patient in project openmrs-module-pihcore by PIH.
the class PihPatientMergeActionsTest method shouldVoidMostRecentRegistrationEncountersOnNonPreferredPatientIfMoreRecentThanPreferred.
@Test
public void shouldVoidMostRecentRegistrationEncountersOnNonPreferredPatientIfMoreRecentThanPreferred() {
Patient preferred = new Patient(1);
Patient nonPreferred = new Patient(2);
Encounter preferredEncounter1 = createEncounter(1, new DateTime(2012, 9, 10, 0, 0, 0).toDate());
Encounter preferredEncounter2 = createEncounter(2, new DateTime(2012, 10, 10, 0, 0, 0).toDate());
Encounter nonPreferredEncounter1 = createEncounter(3, new DateTime(2012, 11, 10, 0, 0, 0).toDate());
Encounter nonPreferredEncounter2 = createEncounter(4, new DateTime(2012, 12, 10, 0, 0, 0).toDate());
when(encounterService.getEncounters(preferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(Arrays.asList(preferredEncounter1, preferredEncounter2));
when(encounterService.getEncounters(nonPreferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(Arrays.asList(nonPreferredEncounter1, nonPreferredEncounter2));
pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
verify(encounterService, never()).voidEncounter(eq(preferredEncounter1), anyString());
verify(encounterService, never()).voidEncounter(eq(preferredEncounter2), anyString());
verify(encounterService).voidEncounter(eq(nonPreferredEncounter1), anyString());
verify(encounterService).voidEncounter(eq(nonPreferredEncounter2), anyString());
}
use of org.openmrs.Patient in project openmrs-module-pihcore by PIH.
the class PihPatientMergeActionsTest method shouldNotRemoveNonPreferredPhoneNumberAndMothersNameIfNotPresentOnPreferredPatient.
@Test
public void shouldNotRemoveNonPreferredPhoneNumberAndMothersNameIfNotPresentOnPreferredPatient() {
Patient preferred = new Patient();
Patient nonPreferred = new Patient();
PersonAttribute nonPreferredPhoneNumber = new PersonAttribute(phoneNumber, "non-preferred");
PersonAttribute nonPreferredMothersName = new PersonAttribute(mothersName, "non-preferred");
nonPreferred.addAttribute(nonPreferredPhoneNumber);
nonPreferred.addAttribute(nonPreferredMothersName);
// sanity check
assertThat(preferred.getActiveAttributes().size(), is(0));
assertThat(nonPreferred.getActiveAttributes().size(), is(2));
pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
assertThat(preferred.getActiveAttributes().size(), is(0));
assertThat(nonPreferred.getActiveAttributes().size(), is(2));
}
use of org.openmrs.Patient in project openmrs-module-pihcore by PIH.
the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit.
// TODO un-ignore once we have the EMR API module updated
@Test
@Ignore
public void shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit() throws Exception {
PihRadiologyOrdersMergeActions pihRadiologyOrdersMergeActions = Context.getRegisteredComponent("pihRadiologyOrdersMergeActions", PihRadiologyOrdersMergeActions.class);
Config config = mock(Config.class);
runtimeProperties.setProperty(ConfigLoader.PIH_CONFIGURATION_RUNTIME_PROPERTY, "mirebalais");
config = new Config(ConfigLoader.loadFromRuntimeProperties());
pihRadiologyOrdersMergeActions.setConfig(config);
Patient preferredPatient = patientService.getPatient(6);
Patient nonPreferredPatient = patientService.getPatient(10004);
List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(nonPreferredPatient);
// patient has 1 Radiology Encounter
Assert.assertEquals(1, encountersByPatient.size());
Assert.assertEquals("RadiologyOrder", encountersByPatient.get(0).getEncounterType().getName());
Set<Order> orders = encountersByPatient.get(0).getOrders();
Assert.assertEquals(1, orders.size());
Order radiologyOrder = null;
for (Order order : orders) {
radiologyOrder = order;
}
Assert.assertEquals("RadiologyOrder", radiologyOrder.getOrderType().getName());
adtService.mergePatients(preferredPatient, nonPreferredPatient);
assertTrue("RadiologyOrder was not merged", orderService.getAllOrdersByPatient(preferredPatient).contains(radiologyOrder));
}
use of org.openmrs.Patient in project openmrs-module-pihcore by PIH.
the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasNoOrders.
@Test
public void shouldMergePatientsWhenNonPreferredPatientHasNoOrders() throws Exception {
Patient preferredPatient = patientService.getPatient(6);
List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(preferredPatient);
// patient has 1 Radiology Encounter
Assert.assertEquals(1, encountersByPatient.size());
Assert.assertEquals("RadiologyOrder", encountersByPatient.get(0).getEncounterType().getName());
Set<Order> orders = encountersByPatient.get(0).getOrders();
Assert.assertEquals(1, orders.size());
Order radiologyOrder = null;
for (Order order : orders) {
radiologyOrder = order;
}
Assert.assertEquals("RadiologyOrder", radiologyOrder.getOrderType().getName());
Patient nonPreferredPatient = patientService.getPatient(10001);
adtService.mergePatients(preferredPatient, nonPreferredPatient);
assertTrue("RadiologyOrder is not present after merging the patients", orderService.getAllOrdersByPatient(preferredPatient).contains(radiologyOrder));
}
use of org.openmrs.Patient in project openmrs-module-pihcore by PIH.
the class PersonAuditInfoCohortDefinitionEvaluatorTest method testEvaluateByVoidedDetails.
@Test
public void testEvaluateByVoidedDetails() throws Exception {
Date today = DateUtil.getStartOfDay(new Date());
// in standardTestDataset.xml patient 999 is voided, but has no dateVoided. Fix this
Patient voidedPatient = patientService.getPatient(999);
voidedPatient.addName(new PersonName("A", "Non-voided", "Name"));
patientService.voidPatient(voidedPatient, "testing");
PersonAuditInfoCohortDefinition cd = new PersonAuditInfoCohortDefinition();
cd.setIncludeVoided(true);
cd.setVoidedOnOrAfter(today);
cd.setVoidedOnOrBefore(today);
EvaluatedCohort actual = evaluator.evaluate((CohortDefinition) cd, new EvaluationContext());
assertThat(actual, hasExactlyIds(999));
}
Aggregations