Spaces:
Sleeping
Sleeping
Update api/routes.py
Browse files- api/routes.py +7 -9
api/routes.py
CHANGED
|
@@ -18,7 +18,7 @@ async def signup(data: SignupForm):
|
|
| 18 |
existing = await users_collection.find_one({"email": email})
|
| 19 |
if existing:
|
| 20 |
raise HTTPException(status_code=409, detail="Email already exists")
|
| 21 |
-
|
| 22 |
hashed_pw = hash_password(data.password)
|
| 23 |
user_doc = {
|
| 24 |
"email": email,
|
|
@@ -62,7 +62,7 @@ async def add_patient(data: PatientCreate, current_user: dict = Depends(get_curr
|
|
| 62 |
"created_at": datetime.utcnow()
|
| 63 |
}
|
| 64 |
result = await patients_collection.insert_one(patient_doc)
|
| 65 |
-
return {
|
| 66 |
|
| 67 |
# --- GET ALL PATIENTS ---
|
| 68 |
@router.get("/patients")
|
|
@@ -156,7 +156,7 @@ async def delete_patient(patient_id: str, current_user: dict = Depends(get_curre
|
|
| 156 |
raise HTTPException(status_code=404, detail="Patient not found or unauthorized")
|
| 157 |
|
| 158 |
return {"message": "Patient deleted successfully"}
|
| 159 |
-
|
| 160 |
# --- COUNT PATIENTS BY DOCTOR ---
|
| 161 |
@router.get("/patients/count")
|
| 162 |
async def count_patients(current_user: dict = Depends(get_current_user)):
|
|
@@ -166,14 +166,14 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
|
|
| 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
|
| 170 |
|
| 171 |
if patients_collection is None:
|
| 172 |
print("β patients_collection is None")
|
| 173 |
-
raise HTTPException(status_code=500, detail="Database
|
| 174 |
|
| 175 |
-
filter_query = {
|
| 176 |
-
print("π Running count_documents with
|
| 177 |
|
| 178 |
count = await patients_collection.count_documents(filter_query)
|
| 179 |
|
|
@@ -185,5 +185,3 @@ async def count_patients(current_user: dict = Depends(get_current_user)):
|
|
| 185 |
traceback.print_exc()
|
| 186 |
print("β ERROR in /patients/count:", repr(e))
|
| 187 |
raise HTTPException(status_code=500, detail="Internal Server Error")
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 18 |
existing = await users_collection.find_one({"email": email})
|
| 19 |
if existing:
|
| 20 |
raise HTTPException(status_code=409, detail="Email already exists")
|
| 21 |
+
|
| 22 |
hashed_pw = hash_password(data.password)
|
| 23 |
user_doc = {
|
| 24 |
"email": email,
|
|
|
|
| 62 |
"created_at": datetime.utcnow()
|
| 63 |
}
|
| 64 |
result = await patients_collection.insert_one(patient_doc)
|
| 65 |
+
return {"id": str(result.inserted_id), "message": "Patient created successfully"}
|
| 66 |
|
| 67 |
# --- GET ALL PATIENTS ---
|
| 68 |
@router.get("/patients")
|
|
|
|
| 156 |
raise HTTPException(status_code=404, detail="Patient not found or unauthorized")
|
| 157 |
|
| 158 |
return {"message": "Patient deleted successfully"}
|
| 159 |
+
|
| 160 |
# --- COUNT PATIENTS BY DOCTOR ---
|
| 161 |
@router.get("/patients/count")
|
| 162 |
async def count_patients(current_user: dict = Depends(get_current_user)):
|
|
|
|
| 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 user email")
|
| 170 |
|
| 171 |
if patients_collection is None:
|
| 172 |
print("β patients_collection is None")
|
| 173 |
+
raise HTTPException(status_code=500, detail="Database not connected")
|
| 174 |
|
| 175 |
+
filter_query = {"created_by": email}
|
| 176 |
+
print("π Running count_documents with:", filter_query)
|
| 177 |
|
| 178 |
count = await patients_collection.count_documents(filter_query)
|
| 179 |
|
|
|
|
| 185 |
traceback.print_exc()
|
| 186 |
print("β ERROR in /patients/count:", repr(e))
|
| 187 |
raise HTTPException(status_code=500, detail="Internal Server Error")
|
|
|
|
|
|