Update main.py
Browse files
main.py
CHANGED
|
@@ -669,11 +669,50 @@ def branch_doctors_min(branch_id: int):
|
|
| 669 |
|
| 670 |
# نرجّع فقط الحقول المطلوبة
|
| 671 |
return {
|
|
|
|
| 672 |
"id": branch_id,
|
| 673 |
"name": branch_name,
|
| 674 |
"doctors": doctors
|
| 675 |
}
|
| 676 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
# ====== DDepartments ======
|
| 678 |
|
| 679 |
@app.get("/api/departments")
|
|
|
|
| 669 |
|
| 670 |
# نرجّع فقط الحقول المطلوبة
|
| 671 |
return {
|
| 672 |
+
"message": "الأطباء المتاحون في هذا الفرع",
|
| 673 |
"id": branch_id,
|
| 674 |
"name": branch_name,
|
| 675 |
"doctors": doctors
|
| 676 |
}
|
| 677 |
|
| 678 |
+
@app.get("/api/doctors/{doctor_id}/branches")
|
| 679 |
+
def doctor_branches(doctor_id: int):
|
| 680 |
+
"""
|
| 681 |
+
يرجّع فروع الطبيب من جدول doctor_details (عمود jsonb اسمه branches).
|
| 682 |
+
الاستعلام: doctor_id = <id>
|
| 683 |
+
الخرج:
|
| 684 |
+
{
|
| 685 |
+
"message": "Doctor branches fetched successfully",
|
| 686 |
+
"doctor_id": <int>,
|
| 687 |
+
"count": <int>,
|
| 688 |
+
"branches": [ { "id": ..., "name": ... , ... }, ... ]
|
| 689 |
+
}
|
| 690 |
+
"""
|
| 691 |
+
rows = supa_select("doctor_details", {
|
| 692 |
+
**eq("doctor_id", doctor_id),
|
| 693 |
+
"select": "doctor_id,branches",
|
| 694 |
+
"limit": "1"
|
| 695 |
+
})
|
| 696 |
+
if not rows:
|
| 697 |
+
raise HTTPException(404, "Doctor details not found")
|
| 698 |
+
|
| 699 |
+
rec = rows[0]
|
| 700 |
+
branches = rec.get("branches") or []
|
| 701 |
+
# تأكيد النوع لو الـ jsonb فاضي أو None
|
| 702 |
+
if not isinstance(branches, list):
|
| 703 |
+
try:
|
| 704 |
+
# في حال اتت كنص JSON (نادر)
|
| 705 |
+
branches = json.loads(branches) if isinstance(branches, str) else []
|
| 706 |
+
except Exception:
|
| 707 |
+
branches = []
|
| 708 |
+
|
| 709 |
+
return {
|
| 710 |
+
"message": "الفروع التي يعمل بها هذا الطبيب",
|
| 711 |
+
"doctor_id": doctor_id,
|
| 712 |
+
"count": len(branches),
|
| 713 |
+
"branches": branches
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
# ====== DDepartments ======
|
| 717 |
|
| 718 |
@app.get("/api/departments")
|