Search in sources :

Example 1 with PatientContextModel

use of org.openmrs.module.coreapps.contextmodel.PatientContextModel 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)

Example 2 with PatientContextModel

use of org.openmrs.module.coreapps.contextmodel.PatientContextModel 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 3 with PatientContextModel

use of org.openmrs.module.coreapps.contextmodel.PatientContextModel 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 4 with PatientContextModel

use of org.openmrs.module.coreapps.contextmodel.PatientContextModel 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 5 with PatientContextModel

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

the class PatientHeaderFragmentController method controller.

public void controller(FragmentConfiguration config, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @SpringBean("baseIdentifierSourceService") IdentifierSourceService identifierSourceService, @FragmentParam(required = false, value = "appContextModel") AppContextModel appContextModel, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @FragmentParam("patient") Object patient, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, UiSessionContext sessionContext, UiUtils uiUtils, FragmentModel model) {
    if (patient instanceof Patient) {
        wrapper.setPatient((Patient) patient);
    } else {
        wrapper = (PatientDomainWrapper) patient;
    }
    config.addAttribute("patient", wrapper);
    config.addAttribute("patientNames", getNames(wrapper.getPersonName()));
    if (appContextModel == null) {
        AppContextModel contextModel = sessionContext.generateAppContextModel();
        contextModel.put("patient", new PatientContextModel(wrapper.getPatient()));
        model.addAttribute("appContextModel", contextModel);
    }
    List<Extension> firstLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.firstLineFragments");
    Collections.sort(firstLineFragments);
    model.addAttribute("firstLineFragments", firstLineFragments);
    List<Extension> secondLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.secondLineFragments");
    Collections.sort(secondLineFragments);
    model.addAttribute("secondLineFragments", secondLineFragments);
    List<ExtraPatientIdentifierType> extraPatientIdentifierTypes = new ArrayList<ExtraPatientIdentifierType>();
    for (PatientIdentifierType type : emrApiProperties.getExtraPatientIdentifierTypes()) {
        List<AutoGenerationOption> options = identifierSourceService.getAutoGenerationOptions(type);
        // TODO note that this may allow use to edit a identifier that should not be editable, or vice versa, in the rare case where there are multiple autogeneration
        // TODO options for a single identifier type (which is possible if you have multiple locations) and the manual entry boolean is different between those two generators
        extraPatientIdentifierTypes.add(new ExtraPatientIdentifierType(type, options.size() > 0 ? options.get(0).isManualEntryEnabled() : true));
    }
    config.addAttribute("extraPatientIdentifierTypes", extraPatientIdentifierTypes);
    config.addAttribute("extraPatientIdentifiersMappedByType", wrapper.getExtraIdentifiersMappedByType(sessionContext.getSessionLocation()));
    config.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) AutoGenerationOption(org.openmrs.module.idgen.AutoGenerationOption) PatientIdentifierType(org.openmrs.PatientIdentifierType)

Aggregations

AppContextModel (org.openmrs.module.appframework.context.AppContextModel)5 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)5 Extension (org.openmrs.module.appframework.domain.Extension)4 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)4 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)4 Location (org.openmrs.Location)3 Patient (org.openmrs.Patient)2 Redirect (org.openmrs.ui.framework.page.Redirect)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)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 AutoGenerationOption (org.openmrs.module.idgen.AutoGenerationOption)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1