Search in sources :

Example 41 with VisitDomainWrapper

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

the class VisitIncludesFragmentController method controller.

public void controller(FragmentConfiguration config, FragmentModel model, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext, HttpServletRequest request, @SpringBean("patientService") PatientService patientService) {
    Object patient = config.get("patient");
    if (patient == null) {
        // retrieve patient id from parameter map
        if (request.getParameter("patientId") != null) {
            String patientId = request.getParameter("patientId");
            if (patientId != null) {
                if (!NumberUtils.isDigits(patientId)) {
                    patient = patientService.getPatientByUuid(patientId);
                } else {
                    patient = patientService.getPatient(NumberUtils.toInt(patientId));
                }
            }
        }
    }
    if (patient instanceof Patient) {
        wrapper.setPatient((Patient) patient);
    } else if (patient instanceof PatientDomainWrapper) {
        wrapper = (PatientDomainWrapper) patient;
    } else {
        throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
    }
    model.addAttribute("patient", wrapper);
    List<VisitType> visitTypes = visitTypeHelper.getUnRetiredVisitTypes();
    // send active visits to the view, if any.
    List<Visit> activeVisits = visitService.getActiveVisitsByPatient(wrapper.getPatient());
    // get visit attributes
    List<VisitAttributeType> visitAttributeTypes = visitService.getAllVisitAttributeTypes();
    // get the current visit's visit type, if any active visit at the current visit location
    VisitDomainWrapper activeVisitWrapper = adtService.getActiveVisit(wrapper.getPatient(), sessionContext.getSessionLocation());
    if (activeVisitWrapper != null) {
        VisitType currentVisitType = activeVisitWrapper.getVisit().getVisitType();
        model.addAttribute("currentVisitType", currentVisitType);
    } else {
        model.addAttribute("currentVisitType", null);
    }
    model.addAttribute("activeVisits", activeVisits);
    model.addAttribute("visitTypes", visitTypes);
    model.addAttribute("visitAttributeTypes", visitAttributeTypes);
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitType(org.openmrs.VisitType) VisitAttributeType(org.openmrs.VisitAttributeType) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper)

Example 42 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfDoesNotEncounterWithinExpirationRange.

@Test
public void test_shouldCloseVisitIfDoesNotEncounterWithinExpirationRange() 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 o 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.setStartDatetime(DateUtils.addHours(new Date(), -14));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create an encounter within the expiration range
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    encounter.setEncounterType(encounterService.getEncounterType(1));
    // expire hours + 1
    encounter.setEncounterDatetime(DateUtils.addHours(new Date(), -(emrApiProperties.getVisitExpireHours() + 1)));
    encounterService.saveEncounter(encounter);
    visit.addEncounter(encounter);
    visitService.saveVisit(visit);
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    // sanity check
    assertNotNull(activeVisit);
    new PihCloseStaleVisitsTask().execute();
    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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 43 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasCheckinAtEmergencyLocationButNoEncounterWithinFortyEightHours.

@Test
public void test_shouldNotKeepVisitOpenIfItHasCheckinAtEmergencyLocationButNoEncounterWithinFortyEightHours() 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 a check-in at Ijans Location
    Encounter checkIn = new Encounter();
    checkIn.setPatient(patient);
    checkIn.setEncounterType(emrApiProperties.getCheckInEncounterType());
    checkIn.setEncounterDatetime(visit.getStartDatetime());
    // we've added this to the test dataset
    checkIn.setLocation(locationService.getLocation("Ijans"));
    encounterService.saveEncounter(checkIn);
    // create another encounter, but not within 48 hours
    Encounter consult = new Encounter();
    consult.setPatient(patient);
    consult.setEncounterType(emrApiProperties.getVisitNoteEncounterType());
    consult.setEncounterDatetime(DateUtils.addHours(new Date(), -49));
    encounterService.saveEncounter(consult);
    visit.addEncounter(consult);
    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 44 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldKeepVisitOpenIfItHasCheckinAtEmergencyLocationAndEncounterWithinFortyEightHours.

@Test
public void test_shouldKeepVisitOpenIfItHasCheckinAtEmergencyLocationAndEncounterWithinFortyEightHours() 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 a check-in at Ijans Location
    Encounter checkIn = new Encounter();
    checkIn.setPatient(patient);
    checkIn.setEncounterType(emrApiProperties.getCheckInEncounterType());
    checkIn.setEncounterDatetime(visit.getStartDatetime());
    // we've added this to the test dataset
    checkIn.setLocation(locationService.getLocation("Ijans"));
    encounterService.saveEncounter(checkIn);
    // 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(checkIn);
    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)

Example 45 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldCloseVisitIfDoesNotHaveEncounterWithinExpirationRange.

@Test
public void test_shouldCloseVisitIfDoesNotHaveEncounterWithinExpirationRange() 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 o 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(), -14));
    visit.setPatient(patient);
    visit.setLocation(location);
    visit.setVisitType(emrApiProperties.getAtFacilityVisitType());
    // create an encounter earlier than the expire range
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    encounter.setEncounterType(encounterService.getEncounterType(1));
    // expire hours + 1
    encounter.setEncounterDatetime(DateUtils.addHours(new Date(), -(emrApiProperties.getVisitExpireHours() + 1)));
    encounterService.saveEncounter(encounter);
    visit.addEncounter(encounter);
    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)

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