Search in sources :

Example 46 with VisitDomainWrapper

use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.

the class RequireUtilTest method shouldReturnTrueIfVisitActive.

@Test
public void shouldReturnTrueIfVisitActive() {
    VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
    when(visit.isActive()).thenReturn(true);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(patientHasActiveVisit()), appContextModel), is(true));
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with VisitDomainWrapper

use of org.openmrs.module.emrapi.visit.VisitDomainWrapper in project openmrs-module-pihcore by PIH.

the class PihCloseStaleVisitsTaskTest method test_shouldKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHours.

@Test
public void test_shouldKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHours() 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 encounterdmit to hospital
    Encounter edTriage = new Encounter();
    edTriage.setPatient(patient);
    edTriage.setEncounterType(encounterService.getEncounterTypeByUuid(ED_TRIAGE_ENCOUNTER_TYPE_UUID));
    edTriage.setEncounterDatetime(visit.getStartDatetime());
    encounterService.saveEncounter(edTriage);
    // create a 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);
    visit.addEncounter(edTriage);
    visit.addEncounter(consult);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().run();
    activeVisit = adtService.getActiveVisit(patient, location);
    assertNotNull(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)

Aggregations

VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)47 Location (org.openmrs.Location)31 Test (org.junit.Test)28 Visit (org.openmrs.Visit)20 Date (java.util.Date)19 Patient (org.openmrs.Patient)17 SimpleObject (org.openmrs.ui.framework.SimpleObject)17 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)16 Encounter (org.openmrs.Encounter)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)8 DateTime (org.joda.time.DateTime)6 ArrayList (java.util.ArrayList)5 Obs (org.openmrs.Obs)4 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)4 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)4 Redirect (org.openmrs.ui.framework.page.Redirect)4 Extension (org.openmrs.module.appframework.domain.Extension)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2