Spaces:
Sleeping
Sleeping
Update api/routes.py
Browse files- api/routes.py +15 -8
api/routes.py
CHANGED
|
@@ -161,18 +161,25 @@ async def delete_patient(patient_id: str, current_user: dict = Depends(get_curre
|
|
| 161 |
@router.get("/patients/count")
|
| 162 |
async def count_patients(current_user: dict = Depends(get_current_user)):
|
| 163 |
try:
|
| 164 |
-
email = current_user
|
| 165 |
-
print("
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
count = await patients_collection.count_documents(filter_query)
|
| 171 |
-
print("β
Count result:", count)
|
| 172 |
|
|
|
|
| 173 |
return {"count": count}
|
| 174 |
-
except Exception as e:
|
| 175 |
-
print("β Exception in /patients/count:", repr(e))
|
| 176 |
-
raise HTTPException(status_code=500, detail="Failed to count patients")
|
| 177 |
|
|
|
|
|
|
|
|
|
|
| 178 |
|
|
|
|
| 161 |
@router.get("/patients/count")
|
| 162 |
async def count_patients(current_user: dict = Depends(get_current_user)):
|
| 163 |
try:
|
| 164 |
+
email = current_user.get("email")
|
| 165 |
+
print("π Authenticated user email:", email)
|
| 166 |
|
| 167 |
+
if not email or not isinstance(email, str):
|
| 168 |
+
raise HTTPException(status_code=400, detail="Invalid email in token")
|
| 169 |
+
|
| 170 |
+
if patients_collection is None:
|
| 171 |
+
print("β patients_collection is not initialized")
|
| 172 |
+
raise HTTPException(status_code=500, detail="Database not connected")
|
| 173 |
+
|
| 174 |
+
filter_query = {"created_by": email}
|
| 175 |
+
print("π Running count_documents with:", filter_query)
|
| 176 |
|
| 177 |
count = await patients_collection.count_documents(filter_query)
|
|
|
|
| 178 |
|
| 179 |
+
print("β
Patient count result:", count)
|
| 180 |
return {"count": count}
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
+
except Exception as e:
|
| 183 |
+
print("β ERROR in /patients/count:", repr(e))
|
| 184 |
+
raise HTTPException(status_code=500, detail="Internal server error")
|
| 185 |
|