diff --git a/client/app/doctor/patients/[patientId]/page.tsx b/client/app/doctor/patients/[patientId]/page.tsx
index bfa2dca4..497e5b8e 100644
--- a/client/app/doctor/patients/[patientId]/page.tsx
+++ b/client/app/doctor/patients/[patientId]/page.tsx
@@ -1,11 +1,108 @@
'use client'
-import { useParams } from "next/navigation"
-const Page = () => {
- const params = useParams()
+import { useGetMedicalHistory } from "@/lib/hooks/doctor/useDoctor"
+import { useParams, useRouter } from "next/navigation"
+import { useEffect, useState } from "react"
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
+import { Badge } from "@/components/ui/badge"
+import { CalendarIcon, ClockIcon, FileTextIcon, PillIcon } from "lucide-react"
+import { format } from "date-fns"
+import Pagination from "@/components/navigation/Pagination"
+
+export default function Page({ searchParams }: { searchParams: { page: number } }) {
+ const page = +searchParams.page || 1;
+ const [currentPage, setCurrentPage] = useState(page);
+ const params = useParams();
+ const router = useRouter()
+
+ const { data, refetch } = useGetMedicalHistory(params.patientId as string, page - 1, 10);
+
+ const handlePageChange = (pageIndex: number) => {
+ if (pageIndex > data?.totalPages! || pageIndex < 1) return null;
+ setCurrentPage(pageIndex);
+ router.push(`/doctor/patients/${params.patientId}/medical-history?page=${pageIndex}`);
+ refetch();
+ };
+
+ useEffect(() => {
+ setCurrentPage(page);
+ }, [page])
+
return (
-
PagePP {params.patientId}
+
+
Medical History
+ {data?.items.map((item, index) => (
+
+
+
+
+
+
+ {item.patient!.name?.charAt(0)}
+
+
+ {item.patient!.name}
+ {item.patient!.email}
+
+
+
+ {item.status}
+
+
+
+
+
+
+
+
+ {format(new Date(item.appointmentDate!), 'PPP')}
+
+
+
+ {item.appointmentType}
+
+
+
+
+
+ Reason: {item.reason}
+
+
+
+ Notes: {item.notes}
+
+
+
+ {item.prescription && (
+
+
Prescription
+
+ {item.prescription.medications?.map((med, medIndex) => (
+
+
+
+
{med.name}
+
- {med.dosage}, {med.frequency}, {med.duration}
+ {med.additionalInstructions!.length > 0 && (
+
{med.additionalInstructions}
+ )}
+
+
+ ))}
+
+
+ )}
+
+
+ ))}
+
+
)
-}
-
-export default Page
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/server/src/infrastructure/repositories/AppointmentRepository.ts b/server/src/infrastructure/repositories/AppointmentRepository.ts
index 16ad8e9a..fe6e2162 100644
--- a/server/src/infrastructure/repositories/AppointmentRepository.ts
+++ b/server/src/infrastructure/repositories/AppointmentRepository.ts
@@ -32,7 +32,10 @@ export default class AppointmentRepository implements IAppointmentRepository {
): Promise> {
const result = await this.model.aggregate([
{
- $match: { patientId: new ObjectId(patientId) }
+ $match: {
+ patientId: new ObjectId(patientId) ,
+ status: AppointmentStatus.COMPLETED
+ }
},
{
$lookup: {
@@ -50,12 +53,23 @@ export default class AppointmentRepository implements IAppointmentRepository {
as: "doctor"
}
},
+ {
+ $lookup: {
+ from: "prescriptions",
+ localField: "_id",
+ foreignField: "appointmentId",
+ as: "prescription"
+ }
+ },
{
$unwind: "$patient"
},
{
$unwind: "$doctor"
},
+ {
+ $unwind:"$prescription"
+ },
{
$project: {
"patient.password": 0,