feat(analysis): add trend charts to the Analysis page

The Analysis page only showed KPI numbers. Add two real time-series and render
them as dependency-free bar charts (matching components/chat/sparkline.tsx):

- backend: GET /api/analytics now returns `trends.patientsByMonth` (new patients
  per month over the last 6 months) and `trends.appointmentsByWeekday`
  (appointments per day for the current week), bucketed in JS from one query each.
- frontend: new components/analysis/bar-chart.tsx and two chart sections on the
  Analysis view (Patient growth, Appointments this week), with i18n keys.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-06-08 19:20:15 +03:00
parent 6213da9477
commit 8ab0552cf8
6 changed files with 199 additions and 0 deletions
+9
View File
@@ -1,3 +1,6 @@
// A single bar/point in a time-series chart (e.g. one month or one weekday).
export type TrendPoint = { label: string; count: number };
// Server-computed clinic analytics returned by GET /api/analytics. All figures
// are aggregates over the active clinic's real data (no fabricated financials).
export type Analytics = {
@@ -20,4 +23,10 @@ export type Analytics = {
open: number;
done: number;
};
// Time-series for charts: new patients over the last 6 months, and
// appointments per day across the current week.
trends: {
patientsByMonth: TrendPoint[];
appointmentsByWeekday: TrendPoint[];
};
};