fixing claimsPage

This commit is contained in:
2025-05-23 18:37:24 +05:30
parent 3acea55c8e
commit be8c328d29
3 changed files with 140 additions and 35 deletions

View File

@@ -1,30 +1,67 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, ResponsiveContainer, Tooltip } from "recharts";
import {
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
ResponsiveContainer,
Tooltip,
} from "recharts";
interface AppointmentsByDayProps {
appointments: any[];
}
export function AppointmentsByDay({ appointments }: AppointmentsByDayProps) {
// Data processing for appointments by day
const daysOfWeek = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
// Initialize counts for each day
const countsByDay = daysOfWeek.map(day => ({ day, count: 0 }));
// Count appointments by day of week
appointments.forEach(appointment => {
const countsByDay = daysOfWeek.map((day) => ({ day, count: 0 }));
// Get current date and set time to start of day (midnight)
const now = new Date();
now.setHours(0, 0, 0, 0);
// Calculate Monday of the current week
const day = now.getDay(); // 0 = Sunday, 1 = Monday, ...
const diffToMonday = day === 0 ? -6 : 1 - day; // adjust if Sunday
const monday = new Date(now);
monday.setDate(now.getDate() + diffToMonday);
// Sunday of the current week
const sunday = new Date(monday);
sunday.setDate(monday.getDate() + 6);
// Filter appointments only from this week (Monday to Sunday)
const appointmentsThisWeek = appointments.filter((appointment) => {
if (!appointment.date) return false;
const date = new Date(appointment.date);
// Reset time to compare just the date
date.setHours(0, 0, 0, 0);
return date >= monday && date <= sunday;
});
// Count appointments by day for current week
appointmentsThisWeek.forEach((appointment) => {
const date = new Date(appointment.date);
const dayOfWeek = date.getDay(); // 0 = Sunday, 1 = Monday, ...
const dayIndex = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // Adjust to make Monday first
countsByDay[dayIndex].count += 1;
const dayIndex = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // Monday=0, Sunday=6
if (countsByDay[dayIndex]) {
countsByDay[dayIndex].count += 1;
}
});
return (
<Card className="shadow-sm">
<CardHeader className="pb-2">
<CardTitle className="text-base font-medium">Appointments by Day</CardTitle>
<p className="text-xs text-muted-foreground">Distribution of appointments throughout the week</p>
<CardTitle className="text-base font-medium">
Appointments by Day
</CardTitle>
<p className="text-xs text-muted-foreground">
Distribution of appointments throughout the week
</p>
</CardHeader>
<CardContent>
<div className="h-[200px]">
@@ -34,9 +71,14 @@ export function AppointmentsByDay({ appointments }: AppointmentsByDayProps) {
margin={{ top: 5, right: 5, left: 0, bottom: 5 }}
>
<CartesianGrid strokeDasharray="3 3" vertical={false} />
<XAxis dataKey="day" fontSize={12} tickLine={false} axisLine={false} />
<XAxis
dataKey="day"
fontSize={12}
tickLine={false}
axisLine={false}
/>
<YAxis fontSize={12} tickLine={false} axisLine={false} />
<Tooltip
<Tooltip
formatter={(value) => [`${value} appointments`, "Count"]}
labelFormatter={(value) => `${value}`}
/>
@@ -47,4 +89,4 @@ export function AppointmentsByDay({ appointments }: AppointmentsByDayProps) {
</CardContent>
</Card>
);
}
}

View File

@@ -16,7 +16,9 @@ export function NewPatients({ patients }: NewPatientsProps) {
patients.forEach(patient => {
const createdDate = new Date(patient.createdAt);
const monthIndex = createdDate.getMonth();
patientsByMonth[monthIndex].count += 1;
if (patientsByMonth[monthIndex]) {
patientsByMonth[monthIndex].count += 1;
}
});
// Add some sample data for visual effect if no patients
@@ -24,9 +26,10 @@ export function NewPatients({ patients }: NewPatientsProps) {
// Sample data pattern similar to the screenshot
const sampleData = [17, 12, 22, 16, 15, 17, 22, 28, 20, 16];
sampleData.forEach((value, index) => {
if (index < patientsByMonth.length) {
if (index < patientsByMonth.length ) {
if (patientsByMonth[index]) {
patientsByMonth[index].count = value;
}
}}
});
}