diff --git a/app/(pages)/admin/reports/page.tsx b/app/(pages)/admin/reports/page.tsx index 81b9a96..942f78c 100644 --- a/app/(pages)/admin/reports/page.tsx +++ b/app/(pages)/admin/reports/page.tsx @@ -1,360 +1,275 @@ "use client"; -// export default function Reports() { -// return ( -//
-// Extract Reports for specific hospital which will shows its total usre s, -// doctors , receps, etc -//
-// ); -// } - -import React, { useState } from "react"; +import React, { useState, ChangeEvent } from "react"; import { + Select, + SelectItem, Card, CardBody, CardHeader, - Divider, - Select, - SelectItem, - Button, Table, - TableHeader, - TableColumn, TableBody, - TableRow, TableCell, - Input, - Modal, - ModalContent, - ModalHeader, - ModalBody, - ModalFooter, + TableColumn, + TableHeader, + TableRow, } from "@nextui-org/react"; +import { ResponsivePie } from "@nivo/pie"; +import { ResponsiveLine } from "@nivo/line"; interface Hospital { id: number; name: string; totalUsers: number; doctors: number; - nurses: number; receptionists: number; + nurses: number; patients: number; - beds: number; - occupancyRate: number; } -const initialHospitals: Hospital[] = [ +const hospitals: Hospital[] = [ { id: 1, name: "Central Hospital", totalUsers: 500, doctors: 50, - nurses: 150, receptionists: 20, + nurses: 150, patients: 280, - beds: 300, - occupancyRate: 85, }, { id: 2, name: "City General Hospital", totalUsers: 750, doctors: 80, - nurses: 220, receptionists: 30, + nurses: 220, patients: 420, - beds: 450, - occupancyRate: 92, }, { id: 3, name: "Community Health Center", totalUsers: 300, doctors: 30, - nurses: 90, receptionists: 15, + nurses: 90, patients: 165, - beds: 180, - occupancyRate: 78, }, ]; const Reports: React.FC = () => { - const [hospitals, setHospitals] = useState(initialHospitals); const [selectedHospital, setSelectedHospital] = useState( null ); - const [compareHospital, setCompareHospital] = useState(null); - const [isAddHospitalOpen, setIsAddHospitalOpen] = useState(false); - const [newHospital, setNewHospital] = useState>({ - name: "", - totalUsers: 0, - doctors: 0, - nurses: 0, - receptionists: 0, - patients: 0, - beds: 0, - occupancyRate: 0, - }); - - const renderHospitalData = (hospital: Hospital) => ( -
- {Object.entries(hospital).map(([key, value]) => { - if (key !== "id" && key !== "name") { - return ( - - -

{key}

-

{value}

-
- - - -
- ); - } - return null; - })} -
- ); - const handleAddHospital = () => { - const id = Math.max(...hospitals.map((h) => h.id)) + 1; - setHospitals([...hospitals, { ...newHospital, id }]); - setIsAddHospitalOpen(false); - setNewHospital({ - name: "", - totalUsers: 0, - doctors: 0, - nurses: 0, - receptionists: 0, - patients: 0, - beds: 0, - occupancyRate: 0, - }); + const handleSelectionChange = (e: ChangeEvent): void => { + const hospitalId: number = parseInt(e.target.value, 10); + const hospital: Hospital | undefined = hospitals.find( + (h) => h.id === hospitalId + ); + setSelectedHospital(hospital || null); }; + const getPieChartData = (hospital: Hospital) => [ + { id: "doctors", label: "Doctors", value: hospital.doctors }, + { id: "nurses", label: "Nurses", value: hospital.nurses }, + { + id: "receptionists", + label: "Receptionists", + value: hospital.receptionists, + }, + { id: "patients", label: "Patients", value: hospital.patients }, + ]; + + const getLineChartData = () => [ + { + id: "doctors", + data: hospitals.map((h) => ({ x: h.name, y: h.doctors })), + }, + { + id: "nurses", + data: hospitals.map((h) => ({ x: h.name, y: h.nurses })), + }, + { + id: "receptionists", + data: hospitals.map((h) => ({ x: h.name, y: h.receptionists })), + }, + { + id: "patients", + data: hospitals.map((h) => ({ x: h.name, y: h.patients })), + }, + ]; + return ( -
-

Hospital Reports Dashboard

+
+

Hospital Reports Dashboard

-
- - -
+ {selectedHospital && ( <> -

+

{selectedHospital.name} Report

- {renderHospitalData(selectedHospital)} +
+ + Staff and Patient Distribution + + + + + + Hospital Statistics + + + + + + + + + + {Object.entries(selectedHospital).map(([key, value]) => { + if (key !== "id" && key !== "name") { + return ( + + + + + ); + } + return null; + })} + +
StatisticValue
+ {key.charAt(0).toUpperCase() + key.slice(1)} + {value}
+
+
+
)} -
-

Compare Hospitals

-
- - -
- - {selectedHospital && compareHospital && ( -
-
-

- {selectedHospital.name} -

- {renderHospitalData(selectedHospital)} -
-
-

{compareHospital.name}

- {renderHospitalData(compareHospital)} -
-
- )} -
- -
-

All Hospitals Overview

- - - Name - Total Users - Doctors - Nurses - Patients - Occupancy Rate - - - {hospitals.map((hospital) => ( - - {hospital.name} - {hospital.totalUsers} - {hospital.doctors} - {hospital.nurses} - {hospital.patients} - {hospital.occupancyRate}% - - ))} - -
-
+ axisTop={null} + axisRight={null} + axisBottom={{ + tickSize: 5, + tickPadding: 5, + tickRotation: 0, + legend: "Hospital", + legendOffset: 36, + legendPosition: "middle", + }} + axisLeft={{ + tickSize: 5, + tickPadding: 5, + tickRotation: 0, + legend: "Count", + legendOffset: -40, + legendPosition: "middle", + }} + pointSize={10} + pointColor={{ theme: "background" }} + pointBorderWidth={2} + pointBorderColor={{ from: "serieColor" }} + pointLabelYOffset={-12} + useMesh={true} + legends={[ + { + anchor: "bottom-right", + direction: "column", + justify: false, + translateX: 100, + translateY: 0, + itemsSpacing: 0, + itemDirection: "left-to-right", + itemWidth: 80, + itemHeight: 20, + itemOpacity: 0.75, + symbolSize: 12, + symbolShape: "circle", + symbolBorderColor: "rgba(0, 0, 0, .5)", + effects: [ + { + on: "hover", + style: { + itemBackground: "rgba(0, 0, 0, .03)", + itemOpacity: 1, + }, + }, + ], + }, + ]} + /> + + - - - - Add New Hospital - - - - setNewHospital({ ...newHospital, name: e.target.value }) - } - /> - - setNewHospital({ - ...newHospital, - totalUsers: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - doctors: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - nurses: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - receptionists: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - patients: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - beds: parseInt(e.target.value) || 0, - }) - } - /> - - setNewHospital({ - ...newHospital, - occupancyRate: parseFloat(e.target.value) || 0, - }) - } - /> - - - - - - - + + + NAME + TOTAL USERS + DOCTORS + RECEPTIONISTS + NURSES + PATIENTS + + + {hospitals.map((hospital: Hospital) => ( + + {hospital.name} + {hospital.totalUsers} + {hospital.doctors} + {hospital.receptionists} + {hospital.nurses} + {hospital.patients} + + ))} + +
); };