Ali2206 commited on
Commit
3680b78
·
verified ·
1 Parent(s): e68f1ed

Update api/routes.py

Browse files
Files changed (1) hide show
  1. api/routes.py +19 -1
api/routes.py CHANGED
@@ -192,7 +192,25 @@ async def list_doctor_appointments(current_user: dict = Depends(get_current_user
192
  raise HTTPException(status_code=403, detail="Only doctors can view this")
193
 
194
  cursor = appointments_collection.find({"doctor_id": {"$exists": True}})
195
- return [{**a, "_id": str(a["_id"]), "patient_id": str(a["patient_id"]), "doctor_id": str(a["doctor_id"])} async for a in cursor]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  # --- LIST PATIENT'S APPOINTMENTS ---
198
  @router.get("/appointments/patient")
 
192
  raise HTTPException(status_code=403, detail="Only doctors can view this")
193
 
194
  cursor = appointments_collection.find({"doctor_id": {"$exists": True}})
195
+ appointments = []
196
+
197
+ async for a in cursor:
198
+ patient = await users_collection.find_one({"_id": a["patient_id"]})
199
+ patient_info = {
200
+ "full_name": patient.get("full_name", ""),
201
+ "email": patient.get("email", ""),
202
+ } if patient else {}
203
+
204
+ appointments.append({
205
+ "_id": str(a["_id"]),
206
+ "doctor_id": str(a["doctor_id"]),
207
+ "patient": patient_info,
208
+ "date": a["date"].strftime("%Y-%m-%d") if isinstance(a["date"], datetime) else a["date"],
209
+ "time": a["time"],
210
+ "reason": a["reason"]
211
+ })
212
+
213
+ return appointments
214
 
215
  # --- LIST PATIENT'S APPOINTMENTS ---
216
  @router.get("/appointments/patient")