Spaces:
Sleeping
Sleeping
Update api/routes.py
Browse files- api/routes.py +16 -10
api/routes.py
CHANGED
|
@@ -191,23 +191,29 @@ async def list_doctor_appointments(current_user: dict = Depends(get_current_user
|
|
| 191 |
if current_user.get("role") != "doctor":
|
| 192 |
raise HTTPException(status_code=403, detail="Only doctors can view this")
|
| 193 |
|
| 194 |
-
cursor = appointments_collection.find({"doctor_id":
|
| 195 |
appointments = []
|
| 196 |
|
| 197 |
async for a in cursor:
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
appointments.append({
|
| 205 |
"_id": str(a["_id"]),
|
| 206 |
"doctor_id": str(a["doctor_id"]),
|
| 207 |
-
"patient":
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
})
|
| 212 |
|
| 213 |
return appointments
|
|
|
|
| 191 |
if current_user.get("role") != "doctor":
|
| 192 |
raise HTTPException(status_code=403, detail="Only doctors can view this")
|
| 193 |
|
| 194 |
+
cursor = appointments_collection.find({"doctor_id": ObjectId(current_user["_id"])})
|
| 195 |
appointments = []
|
| 196 |
|
| 197 |
async for a in cursor:
|
| 198 |
+
try:
|
| 199 |
+
patient_id = a.get("patient_id")
|
| 200 |
+
if not isinstance(patient_id, ObjectId):
|
| 201 |
+
patient_id = ObjectId(patient_id)
|
| 202 |
+
|
| 203 |
+
patient = await users_collection.find_one({"_id": patient_id})
|
| 204 |
+
except Exception:
|
| 205 |
+
patient = None
|
| 206 |
|
| 207 |
appointments.append({
|
| 208 |
"_id": str(a["_id"]),
|
| 209 |
"doctor_id": str(a["doctor_id"]),
|
| 210 |
+
"patient": {
|
| 211 |
+
"full_name": patient.get("full_name", "Unknown") if patient else "Unknown",
|
| 212 |
+
"email": patient.get("email", "") if patient else "",
|
| 213 |
+
},
|
| 214 |
+
"date": a.get("date").strftime("%Y-%m-%d") if isinstance(a.get("date"), datetime) else a.get("date"),
|
| 215 |
+
"time": a.get("time", ""),
|
| 216 |
+
"reason": a.get("reason", "")
|
| 217 |
})
|
| 218 |
|
| 219 |
return appointments
|