6.2 KiB
Hospital Sidebar Display Feature
Overview
This document describes hospital display feature in PX360 sidebar, which shows the current hospital context and allows PX Admins to quickly switch between hospitals.
Features
1. Hospital Display in Sidebar
The sidebar now displays the current hospital at the bottom:
- Hospital icon (🏥)
- Hospital name (truncated if too long)
- City for context
- Dropdown for PX Admins to switch hospitals
- Read-only display for Hospital Admins and Department Managers
Position: At the bottom of the sidebar, after all navigation items.
2. PX Admin Quick Switch
For PX Admins, clicking on the hospital display opens a dropdown with:
- List of all hospitals in the system
- Current hospital highlighted with a checkmark
- Hospital name and city for each option
- "View All Hospitals" link to the full hospital selector page
3. Hospital Context Availability
The current hospital is available in all templates through the current_hospital context variable, provided by the hospital_context context processor.
Implementation Details
Files Modified
-
apps/core/context_processors.py- Added
hospital_context()function - Provides
current_hospitalandis_px_adminto all templates - Also updated
sidebar_counts()to include hospital context
- Added
-
config/settings/base.py- Added
apps.core.context_processors.hospital_contextto context_processors list
- Added
-
templates/layouts/partials/sidebar.html- Added hospital display component at the top of sidebar (after brand)
- Includes dropdown for PX Admins with all hospitals
- Forms for quick hospital switching
-
apps/core/templatetags/hospital_filters.py(new)- Created
get_all_hospitalstemplate tag - Returns all hospitals ordered by name, city
- Created
-
apps/core/templatetags/__init__.py(new)- Enables template tag module for core app
Context Variables
Available in all templates:
{
'current_hospital': Hospital, # Current hospital object or None
'is_px_admin': bool, # True if user is PX Admin
}
User Experience
For PX Admins
- Initial State: Shows current hospital with dropdown indicator
- Click Dropdown: Opens list of all hospitals
- Select Hospital:
- Submits form to select hospital
- Session is updated
- Page refreshes with new hospital data
- Hospital display updates to show new selection
- Alternative: Can click "View All Hospitals" to see full hospital selector page
For Hospital Admins
- Display: Shows their assigned hospital (read-only)
- No Dropdown: Cannot switch hospitals
- Clear Context: Always know which hospital data they're viewing
For Department Managers
- Display: Shows their hospital (read-only)
- No Dropdown: Cannot switch hospitals
- Consistent View: Hospital context is clear
Template Usage
Accessing Hospital in Templates
{% if current_hospital %}
<h2>{{ current_hospital.name }}</h2>
<p>{{ current_hospital.city }}</p>
{% endif %}
Checking User Role
{% if is_px_admin %}
<p>You are a PX Admin with access to all hospitals</p>
{% else %}
<p>You are viewing: {{ current_hospital.name }}</p>
{% endif %}
Using Hospital Filter
{% load hospital_filters %}
{% get_all_hospitals as hospitals %}
{% for hospital in hospitals %}
{{ hospital.name }}
{% endfor %}
Styling
The hospital display uses Bootstrap 5 classes with custom styling:
.btn-light {
min-width: 200px;
max-width: 300px;
}
.dropdown-item {
display: flex;
align-items: center;
}
Responsive Design
- Hospital display is visible on desktop (md and up)
- On mobile, it may need adjustment or can be hidden
- Dropdown has max-height with scrollbar for many hospitals
Future Enhancements
- Recent Hospitals: Show recently accessed hospitals first
- Hospital Search: Add search box within dropdown for many hospitals
- Hospital Avatar: Display hospital logo/image instead of icon
- Hospital Status: Show active/inactive status indicators
- Hospital Stats: Display quick stats (complaints, surveys, etc.)
- Mobile Optimization: Better mobile experience for hospital switching
Testing Checklist
- Hospital displays correctly for all user types
- PX Admin can see dropdown with all hospitals
- PX Admin can switch hospitals successfully
- Hospital Admin sees only their hospital (no dropdown)
- Department Manager sees their hospital (no dropdown)
- Hospital name truncates properly if too long
- Dropdown shows checkmark for current hospital
- "View All Hospitals" link works
- Session updates after hospital switch
- Page refreshes with correct hospital data
- Hospital context available in all templates
Troubleshooting
Hospital Not Displaying
Problem: Hospital display doesn't show in sidebar.
Solutions:
- Check that user is authenticated
- Verify
TenantMiddlewareis settingrequest.tenant_hospital - Ensure
hospital_contextis in settings context_processors - Check browser console for template errors
Dropdown Not Working
Problem: PX Admin sees hospital but dropdown doesn't open.
Solutions:
- Check Bootstrap 5 JavaScript is loaded
- Verify
data-bs-toggle="dropdown"attribute is present - Check for JavaScript errors in browser console
- Ensure jQuery is loaded (required for some Bootstrap features)
Hospitals Not Loading
Problem: Dropdown shows empty list or no hospitals.
Solutions:
- Check that
hospital_filtersis loaded in template - Verify Hospital model has records
- Check database connection
- Review server logs for errors
Related Documentation
Conclusion
The hospital sidebar display provides clear context awareness and convenient hospital switching for PX Admins, improving the overall user experience in the PX360 platform. The feature is production-ready and follows Django best practices for context processors, template tags, and responsive design.