Ali2206 commited on
Commit
d93a5a1
Β·
verified Β·
1 Parent(s): 481365f

Update api/routes.py

Browse files
Files changed (1) hide show
  1. api/routes.py +11 -7
api/routes.py CHANGED
@@ -165,21 +165,25 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
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
 
 
165
  print("πŸ“Œ Authenticated user email:", email)
166
 
167
  if not email or not isinstance(email, str):
168
+ print("❗ Email missing or invalid:", email)
169
+ raise HTTPException(status_code=400, detail="Invalid email in user context")
170
 
171
  if patients_collection is None:
172
+ print("❌ patients_collection is None")
173
+ raise HTTPException(status_code=500, detail="Database connection issue")
174
 
175
+ filter_query = { "created_by": email }
176
+ print("πŸ” Running count_documents with filter:", filter_query)
177
 
178
  count = await patients_collection.count_documents(filter_query)
179
 
180
+ print("βœ… Count result:", count)
181
  return {"count": count}
182
 
183
  except Exception as e:
184
+ import traceback
185
+ traceback.print_exc()
186
  print("❌ ERROR in /patients/count:", repr(e))
187
+ raise HTTPException(status_code=500, detail="Internal Server Error")
188
+
189