Skip to content

Latest commit

 

History

History
345 lines (272 loc) · 8.13 KB

File metadata and controls

345 lines (272 loc) · 8.13 KB

Appointment History Feature ✅

Overview

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.


Features

1. Complete Appointment History

  • View ALL appointments (not just recent 5)
  • Detailed table with all information
  • Sorted by date (most recent first)

2. Statistics Dashboard

Four summary cards showing:

  • Total Appointments - All appointments ever booked
  • Completed - Successfully completed visits
  • Upcoming - Future scheduled appointments
  • Cancelled - Cancelled or no-show appointments

3. Advanced Filters

Status Filter

  • All Statuses
  • Completed
  • Scheduled
  • Waiting
  • In Progress
  • Cancelled
  • No Show

Department Filter

  • All Departments
  • Filter by specific department (Cardiology, Orthopedics, etc.)

Time Period Filter

  • All Time - Complete history
  • Today - Today's appointments only
  • This Week - Current week
  • This Month - Current month
  • This Year - Current year

4. Detailed Table View

Columns displayed:

  1. Date & Time - Appointment date and time
  2. Appointment # - Unique appointment number
  3. Doctor - Doctor name and specialization
  4. Department - Department with icon
  5. Symptoms/Reason - Why patient visited
  6. Status - Color-coded status badge
  7. Actions - View details, Cancel (if applicable)

5. Color-Coded Status Badges

  • Completed - Green
  • 📅 Scheduled - Blue
  • Waiting - Yellow
  • 🔄 In Progress - Light blue
  • Cancelled - Red
  • 👤 No Show - Gray

6. Quick Actions

  • Book New - Quick link to book appointment
  • Back to Dashboard - Return to main dashboard
  • View Details - See full appointment details
  • Cancel - Cancel upcoming appointments

7. Responsive Design

  • Mobile-friendly table
  • Adapts to all screen sizes
  • Touch-friendly buttons

8. Empty State

  • Friendly message when no appointments found
  • Suggests booking first appointment
  • Adjusts message based on filters

How to Access

From Dashboard

  1. Login as patient
  2. Click "View History" button in quick actions
  3. Or click "View All History" in past appointments section

Direct URL

http://localhost:5000/patient/history

Navigation

  • Patient Dashboard → View History button
  • Patient Dashboard → Past Appointments → View All History link

Usage Examples

View All Appointments

  1. Go to /patient/history
  2. See complete list of all appointments

Filter by Status

  1. Select status from dropdown (e.g., "Completed")
  2. Click Apply or dropdown auto-submits
  3. See only completed appointments

Filter by Department

  1. Select department (e.g., "Cardiology")
  2. See only cardiology appointments

Filter by Time Period

  1. Select period (e.g., "This Month")
  2. See only this month's appointments

Combine Filters

  1. Select Status: "Completed"
  2. Select Department: "Cardiology"
  3. Select Period: "This Year"
  4. See completed cardiology appointments from this year

Reset Filters

Click "Reset" button to clear all filters


Technical Implementation

Files Created/Modified

  1. app/templates/patient/history.html - NEW

    • Complete history page template
    • Advanced filtering UI
    • Statistics dashboard
    • Responsive table design
  2. app/routes/patient_portal.py - MODIFIED

    • Added /history route
    • Filter logic implementation
    • Statistics calculation
    • Query optimization
  3. app/templates/patient/dashboard.html - MODIFIED

    • Added "View History" button
    • Added "View All History" link in past appointments
    • Updated styling for new buttons

Route Handler

@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 results

Filter Logic

Status 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

Statistics Calculation

# 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'])

UI Components

Statistics Cards

<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>

Filter Form

<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>

Appointments Table

<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>

Benefits

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


Testing

Run the test script:

python test_appointment_history.py

This will:

  • Show patient's appointment statistics
  • Display sample appointment history
  • List all features
  • Show how to access the page

Screenshots Description

Main History 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

Filtered View

  • Same layout
  • Shows only filtered results
  • Filter selections highlighted
  • Result count displayed

Empty State

  • Large icon
  • "No Appointments Found" message
  • "Book Your First Appointment" button
  • Friendly, encouraging design

Future Enhancements (Optional)

  • 📊 Export history to PDF
  • 📧 Email appointment history
  • 📈 Appointment analytics/charts
  • 🔍 Search by doctor name
  • 📅 Date range picker
  • 💾 Save filter preferences
  • 🔔 Reminder settings per appointment

Status: COMPLETE ✅

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