Search in sources :

Example 1 with VisitDomainWrapper

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

the class CheckinPageController method controller.

public Object controller(@RequestParam("patientId") Patient patient, @RequestParam(value = "closeVisit", required = false) Boolean closeVisit, UiUtils ui, UiSessionContext uiSessionContext, PageModel model, EmrApiProperties emrApiProperties, @SpringBean AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
    patientDomainWrapper.setPatient(patient);
    VisitDomainWrapper activeVisit = patientDomainWrapper.getActiveVisit(uiSessionContext.getSessionLocation());
    if (closeVisit != null && closeVisit && activeVisit != null) {
        adtService.closeAndSaveVisit(activeVisit.getVisit());
        activeVisit = null;
    }
    // if there is no active visit, redirect directly to the form
    if (activeVisit == null) {
        return new Redirect("/registrationapp/registrationSummary.page?patientId=" + patient.getId() + "&appId=registrationapp.registerPatient" + "&breadcrumbOverrideProvider=coreapps&breadcrumbOverridePage=findpatient%2FfindPatient&breadcrumbOverrideApp=mirebalais.liveCheckin&breadcrumbOverrideLabel=mirebalais.app.patientRegistration.checkin.label");
    } else // prompt the user to see if they want close the existing visit
    {
        List<Encounter> existingEncounters = new ArrayList<Encounter>();
        if (activeVisit != null) {
            for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
                if (!encounter.isVoided() && emrApiProperties.getCheckInEncounterType().equals(encounter.getEncounterType())) {
                    existingEncounters.add(encounter);
                }
            }
        }
        SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.escapeJs(ui.message("mirebalais.checkin.title")));
        SimpleObject patientPageBreadcrumb = SimpleObject.create("label", ui.escapeJs(patient.getFamilyName()) + ", " + ui.escapeJs(patient.getGivenName()), "link", ui.thisUrlWithContextPath());
        model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
        model.addAttribute("activeVisit", activeVisit);
        model.addAttribute("existingEncounters", existingEncounters);
        model.addAttribute("patient", patientDomainWrapper);
        model.addAttribute("appName", "mirebalais.liveCheckin");
        return null;
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Redirect(org.openmrs.ui.framework.page.Redirect)

Example 2 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldNotCloseVisitIfMostRecentDispositionKeepsVisitOpen.

@Test
public void test_shouldNotCloseVisitIfMostRecentDispositionKeepsVisitOpen() 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 with a disposition obs
    Encounter encounter = new Encounter();
    encounter.setPatient(patient);
    encounter.setEncounterType(encounterService.getEncounterType(1));
    encounter.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 + ":Admit to hospital"));
    dispositionObsGroup.addGroupMember(dispositionObs);
    encounter.addObs(dispositionObsGroup);
    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);
    assertNotNull(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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 3 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButAlsoDischargeEncounter.

@Test
public void test_shouldNotKeepVisitOpenIfItHasEDTriageAndEncounterWithinFortyEightHoursButAlsoDischargeEncounter() 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.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 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);
    // 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().execute();
    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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with VisitDomainWrapper

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

the class PihCloseStaleVisitsTaskTest method test_shouldNotCloseVisitIfHasEncounterWithinExpirationRange.

@Test
public void test_shouldNotCloseVisitIfHasEncounterWithinExpirationRange() 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);
    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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 5 with VisitDomainWrapper

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

the class PatientPageController method controller.

public Object controller(@RequestParam("patientId") Patient patient, PageModel model, @RequestParam(required = false, value = "app") AppDescriptor app, @RequestParam(required = false, value = "dashboard") String dashboard, @InjectBeans PatientDomainWrapper patientDomainWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("applicationEventService") ApplicationEventService applicationEventService, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, UiSessionContext sessionContext) {
    if (!Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_DASHBOARD)) {
        return new Redirect("coreapps", "noAccess", "");
    } else if (patient.isVoided() || patient.isPersonVoided()) {
        return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
    }
    if (StringUtils.isEmpty(dashboard)) {
        dashboard = "patientDashboard";
    }
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("app", app);
    Location visitLocation = null;
    try {
        visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
    } catch (IllegalArgumentException ex) {
    // location does not support visits
    }
    VisitDomainWrapper activeVisit = null;
    if (visitLocation != null) {
        activeVisit = adtService.getActiveVisit(patient, visitLocation);
    }
    model.addAttribute("activeVisit", activeVisit);
    AppContextModel contextModel = sessionContext.generateAppContextModel();
    contextModel.put("patient", new PatientContextModel(patient));
    contextModel.put("visit", activeVisit == null ? null : new VisitContextModel(activeVisit));
    model.addAttribute("appContextModel", contextModel);
    List<Extension> overallActions = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".overallActions", contextModel);
    Collections.sort(overallActions);
    model.addAttribute("overallActions", overallActions);
    List<Extension> visitActions;
    if (activeVisit == null) {
        visitActions = new ArrayList<Extension>();
    } else {
        visitActions = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".visitActions", contextModel);
        Collections.sort(visitActions);
    }
    model.addAttribute("visitActions", visitActions);
    List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".includeFragments", contextModel);
    Collections.sort(includeFragments);
    model.addAttribute("includeFragments", includeFragments);
    List<Extension> firstColumnFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".firstColumnFragments", contextModel);
    Collections.sort(firstColumnFragments);
    model.addAttribute("firstColumnFragments", firstColumnFragments);
    List<Extension> secondColumnFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".secondColumnFragments", contextModel);
    Collections.sort(secondColumnFragments);
    model.addAttribute("secondColumnFragments", secondColumnFragments);
    List<Extension> otherActions = appFrameworkService.getExtensionsForCurrentUser((dashboard == "patientDashboard" ? "clinicianFacingPatientDashboard" : dashboard) + ".otherActions", contextModel);
    Collections.sort(otherActions);
    model.addAttribute("otherActions", otherActions);
    // used for breadcrumbs to link back to the base dashboard in the case when this is used to render a context-specific dashboard
    model.addAttribute("baseDashboardUrl", coreAppsProperties.getDashboardUrl());
    model.addAttribute("dashboard", dashboard);
    applicationEventService.patientViewed(patient, sessionContext.getCurrentUser());
    return null;
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Redirect(org.openmrs.ui.framework.page.Redirect) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel)

Aggregations

VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)37 Location (org.openmrs.Location)23 Test (org.junit.Test)19 Date (java.util.Date)16 Visit (org.openmrs.Visit)16 Patient (org.openmrs.Patient)14 SimpleObject (org.openmrs.ui.framework.SimpleObject)13 Encounter (org.openmrs.Encounter)10 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)10 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ArrayList (java.util.ArrayList)5 DateTime (org.joda.time.DateTime)5 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)4 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)4 Redirect (org.openmrs.ui.framework.page.Redirect)4 Obs (org.openmrs.Obs)3 Extension (org.openmrs.module.appframework.domain.Extension)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2