Update main.py
Browse files
main.py
CHANGED
|
@@ -923,7 +923,7 @@ def list_branches_summary():
|
|
| 923 |
def branch_details(branch_id: int):
|
| 924 |
"""
|
| 925 |
ูุฑุฌูุน ุชูุงุตูู ูุฑุน ูุงุญุฏ ู
ู branches_details.json
|
| 926 |
-
|
| 927 |
"""
|
| 928 |
path = BASE_DIR / "branches_details.json"
|
| 929 |
if not path.exists():
|
|
@@ -935,14 +935,63 @@ def branch_details(branch_id: int):
|
|
| 935 |
raise HTTPException(500, "branches_details.json contains invalid JSON")
|
| 936 |
|
| 937 |
items = info.get("data", info)
|
|
|
|
|
|
|
| 938 |
if isinstance(items, list):
|
| 939 |
for it in items:
|
| 940 |
if it.get("id") == branch_id:
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
|
| 945 |
-
|
| 946 |
|
| 947 |
# ====== Blog ======
|
| 948 |
|
|
|
|
| 923 |
def branch_details(branch_id: int):
|
| 924 |
"""
|
| 925 |
ูุฑุฌูุน ุชูุงุตูู ูุฑุน ูุงุญุฏ ู
ู branches_details.json
|
| 926 |
+
ู
ุน ุฅูุญุงู ุตูุฑุฉ ูู ุฏูุชูุฑ ู
ู ุฌุฏูู doctors (ุญูู image).
|
| 927 |
"""
|
| 928 |
path = BASE_DIR / "branches_details.json"
|
| 929 |
if not path.exists():
|
|
|
|
| 935 |
raise HTTPException(500, "branches_details.json contains invalid JSON")
|
| 936 |
|
| 937 |
items = info.get("data", info)
|
| 938 |
+
branch = None
|
| 939 |
+
|
| 940 |
if isinstance(items, list):
|
| 941 |
for it in items:
|
| 942 |
if it.get("id") == branch_id:
|
| 943 |
+
branch = it
|
| 944 |
+
break
|
| 945 |
+
elif isinstance(items, dict):
|
| 946 |
+
branch = items.get(str(branch_id))
|
| 947 |
+
|
| 948 |
+
if not branch:
|
| 949 |
+
raise HTTPException(404, f"Branch {branch_id} not found")
|
| 950 |
+
|
| 951 |
+
# ---- ุฅูุญุงู ุงูุตูุฑ ููู ุฏูุชูุฑ ----
|
| 952 |
+
doctors_list = branch.get("doctors") or []
|
| 953 |
+
# ุจููุจู id ุฃู doctor_id (ููุชู
ุงุดู ู
ุน ุฃู ููุฑู
ุงุช)
|
| 954 |
+
doc_ids = []
|
| 955 |
+
for d in doctors_list:
|
| 956 |
+
did = d.get("id") or d.get("doctor_id")
|
| 957 |
+
if isinstance(did, int):
|
| 958 |
+
doc_ids.append(did)
|
| 959 |
+
|
| 960 |
+
doc_ids = sorted(set(doc_ids))
|
| 961 |
+
images_map = {}
|
| 962 |
+
|
| 963 |
+
if doc_ids:
|
| 964 |
+
# ูุฌูุจ ุงูุตูุฑ ุฏูุนุฉ ูุงุญุฏุฉ
|
| 965 |
+
ids_csv = ",".join(str(i) for i in doc_ids)
|
| 966 |
+
try:
|
| 967 |
+
rows = supa_select("doctors", {
|
| 968 |
+
"select": "id,image",
|
| 969 |
+
"id": f"in.({ids_csv})",
|
| 970 |
+
"limit": str(len(doc_ids))
|
| 971 |
+
})
|
| 972 |
+
images_map = {r["id"]: r.get("image") for r in rows}
|
| 973 |
+
except Exception as e:
|
| 974 |
+
# ูู ุญุตู ุฎุทุฃุ ููู
ู ุจุฏูู ุตูุฑ ุจุฏู ู
ุง ููุดู ููููุง
|
| 975 |
+
print("[branch_details] fetch doctors images failed:", e)
|
| 976 |
+
images_map = {}
|
| 977 |
+
|
| 978 |
+
# ูุถูู image ููู ุนูุตุฑ ูู ุงููุงุฆู
ุฉ
|
| 979 |
+
enriched_doctors = []
|
| 980 |
+
for d in doctors_list:
|
| 981 |
+
did = d.get("id") or d.get("doctor_id")
|
| 982 |
+
# ููุจูู ุนูู ููุณ ุงูุดูู ุงูุฃุตูู + ููุญู ุงูู image
|
| 983 |
+
enriched = dict(d)
|
| 984 |
+
if isinstance(did, int):
|
| 985 |
+
enriched["image"] = images_map.get(did)
|
| 986 |
+
else:
|
| 987 |
+
enriched["image"] = None
|
| 988 |
+
enriched_doctors.append(enriched)
|
| 989 |
+
|
| 990 |
+
# ูุฑุฌูุน ููุณ ุงููููู ุงููุฏูู
ุ ููู ู
ุน doctors ู
ูุซุฑู ุจุงูุตูุฑ
|
| 991 |
+
result = dict(branch)
|
| 992 |
+
result["doctors"] = enriched_doctors
|
| 993 |
|
| 994 |
+
return {"message": "Branch Fetched Successfully", "data": result}
|
| 995 |
|
| 996 |
# ====== Blog ======
|
| 997 |
|