Search in sources :

Example 11 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihTestOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasNoTestOrders.

@Test
public void shouldMergePatientsWhenNonPreferredPatientHasNoTestOrders() throws Exception {
    Patient preferredPatient = patientService.getPatient(10005);
    List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(preferredPatient);
    // patient has 1 Test
    Assert.assertEquals(1, encountersByPatient.size());
    Assert.assertEquals("TestOrder", encountersByPatient.get(0).getEncounterType().getName());
    Set<Order> orders = encountersByPatient.get(0).getOrders();
    Assert.assertEquals(1, orders.size());
    Order testOrder = orders.iterator().next();
    Assert.assertEquals("Test order", testOrder.getOrderType().getName());
    Patient nonPreferredPatient = patientService.getPatient(10001);
    adtService.mergePatients(preferredPatient, nonPreferredPatient);
    assertTrue("TestOrder is present after merging the patients", orderService.getAllOrdersByPatient(preferredPatient).contains(testOrder));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Example 12 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihTestOrdersMergeActionsComponentTest method shouldMergePatientsWhenBothPatientHaveOpenPathologyTestOrders.

@Test
public void shouldMergePatientsWhenBothPatientHaveOpenPathologyTestOrders() throws Exception {
    Patient preferredPatient = patientService.getPatient(10006);
    List<Encounter> encountersByPreferredPatient = encounterService.getEncountersByPatient(preferredPatient);
    // patient has 1 Test Order Encounter
    Assert.assertEquals(1, encountersByPreferredPatient.size());
    Assert.assertEquals("TestOrder", encountersByPreferredPatient.get(0).getEncounterType().getName());
    Set<Order> ordersByPreferredPatient = encountersByPreferredPatient.get(0).getOrders();
    Assert.assertEquals(1, ordersByPreferredPatient.size());
    Order testOrderOfPreferredPatient = ordersByPreferredPatient.iterator().next();
    Patient nonPreferredPatient = patientService.getPatient(10007);
    List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(nonPreferredPatient);
    // patient has 1 Test Order Encounter
    Assert.assertEquals(1, encountersByPatient.size());
    Assert.assertEquals("TestOrder", encountersByPatient.get(0).getEncounterType().getName());
    Set<Order> orders = encountersByPatient.get(0).getOrders();
    Assert.assertEquals(1, orders.size());
    Order testOrder = orders.iterator().next();
    Assert.assertEquals("PathologyOrder", testOrder.getOrderType().getName());
    adtService.mergePatients(preferredPatient, nonPreferredPatient);
    assertTrue("Pathology Test Order was merged", orderService.getAllOrdersByPatient(preferredPatient).contains(testOrderOfPreferredPatient));
    assertTrue("Pathology Test Order was merged", orderService.getAllOrdersByPatient(preferredPatient).contains(testOrder));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Example 13 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class DailyCheckInsDataSetManagerTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    VisitType atFacility = emrApiProperties.getAtFacilityVisitType();
    Location registrationDesk = locationService.getLocation("Biwo Resepsyon");
    Location outpatient = locationService.getLocation("Klinik Ekstèn");
    Location mirebalaisHospital = locationService.getLocation("Hôpital Universitaire de Mirebalais - Prensipal");
    EncounterType registration = getRegistrationEncounterType();
    EncounterType checkIn = getCheckInEncounterType();
    EncounterType consult = getConsultationEncounterType();
    // never registered or seen
    data.randomPatient().age(50).dateCreated("2013-10-01").save();
    // registered at Clinic Registration, checked in at Outpatient Clinic for a CLINICAL visit (and had a consult)
    p2 = data.randomPatient().age(50).save();
    Visit v1 = data.visit().patient(p2).visitType(atFacility).started("2013-10-01 09:30:00").stopped("2013-10-01 16:45:00").location(mirebalaisHospital).save();
    data.encounter().visit(v1).encounterType(registration).location(registrationDesk).encounterDatetime("2013-10-01 09:30:00").save();
    Encounter p2CheckIn = data.encounter().visit(v1).encounterType(checkIn).location(outpatient).encounterDatetime("2013-10-01 09:45:00").save();
    data.obs().encounter(p2CheckIn).concept("Type of HUM visit", "PIH").value("CLINICAL", "PIH").save();
    data.encounter().visit(v1).encounterType(consult).encounterDatetime("2013-10-01 10:45:00").location(outpatient).save();
    // checked in at Outpatient Clinic for a Pharmacy only visit
    p3 = data.randomPatient().age(50).save();
    data.encounter().patient(p3).encounterType(registration).location(registrationDesk).encounterDatetime("2013-01-01 09:30:00").save();
    Visit v2 = data.visit().patient(p3).visitType(atFacility).started("2013-10-01 10:30:00").stopped("2013-10-01 16:45:00").location(mirebalaisHospital).save();
    Encounter p3checkIn = data.encounter().visit(v2).encounterType(checkIn).location(outpatient).encounterDatetime("2013-10-01 10:45:00").save();
    data.obs().encounter(p3checkIn).concept("Type of HUM visit", "PIH").value("Pharmacy only", "PIH").save();
    // registered before and had a consult, then checked in again today for a CLINICAL visit (but no consult yet)
    p4 = data.randomPatient().age(50).save();
    data.encounter().patient(p4).encounterType(consult).encounterDatetime("2009-01-01").location(outpatient).save();
    Visit v3 = data.visit().patient(p4).visitType(atFacility).started("2013-10-01 14:30:00").location(mirebalaisHospital).save();
    Encounter p4CheckIn = data.encounter().visit(v3).encounterType(checkIn).location(outpatient).encounterDatetime("2013-10-01 14:30:00").save();
    data.obs().encounter(p4CheckIn).concept("Type of HUM visit", "PIH").value("CLINICAL", "PIH").save();
}
Also used : Visit(org.openmrs.Visit) VisitType(org.openmrs.VisitType) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) Before(org.junit.Before)

Example 14 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfItHasADischargeEncounterEvenIfDateCreatedAndDateChangedAreWithin12Hours.

@Test
public void test_shouldCloseVisitIfItHasADischargeEncounterEvenIfDateCreatedAndDateChangedAreWithin12Hours() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    // patient already has one visit in test dataset
    Patient patient = patientService.getPatient(7);
    // need to tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
    Location unknownLocation = locationService.getLocation(1);
    unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(unknownLocation);
    Location location = locationService.getLocation(2);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    Visit visit = new Visit();
    visit.setDateCreated(new Date());
    visit.setDateChanged(new Date());
    visit.setStartDatetime(DateUtils.addHours(new Date(), -60));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create an exit from care encounter
    Encounter exitFromCareEncounter = new Encounter();
    exitFromCareEncounter.setPatient(patient);
    exitFromCareEncounter.setEncounterType(emrApiProperties.getExitFromInpatientEncounterType());
    exitFromCareEncounter.setEncounterDatetime(visit.getStartDatetime());
    encounterService.saveEncounter(exitFromCareEncounter);
    visit.addEncounter(exitFromCareEncounter);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNull(activeVisit);
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 15 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButMostRecentDispositionIsDischarge.

@Test
public void test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButMostRecentDispositionIsDischarge() throws Exception {
    ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
    ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
    ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
    // patient already has one visit in test dataset
    Patient patient = patientService.getPatient(7);
    // need to tag the unknown location so we don't run into an error when testing against the existing visits in the test dataset
    Location unknownLocation = locationService.getLocation(1);
    unknownLocation.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(unknownLocation);
    Location location = locationService.getLocation(2);
    location.addTag(emrApiProperties.getSupportsVisitsLocationTag());
    locationService.saveLocation(location);
    Visit visit = new Visit();
    // because recently-created visits won't be closed
    visit.setDateCreated(DateUtils.addHours(new Date(), -30));
    visit.setStartDatetime(DateUtils.addHours(new Date(), -60));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create ED Triage encounter
    Encounter edTriage = new Encounter();
    edTriage.setPatient(patient);
    edTriage.setEncounterType(encounterService.getEncounterTypeByUuid(ED_TRIAGE_ENCOUNTER_TYPE_UUID));
    edTriage.setEncounterDatetime(visit.getStartDatetime());
    encounterService.saveEncounter(edTriage);
    // create another encounter within 48 hours
    Encounter consult = new Encounter();
    consult.setPatient(patient);
    consult.setEncounterType(emrApiProperties.getVisitNoteEncounterType());
    consult.setEncounterDatetime(DateUtils.addHours(new Date(), -47));
    encounterService.saveEncounter(consult);
    // create an encounter with a disposition obs of "discharge"
    Encounter encounterWithDisposition = new Encounter();
    encounterWithDisposition.setPatient(patient);
    encounterWithDisposition.setEncounterType(encounterService.getEncounterType(1));
    encounterWithDisposition.setEncounterDatetime(visit.getStartDatetime());
    Obs dispositionObsGroup = new Obs();
    dispositionObsGroup.setConcept(dispositionService.getDispositionDescriptor().getDispositionSetConcept());
    Obs dispositionObs = new Obs();
    dispositionObs.setConcept(dispositionService.getDispositionDescriptor().getDispositionConcept());
    // this fake code is set in ContextSensitiveMetadataTestUtils
    dispositionObs.setValueCoded(emrConceptService.getConcept(EmrApiConstants.EMR_CONCEPT_SOURCE_NAME + ":Discharged"));
    dispositionObsGroup.addGroupMember(dispositionObs);
    encounterWithDisposition.addObs(dispositionObsGroup);
    encounterService.saveEncounter(encounterWithDisposition);
    visit.addEncounter(edTriage);
    visit.addEncounter(consult);
    visit.addEncounter(encounterWithDisposition);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNull(activeVisit);
}
Also used : Obs(org.openmrs.Obs) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) Location(org.openmrs.Location) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19