From 070d6c81fda4517fe519421e91163ff609f3afd7 Mon Sep 17 00:00:00 2001 From: Sir Blob <76974209+GamerBoss101@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:52:46 -0500 Subject: [PATCH] Doctor Patient Edit Form Update --- package.json | 1 + .../suite/doctor/account/PatientForm.tsx | 120 +++++++++ .../(panels)/suite/doctor/account/page.jsx | 235 ++++++------------ src/components/panel-ui/patient/app-chat.tsx | 4 +- src/components/ui/collapsible.tsx | 11 + 5 files changed, 216 insertions(+), 155 deletions(-) create mode 100644 src/app/(panels)/suite/doctor/account/PatientForm.tsx create mode 100644 src/components/ui/collapsible.tsx diff --git a/package.json b/package.json index 9089a28..47194a3 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@clerk/nextjs": "^6.10.2", + "@radix-ui/react-collapsible": "^1.1.2", "@radix-ui/react-dialog": "^1.1.5", "@radix-ui/react-dropdown-menu": "^2.1.5", "@radix-ui/react-label": "^2.1.1", diff --git a/src/app/(panels)/suite/doctor/account/PatientForm.tsx b/src/app/(panels)/suite/doctor/account/PatientForm.tsx new file mode 100644 index 0000000..3cb246c --- /dev/null +++ b/src/app/(panels)/suite/doctor/account/PatientForm.tsx @@ -0,0 +1,120 @@ +"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 }: any) { + + const [medications, setMedications] = useState(person.medications || []) + + async function onSubmit(event: React.FormEvent) { + event.preventDefault() + + } + + 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: any, 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/doctor/account/page.jsx b/src/app/(panels)/suite/doctor/account/page.jsx index f1d9fab..1107cab 100644 --- a/src/app/(panels)/suite/doctor/account/page.jsx +++ b/src/app/(panels)/suite/doctor/account/page.jsx @@ -2,170 +2,99 @@ import { useState, useEffect } from 'react'; import axios from 'axios'; import { useUser } from '@clerk/nextjs'; + import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Card, CardHeader, CardContent, CardFooter } from '@/components/ui/card'; +import { Card, CardHeader, CardContent } from '@/components/ui/card'; + +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" +import { ChevronDown, ChevronUp } from "lucide-react" + +import { PersonForm } from './PatientForm'; const AccountPage = () => { const { user } = useUser(); const [userData, setUserData] = useState(null); const [patients, setPatients] = useState([]); - const [selectedPatient, setSelectedPatient] = useState(null); - const [medications, setMedications] = useState([]); - const [diagnoses, setDiagnoses] = 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); - } - }; - - const handlePatientSelect = (patient) => { - setSelectedPatient(patient); - setMedications(patient.medications); - setDiagnoses(patient.medicalConditions); - }; - - const handleMedicationsChange = (index, field, value) => { - const updatedMedications = [...medications]; - updatedMedications[index][field] = value; - setMedications(updatedMedications); - }; - - const handleDiagnosesChange = (e) => { - setDiagnoses(e.target.value.split(',')); - }; - - const handleAddMedication = () => { - setMedications([...medications, { name: '', dosage: '', frequency: '' }]); - }; - - const handleSave = async () => { - try { - await axios.put(`/api/patients?email=${selectedPatient.email}`, { - medications, - medicalConditions: diagnoses, + 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)); + } }); - alert('Patient data updated successfully'); - } catch (error) { - console.error('Error updating patient data:', error); - alert('Failed to update patient 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 => ( -
  • handlePatientSelect(patient)} - className="cursor-pointer hover:bg-gray-200 p-2" - > - {patient.name} -
  • - ))} -
- - {selectedPatient && ( - - -

Edit Patient: {selectedPatient.name}

-
- -
- - {medications.map((medication, index) => ( -
- 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" - /> -
- ))} - -
-
- - -
-
- - - -
- )} -
- )} -
-
-
+
+ + +

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 +}; + +export default AccountPage; \ No newline at end of file diff --git a/src/components/panel-ui/patient/app-chat.tsx b/src/components/panel-ui/patient/app-chat.tsx index c6fa2cc..c8360b0 100644 --- a/src/components/panel-ui/patient/app-chat.tsx +++ b/src/components/panel-ui/patient/app-chat.tsx @@ -1,7 +1,7 @@ import Image from "next/image" -// @ts-ignore -export function Message({ avatarUrl, message, sender }) { + +export function Message({ avatarUrl, message, sender }: { avatarUrl: string, message: string, sender: string }) { return (