Search in sources :

Example 6 with Patient

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());
}
Also used : Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Patient

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));
}
Also used : Patient(org.openmrs.Patient) PersonAttribute(org.openmrs.PersonAttribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Patient

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));
}
Also used : Order(org.openmrs.Order) Config(org.openmrs.module.pihcore.config.Config) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Ignore(org.junit.Ignore) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 9 with Patient

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));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 10 with Patient

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));
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) PersonAuditInfoCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28