Search in sources :

Example 6 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-coreapps by openmrs.

the class PatientDashboardPageController method controller.

public Object controller(@RequestParam("patientId") Patient patient, @RequestParam(value = "visitId", required = false) Visit visit, @RequestParam(value = "tab", defaultValue = "visits") String selectedTab, PageModel model, @InjectBeans PatientDomainWrapper patientDomainWrapper, @SpringBean("orderService") OrderService orderService, @SpringBean("adtService") AdtService adtService, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @SpringBean("applicationEventService") ApplicationEventService applicationEventService, UiSessionContext sessionContext) {
    if (!Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_VISITS)) {
        return new Redirect("coreapps", "noAccess", "");
    } else if (patient.isVoided() || patient.isPersonVoided()) {
        return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
    }
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("selectedTab", selectedTab);
    model.addAttribute("selectedVisit", visit);
    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);
    List<Extension> encounterTemplateExtensions = appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION);
    model.addAttribute("encounterTemplateExtensions", encounterTemplateExtensions);
    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("patientDashboard.overallActions", contextModel);
    Collections.sort(overallActions);
    model.addAttribute("overallActions", overallActions);
    List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.includeFragments");
    Collections.sort(includeFragments);
    model.addAttribute("includeFragments", includeFragments);
    List<Extension> visitActions = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.visitActions");
    Collections.sort(visitActions);
    model.addAttribute("visitActions", visitActions);
    model.addAttribute("patientTabs", appFrameworkService.getExtensionsForCurrentUser("patientDashboard.tabs"));
    model.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
    model.addAttribute("encounterCount", coreAppsProperties.getPatientDashboardEncounterCount());
    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)

Example 7 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-coreapps by openmrs.

the class VisitsSectionFragmentController method controller.

public void controller(FragmentConfiguration config, PageModel pageModel, FragmentModel model, UiUtils ui, UiSessionContext sessionContext, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper) {
    config.require("patient");
    Object patient = config.get("patient");
    if (patient instanceof Patient) {
        patientWrapper.setPatient((Patient) patient);
        config.addAttribute("patient", patientWrapper);
    } else if (patient instanceof PatientDomainWrapper) {
        patientWrapper = (PatientDomainWrapper) patient;
    }
    AppContextModel contextModel = sessionContext.generateAppContextModel();
    contextModel.put("patient", new PatientContextModel(patientWrapper.getPatient()));
    // backwards-compatible for links that still specify patient uuid substitution with "{{patientId}}"
    contextModel.put("patientId", patientWrapper.getPatient().getUuid());
    AppDescriptor app = (AppDescriptor) pageModel.get("app");
    String visitsPageWithSpecificVisitUrl = null;
    String visitsPageUrl = null;
    // see if the app specifies urls to use
    if (app != null) {
        try {
            visitsPageWithSpecificVisitUrl = app.getConfig().get("visitUrl").getTextValue();
        } catch (Exception ex) {
        }
        try {
            visitsPageUrl = app.getConfig().get("visitsUrl").getTextValue();
        } catch (Exception ex) {
        }
    }
    if (visitsPageWithSpecificVisitUrl == null) {
        visitsPageWithSpecificVisitUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
    }
    visitsPageWithSpecificVisitUrl = "/" + ui.contextPath() + "/" + visitsPageWithSpecificVisitUrl;
    if (visitsPageUrl == null) {
        visitsPageUrl = coreAppsProperties.getVisitsPageUrl();
    }
    // hack fix for RA-1002--if there is an active visit, and we are using the "regular" visit dashboard we actually want to link to the specific visit
    Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patientWrapper.getPatient(), visitLocation);
    if (visitsPageUrl.contains("/coreapps/patientdashboard/patientDashboard.page?") && activeVisit != null) {
        visitsPageUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
        contextModel.put("visit", activeVisit.getVisit());
    }
    visitsPageUrl = "/" + ui.contextPath() + "/" + visitsPageUrl;
    model.addAttribute("visitsUrl", templateFactory.handlebars(visitsPageUrl, contextModel));
    List<VisitDomainWrapper> recentVisits = patientWrapper.getAllVisitsUsingWrappers();
    if (recentVisits.size() > 5) {
        recentVisits = recentVisits.subList(0, 5);
    }
    Map<VisitDomainWrapper, String> recentVisitsWithLinks = new LinkedHashMap<VisitDomainWrapper, String>();
    for (VisitDomainWrapper recentVisit : recentVisits) {
        contextModel.put("visit", new VisitContextModel(recentVisit));
        // since the "recentVisit" isn't part of the context module, we bind it first to the visit url, before doing the handlebars binding against the context
        recentVisitsWithLinks.put(recentVisit, templateFactory.handlebars(ui.urlBind(visitsPageWithSpecificVisitUrl, recentVisit.getVisit()), contextModel));
    }
    Map<Integer, Map<String, Object>> recentVisitsWithAttr = visitTypeHelper.getVisitColorAndShortName(recentVisits);
    model.addAttribute("recentVisitsWithAttr", recentVisitsWithAttr);
    model.addAttribute("recentVisitsWithLinks", recentVisitsWithLinks);
    config.addAttribute("showVisitTypeOnPatientHeaderSection", visitTypeHelper.showVisitTypeOnPatientHeaderSection());
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Patient(org.openmrs.Patient) LinkedHashMap(java.util.LinkedHashMap) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) AppDescriptor(org.openmrs.module.appframework.domain.AppDescriptor) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Location(org.openmrs.Location)

Example 8 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentController method getVisitDetails.

public SimpleObject getVisitDetails(@SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @InjectBeans CoreAppsProperties coreAppsProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("encounterService") EncounterService encounterService, @RequestParam("visitId") Visit visit, @RequestParam(value = "fromEncounter", required = false) Integer encounterIndex, @RequestParam(value = "encounterCount", required = false) Integer encounterCount, UiUtils uiUtils, UiSessionContext sessionContext) throws ParseException {
    if (encounterIndex == null)
        encounterIndex = 0;
    if (encounterCount == null) {
        encounterCount = coreAppsProperties.getPatientDashboardEncounterCount();
    }
    ParseEncounterToJson parseEncounterToJson = new ParseEncounterToJson(appFrameworkService, uiUtils, encounterService);
    SimpleObject simpleObject = SimpleObject.fromObject(visit, uiUtils, "id", "uuid", "location");
    User authenticatedUser = sessionContext.getCurrentUser();
    boolean canDeleteVisit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_VISIT);
    Date startDatetime = visit.getStartDatetime();
    Date stopDatetime = visit.getStopDatetime();
    simpleObject.put("startDatetime", uiUtils.format(startDatetime));
    if (stopDatetime != null) {
        simpleObject.put("stopDatetime", uiUtils.format(stopDatetime));
    } else {
        simpleObject.put("stopDatetime", null);
    }
    VisitDomainWrapper visitWrapper = new VisitDomainWrapper(visit, emrApiProperties);
    List<SimpleObject> encounters = getEncounterListAsJson(parseEncounterToJson, visitWrapper, authenticatedUser, encounterIndex, encounterCount);
    simpleObject.put("encounters", encounters);
    simpleObject.put("admitted", visitWrapper.isAdmitted());
    simpleObject.put("canDeleteVisit", verifyIfUserHasPermissionToDeleteVisit(visit, authenticatedUser, canDeleteVisit));
    AppContextModel contextModel = sessionContext.generateAppContextModel();
    contextModel.put("patient", new PatientContextModel(visit.getPatient()));
    contextModel.put("visit", new VisitContextModel(new VisitDomainWrapper(visit, emrApiProperties)));
    List<Extension> visitActions = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.visitActions", contextModel);
    Collections.sort(visitActions);
    simpleObject.put("availableVisitActions", convertVisitActionsToSimpleObject(visitActions));
    return simpleObject;
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) ParseEncounterToJson(org.openmrs.module.coreapps.parser.ParseEncounterToJson) User(org.openmrs.User) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel)

Example 9 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfVisitNotWithinPastThirtyDays.

@Test
public void shouldReturnFalseIfVisitNotWithinPastThirtyDays() {
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(patientVisitWithinPastThirtyDays(config)), appContextModel), is(false));
}
Also used : AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) DateTime(org.joda.time.DateTime) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with VisitContextModel

use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege.

@Test
public void shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege() {
    user.addRole(admin);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.CONSULT_NOTE_LOCATION), or(and(userHasPrivilege(Privileges.TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY), patientVisitWithinPastThirtyDays(config))))), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AppContextModel (org.openmrs.module.appframework.context.AppContextModel)20 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)20 Test (org.junit.Test)16 Config (org.openmrs.module.pihcore.config.Config)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Location (org.openmrs.Location)15 SimpleObject (org.openmrs.ui.framework.SimpleObject)13 DateTime (org.joda.time.DateTime)8 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)4 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)4 Date (java.util.Date)3 Extension (org.openmrs.module.appframework.domain.Extension)3 Redirect (org.openmrs.ui.framework.page.Redirect)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Patient (org.openmrs.Patient)1 User (org.openmrs.User)1 AppDescriptor (org.openmrs.module.appframework.domain.AppDescriptor)1 ParseEncounterToJson (org.openmrs.module.coreapps.parser.ParseEncounterToJson)1 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)1