-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (26 loc) · 919 Bytes
/
app.py
File metadata and controls
35 lines (26 loc) · 919 Bytes
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
"""
app.py
Flask application — serves DICOM scans as PNG images.
Usage:
python app.py
"""
from flask import Flask, send_file, abort
from services.dicom_service import dicom_to_png
from services.db_service import get_scan as db_get_scan
import os
app = Flask(__name__)
@app.route('/scan/<int:scan_uid>')
def get_scan(scan_uid):
"""Returns a DICOM scan converted to PNG."""
scan = db_get_scan(scan_uid)
if scan is None:
abort(404, description=f"Scan {scan_uid} not found in database")
return # unreachable; abort() raises — helps type checkers narrow the type
image_path = scan["images_file"]
if not os.path.exists(image_path):
abort(404, description=f"DICOM file not found on disk: {image_path}")
return
img_bytes = dicom_to_png(image_path)
return send_file(img_bytes, mimetype='image/png')
if __name__ == "__main__":
app.run(debug=True)