mirror of
https://github.com/temetro/temetro.git
synced 2026-08-21 23:47:14 +00:00
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:
@@ -3,6 +3,7 @@
|
||||
import { type ReactNode, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { BarChart } from "@/components/analysis/bar-chart";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { type Analytics, getAnalytics } from "@/lib/analytics";
|
||||
|
||||
@@ -45,6 +46,27 @@ function Section({
|
||||
);
|
||||
}
|
||||
|
||||
// A full-width section that frames a single chart in a card.
|
||||
function ChartSection({
|
||||
title,
|
||||
description,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
description: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="flex flex-col gap-3">
|
||||
<div>
|
||||
<h2 className="font-semibold text-lg tracking-tight">{title}</h2>
|
||||
<p className="text-muted-foreground text-sm">{description}</p>
|
||||
</div>
|
||||
<Card className="p-5">{children}</Card>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function AnalysisView() {
|
||||
const { t } = useTranslation();
|
||||
const [data, setData] = useState<Analytics | null>(null);
|
||||
@@ -92,6 +114,16 @@ export function AnalysisView() {
|
||||
/>
|
||||
</Section>
|
||||
|
||||
<ChartSection
|
||||
description={t("analysis.charts.patientGrowthDescription")}
|
||||
title={t("analysis.charts.patientGrowthTitle")}
|
||||
>
|
||||
<BarChart
|
||||
data={data?.trends.patientsByMonth ?? []}
|
||||
emptyLabel={t("analysis.charts.empty")}
|
||||
/>
|
||||
</ChartSection>
|
||||
|
||||
<Section
|
||||
description={t("analysis.appointments.description")}
|
||||
title={t("analysis.appointments.title")}
|
||||
@@ -114,6 +146,16 @@ export function AnalysisView() {
|
||||
/>
|
||||
</Section>
|
||||
|
||||
<ChartSection
|
||||
description={t("analysis.charts.weeklyAppointmentsDescription")}
|
||||
title={t("analysis.charts.weeklyAppointmentsTitle")}
|
||||
>
|
||||
<BarChart
|
||||
data={data?.trends.appointmentsByWeekday ?? []}
|
||||
emptyLabel={t("analysis.charts.empty")}
|
||||
/>
|
||||
</ChartSection>
|
||||
|
||||
<Section
|
||||
description={t("analysis.prescriptions.description")}
|
||||
title={t("analysis.prescriptions.title")}
|
||||
|
||||
Reference in New Issue
Block a user