File size: 1,566 Bytes
8e88bfa
bf9bd0a
abb0ffc
bf9bd0a
abb0ffc
bf9bd0a
 
abb0ffc
 
 
8e88bfa
 
 
 
636aa6f
 
abb0ffc
8e88bfa
abb0ffc
c100daa
bf9bd0a
c100daa
8e88bfa
bf9bd0a
636aa6f
abb0ffc
636aa6f
abb0ffc
636aa6f
 
8e88bfa
bf9bd0a
 
abb0ffc
8e88bfa
 
 
 
 
 
abb0ffc
636aa6f
abb0ffc
 
636aa6f
 
 
 
 
bf9bd0a
abb0ffc
 
 
8e88bfa
 
 
 
bf9bd0a
8e88bfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)