from . import RestToolbox_modified as RestToolbox from . import field_rotation as field_rotation CUR_DIR = os.path.realpath(os.path.dirname(__file__)) # Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # Here starts the bottle server fieldrot_app = Bottle() @fieldrot_app.route('/fieldrot', method="POST") def fieldrot(): colormaps = ["Greys", "brg", "gray", "prism"] displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["colormaps"] = colormaps variables["displayname"] = displayname response.set_cookie("account", username,
import datetime import numpy as np import base64 parent_module = sys.modules['.'.join(__name__.split('.')[:-1]) or '__main__'] if __name__ == '__main__' or parent_module.__name__ == '__main__': # sys.path.append(os.path.abspath(os.path.realpath("python_packages"))) import config import RestToolbox_modified as RestToolbox from python_packages.bottlepy.bottle import Bottle, static_file else: from . import config from . import RestToolbox_modified as RestToolbox from .python_packages.bottlepy.bottle import Bottle, static_file app_general = Bottle() CUR_DIR = os.path.realpath(os.path.dirname(__file__)) CUR_DIR_STATIC = os.path.join(CUR_DIR, "static") CUR_DIR_STATIC_DOCS = os.path.join(CUR_DIR_STATIC, "docs") @app_general.get('/<filename:re:.*\.(png)>') @app_general.get('/<filename:re:.*\.(html)>') @app_general.get('/<filename:re:.*\.(js)>') @app_general.get('/<filename:re:.*\.(woff2)>') @app_general.get('/<filename:re:.*\.(woff)>') @app_general.get('/<filename:re:.*\.(ttf)>') @app_general.get('/<filename:re:.*\.(map)>') @app_general.get('/<filename:re:.*\.(css)>') def misc_file(filename):
"JawWidth", "IsoOffsetX", "IsoOffsetY", "FieldRot", "IsoMethod" ], "MLC only": [ "LeafSide1", "LeafSide2", "JawSide1", "JawSide2", "LeafWidth", "JawWidth", "IsoOffsetX", "IsoOffsetY", "FieldRot", "IsoMethod" ] } FIELDROTATION_PARAMETERS = { "Collimator absolute": ["Angle"], "Collimator relative": ["Angle"], "Couch relative": ["Angle"] } # Here starts the bottle server trends_app = Bottle() def get_unique_names(table): # Collect machines, beams and phantoms from table conn = sql.connect(config.TRENDS_DATABASE) curs = conn.cursor() curs.execute("SELECT Machine, Beam, Phantom FROM " + table) data = curs.fetchall() curs.close() conn.close() machines = list(set([i[0] for i in data])) machines.sort() beams = {} phantoms = {} for m in machines:
elif phantom == "Catphan 600": mycbct_temp = pylinac_ct.CatPhan600(path) elif phantom == "Catphan 604": mycbct_temp = pylinac_ct.CatPhan604(path) mycbct_temp.analyze(hu_tolerance=hu_tolerance, scaling_tolerance=scaling_tolerance, thickness_tolerance=thickness_tolerance, low_contrast_tolerance=low_contrast_tolerance, cnr_threshold=cnr_threshold) except Exception as e: return e else: return mycbct_temp # Here starts the bottle server ctp_app = Bottle() @ctp_app.route('/catphan', method="POST") def catphan_start(): colormaps = ["gray", "Greys", "brg", "prism"] displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() except ConnectionError: return template("error_template", {"error_message": "Orthanc is refusing connection."}) variables["displayname"] = displayname response.set_cookie("account", username, secret=config.SECRET_KEY, samesite="lax")
from .python_packages.pylinac.flatsym_version231 import FlatSym as FlatSym from .python_packages import mpld3 CUR_DIR = os.path.realpath(os.path.dirname(__file__)) # Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # Here starts the bottle server flatsym_app = Bottle() @flatsym_app.route('/flatsym', method="POST") def flatsym(): username = request.get_cookie("account", secret=config.SECRET_KEY) displayname = request.forms.hidden_displayname if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["displayname"] = displayname response.set_cookie("account", username, secret=config.SECRET_KEY,
import general_functions import RestToolbox_modified as RestToolbox from python_packages.bottlepy.bottle import Bottle, request, TEMPLATE_PATH, template, redirect, response else: from . import config from . import general_functions from . import RestToolbox_modified as RestToolbox from .python_packages.bottlepy.bottle import Bottle, request, TEMPLATE_PATH, template, redirect, response CUR_DIR = os.path.realpath(os.path.dirname(__file__)) # Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Here starts the bottle server admin_app = Bottle() @admin_app.route('/administration', method="POST") def administration(): username = request.get_cookie("account", secret=config.SECRET_KEY) displayname = request.forms.hidden_displayname if not username: redirect("/login") elif not general_functions.check_is_admin(username): return template("error_template", {"error_message": "Insufficient rights."}) else: variables = {"displayname": displayname} response.set_cookie("account",
def main(): # This function acts as a console script entry-point. if len(sys.argv) != 3 or not check_ip(sys.argv[1]): print("Invalid ip:port. Follow this example: \n" "pyqaserver 127.0.0.1:8080 \path_to_database") sys.exit() if not check_database(sys.argv[2]): print("Path to database directory does not exist.") sys.exit() # Redefine folder path in config.py path = sys.argv[2] config.WORKING_DIRECTORY = path # Create new general_settings database. config.GENERAL_DATABASE = os.path.join(path, config.GENERAL_DATABASE_NAME) if not os.path.exists(config.GENERAL_DATABASE): create_general_settings_database(config.GENERAL_DATABASE) print("Created {}".format(config.GENERAL_DATABASE)) else: print("Using {}".format(config.GENERAL_DATABASE)) # Create new trends database. config.TRENDS_DATABASE = os.path.join(path, config.TRENDS_DATABASE_NAME) if not os.path.exists(config.TRENDS_DATABASE): create_trends_database(config.TRENDS_DATABASE) print("Created {}".format(config.TRENDS_DATABASE)) else: print("Using {}".format(config.TRENDS_DATABASE)) # Set Orthanc ip address and credentials: orthanc_settings = get_orthanc_settings(config.GENERAL_DATABASE) config.ORTHANC_IP = orthanc_settings["IP"] config.ORTHANC_PORT = orthanc_settings["Port"] config.USERNAME_ORTHANC = orthanc_settings["User"] config.PASSWORD_ORTHANC = orthanc_settings["Password"] config.ORTHANC_URL = "http://{}:{}".format(str(config.ORTHANC_IP), str(config.ORTHANC_PORT)) RestToolbox.SetCredentials(config.USERNAME_ORTHANC, config.PASSWORD_ORTHANC) # Set institution name (not used a lot): institution_setttings = get_institution_settings(config.GENERAL_DATABASE) config.INSTITUTION = institution_setttings["Name"] ########################################################################### # Create new reference images folder config.REFERENCE_IMAGES_FOLDER = os.path.join( path, config.REFERENCE_IMAGES_FOLDER_NAME) if os.path.isdir(config.REFERENCE_IMAGES_FOLDER): print("Using {}".format(config.REFERENCE_IMAGES_FOLDER)) else: os.makedirs(config.REFERENCE_IMAGES_FOLDER) print("Created {}".format(config.REFERENCE_IMAGES_FOLDER)) ########################################################################### # Create dynalog folders and files dynpath = os.path.join(path, config.DYNALOG_FOLDER_NAME) config.DYNALOG_FOLDER = dynpath config.DYNALOG_DATABASE = os.path.join(dynpath, config.DYNALOG_DATABASE_NAME) config.DYNALOG_CONFIG = os.path.join(dynpath, config.DYNALOG_CONFIG_NAME) config.DYNALOG_ARCHIVE = os.path.join(dynpath, config.DYNALOG_ARCHIVE_FOLDER_NAME) config.DYNALOG_FAILED = os.path.join(dynpath, config.DYNALOG_FAILED_FOLDER_NAME) config.DYNALOG_SEND_POST = os.path.join(dynpath, config.DYNALOG_SEND_POST_NAME) if os.path.isdir(dynpath): print("Using {}".format(dynpath)) # Create config.ini if not os.path.exists(config.DYNALOG_CONFIG): create_dynalog_config_ini(config.DYNALOG_CONFIG) print("Created {}".format(config.DYNALOG_CONFIG)) else: print("Using {}".format(config.DYNALOG_CONFIG)) # Create dynalog_send_post_request.py if not os.path.exists(config.DYNALOG_SEND_POST): create_dynalog_send_post_request_file(config.DYNALOG_SEND_POST) print("Created {}".format(config.DYNALOG_SEND_POST)) else: print("Using {}".format(config.DYNALOG_SEND_POST)) # Create database.db if not os.path.exists(config.DYNALOG_DATABASE): create_dynalog_database(config.DYNALOG_DATABASE) print("Created {}".format(config.DYNALOG_DATABASE)) else: print("Using {}".format(config.DYNALOG_DATABASE)) # Create ARCHIVE directory if not os.path.isdir(config.DYNALOG_ARCHIVE): os.makedirs(config.DYNALOG_ARCHIVE) print("Created {}".format(config.DYNALOG_ARCHIVE)) else: print("Using {}".format(config.DYNALOG_ARCHIVE)) # Create dynalog_failed directory if not os.path.isdir(config.DYNALOG_FAILED): os.makedirs(config.DYNALOG_FAILED) print("Created {}".format(config.DYNALOG_FAILED)) else: print("Using {}".format(config.DYNALOG_FAILED)) else: os.makedirs(dynpath) os.makedirs(config.DYNALOG_ARCHIVE) os.makedirs(config.DYNALOG_FAILED) create_dynalog_config_ini(config.DYNALOG_CONFIG) create_dynalog_send_post_request_file(config.DYNALOG_SEND_POST) create_dynalog_database(config.DYNALOG_DATABASE) print("Created {}".format(dynpath)) print("Created {}".format(config.DYNALOG_CONFIG)) print("Created {}".format(config.DYNALOG_SEND_POST)) print("Created {}".format(config.DYNALOG_DATABASE)) print("Created {}".format(config.DYNALOG_ARCHIVE)) print("Created {}".format(config.DYNALOG_FAILED)) ########################################################################### # Create temp directories temp_path = os.path.join(path, config.TEMP_DIRECTORY_NAME) config.TEMP_DIRECTORY = temp_path config.TEMP_DCM_FOLDER = os.path.join(temp_path, config.TEMP_DCM_FOLDER_NAME) config.TEMP_NONDCM_FOLDER = os.path.join(temp_path, config.TEMP_NONDCM_FOLDER_NAME) config.TEMP_DYNALOG_FOLDER = os.path.join(temp_path, config.TEMP_DYNALOG_FOLDER_NAME) config.PDF_REPORT_FOLDER = os.path.join(temp_path, config.PDF_REPORT_FOLDER_NAME) if os.path.isdir(temp_path): # Create DCM temp directory if not os.path.isdir(config.TEMP_DCM_FOLDER): os.makedirs(config.TEMP_DCM_FOLDER) print("Created {}".format(config.TEMP_DCM_FOLDER)) else: print("Using {}".format(config.TEMP_DCM_FOLDER)) # Create NONDCM temp directory if not os.path.isdir(config.TEMP_NONDCM_FOLDER): os.makedirs(config.TEMP_NONDCM_FOLDER) print("Created {}".format(config.TEMP_NONDCM_FOLDER)) else: print("Using {}".format(config.TEMP_NONDCM_FOLDER)) # Create PDF temp directory if not os.path.isdir(config.PDF_REPORT_FOLDER): os.makedirs(config.PDF_REPORT_FOLDER) print("Created {}".format(config.PDF_REPORT_FOLDER)) else: print("Using {}".format(config.PDF_REPORT_FOLDER)) # Create DYNALOG temp directory if not os.path.isdir(config.TEMP_DYNALOG_FOLDER): os.makedirs(config.TEMP_DYNALOG_FOLDER) print("Created {}".format(config.TEMP_DYNALOG_FOLDER)) else: print("Using {}".format(config.TEMP_DYNALOG_FOLDER)) else: os.makedirs(config.TEMP_DCM_FOLDER) os.makedirs(config.TEMP_NONDCM_FOLDER) os.makedirs(config.TEMP_DYNALOG_FOLDER) os.makedirs(config.PDF_REPORT_FOLDER) print("Created {}".format(config.TEMP_DCM_FOLDER)) print("Created {}".format(config.TEMP_NONDCM_FOLDER)) print("Created {}".format(config.TEMP_DYNALOG_FOLDER)) print("Created {}".format(config.PDF_REPORT_FOLDER)) print("\n") # Here starts the bottle app app = Bottle() @app.error(500) def custom500(error): return template("error_template.tpl", error_message="Cause unknown.") @app.route('') @app.route('/') @app.route('/qaserver') # legacy @app.route('/qaserver/') # legacy @app.route('/qaserver/login') # legacy def redirect_to_login(): redirect("/login") @app.route("/login") def login_form(): images = [] for f in os.listdir(os.path.join(CUR_DIR, "static", "images")): if f.endswith('.png'): images.append(os.path.join("images", f)) if images: image = random.choice(images) else: image = "blank" return template("login.tpl", institution=config.INSTITUTION, image=image) @app.route('/login_check_credentials', method='POST') def login_check_credentials(): username = request.forms.username password = request.forms.password user_list = get_one_user(username) if user_list is None: return "User not recognized!" else: if not check_encrypted_password(password, user_list["Password"]): return "Wrong password!" else: return "Success!" @app.route('/login', method='POST') def login_submit(): username = request.forms.username password = request.forms.password user_list = get_one_user(username) if user_list is None: return template("error_template.tpl", error_message="User not recognized.") else: if not check_encrypted_password(password, user_list["Password"]): return template("error_template.tpl", error_message="Wrong password.") else: response.set_cookie("account", username, secret=config.SECRET_KEY, samesite="lax") return template("menu_page.tpl", institution=config.INSTITUTION, orthanc_url=config.ORTHANC_URL, qaserver_version=config.QASERVER_VERSION, displayname=user_list["DisplayName"], is_admin=check_is_admin(username)) # Merge apps app.merge(app_general) app.merge(wl_app) app.merge(ss_app) app.merge(pf_app) app.merge(plimg_app) app.merge(ctp_app) app.merge(dyn_app) app.merge(flatsym_app) app.merge(vmat_app) app.merge(fieldsize_app) app.merge(imgreview_app) app.merge(fieldrot_app) app.merge(admin_app) app.merge(trends_app) ip, port = sys.argv[1].split(":") bottle_run(app=app, server="waitress", host=ip, port=port, reloader=False, debug=False)
from .python_packages.pylinac.planar_imaging232 import DoselabMC2MV as DoselabMC2MV from .python_packages.pylinac.planar_imaging232 import DoselabMC2kV as DoselabMC2kV CUR_DIR = os.path.realpath(os.path.dirname(__file__)) # Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # Here starts the bottle server plimg_app = Bottle() @plimg_app.route('/planar_imaging', method="POST") def planar_imaging_start(): colormaps = ["gray", "Greys", "brg", "prism"] displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() except ConnectionError: return template( "error_template",
from . import RestToolbox_modified as RestToolbox from .python_packages import mpld3 CUR_DIR = os.path.realpath(os.path.dirname(__file__)) # Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # Here starts the bottle server ss_app = Bottle() @ss_app.route('/starshot', method="POST") def starshot_module(): displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["displayname"] = displayname response.set_cookie("account", username, secret=config.SECRET_KEY, samesite="lax") except ConnectionError: return template("error_template", {"error_message": "Orthanc is refusing connection."}) return template("starshot", variables)
# Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # MLC type for PicketFence analysis: LEAF_TYPE = [ "Varian_120", "Varian_120HD", "Varian_80", "Elekta_80", "Elekta_160" ] # Here starts the bottle server pf_app = Bottle() @pf_app.route('/picket_fence', method="POST") def picket_fence(): displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["displayname"] = displayname except ConnectionError: return template("error_template", {"error_message": "Orthanc is refusing connection."})
# Path to Bottle templates TEMPLATE_PATH.insert(0, os.path.join(CUR_DIR, 'views')) # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # MLC type LEAF_TYPE = [ "Varian_120", "Varian_120HD", "Varian_80", "Elekta_80", "Elekta_160" ] # Here starts the bottle server fieldsize_app = Bottle() @fieldsize_app.route('/fieldsize', method="POST") def fieldsize(): displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["displayname"] = displayname response.set_cookie("account", username, secret=config.SECRET_KEY, samesite="lax")
# Global filepaths for bokeh import BOKEH_FILE_CSS = config.BOKEH_FILE_CSS BOKEH_FILE_JS = config.BOKEH_FILE_JS BOKEH_WIDGETS_CSS = config.BOKEH_WIDGETS_CSS BOKEH_WIDGETS_JS = config.BOKEH_WIDGETS_JS BOKEH_TABLES_CSS = config.BOKEH_TABLES_CSS BOKEH_TABLES_JS = config.BOKEH_TABLES_JS # Url to some mpld3 library D3_URL = config.D3_URL MPLD3_URL = config.MPLD3_URL PI = np.pi # Here starts the bottle server imgreview_app = Bottle() @imgreview_app.route('/image_review', method="POST") def image_review(): colormaps = ["Greys", "gray", "brg", "prism"] displayname = request.forms.hidden_displayname username = request.get_cookie("account", secret=config.SECRET_KEY) if not username: redirect("/login") try: variables = general_functions.Read_from_dcm_database() variables["colormaps"] = colormaps variables["displayname"] = displayname response.set_cookie("account", username, secret=config.SECRET_KEY, samesite="lax") except ConnectionError: