def echo(): global config update_sql_settings() initial_button_type = echo_button.button_type initial_label = echo_button.label if validate_sql_connection(config): echo_button.button_type = 'success' echo_button.label = 'Success' else: echo_button.button_type = 'warning' echo_button.label = 'Fail' time.sleep(1.5) echo_button.button_type = initial_button_type echo_button.label = initial_label
def test_dvh_code(): if test_import_sql_cnx_definitions(): is_import_valid = validate_import_settings() is_sql_connection_valid = validate_sql_connection() if not is_import_valid and not is_sql_connection_valid: print( "ERROR: Create the directories listed above or input valid directories.\n", "ERROR: Cannot connect to SQL.\n", "Please run:\n $ python start.py settings", sep='') elif not is_import_valid: print( "ERROR: Create the directories listed above or input valid directories by running:\n", " $ python start.py settings --dir", sep='') elif not is_sql_connection_valid: print( "ERROR: Cannot connect to SQL.\n", "Verify database is active and/or update SQL connection information with:\n", " $ python start.py settings --sql", sep='') else: print("Importing test files") dicom_to_sql(start_path="test_files/", organize_files=False, move_files=False, force_update=False) print("Reading data from SQL DB with analysis_tools.py") test = DVH() print( "Reading dicom information from test files with utilities.py (for plan review module)" ) test_files = Temp_DICOM_FileSet(start_path="test_files/") print("Deleting test data from SQL database") for i in range(0, test_files.count): cond_str = "mrn = '" + test_files.mrn[i] cond_str += "' and study_instance_uid = '" + test_files.study_instance_uid[ i] + "'" DVH_SQL().delete_rows(cond_str) print("Tests successful!")
def main(): parser = argparse.ArgumentParser( description='Command line interface for DVH Analytics') parser.add_argument('--sql', help='Modify SQL connection settings', default=False, action='store_true') parser.add_argument('--dir', help='Modify import directory settings', default=False, action='store_true') parser.add_argument('--start-path', dest='start_path', help='modify the start path for dicom import', default=None) parser.add_argument( '--force-update', help= 'Import will add to SQL DB even if DB already contains data from dicom files', default=False, action='store_true') parser.add_argument( '--allow-websocket-origin', dest='allow_websocket_origin', help='Allows Bokeh server to accept a non-default origin', default=None) parser.add_argument('--port', dest='port', help='Initializes Bokeh server on a non-default port', default=None) parser.add_argument('command', nargs='+', help='bar help') args = parser.parse_args() if args.command: if args.command[0] == 'settings_simple': if not args.sql and not args.dir: settings() else: if args.sql: settings(sql=True) if args.dir: settings(dir=True) elif args.command[0] == 'test': test_dvh_code() elif args.command[0] == 'echo': validate_sql_connection() elif args.command[0] == 'print_mrns': print_mrns() elif args.command[0] == 'import': # Set defaults start_path = False force_update = False if args.start_path: if os.path.isdir(args.start_path): start_path = str(args.start_path) else: print(args.start_path, 'is not a valid path', sep=' ') if args.force_update: force_update = True dicom_to_sql(start_path=start_path, force_update=force_update) elif args.command[0] == 'run': if test_import_sql_cnx_definitions(): if DVH_SQL().is_sql_table_empty('DVHs'): print("There is no data in your SQL table.") print( "You may import data from the admin view (use the 'admin' command instead of 'run'" ) else: command = ["bokeh", "serve"] if args.allow_websocket_origin: command.append("--allow-websocket-origin") command.append(args.allow_websocket_origin) if args.port: command.append("--port") # Defaults to 5006 command.append(args.port) if not args.allow_websocket_origin and not args.port: command.append("--show") command.append(script_dir) call(command) else: print( "Could not connect to SQL. You may need to update/initiate settings." ) print("Try running with 'settings' command instead of 'run'") elif args.command[0] == 'admin': if test_import_sql_cnx_definitions(): command = ["bokeh", "serve", "--show", "--port"] if args.port: command.append(args.port) else: command.append("5007") if args.allow_websocket_origin: command.append("--allow-websocket-origin") command.append(args.allow_websocket_origin) file_name = 'admin.py' abs_file_path = os.path.join(script_dir, file_name) command.append(abs_file_path) call(command) else: print( "Could not connect to SQL. You may need to update/initiate settings." ) print("Try running with 'settings' command instead of 'admin'") elif args.command[0] == 'settings': initialize_default_import_settings_file() initialize_default_sql_connection_config_file() command = ["bokeh", "serve", "--show", "--port"] if args.port: command.append(args.port) else: command.append("5008") if args.allow_websocket_origin: command.append("--allow-websocket-origin") command.append(args.allow_websocket_origin) file_name = 'settings.py' abs_file_path = os.path.join(script_dir, file_name) command.append(abs_file_path) call(command) elif args.command[0] == 'create_tables': DVH_SQL().initialize_database()