Binrushd-Medical-Center commited on
Commit
85f1917
ยท
verified ยท
1 Parent(s): 9a68274

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +54 -5
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
- return {"message": "Branch Fetched Successfully", "data": it}
942
- elif isinstance(items, dict) and str(branch_id) in items:
943
- return {"message": "Branch Fetched Successfully", "data": items[str(branch_id)]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
 
945
- raise HTTPException(404, f"Branch {branch_id} not found")
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