Added a comprehensive appointment history page to the patient portal where patients can view all their past and upcoming appointments with advanced filtering and search capabilities.
- View ALL appointments (not just recent 5)
- Detailed table with all information
- Sorted by date (most recent first)
Four summary cards showing:
- Total Appointments - All appointments ever booked
- Completed - Successfully completed visits
- Upcoming - Future scheduled appointments
- Cancelled - Cancelled or no-show appointments
- All Statuses
- Completed
- Scheduled
- Waiting
- In Progress
- Cancelled
- No Show
- All Departments
- Filter by specific department (Cardiology, Orthopedics, etc.)
- All Time - Complete history
- Today - Today's appointments only
- This Week - Current week
- This Month - Current month
- This Year - Current year
Columns displayed:
- Date & Time - Appointment date and time
- Appointment # - Unique appointment number
- Doctor - Doctor name and specialization
- Department - Department with icon
- Symptoms/Reason - Why patient visited
- Status - Color-coded status badge
- Actions - View details, Cancel (if applicable)
- ✅ Completed - Green
- 📅 Scheduled - Blue
- ⏰ Waiting - Yellow
- 🔄 In Progress - Light blue
- ❌ Cancelled - Red
- 👤 No Show - Gray
- Book New - Quick link to book appointment
- Back to Dashboard - Return to main dashboard
- View Details - See full appointment details
- Cancel - Cancel upcoming appointments
- Mobile-friendly table
- Adapts to all screen sizes
- Touch-friendly buttons
- Friendly message when no appointments found
- Suggests booking first appointment
- Adjusts message based on filters
- Login as patient
- Click "View History" button in quick actions
- Or click "View All History" in past appointments section
http://localhost:5000/patient/history
- Patient Dashboard → View History button
- Patient Dashboard → Past Appointments → View All History link
- Go to
/patient/history - See complete list of all appointments
- Select status from dropdown (e.g., "Completed")
- Click Apply or dropdown auto-submits
- See only completed appointments
- Select department (e.g., "Cardiology")
- See only cardiology appointments
- Select period (e.g., "This Month")
- See only this month's appointments
- Select Status: "Completed"
- Select Department: "Cardiology"
- Select Period: "This Year"
- See completed cardiology appointments from this year
Click "Reset" button to clear all filters
-
app/templates/patient/history.html - NEW
- Complete history page template
- Advanced filtering UI
- Statistics dashboard
- Responsive table design
-
app/routes/patient_portal.py - MODIFIED
- Added
/historyroute - Filter logic implementation
- Statistics calculation
- Query optimization
- Added
-
app/templates/patient/dashboard.html - MODIFIED
- Added "View History" button
- Added "View All History" link in past appointments
- Updated styling for new buttons
@patient_portal_bp.route("/history")
@user_required
def history():
"""View complete appointment history with filters."""
# Get filter parameters
filter_status = request.args.get("status", "")
filter_department = request.args.get("department", "")
filter_period = request.args.get("period", "all")
# Apply filters to query
# Calculate statistics
# Return filtered resultsStatus Filter:
if filter_status:
query = query.filter_by(status=filter_status)Department Filter:
if filter_department:
query = query.filter_by(department_id=int(filter_department))Time Period Filter:
if filter_period == "today":
query = query.filter(Appointment.appointment_date == today)
elif filter_period == "week":
week_start = today - timedelta(days=today.weekday())
query = query.filter(Appointment.appointment_date >= week_start)
# ... etc# Total appointments
all_appointments = Appointment.query.filter_by(patient_id=patient.id).all()
# Completed count
completed_count = sum(1 for a in all_appointments if a.status == 'completed')
# Upcoming count
upcoming_count = sum(1 for a in all_appointments
if a.appointment_date >= today
and a.status in ['scheduled', 'confirmed', 'waiting'])
# Cancelled count
cancelled_count = sum(1 for a in all_appointments
if a.status in ['cancelled', 'no_show'])<div class="stats-summary">
<div class="stat-box stat-total">
<i class="fas fa-calendar-check"></i>
<div>
<h3>{{ all_appointments|length }}</h3>
<p>Total Appointments</p>
</div>
</div>
<!-- More stat boxes -->
</div><form method="GET" class="filters-form">
<select name="status" onchange="this.form.submit()">
<option value="">All Statuses</option>
<option value="completed">Completed</option>
<!-- More options -->
</select>
<!-- More filters -->
</form><table class="appointments-table">
<thead>
<tr>
<th>Date & Time</th>
<th>Appointment #</th>
<!-- More columns -->
</tr>
</thead>
<tbody>
{% for appt in filtered_appointments %}
<tr>
<td>{{ appt.appointment_date }}</td>
<!-- More cells -->
</tr>
{% endfor %}
</tbody>
</table>✅ Complete History - See all appointments, not just recent
✅ Advanced Filtering - Find specific appointments quickly
✅ Statistics - Understand appointment patterns
✅ Easy Navigation - Quick access from dashboard
✅ Responsive - Works on all devices
✅ User-Friendly - Intuitive interface
✅ Professional - Clean, modern design
✅ Actionable - View details, cancel appointments
Run the test script:
python test_appointment_history.pyThis will:
- Show patient's appointment statistics
- Display sample appointment history
- List all features
- Show how to access the page
- Header with patient name and quick actions
- 4 statistics cards (Total, Completed, Upcoming, Cancelled)
- Filter section with 3 dropdowns
- Table with all appointments
- Color-coded status badges
- Same layout
- Shows only filtered results
- Filter selections highlighted
- Result count displayed
- Large icon
- "No Appointments Found" message
- "Book Your First Appointment" button
- Friendly, encouraging design
- 📊 Export history to PDF
- 📧 Email appointment history
- 📈 Appointment analytics/charts
- 🔍 Search by doctor name
- 📅 Date range picker
- 💾 Save filter preferences
- 🔔 Reminder settings per appointment
The appointment history feature is fully implemented and ready to use!
Summary:
- ✅ Complete history page created
- ✅ Advanced filtering (status, department, period)
- ✅ Statistics dashboard
- ✅ Responsive table design
- ✅ Integration with patient dashboard
- ✅ Empty state handling
- ✅ Color-coded status badges
- ✅ Quick actions and navigation
Last Updated: February 27, 2026
Status: Production Ready