def margin_info(self): specimen_resection_size = input('Size of specimen (resection size): ') margins = ask.check_number_input( 'Please input number of resection margin sizes to be entered: ', 'Please only input number of margins not type') margin_size_df = pd.DataFrame(columns=['margin', 'size']) if margins != '0': for margin in range(0, int(margins)): margin_name = input('Name of margin: ') margin_distance = input('Margin Size: ') margin_size_df.loc[margin] = [margin_name, margin_distance] margin_size_df['margin_size_name'] = margin_size_df[ 'margin'].str.cat(margin_size_df['size'], sep=": ") margin_size = '|'.join(list(margin_size_df['margin_size_name'])) else: margin_size = 'no_margins_described' cut_margins = ask.check_number_input( 'Please input number of cut (shave) margin sizes to be entered: ', 'Please only input number of margins not type') cut_margin_size_df = pd.DataFrame(columns=['cut_margin', 'size']) if cut_margins != '0': for cut_margin in range(0, int(cut_margins)): cut_margin_name = input('Name of cut_margin: ') cut_margin_distance = input('Cut Margin dimensions: ') cut_margin_size_df.loc[cut_margin] = [ cut_margin_name, cut_margin_distance ] cut_margin_size_df['cut_margin_size_name'] = cut_margin_size_df[ 'cut_margin'].str.cat(cut_margin_size_df['size'], sep=": ") cut_margin_size = '|'.join( list(cut_margin_size_df['cut_margin_size_name'])) else: cut_margin_size = 'cut_margins_not_present' margin_report = input( 'Please input description of margins (involved/free/unremarkable etc as given in the report: ' ) return specimen_resection_size, margin_size, cut_margin_size, margin_report
def usg_mass(self, mass_id): print(self.table, mass_id) check = False data_list = ask.default_data_list(self.col_list) while not check: mass_location = self.mammo_breast if self.mammo_breast == "bilateral": mass_location = ask.ask_option("Location of mass " + str(mass_id), RadioTables.breast) location_clock = ask.check_number_input("What is the clock" "position of mass " + str(mass_id) + "?", 'Please enter only numbers' ' additional paramters ' 'can be entered ' 'next') location_add = input('Additional parameters for clock position') location_clock = location_clock + location_add + " o'clock" mass_quadrant = 'data_not_available' quad = ask.ask_y_n('Is the quadrant location given?') if quad: mass_quadrant = ask.ask_list('what is the quadrant location', Radio.lesion_quadrant) mass_shape = ask.ask_list("Shape of mass " + str(mass_id), RadioTables.mass_shape) mass_name = "lesion_" + str(mass_id) mass_dimension, mass_size_unit, mass_longest_dimension = self.lesion_size() mass_margin = ask.ask_option("Margin of mass " + str(mass_id), RadioTables.mass_margin_usg) mass_echo = ask.ask_option("Echo pattern of mass " + str(mass_id), RadioTables.mass_echo) mass_id = "Mass " + str(mass_id) modality = self.table data_list = [self.file_number, mass_name, mass_location, location_clock, mass_quadrant, mass_shape, mass_margin, mass_echo, mass_dimension, mass_longest_dimension, mass_size_unit, modality] check = sql.review_input(self.file_number, columns=self.col_list, data=data_list) data_list = data_list + [self.user_name, sql.last_update()] return data_list
def update_block_id(self, file_number, block_type): block_df = self.block_data pk = uuid.uuid4().hex data_list = self.columns check = False while not check: patient_name = sql.get_value_no_error(col_name='patient_name', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) mr_number = sql.get_value_no_error(col_name='mr_number', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) date_of_birth = sql.get_value_no_error(col_name='date_of_birth', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) date_first_visit = sql.get_value_no_error( col_name='date_first_visit', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) block_sr_number = sql.get_value_no_error( col_name='block_sr_number', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) block_location = sql.get_value_no_error(col_name='block_location', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) blocks_received_at_pccm = sql.get_value_no_error( col_name='blocks_received_at_pccm', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) consent_discussed = sql.get_value_no_error( col_name='consent_discussed', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) consent = sql.get_value_no_error(col_name='consent', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) block_id = self.check_block_value_in_db( input_statement='Please enter block id: ', value_name='block_id', integer=False) if blocks_received_at_pccm == 'NA': number_of_blocks, block_series, current_block_location = [ 'NA', ] * 3 else: number_of_blocks = ask.check_number_input( 'Please enter number of blocks recieved at PCCM: ', 'Number of blocks has to be a whole number or NA') block_series = input( "Series of blocks recieved (Please enter series in the form A-B and separate " "series by '|' e.g, A-B|E): ") current_block_location = ask.ask_list( 'Current location of block', BlockList.edit_values['current_block_location']) data_list = [ pk, file_number, patient_name, mr_number, date_of_birth, date_first_visit, block_sr_number, block_location, block_type, block_id, current_block_location, blocks_received_at_pccm, number_of_blocks, block_series, str(consent_discussed), consent, self.user_name, sql.last_update() ] # print(data_list, self.columns_db) block_df.loc[pk] = data_list check, block_df = sql.review_df_row(block_df) return data_list[1:], pk
def add_block_id(self, file_number): block_df = self.block_data pk = uuid.uuid4().hex data_list = self.columns check = False while not check: check_name = False while not check_name: patient_name = input('Please enter patient name: '), print('Patient name: ' + str(patient_name)) check_name = ask.ask_y_n('Is name correct') mr_number = self.check_block_value_in_db( input_statement='Please enter MR number: ', value_name='mr_number', integer=True) date_of_birth = self.get_value_and_check_value( col_name='date_of_birth', file_number=file_number, input_statement='Please input patient date of birth ' '(format: dd.mm.yyyy): ', integer=False) date_first_visit = ask.check_date( 'Please enter date of first visit: ') block_sr_number = self.check_block_value_in_db( input_statement='Please enter block serial number: ', value_name='block_sr_number', integer=True) block_pccm = ask.ask_y_n( 'Have these blocks been recieved at PCCM?') block_location, blocks_received_at_pccm = [ 'NA', ] * 2 if block_pccm: block_location_check = False while not block_location_check: block_location = block_location_format() block_location_check = sql.check_value_not_exist( self.cursor, value_name='block_location', value=block_location, table=self.table_name) blocks_received_at_pccm = ask.check_date_or_today( 'Please enter date blocks recieved at PCCM (or ' 'today): ') consent_discussed, consent = self.get_consent(file_number) block_id = self.check_block_value_in_db( input_statement='Please enter block id: ', value_name='block_id', integer=False) block_type = ask.ask_list('Block type', ['biopsy', 'surgery']) if blocks_received_at_pccm == 'NA': number_of_blocks, block_series, current_block_location = [ 'NA', ] * 3 else: number_of_blocks = ask.check_number_input( 'Please enter number of blocks recieved at PCCM: ', 'Number of blocks has to be a whole number or NA') block_series = input( "Series of blocks recieved (Please enter series in the form A-B and separate " "series by '|' e.g, A-B|E): ") current_block_location = ask.ask_list( 'Current location of block', BlockList.edit_values['current_block_location']) data_list = [ pk, file_number, patient_name, mr_number, date_of_birth, date_first_visit, block_sr_number, block_location, block_type, block_id, current_block_location, blocks_received_at_pccm, number_of_blocks, block_series, str(consent_discussed), consent, self.user_name, sql.last_update() ] block_df.loc[pk] = data_list check, block_df = sql.review_df_row(block_df) return data_list[1:], pk
def cal_table(file_number, mammo_breast): import helper_function.pccm_names as pccm_names table = "calcification_mammography" mass_number = ask.check_number_input("Number of groups of calcifications" " detected? ", error='Please enter' 'number of calcification groups' 'detected only') try: number_calc = int(mass_number) except ValueError: number_calc = 1 location, calc_type, calicification_comments = [list([]) for _ in range(3)] for index in range(0, number_calc): check = False while not check: mass_id = index + 1 if mammo_breast == "Bilateral": mass_location = ask.ask_option("Location of calcification" "group " + str(mass_id), ["Right Breast", "Left Breast"]) else: mass_location = mammo_breast location.append(mass_location) mammo_calcification = ask.ask_option("Calcification Type ", ["Skin", "Vascular", "Coarse or 'Popcorn-like'", "Large Rod-like", "Round and punctate", "Eggshell or Rim", "Dystrophic", "Suture", "Amorphous", "Coarse Heterogeneous", "Fine Pleomorphic", "Fine Linear or" "Fine Linear Branching", "Other"]) calc_type.append(mammo_calcification) mass_id = "Group " + str(index + 1) comment = input('Additional comments for calcification: ') calicification_comments.append(comment) data_list = [file_number, mass_id, str(mass_location), mammo_calcification, comment] col_list = pccm_names.names_radio_mass(table) check = sql.review_input(file_number, col_list, data_list) all_data = [[str(mass_number)], location, calc_type, calicification_comments] data_return = ask.join_lists(all_data, "; ") return tuple(data_return) @staticmethod def lesion_size(): mass_size = ask.check_size_input("Mass dimensions (without unit): ") mass_size_unit = 'NA' if mass_size != 'NA': mass_size_unit = ask.ask_list("Mass dimensions unit: ", RadioTables.mass_units) mass_name = "lesion_" + str(mass_id) mass_dimension, mass_longest_dimension = mass_size mass_longest_dimension = ask.convert_mm_to_cm( mass_longest_dimension, mass_size_unit) return mass_size, mass_size_unit, mass_longest_dimension
def update_patient(self, file_number, block_id): block_df = self.block_data check = False while not check: print('update_patient') pk = uuid.uuid4().hex patient_name = self.get_value_and_check_value( col_name='patient_name', file_number=file_number, input_statement='Please enter patient name: ', integer=False) block_sr_number = self.get_value_and_check_value( col_name='block_sr_number', file_number=file_number, input_statement='Please enter block serial number: ', integer=True) if block_sr_number != 'block_not_available': block_location_check = sql.get_value_no_error( 'block_location', self.table_name, file_number, 'file_number', self.cursor) block_location = block_location_check print('block_location: ' + str(block_location)) block_location_check = ask.ask_y_n('Is this correct?') while not block_location_check: block_location = block_location_format() block_location_check = self.check_block_value_not_exist( value_name='block_location', value=block_location, table=self.table_name) blocks_received_at_pccm = sql.check_db_value( col_name='blocks_received_at_pccm', table=self.table_name, file_number=file_number, cursor=self.cursor, error_statement='Please enter date blocks recieved at PCCM' ' (dd.mm.yyyy): ') block_type = ask.ask_list('Block type', ['biopsy', 'surgery']) if block_id == 'block_id': block_id = self.check_block_value_in_db( input_statement='Please enter block id: ', value_name='block_id', integer=False) number_of_blocks = ask.check_number_input( 'Please enter number of blocks recieved at PCCM: ', 'Number of blocks has to be a whole number or NA') block_series = input( "Series of blocks recieved (Please separate series by ';'): " ) current_block_location = ask.ask_list( 'Current location of block', names.block_list('location')) consent_discussed, consent = self.get_consent(file_number) else: block_type = ask.ask_list('Block type', ['biopsy', 'surgery']) if block_id == 'block_id': block_id = self.check_block_value_in_db( input_statement='Please enter block id: ', value_name='block_id', integer=False) block_location, blocks_received_at_pccm, number_of_blocks, block_series, current_block_location, \ consent_discussed, consent = (block_sr_number, )*7 data_list = [ pk, file_number, patient_name, block_sr_number, block_location, block_type, block_id, current_block_location, blocks_received_at_pccm, number_of_blocks, block_series, consent_discussed, consent, self.user_name, sql.last_update() ] block_df.loc[pk] = data_list check, block_df = sql.review_df_row(block_df) print("error check in update_patient") sql.print_df(block_df) return block_df
def add_update_patient(self): block_df = self.block_data file_number = 'test' check_file = False while not check_file: print('add_update_patient') file_number = input("Enter File Number: ") print("File Number: " + file_number) check_file = ask.ask_y_n("Is this file number correct") check = False while not check: if sql.check_file_number_exist(self.cursor, file_number, self.table_name): print('add_update_patient_not_checck') pk = uuid.uuid4().hex patient_name = self.get_value_and_check_value( col_name='patient_name', file_number=file_number, input_statement='Please enter patient name: ', integer=False) block_sr_number = self.get_value_and_check_value( col_name='block_sr_number', file_number=file_number, input_statement='Please enter block serial number: ', integer=True) # block_location = 'block_location' block_location_check = sql.get_value_no_error( col_name='block_location', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) if not block_location_check: print( 'Block location already exists for another file_number' ) while not block_location_check: block_location = block_location_format() block_location_check = sql.check_value_not_exist( self.cursor, value_name='block_location', value=block_location, table=self.table_name) else: block_location = block_location_check blocks_received_at_pccm = sql.get_value_no_error( col_name='blocks_received_at_pccm', table=self.table_name, pk=file_number, pk_name='file_number', cursor=self.cursor) if not blocks_received_at_pccm: blocks_received_at_pccm = ask.check_date_or_today( 'Please enter date blocks recieved at PCCM (or ' 'today): ') consent_discussed, consent = self.get_consent(file_number) else: pk = uuid.uuid4().hex patient_name = input('Please enter patient name: ') block_sr_number = self.check_block_value_in_db( input_statement='Please enter block serial number: ', value_name='block_sr_number', integer=True) block_pccm = ask.ask_y_n( 'Have these blocks been recieved at PCCM?') block_location, blocks_received_at_pccm = [ 'NA', ] * 2 if block_pccm: block_location_check = False while not block_location_check: block_location = block_location_format() block_location_check = sql.check_value_not_exist( self.cursor, value_name='block_location', value=block_location, table=self.table_name) blocks_received_at_pccm = ask.check_date_or_today( 'Please enter date blocks recieved at PCCM (or ' 'today): ') consent_discussed, consent = self.get_consent(file_number) block_type = ask.ask_list('Block type', ['biopsy', 'surgery']) block_id = self.check_block_value_in_db( input_statement='Please enter block id: ', value_name='block_id', integer=False) number_of_blocks = ask.check_number_input( 'Please enter number of blocks recieved at PCCM: ', 'Number of blocks has to be a whole number or NA') block_series = input( "Series of blocks recieved (Please separate series by ';'): ") current_block_location = ask.ask_list('Current location of block', names.block_list('location')) data_list = [ pk, file_number, patient_name, block_sr_number, block_location, block_type, block_id, current_block_location, blocks_received_at_pccm, number_of_blocks, block_series, str(consent_discussed), consent, self.user_name, sql.last_update() ] # error check print("error check in loop 1") sql.print_df(block_df) block_df.loc[pk] = data_list print("error check in loop 2") sql.print_df(block_df) check, block_df = sql.review_df_row(block_df) # error check print("error check out of loop_to_db") sql.print_df(block_df) return block_df
def chemotherapy(file_number, user_name): col_drug = names("chemo_drug_table") drug_table = pd.DataFrame(columns=col_drug) col_tox = names('chemo_tox_table') toxicity = pd.DataFrame(columns=col_tox) data_list = [ 'data_to_be_entered', ] * 27 + [user_name, sql.last_update()] check = False while not check: chemo = ask.ask_y_n_na( "Has adjuvant chemotherapy been done for the patient?") if chemo == 'Yes': place_chemo = ask.ask_y_n_na( "Has Adjuvant Chemotherapy been done at PCCM?", "At PCCM", "Outside", "Not Certain, requires follow-up") details_chemo = ask.ask_y_n( "Are Adjuvant Chemotherapy details available?", "Details Available", "Follow-up required") chemo = "act_given" if details_chemo == "Follow-up required": plan_chemo, date_start_chemo, cyc_number, drug_cyc, drug_doses, drug_units, tox_type, tox_grade, \ tox_treat, tox_response, tox_cycle, change_tox,chemo_response_by, chemo_response, chemo_size, \ chemo_size_date, trast_chemo, trast_regime, trast_courses,date_complete, reason_incomplete, \ hormone_therapy, therapy_type, therapy_duration, therapy_side, ovary_status, patient_wt, drug_freq\ = (details_chemo,)*28 elif details_chemo == "Details Available": plan_chemo = input( "What is the plan of Adjuvant Chemotherapy (for eg., " "4 cycles AC followed by 12 cycles Paclitaxel):") date_start_chemo = ask.check_date( "Date of starting Adjuvant Chemotherapy: ") patient_wt = ask.check_number_input( "Weight of patient at start of therapy (in kgs): ", 'Weight must ' 'be a number') check_wt = ask.ask_y_n( "Is weight at any other time point mentioned in report?") while check_wt: other_wt = input("Time point at which weight mentioned: ") other_wt = other_wt + " " + input("Weight of patient at " + other_wt + ": ") patient_wt = patient_wt + "; " + other_wt check_wt = ask.ask_y_n( "Is weight at any other time point mentioned in report " "(with date, if given)?") drug_table = drug_table_enter(file_number, drug_table) data_drug = col_drug[1:] data_drug_list = [] for index in data_drug: data_drug = "; ".join(list(drug_table.loc[:, index])) data_drug_list.append(data_drug) drug_cyc, cyc_number, drug_freq, drug_doses, drug_units = data_drug_list toxicity = tox_table(file_number, drug_cyc, toxicity) columns = col_tox tox_details = [] for column in columns: tox_detail = toxicity.loc[:, column].drop_duplicates() tox_details.append(list(tox_detail)) tox_details = ask.join_lists(tox_details, "; ") file_number_tox, drug_tox, tox_type, tox_grade, tox_treat, tox_response, tox_cycle, change_tox \ = tox_details trast_chemo = ask.ask_y_n("Trastuzumab used?") if trast_chemo: trast_regime = ask.ask_option("Trastuzumab use was", ["Sequential", "Concurrent"]) trast_chemo = "Trastuzumab used" trast_courses = ask.check_number_input( "Number of courses of trastuzumab/herceptin taken: ", 'Enter number only') else: trast_chemo, trast_regime, trast_courses, therapy_side = ( "Trastuzumab not used", ) * 4 date_complete = ask.check_date( "Date of completion of Adjuvant Chemotherapy: ") complete_chemo = ask.ask_y_n( "Was Adjuvant Chemotherapy completed as per schedule?") if complete_chemo: reason_incomplete = "Adjuvant Chemotherapy completed as per schedule" else: reason_incomplete = ask.ask_option( "Reason for discontinuation", [ "Toxicity", "Reluctance of patient", "Progression on chemotherapy", "Advised by treating doctor", "Death due to toxicity", "Death due to progressive disease", "Preferred treatment at another centre", "Death due to unrelated cause", "Patient was unable to afford treatment" ]) reason_incomplete = "Adjuvant Chemotherapy incomplete: " + reason_incomplete menopause = ask.ask_option("Menopausal Status", [ "Pre-menopausal", "Peri-menopausal", "Post-Menopausal", "Other" ]) if menopause in {"Pre-menopausal", "Peri-menopausal"}: ovary_status = ask.ask_option( "Status of ovarian function after Chemotherapy", [ "Menses ongoing", "Amenorrhoea on Chemo", "Amenorrhoea post Chemotherapy" ]) else: ovary_status = menopause #hormone_therapy, therapy_type, therapy_duration, therapy_side = hormone_therapy_chemo() hormone_therapy, therapy_type, therapy_duration, therapy_side = ( 'NA', ) * 4 else: plan_chemo, date_start_chemo, cyc_number, drug_cyc, drug_doses, drug_units, drug_freq,tox_type, \ tox_grade, tox_treat, tox_response, tox_cycle, change_tox,chemo_response_by, chemo_response, \ chemo_size, chemo_size_date, trast_chemo, trast_regime, trast_courses, hormone_therapy, therapy_type, \ therapy_duration, therapy_side, date_complete, reason_incomplete,ovary_status, patient_wt \ = (details_chemo,)*28 elif chemo == 'No': place_chemo, plan_chemo, date_start_chemo, cyc_number, drug_cyc, drug_doses, drug_units, \ drug_freq,tox_type, tox_grade, tox_treat, tox_response, tox_cycle, change_tox, chemo_response_by, \ chemo_response, chemo_size, chemo_size_date, trast_chemo, trast_regime, trast_courses, hormone_therapy, \ therapy_type, therapy_duration, therapy_side, date_complete, reason_incomplete, details_chemo, chemo, \ ovary_status, patient_wt = ("Adjuvant Chemotherapy not given",)*31 else: place_chemo, plan_chemo, date_start_chemo, cyc_number, drug_cyc, drug_doses, drug_units, drug_freq, \ tox_type, tox_grade, tox_treat, tox_response, tox_cycle, change_tox, chemo_response_by, chemo_response, \ chemo_size, chemo_size_date, trast_chemo, trast_regime, trast_courses, hormone_therapy, therapy_type, \ therapy_duration,ovary_status, therapy_side, date_complete, reason_incomplete, details_chemo, patient_wt \ = (chemo,)*30 data_list = [ chemo, place_chemo, details_chemo, plan_chemo, date_start_chemo, patient_wt, drug_cyc, cyc_number, drug_freq, drug_doses, drug_units, tox_type, tox_grade, tox_treat, tox_response, tox_cycle, change_tox, reason_incomplete, date_complete, trast_chemo, trast_regime, trast_courses, ovary_status, hormone_therapy, therapy_type, therapy_duration, therapy_side, user_name, sql.last_update() ] col_list = names("adjuvant_chemotherapy") check = sql.review_input(file_number, col_list, data_list) return data_list, drug_table, toxicity