Exemple #1
0
    def update_data(self, load_saved_dvh_data=False):
        wait = wx.BusyCursor()
        tables = ['Plans', 'Rxs', 'Beams']
        if hasattr(self.dvh, 'study_instance_uid'):
            if not load_saved_dvh_data:
                condition_str = "study_instance_uid in ('%s')" % "','".join(
                    self.dvh.study_instance_uid)
                self.data = {
                    key: QuerySQL(key, condition_str)
                    for key in tables
                }
        else:
            self.data = {key: None for key in tables}
        del wait

        if hasattr(self.dvh, 'study_instance_uid'):
            wait = wx.BusyCursor()
            self.stats_data = StatsData(self.dvh, self.data)
            self.regression.stats_data = self.stats_data
            self.control_chart.stats_data = self.stats_data
            try:
                self.regression.update_combo_box_choices()
            except ValueError:
                # TODO: Print error in GUI
                pass
            self.control_chart.update_combo_box_y_choices()
            del wait
Exemple #2
0
    def update_data(self, load_saved_dvh_data=False, group_2_only=False):
        wx.BeginBusyCursor()
        tables = ['Plans', 'Rxs', 'Beams']
        for grp, grp_data in self.group_data.items():
            if not(grp == 1 and group_2_only) or grp == 2:
                if hasattr(grp_data['dvh'], 'study_instance_uid'):
                    if not load_saved_dvh_data:
                        condition_str = "study_instance_uid in ('%s')" % "','".join(
                           grp_data['dvh'].study_instance_uid)
                        grp_data['data'] = {key: QuerySQL(key, condition_str) for key in tables}
                        grp_data['stats_data'] = StatsData(grp_data['dvh'], grp_data['data'], group=grp)
                else:
                    grp_data['data'] = {key: None for key in tables}
                    grp_data['stats_data'] = None

        if self.group_data[2]['stats_data']:
            sync_variables_in_stats_data_objects(self.group_data[1]['stats_data'],
                                                 self.group_data[2]['stats_data'])
        self.time_series.update_data(self.group_data)
        self.control_chart.update_data(self.group_data)
        self.correlation.set_data(self.group_data)
        self.regression.update_combo_box_choices()
        self.radbio.update_dvh_data(self.group_data)

        wx.EndBusyCursor()
Exemple #3
0
def update_uncategorized_rois_in_database():
    roi_map = DatabaseROIs()
    dvh_data = QuerySQL('DVHs', "physician_roi = 'uncategorized'")

    with DVH_SQL() as cnx:
        for i in range(len(dvh_data.roi_name)):
            uid = dvh_data.study_instance_uid[i]
            mrn = dvh_data.mrn[i]
            physician = get_physician_from_uid(uid)
            roi_name = dvh_data.roi_name[i]

            new_physician_roi = roi_map.get_physician_roi(physician, roi_name)
            new_institutional_roi = roi_map.get_institutional_roi(
                physician, roi_name)

            if new_physician_roi != 'uncategorized':
                print(mrn,
                      physician,
                      new_institutional_roi,
                      new_physician_roi,
                      roi_name,
                      sep=' ')
                condition = "study_instance_uid = '" + uid + "'" + "and roi_name = '" + roi_name + "'"
                cnx.update('DVHs', 'physician_roi', new_physician_roi,
                           condition)
                cnx.update('DVHs', 'institutional_roi', new_institutional_roi,
                           condition)
    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
        """

        self.dvh_bin_width = dvh_bin_width

        if uid:
            constraints_str = "study_instance_uid in ('%s')" % "', '".join(uid)
            if dvh_condition:
                constraints_str = "(%s) and %s" % (dvh_condition,
                                                   constraints_str)
        else:
            constraints_str = ''

        # Get DVH data from SQL and set as attributes
        dvh_data = QuerySQL('DVHs', constraints_str)
        if dvh_data.mrn:
            ignored_keys = {
                'cnx', 'cursor', 'table_name', 'constraints_str',
                'condition_str'
            }
            self.keys = []
            for key, value in dvh_data.__dict__.items():
                if not key.startswith("__") and key not in ignored_keys:
                    if key == 'dvh_string':
                        dvh_split = [
                            dvh.split(',')[::self.dvh_bin_width]
                            for i, dvh in enumerate(value)
                        ]
                    setattr(self, key, value)
                    if '_string' not in key:
                        self.keys.append(key)

            # Move mrn to beginning of self.keys
            if 'mrn' in self.keys:
                self.keys.pop(self.keys.index('mrn'))
                self.keys.insert(0, 'mrn')

            # uid passed into DVH init is a unique list for querying and it is not in order of query results
            self.uid = self.study_instance_uid

            # Add these properties to dvh_data since they aren't in the DVHs SQL table
            self.count = len(self.mrn)
            self.study_count = len(set(self.uid))
            self.rx_dose = self.get_plan_values('rx_dose')
            self.sim_study_date = self.get_plan_values('sim_study_date')
            self.keys.append('rx_dose')
            self.endpoints = {'data': None, 'defs': None}
            self.eud = None
            self.ntcp_or_tcp = None

            self.bin_count = max([len(dvh) for dvh in dvh_split])

            self.dvh = np.zeros([self.bin_count, self.count])

            # Get needed values not in DVHs table
            for i in range(self.count):
                # Process dvh_string to numpy array, and pad with zeros at the end
                # so that all dvhs are the same length
                current_dvh = np.array(dvh_split[i],
                                       dtype='|S4').astype(np.float)
                current_dvh_max = np.max(current_dvh)
                if current_dvh_max > 0:
                    current_dvh = np.divide(current_dvh, current_dvh_max)
                zero_fill = np.zeros(self.bin_count - len(current_dvh))
                self.dvh[:, i] = np.concatenate((current_dvh, zero_fill))

            self.dth = []
            for i in range(self.count):
                # Process dth_string to numpy array
                try:
                    self.dth.append(
                        np.array(self.dth_string[i].split(','),
                                 dtype='|S4').astype(np.float))
                except Exception:
                    self.dth.append(np.array([0]))

            # Store these now so they can be saved in DVH object without needing to query later
            with DVH_SQL() as cnx:
                self.physician_count = len(
                    cnx.get_unique_values(
                        'Plans', 'physician',
                        "study_instance_uid in ('%s')" % "','".join(self.uid)))
            self.total_fxs = self.get_plan_values('fxs')
            self.fx_dose = self.get_rx_values('fx_dose')
        else:
            self.count = 0