Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -430,6 +430,34 @@ def upload_reports():
|
|
430 |
logger.exception("Upload failed: %s", exc)
|
431 |
return jsonify({"error": "upload failed", "detail": str(exc)}), 500
|
432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
|
434 |
@app.route("/ping", methods=["GET"])
|
435 |
def ping():
|
|
|
430 |
logger.exception("Upload failed: %s", exc)
|
431 |
return jsonify({"error": "upload failed", "detail": str(exc)}), 500
|
432 |
|
433 |
+
@app.route("/<patient_id>/<filename>")
|
434 |
+
def serve_report(patient_id, filename):
|
435 |
+
"""
|
436 |
+
Serve a specific uploaded PDF (or other allowed file) for a patient.
|
437 |
+
URL format: /<patient_id>/<filename>
|
438 |
+
Example: /p14562/report1.pdf
|
439 |
+
"""
|
440 |
+
try:
|
441 |
+
patient_folder = REPORTS_ROOT / str(patient_id)
|
442 |
+
|
443 |
+
if not patient_folder.exists():
|
444 |
+
abort(404, description=f"Patient folder not found: {patient_id}")
|
445 |
+
|
446 |
+
# security check: only allow files with allowed extensions
|
447 |
+
ext = filename.rsplit(".", 1)[-1].lower() if "." in filename else ""
|
448 |
+
if ext not in ALLOWED_EXTENSIONS:
|
449 |
+
abort(403, description=f"Extension '{ext}' not allowed")
|
450 |
+
|
451 |
+
return send_from_directory(
|
452 |
+
directory=str(patient_folder),
|
453 |
+
path=filename,
|
454 |
+
as_attachment=False # set True if you want download instead of inline view
|
455 |
+
)
|
456 |
+
|
457 |
+
except Exception as e:
|
458 |
+
logger.exception("Failed to serve file %s/%s: %s", patient_id, filename, e)
|
459 |
+
abort(500, description=f"Failed to serve file: {e}")
|
460 |
+
|
461 |
|
462 |
@app.route("/ping", methods=["GET"])
|
463 |
def ping():
|