from flask import Flask, request, jsonify from flask_cors import CORS import json, os app = Flask(__name__, static_folder="static", static_url_path="/static") CORS(app) # ----------------------------- # LOAD JSON SAFELY # ----------------------------- BASE_DIR = os.path.dirname(os.path.abspath(__file__)) JSON_PATH = os.path.join(BASE_DIR, "doctors.json") with open(JSON_PATH, "r", encoding="utf-8") as f: DOCTORS = json.load(f) # ----------------------------- # API : GET DOCTORS # ----------------------------- @app.route("/doctors", methods=["GET"]) def get_doctors(): district = request.args.get("district") disease = request.args.get("disease", "").lower() if not district: return jsonify({"error": "district required"}), 400 # District filter result = [ d for d in DOCTORS if d.get("district", "").lower() == district.lower() ] # Disease filter if disease: result = [ d for d in result if any(disease in s.lower() for s in d.get("specialist", [])) ] # Add image + map url for d in result: d["map_url"] = f"https://www.google.com/maps?q={d['lat']},{d['lon']}" d["image_url"] = f"/static/images/{d['image']}" return jsonify({ "count": len(result), "doctors": result }) # ----------------------------- # HEALTH CHECK # ----------------------------- @app.route("/") def health(): return jsonify({"status": "API running"}) if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)