def load_xml(xml_path): """ Function that determines the full path to the XML file :param xml_path: path to the XML file (could be a relative path) :type xml_path: str :return: XML_file -> full path to the XML file to be read if it exists in the filesystem, None otherwise :rtype: str """ # Read the XML file with the identifying DICOM fields load_xml = PathMethods.resource_path(xml_path) XML_filename = load_xml.return_path() if os.path.isfile(XML_filename): XML_file = XML_filename else: XML_filepath = os.path.dirname(os.path.abspath(__file__)) XML_file = XML_filepath + "/" + XML_filename return XML_file if os.path.isfile(XML_file) else None
def initialize(self): self.frame = Frame(self.parent) self.frame.pack(expand=1, fill='both') # Insert DICAT logo on the right side of the screen load_img = PathMethods.resource_path("images/DICAT_logo.gif") imgPath = load_img.return_path() logo = PhotoImage(file=imgPath) logo_image = Label(self.frame, image=logo, bg='white') logo_image.image = logo logo_image.pack(side='left', fill='both') # Create the Welcome to DICAT text variable text = Text(self.frame, padx=40, wrap='word') scroll = Scrollbar(self.frame, command=text.yview) text.configure(yscrollcommand=scroll.set) text.tag_configure('title', font=('Verdana', 20, 'bold', 'italic'), justify='center') text.tag_configure('bold', font=('Verdana', 12, 'bold')) text.tag_configure('default', font=('Verdana', 12)) # Insert title into the text variable title = "\nWelcome to DICAT!\n\n" text.insert(END, title, 'title') # Insert introduction of the tool into the text variable intro = "DICAT (DICOM Anonymization Tool) is a simple tool for " intro += "de-identification of DICOM datasets. In addition to " intro += "de-identifying DICOM files, this tool contains a feature " intro += "that allows mapping the candidate's information to its " intro += "study identifier.\n" text.insert(END, intro, 'default') # Insert explanation of the DICOM anonymizer tab into the text variable tab1 = "\n\nThe DICOM de-identifier tab allows to:\n" text.insert(END, tab1, 'bold') anonymizer = ''' 1) select a DICOM directory 2) view the DICOM headers information 3) run the de-identifier tool on all DICOMs of the selected directory ''' text.insert(END, anonymizer, 'default') # Insert explanation of the ID key tab into the text variable tab2 = "\n\nThe ID key tab allows to:\n" text.insert(END, tab2, 'bold') IDkey = ''' 1) store ID information for a given candidate 2) look for ID information from a given candidate ''' text.insert(END, IDkey, 'default') # Display the text variable text.pack(side='left', fill='both', expand=1) scroll.pack(side="right", fill='y') # Disable the edit functionality of the displayed text text.config(state='disabled')
def deidentify(self): # clear edit table if it exists if hasattr(self, 'field_edit_win'): self.field_edit_win.destroy() # Read the XML file with the identifying DICOM fields load_xml = PathMethods.resource_path("data/fields_to_zap.xml") XML_filename = load_xml.return_path() # Remove the message from the grid self.messageView.grid_forget() if os.path.isfile(XML_filename): XML_file = XML_filename else: XML_filepath = os.path.dirname(os.path.abspath(__file__)) XML_file = XML_filepath + "/" + XML_filename field_dict = methods.grep_dicom_fields(XML_file) # Read DICOM header and grep identifying DICOM field values field_dict = methods.grep_dicom_values(self.dirname, field_dict) fields_keys = list(field_dict.keys()) keys_length = len(fields_keys) + 1 self.edited_entries = [Tkinter.StringVar() for i in range(keys_length)] if len(field_dict) != 0: self.field_edit_win = Frame(self.parent) self.field_edit_win.pack(expand=1, fill='both') self.field_edit_win.columnconfigure(0, weight=1) self.field_edit_win.columnconfigure(1, weight=1) self.field_edit_win.rowconfigure(0, weight=1) self.field_edit_win.rowconfigure(1, weight=1) # Set column names self.field_edit_win.Name_field = Tkinter.Label(self.field_edit_win, text="Dicom Field", relief="ridge", width=30, anchor="w", fg="white", bg="#282828") self.field_edit_win.Name_field.grid(column=0, row=0, padx=(5, 0), pady=(5, 0), sticky=N + S + W + E) self.field_edit_win.Name_value = Tkinter.Label( self.field_edit_win, text="Value in Dicom", relief="ridge", width=55, anchor="w", fg="white", bg="#282828") self.field_edit_win.Name_value.grid(column=1, row=0, padx=(0, 5), pady=(5, 0), sticky=N + S + W + E) # Display description of fields to zap in first column self.key_index = 1 for keys in fields_keys: self.field_edit_win.Field_label = Tkinter.Label( self.field_edit_win, text=str(field_dict[keys]['Description']) + ':', relief="ridge", width=30, anchor="w", fg="black", bg="#B0B0B0") self.field_edit_win.Field_label.grid(column=0, row=self.key_index, padx=(5, 0), sticky=N + S + W + E) # Enter value to modify if not field_dict[keys]['Editable']: # kr# var = Tkinter.StringVar() self.field_edit_win.Field = Tkinter.Entry( self.field_edit_win, textvariable=var, state="disable", width=55) if 'Value' in field_dict[keys]: var.set(field_dict[keys]['Value']) else: self.field_edit_win.Field = Tkinter.Entry( self.field_edit_win, textvariable=self.edited_entries[self.key_index], width=55) if 'Value' in field_dict[keys]: self.field_edit_win.Field.insert( self.key_index, field_dict[keys]['Value']) else: self.field_edit_win.Field.insert(self.key_index, "") self.field_edit_win.Field.grid(column=1, row=self.key_index, padx=(0, 5), sticky=N + S + W + E) self.field_edit_win.rowconfigure(self.key_index, weight=1) self.key_index += 1 self.field_dict = field_dict self.bottomPanel = Tkinter.Frame(self.field_edit_win) self.bottomPanel.grid(row=self.key_index, column=0, columnspan=2, pady=10) self.field_edit_win.button_done = Tkinter.Button( self.bottomPanel, text=u"De-identify", command=self.collect_edited_data) self.field_edit_win.button_done.grid(column=0, row=0, padx=20) self.field_edit_win.buttonClear = Tkinter.Button( self.bottomPanel, text=u"Clear", command=self.clear, width=8) self.field_edit_win.buttonClear.grid(column=1, row=0, padx=20)
def initialize(self): self.frame = Frame(self.parent) self.frame.pack(expand=1, fill='both') # Insert DICAT logo on the right side of the screen load_img = PathMethods.resource_path("images/DICAT_logo.gif") imgPath = load_img.return_path() logo = PhotoImage(file = imgPath) logo_image = Label(self.frame, image = logo, bg='white' ) logo_image.image = logo logo_image.pack(side='left', fill='both') # Create the Welcome to DICAT text variable text = Text(self.frame, padx=40, wrap='word') scroll = Scrollbar(self.frame, command=text.yview) text.configure(yscrollcommand=scroll.set) text.tag_configure('title', font=('Verdana', 20, 'bold', 'italic'), justify='center' ) text.tag_configure('bold', font=('Verdana', 12, 'bold')) text.tag_configure('default', font=('Verdana', 12)) # Insert title into the text variable title = "\nWelcome to DICAT!\n\n" text.insert(END, title, 'title') # Insert introduction of the tool into the text variable intro = "DICAT (DICOM Anonymization Tool) is a simple tool for " intro += "de-identification of DICOM datasets. In addition to " intro += "de-identifying DICOM files, this tool contains a feature " intro += "that allows mapping the candidate's information to its " intro += "study identifier.\n" text.insert(END, intro, 'default') # Insert explanation of the DICOM anonymizer tab into the text variable tab1 = "\n\nThe DICOM de-identifier tab allows to:\n" text.insert(END, tab1, 'bold') anonymizer = ''' 1) select a DICOM directory 2) view the DICOM headers information 3) run the de-identifier tool on all DICOMs of the selected directory ''' text.insert(END, anonymizer, 'default') # Insert explanation of the ID key tab into the text variable tab2 = "\n\nThe ID key tab allows to:\n" text.insert(END, tab2, 'bold') IDkey = ''' 1) store ID information for a given candidate 2) look for ID information from a given candidate ''' text.insert(END, IDkey, 'default') # Display the text variable text.pack(side='left', fill='both', expand=1) scroll.pack(side="right", fill='y') # Disable the edit functionality of the displayed text text.config(state='disabled')
def deidentify(self): # Read the XML file with the identifying DICOM fields load_xml = PathMethods.resource_path("data/fields_to_zap.xml") XML_filename = load_xml.return_path() # Remove the message from the grid self.messageView.grid_forget() if os.path.isfile(XML_filename): XML_file = XML_filename else: XML_filepath = os.path.dirname(os.path.abspath(__file__)) XML_file = XML_filepath + "/" + XML_filename field_dict = methods.grep_dicom_fields(XML_file) # Read DICOM header and grep identifying DICOM field values field_dict = methods.grep_dicom_values(self.dirname, field_dict) fields_keys = list(field_dict.keys()) keys_length = len(fields_keys) + 1 self.edited_entries = [Tkinter.StringVar() for i in range(keys_length)] if len(field_dict) != 0: self.field_edit_win = Frame(self.parent) self.field_edit_win.pack(expand=1, fill='both') self.field_edit_win.columnconfigure(0, weight=1) self.field_edit_win.columnconfigure(1, weight=1) self.field_edit_win.rowconfigure(0, weight=1) self.field_edit_win.rowconfigure(1, weight=1) # Set column names self.field_edit_win.Name_field = Tkinter.Label(self.field_edit_win, text="Dicom Field", relief="ridge", width=30, anchor="w", fg="white", bg="#282828") self.field_edit_win.Name_field.grid(column=0, row=0, padx=(5, 0), pady=(5, 0), sticky=N + S + W + E) self.field_edit_win.Name_value = Tkinter.Label( self.field_edit_win, text="Value in Dicom", relief="ridge", width=55, anchor="w", fg="white", bg="#282828") self.field_edit_win.Name_value.grid(column=1, row=0, padx=(0, 5), pady=(5, 0), sticky=N + S + W + E) # Display description of fields to zap in first column self.key_index = 1 for keys in fields_keys: self.field_edit_win.Field_label = Tkinter.Label( self.field_edit_win, text=str(field_dict[keys]['Description']) + ':', relief="ridge", width=30, anchor="w", fg="black", bg="#B0B0B0") self.field_edit_win.Field_label.grid(column=0, row=self.key_index, padx=(5, 0), sticky=N + S + W + E) # Enter value to modify if not field_dict[keys]['Editable']: # kr# var = Tkinter.StringVar() self.field_edit_win.Field = Tkinter.Entry( self.field_edit_win, textvariable=var, state="disable", width=55) if 'Value' in field_dict[keys]: var.set(field_dict[keys]['Value']) else: self.field_edit_win.Field = Tkinter.Entry( self.field_edit_win, textvariable=self.edited_entries[self.key_index], width=55) if 'Value' in field_dict[keys]: self.field_edit_win.Field.insert(self.key_index, field_dict[keys][ 'Value']) else: self.field_edit_win.Field.insert(self.key_index, "") self.field_edit_win.Field.grid(column=1, row=self.key_index, padx=(0, 5), sticky=N + S + W + E) self.field_edit_win.rowconfigure(self.key_index, weight=1) self.key_index += 1 self.field_dict = field_dict self.bottomPanel = Tkinter.Frame(self.field_edit_win) self.bottomPanel.grid(row=self.key_index, column=0, columnspan=2, pady=10) self.field_edit_win.button_done = Tkinter.Button( self.bottomPanel, text=u"De-identify", command=self.collect_edited_data) self.field_edit_win.button_done.grid(column=0, row=0, padx=20) self.field_edit_win.buttonClear = Tkinter.Button(self.bottomPanel, text=u"Clear", command=self.clear, width=8) self.field_edit_win.buttonClear.grid(column=1, row=0, padx=20)