Skip to main content

Overview

The Analytics Dashboard provides deep-dive business intelligence for clinic operations. It features interactive charts, KPI tracking, appointment analytics, service performance metrics, and doctor productivity monitoring.
This feature is restricted to administrators only. Attempting to access as non-admin automatically redirects to /dashboard.

Time Period Filtering

All analytics can be filtered by time period using the dropdown selector:
Last 7 days of data - ideal for weekly performance reviews
API Parameter: ?period=30 (7, 30, or 90)

Key Performance Indicators

The KPI strip displays six critical metrics with color-coded cards:

🏥 Pacientes Activos

Teal Card
Total active patients in the system

💵 Cobrado este mes

Green Card
Total revenue collected current month (DOP)

📋 Facturado este mes

Blue Card
Total amount billed/invoiced current month (DOP)

🎫 Ticket Promedio

Amber Card
Average transaction value per appointment (DOP)

📅 Pendientes Hoy

Slate Card
Appointments scheduled for today

❌ Canceladas Hoy

Rose Card
Cancelled appointments today
Data Source: kpis object from sp_get_analytics_dashboard procedure
interface KPIs {
  active_patients: number;
  revenue_month: number;
  billed_month: number;
  avg_ticket: number;
  pending_today: number;
  cancelled_today: number;
}

Revenue Analysis

Monthly Revenue Chart

Interactive SVG bar chart showing 6-month revenue trends: Features:
  • Gradient-filled bars (#0d9488#14b8a6)
  • Grid lines at 25%, 50%, 75%, and 100% of max
  • Axis labels in Spanish (month abbreviations)
  • Currency formatting on Y-axis
  • Hover interactions
Calculation:
function barChartPath(rows) {
  const maxY = Math.max(...rows.map(r => Number(r.total)), 1);
  const W = 520, H = 140;
  const barW = Math.min(40, W / rows.length - 6);
  
  return rows.map((r, i) => {
    const h = (Number(r.total) / maxY) * H;
    const x = (W / rows.length) * i + (W / rows.length - barW) / 2;
    return { ...r, h, x, y: H - h, barW };
  });
}
Data Structure:
[
  { "month": "2026-03", "total": 125000.00, "label": "Mar" }
]

Appointment Analytics

Status Distribution Donut Chart

SVG donut chart displaying appointment status breakdown: Status Categories:
Color: Teal (#0d9488)
Initial scheduled state
Color: Blue (#3b82f6)
Patient confirmed attendance
Color: Amber (#f59e0b)
Patient checked in and waiting
Color: Green (#22c55e)
Appointment finished
Color: Red (#ef4444)
Appointment cancelled
SVG Rendering:
const donutSegments = data.apptStatus.map((s, i) => {
  const pct = totalAppts > 0 ? Number(s.total) / totalAppts : 0;
  const circumference = 2 * Math.PI * 54; // radius = 54
  const dash = pct * circumference;
  return {
    color: colors[i],
    dash,
    gap: circumference - dash,
    offset: currentOffset * circumference
  };
});
Legend: Side legend with dots, labels, and counts.

Daily Appointments Sparkline

Area + line chart showing last 14 days of appointment volume: Visualization:
  • Teal line with gradient area fill
  • Circular data point markers
  • Daily labels (every other day for clarity)
  • Value labels above each point
Use Case: Identify daily appointment patterns and capacity utilization.

Patient Growth

New Patients by Month

Bar chart tracking patient registration trends: Features:
  • Blue gradient bars (#2563eb#3b82f6)
  • Value labels displayed above bars
  • Monthly breakdown
  • Zero values displayed as empty bars
Business Value: Monitor patient acquisition and growth rate.

Service Performance

Top Services Rankings

Ranked list of most frequently performed services: Display Format:
#1 [Service Name] ████████████████ 45 veces  RD$85,000
#2 [Service Name] ███████████      32 veces  RD$64,000
#3 [Service Name] ████████         28 veces  RD$42,000
Metrics Shown:
  • Rank: Position (1-6)
  • Service Name: Treatment/procedure name (truncated)
  • Frequency Bar: Relative performance (scaled to #1)
  • Count: Number of times performed
  • Revenue: Total income generated (DOP)
Color Palette:
const colors = [
  '#0d9488', // Teal
  '#2563eb', // Blue
  '#7c3aed', // Purple
  '#db2777', // Pink
  '#d97706', // Amber
  '#059669'  // Green
];
Data Source: topServices from analytics API

Doctor Productivity

Completion Rate Tracking

Monitor doctor performance with appointment completion metrics: Display Components:

Doctor Avatar

Circular badge with initials (e.g., “JD” for Juan Díaz)

Progress Bar

Visual completion rate with teal gradient fill
Metrics Per Doctor:
  • Doctor Name: Full name
  • Completed: Number of finished appointments
  • Total: Total scheduled appointments
  • Rate: Percentage (completed / total * 100)
Calculation:
const rate = total_appts > 0 
  ? Math.round((completed / total_appts) * 100) 
  : 0;
Data Structure:
[
  {
    "doctor_name": "Dr. Juan Díaz",
    "completed": 28,
    "total_appts": 32,
    "rate": 88
  }
]
Use Case: Identify high-performing doctors and those needing support.

API Integration

Analytics Endpoint

GET /api/analytics?period=30&branchId=all
Query Parameters:
ParameterTypeDefaultDescription
periodnumber30Time range in days (7, 30, 90)
branchIdstring”all”Branch ID or “all” for system-wide
Response Structure:
{
  "revenue": Array<{month: string, total: number, label: string}>,
  "apptStatus": Array<{status: string, total: number}>,
  "newPatients": Array<{month: string, total: number, label: string}>,
  "topServices": Array<{name: string, count: number, revenue: number}>,
  "dailyAppts": Array<{day: string, total: number}>,
  "doctorProductivity": Array<DoctorStats>,
  "kpis": KPIObject
}
Source: /src/routes/api/analytics/+server.js
Procedure: sp_get_analytics_dashboard(period, branchId)
Result Sets (7 total):
  1. Revenue by month (6 months)
  2. Appointment status distribution
  3. New patients by month
  4. Top services by frequency and revenue
  5. Daily appointment counts (14 days)
  6. Doctor productivity metrics
  7. KPI summary object

Visual Design

SVG Chart Configuration

Revenue Chart:
  • ViewBox: 0 0 520 170
  • Bar height: 140px (scaled)
  • Grid lines at 25% intervals
Donut Chart:
  • Center: (80, 80)
  • Radius: 54px
  • Stroke width: 24px
  • Rotation: -90° (start at top)
Sparkline:
  • ViewBox: 0 0 520 160
  • Data range: 0-130px (vertical)
  • Point radius: 4px

Responsive Behavior

  • KPI grid: 3 columns
  • Chart rows: 2 columns side-by-side

Loading States

Skeleton Placeholders:
  • 4 animated shimmer cards
  • Gradient animation: left to right
  • Colors: #f1f5f9#e2e8f0
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

Usage Examples

Example 1: Weekly Performance Review

1

Set Period

Select “Últimos 7 días” from dropdown
2

Review KPIs

Check pending and cancelled appointments for today
3

Analyze Trends

Review daily appointment sparkline for patterns
4

Check Productivity

Review doctor completion rates

Example 2: Monthly Revenue Analysis

1

Set Period

Select “Últimos 30 días”
2

Compare Revenue

Check “Cobrado” vs “Facturado” KPIs
3

Review Bar Chart

Analyze 6-month revenue trend
4

Identify Top Services

Check which treatments generate most revenue

Example 3: Service Strategy Planning

1

Set Period

Select “Últimos 90 días” for quarterly view
2

Review Top Services

Identify most profitable treatments
3

Check Frequency

Compare service counts to revenue
4

Strategic Decisions

Focus marketing on high-revenue, high-frequency services

Financial Reports

Detailed revenue reports and debt tracking

Admin Dashboard

Real-time operational overview

Build docs developers (and LLMs) love