Binrushd-Medical-Center commited on
Commit
b9ab76d
·
verified ·
1 Parent(s): 8428b25

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +43 -0
main.py CHANGED
@@ -631,6 +631,49 @@ def doctor_details(doctor_id: int):
631
  raise HTTPException(status_code=404, detail="Doctor details not found")
632
  return rows[0]
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  # ====== DDepartments ======
635
 
636
  @app.get("/api/departments")
 
631
  raise HTTPException(status_code=404, detail="Doctor details not found")
632
  return rows[0]
633
 
634
+ @app.get("/api/branches/{branch_id}/doctors")
635
+ def branch_doctors_min(branch_id: int):
636
+ """
637
+ يرجّع JSON مختصر لفرع معيّن من branches_details.json:
638
+ { "id": <branch_id>, "name": <branch_name or fallback>, "doctors": [ {id, name}, ... ] }
639
+ يعتمد فقط على ملف branches_details.json.
640
+ """
641
+ path = BASE_DIR / "branches_details.json"
642
+ if not path.exists():
643
+ raise HTTPException(500, "branches_details.json not found")
644
+
645
+ try:
646
+ info = json.loads(path.read_text(encoding="utf-8"))
647
+ except json.JSONDecodeError:
648
+ raise HTTPException(500, "branches_details.json contains invalid JSON")
649
+
650
+ # قد يكون الشكل {"message": "...", "data": [ ... ]} أو مباشرة [ ... ]
651
+ items = info.get("data", info)
652
+
653
+ branch = None
654
+ if isinstance(items, list):
655
+ for it in items:
656
+ if it.get("id") == branch_id:
657
+ branch = it
658
+ break
659
+ elif isinstance(items, dict):
660
+ # في حال كانت مفاتيحها ids كنصوص
661
+ branch = items.get(str(branch_id))
662
+
663
+ if not branch:
664
+ raise HTTPException(404, f"Branch {branch_id} not found")
665
+
666
+ # لو الاسم مش موجود في details نرجّع اسم افتراضي
667
+ branch_name = branch.get("name") or f"فرع رقم {branch_id}"
668
+ doctors = branch.get("doctors", [])
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")