Example #1
0
    def __init__(self, *config, db_type='pgsql'):
        """
        :param config: optional SQL login credentials, stored values used if nothing provided
        :param db_type: either 'pgsql' or 'sqlite'
        :type db_type: str
        """

        stored_options = Options()

        if config:
            self.db_type = db_type
            config = config[0]
        else:
            # Read SQL configuration file
            self.db_type = stored_options.DB_TYPE
            config = stored_options.SQL_LAST_CNX[self.db_type]

        if self.db_type == 'sqlite':
            db_file_path = config['host']
            if not dirname(
                    db_file_path
            ):  # file_path has not directory, assume it lives in DATA_DIR
                db_file_path = join(DATA_DIR, db_file_path)
            self.db_name = None
            self.cnx = sqlite3.connect(db_file_path)
        else:
            self.db_name = config['dbname']
            self.cnx = psycopg2.connect(**config)

        self.cursor = self.cnx.cursor()
        self.tables = ['DVHs', 'Plans', 'Rxs', 'Beams', 'DICOM_Files']
Example #2
0
    def __init__(self):
        wx.Dialog.__init__(self, None, title='About DVH Analytics')

        scrolled_window = wx.ScrolledWindow(self, wx.ID_ANY)

        with open(LICENSE_PATH, 'r') as license_file:
            license_text = ''.join([line for line in license_file])

        license_text = "DVH Analytics v%s\ndvhanalytics.com\n\n%s" % (Options().VERSION, license_text)

        sizer_wrapper = wx.BoxSizer(wx.VERTICAL)
        sizer_text = wx.BoxSizer(wx.VERTICAL)

        scrolled_window.SetScrollRate(20, 20)

        license_text = wx.StaticText(scrolled_window, wx.ID_ANY, license_text)
        sizer_text.Add(license_text, 0, wx.EXPAND | wx.ALL, 5)
        scrolled_window.SetSizer(sizer_text)
        sizer_wrapper.Add(scrolled_window, 1, wx.EXPAND, 0)

        self.SetBackgroundColour(wx.WHITE)

        self.SetSizer(sizer_wrapper)
        self.SetSize((750, 900))
        self.Center()

        self.ShowModal()
Example #3
0
    def __init__(self, *config, db_type=None, group=1):
        """
        :param config: optional SQL login credentials, stored values used if nothing provided
        :param db_type: either 'pgsql' or 'sqlite'
        :type db_type: str or None
        :param group: use a group-specific connection, either 1 or 2
        :type group: int
        """

        stored_options = Options()

        if config:
            self.db_type = db_type if db_type is not None else 'pgsql'
            config = config[0]
        else:
            # Read SQL configuration file
            if group == 2 and stored_options.SYNC_SQL_CNX:
                group = 1
            self.db_type = stored_options.DB_TYPE_GRPS[group] if db_type is None else db_type
            config = stored_options.SQL_LAST_CNX_GRPS[group][self.db_type]

        if self.db_type == 'sqlite':
            db_file_path = config['host']
            if not dirname(db_file_path):  # file_path has not directory, assume it lives in DATA_DIR
                db_file_path = join(DATA_DIR, db_file_path)
            self.db_name = None
            self.cnx = sqlite3.connect(db_file_path)
        else:
            self.db_name = config['dbname']
            self.cnx = psycopg2.connect(**config)

        self.cursor = self.cnx.cursor()
        self.tables = ['DVHs', 'Plans', 'Rxs', 'Beams', 'DICOM_Files']
Example #4
0
Hierarchy of classes:
    Plan -> FxGroup -> Beam -> ControlPoint
"""
# Copyright (c) 2016-2019 Dan Cutright
# This file is part of DVH Analytics, released under a BSD license.
#    See the file LICENSE included with this distribution, also
#    available at https://github.com/cutright/DVH-Analytics

from dicompylercore import dicomparser
import numpy as np
from shapely.geometry import Polygon
from shapely import speedups
from dvha.tools.utilities import flatten_list_of_lists as flatten
from dvha.options import Options

options = Options()

# Enable shapely calculations using C, as opposed to the C++ default
if speedups.available:
    speedups.enable()


class Plan:
    """
    Collect plan information from an RT Plan DICOM file.
    Automatically parses fraction data with FxGroup class
    """
    def __init__(self, rt_plan_file):
        """
        :param rt_plan_file: absolute file path of a DICOM RT Plan file
        """
Example #5
0
"""
Class to retrieve DVH data from SQL, calculate parameters dependent on DVHs, and extract plotting data
"""
# Copyright (c) 2016-2019 Dan Cutright
# This file is part of DVH Analytics, released under a BSD license.
#    See the file LICENSE included with this distribution, also
#    available at https://github.com/cutright/DVH-Analytics

from copy import deepcopy
from dateutil.parser import parse as date_parser
import numpy as np
from dvha.db.sql_connector import DVH_SQL
from dvha.db.sql_to_python import QuerySQL
from dvha.options import Options

MAX_DOSE_VOLUME = Options().MAX_DOSE_VOLUME


# This class retrieves DVH data from the SQL database and calculates statistical DVHs (min, max, quartiles)
# It also provides some inspection tools of the retrieved data
class DVH:
    def __init__(self, uid=None, dvh_condition=None, dvh_bin_width=5):
        """
        This class will retrieve DVHs and other data in the DVH SQL table meeting the given constraints,
        it will also parse the DVH_string into python lists and retrieve the associated Rx dose
        :param uid: a list of allowed study_instance_uids in data set
        :param dvh_condition: a string in SQL syntax applied to a DVH Table query
        :param dvh_bin_width: retrieve every nth value from dvh_string in SQL
        :type dvh_bin_width: int
        """
Example #6
0
    def __init__(self, *args, **kwds):
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        self.layout_set = False

        self.sizer_dvhs = wx.BoxSizer(wx.VERTICAL)

        set_msw_background_color(self)  # If windows, change the background color

        self.options = Options()

        # Initial DVH object and data
        self.save_data = {}
        self.group_data = {1: {'dvh': None,
                               'data': {key: None for key in ['Plans', 'Beams', 'Rxs']},
                               'stats_data': None},
                           2: {'dvh': None,
                               'data': {key: None for key in ['Plans', 'Beams', 'Rxs']},
                               'stats_data': None}}

        self.toolbar_keys = ['Open', 'Close', 'Save', 'Export', 'Import', 'Database', 'ROI Map', 'Settings']
        self.toolbar_ids = {key: i + 1000 for i, key in enumerate(self.toolbar_keys)}

        # sql_columns.py contains dictionaries of all queryable variables along with their
        # SQL columns and tables. Numerical categories include their units as well.
        self.categorical_columns = sql_columns.categorical
        self.numerical_columns = sql_columns.numerical

        # Keep track of currently selected row in the query tables
        self.selected_index_categorical = None
        self.selected_index_numerical = None

        # Load ROI Map now and pass to other objects for continuity
        # TODO: Need a method to address multiple users editing roi_map at the same time
        self.roi_map = DatabaseROIs()

        self.query_filters = None
        self.reset_query_filters()

        self.__add_menubar()
        self.__add_tool_bar()
        self.__add_layout_objects()
        self.__bind_layout_objects()

        columns = {'categorical': ['category_1', 'category_2', 'Filter Type'],
                   'numerical': ['category', 'min', 'max', 'Filter Type']}
        self.data_table_categorical = DataTable(self.table_categorical, columns=columns['categorical'])
        self.data_table_numerical = DataTable(self.table_numerical, columns=columns['numerical'])

        self.__set_properties()
        self.__set_tooltips()
        self.__add_notebook_frames()
        self.__do_layout()

        self.disable_query_buttons('categorical')
        self.disable_query_buttons('numerical')
        self.button_query_execute.Disable()
        self.__disable_notebook_tabs()

        self.Bind(wx.EVT_CLOSE, self.on_quit)
        self.tool_bar_windows = {key: None for key in ['import', 'database', 'roi_map']}

        wx.CallAfter(self.__catch_failed_sql_connection_on_app_launch)

        self.__do_subscribe()