From 6815efd61143b7a9880d18ce4f17f0d93d36543f Mon Sep 17 00:00:00 2001 From: Sir Blob <76974209+GamerBoss101@users.noreply.github.com> Date: Sat, 25 Jan 2025 15:58:38 -0500 Subject: [PATCH] patient accounts page --- package.json | 2 +- .../suite/patient/account/PatientForm.tsx | 115 ++++++++++++++++++ .../(panels)/suite/patient/account/page.jsx | 100 +++++++++++++++ 3 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/app/(panels)/suite/patient/account/PatientForm.tsx create mode 100644 src/app/(panels)/suite/patient/account/page.jsx diff --git a/package.json b/package.json index 47194a3..e0b6340 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "https-localhost": "^4.7.1", "lucide-react": "^0.474.0", "mongoose": "^8.9.5", - "multer": "^1.4.5-lts.1", + "multer": "1.4.5-lts.1", "next": "15.1.6", "next-themes": "^0.4.4", "openai-whisper": "^1.0.2", diff --git a/src/app/(panels)/suite/patient/account/PatientForm.tsx b/src/app/(panels)/suite/patient/account/PatientForm.tsx new file mode 100644 index 0000000..04b0a7f --- /dev/null +++ b/src/app/(panels)/suite/patient/account/PatientForm.tsx @@ -0,0 +1,115 @@ +"use client" + +import { useState } from "react" +import axios from "axios" + +import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" + + +export function PersonForm({ person }: { person: { email: string, name: string, medications: any[], diagnoses: string[] } }) { + + const [medications, setMedications] = useState(person.medications || []) + + const [diagnoses, setDiagnoses] = useState(person.diagnoses || []) + + const handleDiagnosesChange = (event: React.ChangeEvent) => { + const value = event.target.value + setDiagnoses(value.split(',')) + } + + const handleAddMedication = () => { + setMedications([...medications, { name: '', dosage: '', frequency: '' }]) + } + + const handleMedicationsChange = (index: number, field: string, value: string) => { + const updatedMedications = [...medications] + updatedMedications[index][field] = value + setMedications(updatedMedications) + } + + const handleSave = async () => { + try { + await axios.put(`/api/patients?email=${person.email}`, { + medications, + medicalConditions: diagnoses, + }); + alert('Patient data updated successfully'); + } catch (error) { + console.error('Error updating patient data:', error); + alert('Failed to update patient data'); + } + }; + + + return ( + + +

Edit Patient: {person.name}

+
+ +
+ +
+ {medications.map((medication: { name: string, dosage: string, frequency:string }, index: number) => ( +
+ handleMedicationsChange(index, 'name', e.target.value)} + className="mb-2" + /> + handleMedicationsChange(index, 'dosage', e.target.value)} + className="mb-2" + /> + handleMedicationsChange(index, 'frequency', e.target.value)} + className="mb-2" + /> +
+ ))} +
+ + + + +
+
+
+ + +
+
+ + + +
+ ) +} + diff --git a/src/app/(panels)/suite/patient/account/page.jsx b/src/app/(panels)/suite/patient/account/page.jsx new file mode 100644 index 0000000..613633b --- /dev/null +++ b/src/app/(panels)/suite/patient/account/page.jsx @@ -0,0 +1,100 @@ +"use client" +import { useState, useEffect } from 'react'; +import axios from 'axios'; +import { useUser } from '@clerk/nextjs'; + +import { Button } from '@/components/ui/button'; +import { Label } from '@/components/ui/label'; +import { Card, CardHeader, CardContent } from '@/components/ui/card'; + +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" +import { ChevronDown } from "lucide-react" + +import { PersonForm } from './PatientForm'; + +const AccountPage = () => { + const { user } = useUser(); + const [userData, setUserData] = useState(null); + const [patients, setPatients] = useState([]); + + useEffect(() => { + if (user) { + axios.get(`/api/user?userId=${user.id}`).then(response => { + setUserData(response.data); + if (response.data.role === 'caregiver') { + axios.get('/api/patients').then(res => setPatients(res.data)); + } + }); + } + }, [user]); + + const handleRoleChange = async () => { + const newRole = userData.role === 'patient' ? 'caregiver' : 'patient'; + await axios.put(`/api/user?userId=${user.id}`, { role: newRole }); + setUserData({ ...userData, role: newRole }); + if (newRole === 'caregiver') { + axios.get('/api/patients').then(res => setPatients(res.data)); + } else { + setPatients([]); + setSelectedPatient(null); + } + }; + + if (!userData) return
Loading...
; + + return ( +
+ + +

Account Page

+
+ +
+ +

{userData.name}

+
+
+ +

{userData.email}

+
+
+ +

{userData.role}

+
+ + + {userData.role === 'caregiver' && ( +
+

Patients

+
    + {patients.map(patient => ( + +
    +
    +

    {patient.name}

    +

    {patient.role}

    +
    + + + +
    + + + +
    + ))} +
+
+ )} +
+
+
+ ); +}; + +export default AccountPage; \ No newline at end of file