Przejdź do głównej zawartości

Analytics Module

Na tej stronie

Analytics Module dostarcza dashboardy, wykresy i raporty dla zarządzania kliniką. Obejmuje statystyki wizyt, pacjentów, personelu i przychodów.


flowchart TB
subgraph UI
Dashboard[Analytics Dashboard]
KPI[KPI Summary]
Charts[Charts & Graphs]
Tables[Data Tables]
end
subgraph Hooks
useAnalyticsData --> Dashboard
useAnalyticsData --> Charts
end
subgraph API
analyticsService[analyticsService<br/>12 methods]
end
subgraph Backend
Commands[get_dashboard_stats<br/>get_visit_trends<br/>get_staff_performance<br/>...]
end
Dashboard --> Hooks
Hooks --> API
API --> Commands

TabDataUse Case
OverviewKPI summary, trendsDaily overview
VisitsType distribution, time slotsVisit patterns
PatientsDemographics, speciesPatient insights
PerformanceStaff metrics, heatmapTeam management

interface DashboardStats {
totalVisits: number;
totalPatients: number;
avgVisitDuration: number; // minutes
completionRate: number; // 0-100%
}
interface VisitTrend {
date: string; // ISO date
count: number;
}
// Periods: week | month | year
interface StaffPerformance {
staffId: string;
staffName: string;
totalVisits: number;
avgDuration: number;
completionRate: number;
}

┌─────────────────────────────┐
│ Visit Types (Pie Chart) │
├─────────────────────────────┤
│ │
│ Consultation 45% │
│ Vaccination 25% │
│ Surgery 15% │
│ Follow-up 10% │
│ Other 5% │
│ │
└─────────────────────────────┘
┌─────────────────────────────┐
│ Visits by Hour (Bar Chart) │
├─────────────────────────────┤
│ 8: ████ │
│ 9: ████████████ │
│ 10: ████████████████ │ ← Peak
│ 11: ██████████████ │
│ 12: ████████ │
│ ... │
└─────────────────────────────┘
Mon Tue Wed Thu Fri Sat
8:00 🟢 🟢 🟡 🟢 🟢 🟡
9:00 🟡 🟠 🟠 🟠 🟡 🟡
10:00 🔴 🔴 🔴 🔴 🟠 🟡 ← Peak
11:00 🟠 🟠 🟠 🟠 🟠 🟢
12:00 🟡 🟡 🟡 🟡 🟡 🟢

sequenceDiagram
participant UI as Analytics Dashboard
participant Hook as useAnalyticsData
participant Service as analyticsService
participant BE as Backend
UI->>Hook: useAnalyticsData({ dateRange, activeTab })
Hook->>Hook: Determine required data
alt Overview Tab
Hook->>Service: getOverviewBundle(scope)
Service->>BE: get_overview_bundle
else Visits Tab
Hook->>Service: getVisitTypeDistribution(scope)
Hook->>Service: getTimeSlotAnalysis(scope)
else Patients Tab
Hook->>Service: getPatientDemographics(scope)
else Performance Tab
Hook->>Service: getStaffPerformance(scope)
Hook->>Service: getDayHourHeatmap(scope)
end
BE-->>Service: Data
Service-->>Hook: Transformed data
Hook-->>UI: Ready for display

interface AnalyticsScope {
dateRange: {
start: Date;
end: Date;
};
clinicId?: string;
period?: 'week' | 'month' | 'year';
}

Wszystkie zapytania są cache’owane:

// Cache key pattern
analytics:<sessionId>:<endpoint>:<scopeKey>
// Example
analytics:abc123:visitTrends:clinic1:2024-01-01:2024-01-31:month

// Auto-generated insights
getPeakHourInsight(timeSlots)
// → "Najwięcej wizyt o 10:00 (avg. 15/dzień)"
getBestDayHourInsight(heatmap)
// → "Najlepszy dzień: Poniedziałek 9:00-11:00"

// Compare current vs previous period
const { current, previous } = await getVisitTrendsCompare(scope);
// Calculate change
const change = ((current - previous) / previous) * 100;
// → "+15% więcej wizyt niż poprzednio"

ComponentDescription
AnalyticsDashboardMain container
KpiSummaryTop metrics cards
VisitTrendsChartLine/bar chart
VisitTypesPieChartDistribution pie
TimeSlotBarChartHourly breakdown
DayHourHeatmapWeekly heatmap
PerformanceTableStaff rankings

// get_revenue_data
interface RevenueData {
month: string; // "2024-01"
revenue: number;
visitCount: number;
}
// 12-month rolling data
await analyticsService.getRevenueData(12);