def update_ptv_data(tv, study_instance_uid): """ :param tv: treatment volume formatted as a "sets of points" object specified in tools.roi_geometry :type tv: dict :param study_instance_uid: study_instance_uid in SQL database :type study_instance_uid: str """ ptv_cross_section = roi_geom.cross_section(tv) ptv_spread = roi_geom.spread(tv) condition = "study_instance_uid = '%s' and roi_type like 'PTV%%'" % study_instance_uid with DVH_SQL() as cnx: max_dose = cnx.get_max_value('dvhs', 'max_dose', condition=condition) min_dose = cnx.get_min_value('dvhs', 'min_dose', condition=condition) ptv_data = {'ptv_cross_section_max': ptv_cross_section['max'], 'ptv_cross_section_median': ptv_cross_section['median'], 'ptv_max_dose': max_dose, 'ptv_min_dose': min_dose, 'ptv_spread_x': ptv_spread[0], 'ptv_spread_y': ptv_spread[1], 'ptv_spread_z': ptv_spread[2], 'ptv_surface_area': roi_geom.surface_area(tv, coord_type='sets_of_points'), 'ptv_volume': roi_geom.volume(tv)} for key, value in ptv_data.items(): cnx.update('Plans', key, value, "study_instance_uid = '%s'" % study_instance_uid)
def surface_area(study_instance_uid, roi_name): """ Recalculate the surface area of an roi based on data in the SQL DB. """ coordinates_string = query('dvhs', 'roi_coord_string', "study_instance_uid = '%s' and roi_name = '%s'" % (study_instance_uid, roi_name)) roi = roi_form.get_planes_from_string(coordinates_string[0][0]) data = roi_geom.surface_area(roi, coord_type="sets_of_points") update_dvhs_table(study_instance_uid, roi_name, 'surface_area', round(float(data), 2))