Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -15,6 +15,7 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/component
|
|||||||
import {PersonForm} from "./PatientForm";
|
import {PersonForm} from "./PatientForm";
|
||||||
import { Card } from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
|
|
||||||
|
import { faker } from "@faker-js/faker";
|
||||||
|
|
||||||
|
|
||||||
export default function PatientsDOC() {
|
export default function PatientsDOC() {
|
||||||
@@ -36,11 +37,37 @@ export default function PatientsDOC() {
|
|||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
if (userData) {
|
if (userData) {
|
||||||
if (userData.role && userData.role != "caregiver") {
|
if (userData && userData.role != "caregiver") {
|
||||||
router.push("/suite/patient/dashboard");
|
router.push("/suite/patient/dashboard");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateFakePatients(count) {
|
||||||
|
return Array.from({ length: count }, () => ({
|
||||||
|
id: faker.string.uuid(),
|
||||||
|
name: faker.person.fullName(),
|
||||||
|
age: faker.number.int({ min: 18, max: 100 }),
|
||||||
|
gender: faker.helpers.arrayElement(["male", "female", "other"]),
|
||||||
|
bloodType: faker.helpers.arrayElement(["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"]),
|
||||||
|
lastCheckup: faker.date.recent({ days: 90 }),
|
||||||
|
symptoms: faker.helpers.arrayElements(
|
||||||
|
["Fever", "Cough", "Fatigue", "Shortness of breath", "Headache", "Nausea", "Dizziness", "Chest pain"],
|
||||||
|
{ min: 0, max: 3 },
|
||||||
|
),
|
||||||
|
vitalSigns: {
|
||||||
|
temperature: faker.number.float({ min: 36.1, max: 37.5, precision: 0.1 }),
|
||||||
|
heartRate: faker.number.int({ min: 60, max: 100 }),
|
||||||
|
bloodPressure: `${faker.number.int({ min: 90, max: 140 })}/${faker.number.int({ min: 60, max: 90 })}`,
|
||||||
|
respiratoryRate: faker.number.int({ min: 12, max: 20 }),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
let fakePatients = generateFakePatients(20);
|
||||||
|
|
||||||
|
// add two arrays together
|
||||||
|
let finalPatients = patients.concat(fakePatients);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto">
|
<div className="container mx-auto">
|
||||||
<h1 className="text-3xl font-semibold mb-6">Patients</h1>
|
<h1 className="text-3xl font-semibold mb-6">Patients</h1>
|
||||||
@@ -50,12 +77,13 @@ export default function PatientsDOC() {
|
|||||||
{userData && userData.role === 'caregiver' && (
|
{userData && userData.role === 'caregiver' && (
|
||||||
<div>
|
<div>
|
||||||
<ul className="mb-4">
|
<ul className="mb-4">
|
||||||
{patients.map(patient => (
|
{finalPatients.map(patient => (
|
||||||
<Collapsible key={patient.id}>
|
<Collapsible key={patient.id}>
|
||||||
<div className="flex items-center justify-between p-2 bg-gray-100 dark:bg-neutral-800 rounded-t-lg">
|
<div className="flex items-center justify-between p-2 bg-gray-100 dark:bg-neutral-800 rounded-t-lg">
|
||||||
<div>
|
<div>
|
||||||
<h2 className="text-lg font-semibold">{patient.name}</h2>
|
<h2 className="text-lg font-semibold">{patient.name}</h2>
|
||||||
<p className="text-sm text-gray-400">{patient.role}</p>
|
<p className="text-sm text-gray-500 dark:text-neutral-400">Age: {patient.age}</p>
|
||||||
|
<p className="text-sm text-gray-500 dark:text-neutral-400">Last Checkup: {new Date(patient.lastCheckup).toLocaleDateString()}</p>
|
||||||
</div>
|
</div>
|
||||||
<CollapsibleTrigger asChild>
|
<CollapsibleTrigger asChild>
|
||||||
<Button variant="ghost" size="sm">
|
<Button variant="ghost" size="sm">
|
||||||
|
|||||||
@@ -12,95 +12,106 @@ import { useEffect, useState } from "react";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export default function Chat() {
|
export default function Chat() {
|
||||||
|
<<<<<<< HEAD
|
||||||
|
const router = useRouter();
|
||||||
|
const { user } = useUser();
|
||||||
|
const [userData, setUserData] = useState(null);
|
||||||
|
const [userQuery, setUserQuery] = useState("");
|
||||||
|
const [chatHistory, setChatHistory] = useState <
|
||||||
|
{ type: "user" | "bot", text: string }
|
||||||
|
> ([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
=======
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [userData, setUserData] = useState(null);
|
const [userData, setUserData] = useState(null);
|
||||||
const [userQuery, setUserQuery] = useState("");
|
const [userQuery, setUserQuery] = useState("");
|
||||||
const [chatHistory, setChatHistory] = useState([{type: 'bot', text: 'Hello! How can I help you today?'}]);
|
const [chatHistory, setChatHistory] = useState([{type: 'bot', text: 'Hello! How can I help you today?'}]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
>>>>>>> 741c8533456bcb3581f3ec92709b9a6d2ffb6572
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
axios
|
axios
|
||||||
.get(`/api/user?userId=${user.id}`)
|
.get(`/api/user?userId=${user.id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setUserData(response.data);
|
setUserData(response.data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching user data:", error);
|
console.error("Error fetching user data:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (userData && userData.role !== "patient") {
|
if (userData && userData.role !== "patient") {
|
||||||
router.push("/suite/doctor/dashboard");
|
router.push("/suite/doctor/dashboard");
|
||||||
}
|
}
|
||||||
}, [userData, router]);
|
}, [userData, router]);
|
||||||
|
|
||||||
const handleSend = async () => {
|
const handleSend = async () => {
|
||||||
if (!userQuery.trim()) return;
|
if (!userQuery.trim()) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post("/api/chat", { query: userQuery });
|
const response = await axios.post("/api/chat", { query: userQuery });
|
||||||
|
|
||||||
const botResponse = response.data?.answer || "No response from the bot.";
|
const botResponse = response.data?.answer || "No response from the bot.";
|
||||||
|
|
||||||
setChatHistory((prevHistory) => [
|
setChatHistory((prevHistory) => [
|
||||||
...prevHistory,
|
...prevHistory,
|
||||||
{ type: "user", text: userQuery },
|
{ type: "user", text: userQuery },
|
||||||
{ type: "bot", text: botResponse },
|
{ type: "bot", text: botResponse },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setUserQuery("");
|
setUserQuery("");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending message:", error);
|
console.error("Error sending message:", error);
|
||||||
setChatHistory((prevHistory) => [
|
setChatHistory((prevHistory) => [
|
||||||
...prevHistory,
|
...prevHistory,
|
||||||
{ type: "user", text: userQuery },
|
{ type: "user", text: userQuery },
|
||||||
{ type: "bot", text: "An error occurred while processing your request." },
|
{ type: "bot", text: "An error occurred while processing your request." },
|
||||||
]);
|
]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto">
|
<div className="container mx-auto">
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent className="space-y-4 p-4">
|
<CardContent className="space-y-4 p-4">
|
||||||
<div className="block items-center">
|
<div className="block items-center">
|
||||||
{chatHistory.map((msg, idx) => (
|
{chatHistory.map((msg, idx) => (
|
||||||
<Message
|
<Message
|
||||||
key={idx}
|
key={idx}
|
||||||
avatarUrl="/vercel.svg"
|
avatarUrl="/vercel.svg"
|
||||||
message={msg.text}
|
message={msg.text}
|
||||||
sender={msg.type === "user" ? "You" : "Bot"}
|
sender={msg.type === "user" ? "You" : "Bot"}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<Input
|
<Input
|
||||||
id="message"
|
id="message"
|
||||||
placeholder="Ask a medical question"
|
placeholder="Ask a medical question"
|
||||||
value={userQuery}
|
value={userQuery}
|
||||||
onChange={(e) => setUserQuery(e.target.value)}
|
onChange={(e) => setUserQuery(e.target.value)}
|
||||||
className="flex-grow mx-0 rounded-none"
|
className="flex-grow mx-0 rounded-none"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
className="mx-0 rounded-none"
|
className="mx-0 rounded-none"
|
||||||
onClick={handleSend}
|
onClick={handleSend}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
>
|
>
|
||||||
{loading ? "Loading..." : "Send"}
|
{loading ? "Loading..." : "Send"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user