示例#1
0
 def edit_radio(self, table):
     col_list = names(table)
     enter = sql.view_multiple(self.conn, table, col_list, self.file_number)
     if enter == "Add data":
         self.add_radio(table)
     elif enter == "Edit data":
         sql_statement = ('SELECT ' + ", ".join(col_list) + " FROM '" +
                          table + "' WHERE file_number = '" +
                          self.file_number + "'")
         df = pd.read_sql(sql_statement, self.conn)
         sql.print_df(df)
         pk, value_row_to_edit = sql.retrieve_with_pk_to_edit(
             df,
             value_col='reason_report',
             table=table,
             cursor=self.cursor,
             pk=False)
         print('value_row_to_edit: ', value_row_to_edit)
         if not value_row_to_edit:
             sql.delete_rows(self.cursor,
                             table,
                             col_name="file_number",
                             col_data=self.file_number)
             self.add_radio(table)
         else:
             self.edit_data_pk(pk, value_row_to_edit, table)
     else:
         print('\n No edits will be made to this table\n')
示例#2
0
 def edit_data(self):
     enter = sql.view_multiple(self.conn, self.table_name,
                               self.col_list_all, self.file_number)
     if enter == "Add data":
         self.add_data()
     elif enter == "Edit data":
         col_list_all = self.col_list_all
         sql_statement = ('SELECT ' + ", ".join(col_list_all) + " FROM '" +
                          self.table_name + "' WHERE file_number = '" +
                          self.file_number + "'")
         df = pd.read_sql(sql_statement, self.conn)
         sql.print_df(df)
         pk, value_row_to_edit = sql.retrieve_with_pk_to_edit(
             df,
             value_col='pet_scan_date',
             table=self.table_name,
             cursor=self.cursor,
             pk=False)
         print('value_row_to_edit: ', value_row_to_edit)
         if not value_row_to_edit:
             sql.delete_rows(self.cursor,
                             self.table_name,
                             col_name="file_number",
                             col_data=self.file_number)
             self.add_data()
         else:
             print('edit_data_pk')
             self.edit_data_pk(pk, value_row_to_edit)
     else:
         print('\n No edits will be made to this t able\n')
示例#3
0
 def block_description(self):
     block_desc_df = pd.DataFrame(columns=self.block_desc_df_cols)
     try:
         blocks = int(self.block_no)
         print('number of blocks: ' + str(blocks))
     except ValueError:
         blocks = int(input('Number of blocks in report: '))
     if blocks == 0:
         block_desc_df.loc[blocks] = ['No blocks in report', 'NA', 'NA']
     else:
         block_id_list = self.create_block_id(blocks)
         block_desc_df = self.block_description_df(block_id_list,
                                                   block_desc_df)
         sql.print_df(block_desc_df)
         check = ask.ask_y_n("Are block descriptions correct?")
         while not check:
             to_correct = ask.ask_y_n("Correct all entries?")
             if not to_correct:
                 to_do = True
                 while to_do:
                     pk_val = 'block_reference'
                     pk = input("Enter block to change: ")
                     #index = block_id_list.index(pk)
                     #print (block_desc_df.loc[index, :])
                     # print(block_desc_df.loc[block_desc_df[pk_val] == 'foo'])
                     data = block_desc_df.loc[block_desc_df[pk_val] == pk]
                     print(data.to_string())
                     # print(block_desc_df.loc[pk])
                     # df_cols = self.block_desc_df_cols[-2]
                     col_change = ask.ask_list("Name of column to change",
                                               self.block_desc_df_cols)
                     new_val = input("Enter correct value for " +
                                     col_change + ' for ' + pk)
                     block_desc_df.loc[pk, col_change] = new_val
                     sql.print_df(block_desc_df)
                     to_do = ask.ask_y_n("Make more changes?")
                 check = True
             else:
                 block_desc_df = self.block_description_df(
                     block_id_list, block_desc_df)
                 check = ask.ask_y_n("Are block descriptions correct?")
     block_descriptions_all = self.block_description_for_db(block_desc_df)
     return block_desc_df, block_descriptions_all
def edit_table(df, pk_col, df_col, update_by):
    import sql.add_update_sql as sql
    rows = (df.shape)[0]
    for row in range(0, rows):
        print(df.iloc[row].to_string() + '\n')
    to_correct = ask_y_n("Are entries correct?")
    if not to_correct:
        print('To delete a single entry select No here and proceed')
        to_correct = ask_y_n("Re-enter entire table?")
        if to_correct:
            return to_correct, df
        else:
            change_row = True
            while change_row:
                pk_list = list(df[pk_col])
                print(pk_list)
                pk = input("Enter " + pk_col + " to change: ")
                index = pk_list.index(pk)
                to_do = True
                while to_do:
                    print(df.loc[index, :])
                    print(
                        "\nTo delete a single entry select 'file_number' column here and change file number by \n",
                        "appending (_delete) eg., 123/13 file becomes 123/13_delete\n"
                    )
                    col_change = ask_option("Name of column to change", df_col)
                    old_val = df.loc[index, col_change]
                    print(old_val + '\n')
                    new_val = input("Enter correct value for " + col_change +
                                    ' for ' + pk + ": ")
                    df.loc[index, col_change] = new_val
                    df.ix[index, 'update_by'] = update_by
                    df.ix[index, 'last_update'] = sql.last_update()
                    print(df.iloc[index].to_string() + '\n')
                    to_do = ask_y_n("Make more changes to " + pk_col + ' ' +
                                    pk + '?')
                sql.print_df(df)
                change_row = ask_y_n("Change another row?")
            to_correct = False
    return to_correct, df
示例#5
0
 def edit_data(self):
     enter = sql.view_multiple(self.conn, self.table, self.col_list,
                               self.file_number)
     if enter == "Add data":
         data = self.follow_up()
         data.to_sql(self.table, self.conn, index=False, if_exists="append")
     elif enter == "Edit data":
         col_list_all = ["file_number"] + self.col_list
         sql_statement = ('SELECT ' + ", ".join(col_list_all) + " FROM '" +
                          self.table + "' WHERE file_number = '" +
                          self.file_number + "'")
         df = pd.read_sql(sql_statement, self.conn)
         #df = df.dropna()
         # any row with None in it will be deleted.
         sql.print_df(df)
         # check_edit = False
         # while check_edit:
         check_edit, df = sql.edit_table(df,
                                         pk_col='follow_up_period',
                                         df_col=names(),
                                         update_by=self.user_name)
         if check_edit:
             sql.delete_rows(self.cursor, self.table, "file_number",
                             self.file_number)
             df = self.follow_up()
             df.to_sql(self.table,
                       self.conn,
                       index=False,
                       if_exists="append")
         else:
             sql.delete_rows(self.cursor, self.table, "file_number",
                             self.file_number)
             df.to_sql("follow_up_data",
                       self.conn,
                       index=False,
                       if_exists="append")
     else:
         print('\n No edits will be made to this t able\n')
示例#6
0
 def edit_data(self, file_number):
     print('view_multiple')
     enter = sql.view_multiple(self.conn, self.table_name, self.columns,
                               file_number)
     if enter == "Add data":
         self.add_one(file_number)
     elif enter == "Edit data":
         col_pk = ['pk'] + self.columns
         sql_statement = ('SELECT ' + ", ".join(col_pk) + " FROM '" +
                          self.table_name + "' WHERE file_number = '" +
                          file_number + "'")
         df = pd.read_sql(sql_statement, self.conn)
         sql.print_df(df)
         # check_delete = False
         # while not check_delete:
         check_delete, df = sql.edit_table(df,
                                           pk_col='block_id',
                                           df_col=self.columns[:-2],
                                           update_by=self.user_name)
         if check_delete:
             sql.delete_rows(self.cursor, self.table_name, "file_number",
                             file_number)
             data = self.add_update_patient()
             data.to_sql(self.table_name,
                         self.conn,
                         index=False,
                         if_exists="append")
         else:
             sql.delete_rows(self.cursor, self.table_name, "file_number",
                             file_number)
             df.to_sql(self.table_name,
                       self.conn,
                       index=False,
                       if_exists="append")
     else:
         print('\n No edits will be made to this table\n')
示例#7
0
    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
示例#8
0
    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