Patient Update 2

This commit is contained in:
Sir Blob
2025-01-25 16:03:21 -05:00
parent 6815efd611
commit 55bd8e0a54

View File

@@ -7,15 +7,9 @@ import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { Card, CardHeader, CardContent } from '@/components/ui/card'; 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 AccountPage = () => {
const { user } = useUser(); const { user } = useUser();
const [userData, setUserData] = useState(null); const [userData, setUserData] = useState(null);
const [patients, setPatients] = useState([]);
useEffect(() => { useEffect(() => {
if (user) { if (user) {
@@ -28,20 +22,24 @@ const AccountPage = () => {
} }
}, [user]); }, [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 <div>Loading...</div>; if (!userData) return <div>Loading...</div>;
const [medications, setMedications] = useState(userData.medications || []);
const handleMedicationsChange = (index, field, value) => {
const newMedications = [...medications];
newMedications[index][field] = value;
setMedications(newMedications);
}
const handleAddMedication = () => {
setMedications([...medications, { name: '', dosage: '', frequency: '' }]);
}
const [diagnoses, setDiagnoses] = useState(userData.diagnoses || []);
const handleDiagnosesChange = (e) => {
setDiagnoses(e.target.value.split(','));
}
return ( return (
<div className="container mx-auto p-4"> <div className="container mx-auto p-4">
<Card> <Card>
@@ -61,36 +59,61 @@ const AccountPage = () => {
<Label>Role:</Label> <Label>Role:</Label>
<p>{userData.role}</p> <p>{userData.role}</p>
</div> </div>
<Button onClick={handleRoleChange} className="mb-4"> <div className="mb-4">
Change role to {userData.role === 'patient' ? 'caregiver' : 'patient'} <Label>Medications:</Label>
</Button> <br/>
{medications.map((medication, index) => (
{userData.role === 'caregiver' && ( <div key={index} className="mb-2 grid grid-cols-3 gap-2">
<div> <Input
<h2 className="text-xl font-bold mb-4">Patients</h2> type="text"
<ul className="mb-4"> placeholder="Name"
{patients.map(patient => ( value={medication.name}
<Collapsible key={patient.id}> onChange={(e) => handleMedicationsChange(index, 'name', e.target.value)}
<div className="flex items-center justify-between p-2 bg-gray-100 dark:bg-neutral-800 rounded-t-lg"> className="mb-2"
<div> />
<h2 className="text-lg font-semibold">{patient.name}</h2> <Input
<p className="text-sm text-gray-400">{patient.role}</p> type="text"
</div> placeholder="Dosage"
<CollapsibleTrigger asChild> value={medication.dosage}
<Button variant="ghost" size="sm"> onChange={(e) => handleMedicationsChange(index, 'dosage', e.target.value)}
<ChevronDown className="h-4 w-4" /> className="mb-2"
<span className="sr-only">Toggle</span> />
</Button> <Input
</CollapsibleTrigger> type="text"
</div> placeholder="Frequency"
<CollapsibleContent className="p-4 border border-t-0 rounded-b-lg"> value={medication.frequency}
<PersonForm person={patient} /> onChange={(e) => handleMedicationsChange(index, 'frequency', e.target.value)}
</CollapsibleContent> className="mb-2"
</Collapsible> />
))} </div>
</ul> ))}
<div className="mb-2 grid grid-cols-4 gap-2">
<Input
type="text"
placeholder="Name"
className="mb-2"
/>
<Input
type="text"
placeholder="Dosage"
className="mb-2"
/>
<Input
type="text"
placeholder="Frequency"
className="mb-2"
/>
<Button onClick={handleAddMedication}>Add Medication</Button>
</div> </div>
)} </div>
<div className="mb-4">
<Label>Diagnoses:</Label>
<Input
type="text"
value={diagnoses.join(',')}
onChange={handleDiagnosesChange}
/>
</div>
</CardContent> </CardContent>
</Card> </Card>
</div> </div>