示例#1
0
class GUI:
    def __init__(self, database_connection):
        self.database_connection = database_connection
        self.rowNumber = -1
        self.rows = {}
        self.X = ""
        self.H = 'No'
        self.B = 'No'

        self.root = tk.Tk()
        self.root.title('')
        canvas = tk.Canvas(self.root, height=600, width=1500)
        canvas.pack()
        self.frame = tk.Frame(self.root)
        self.frame.place(relx=0, rely=0, relwidth=0.5, relheight=1)
        self.tframe = tk.Frame(self.root)
        self.tframe.place(relx=0.5, rely=0.0, relwidth=0.5, relheight=0.5)

        # table build
        self.table = TableCanvas(self.tframe,
                                 rows=2,
                                 cols=4,
                                 cellwidth=175,
                                 state="readonly")
        self.table_value = TableCanvas(self.frame,
                                       rows=2,
                                       cols=6,
                                       cellwidth=117,
                                       state="readonly")
        self.table_value.show()

        self.table.bind('<ButtonRelease-1>',
                        self.clicked)  # Bind the click release event

        self.table.model.columnlabels['1'] = "VerifiedDate"
        self.table.model.columnlabels['2'] = "Program"
        self.table.model.columnlabels['3'] = "OrdPhysician"
        self.table.model.columnlabels['4'] = "BandQ"
        self.table.show()

        self.table_value.model.columnlabels['1'] = "Total Protein"
        self.table_value.model.columnlabels['2'] = "Albumin"
        self.table_value.model.columnlabels['3'] = "Alpha1"
        self.table_value.model.columnlabels['4'] = "Alpha2"
        self.table_value.model.columnlabels['5'] = "Beta"
        self.table_value.model.columnlabels['6'] = "Gamma"

        self.hframe = tk.Frame(self.root)
        self.hframe.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.57)
        self.History = tk.Label(
            self.frame,
            text='Does this patient have a previous history?',
            font=15)
        self.History.place(relx=0.13, rely=0.22, relwidth=0.8, relheight=0.1)
        self.var1 = tk.IntVar()
        self.var1.set('no')
        self.button_Y_H = tk.Radiobutton(self.frame,
                                         text="Yes",
                                         font=8,
                                         variable=self.var1,
                                         value='yes',
                                         command=self.HY)
        self.button_N_H = tk.Radiobutton(self.frame,
                                         text="No",
                                         font=8,
                                         variable=self.var1,
                                         value='no',
                                         command=self.HN)
        self.button_Y_H.place(relx=0.35,
                              rely=0.35,
                              relwidth=0.10,
                              relheight=0.05)
        self.button_N_H.place(relx=0.55,
                              rely=0.35,
                              relwidth=0.10,
                              relheight=0.05)
        self.Band = tk.Label(
            self.frame,
            text='Is there a band present in the current study?',
            font=15)
        self.Band.place(relx=0.13, rely=0.42, relwidth=0.8, relheight=0.1)
        self.var2 = tk.IntVar()
        self.var2.set('no')
        self.button_Y_B = tk.Radiobutton(self.frame,
                                         text="Yes",
                                         font=8,
                                         variable=self.var2,
                                         value='yes',
                                         command=self.BY)
        self.button_N_B = tk.Radiobutton(self.frame,
                                         text="No",
                                         font=8,
                                         variable=self.var2,
                                         value='no',
                                         command=self.BN)
        self.button_Y_B.place(relx=0.35,
                              rely=0.53,
                              relwidth=0.10,
                              relheight=0.05)
        self.button_N_B.place(relx=0.55,
                              rely=0.53,
                              relwidth=0.10,
                              relheight=0.05)
        self.comment = tk.Text(self.frame, height=30, width=10)
        self.comment.place(relx=0.13, rely=0.60, relwidth=0.8, relheight=0.35)
        self.button_next = tk.Button(self.frame,
                                     text="Next",
                                     font=8,
                                     command=self.next_row)
        self.button_next.place(relx=0.9,
                               rely=0.22,
                               relwidth=0.1,
                               relheight=0.1)
        self.button_prev = tk.Button(self.frame,
                                     text="Previous",
                                     font=8,
                                     command=self.prev_row)
        self.button_prev.place(relx=0.06,
                               rely=0.22,
                               relwidth=0.1,
                               relheight=0.1)
        self.button_close = tk.Button(self.frame,
                                      text="Close",
                                      font=8,
                                      command=self.close)
        self.button_close.place(relx=0.473,
                                rely=0.95,
                                relwidth=0.07,
                                relheight=0.05)
        self.button_pickday = tk.Button(self.frame,
                                        text="Pick Day",
                                        font=8,
                                        command=self.pickDate)
        self.button_pickday.place(relx=0.4,
                                  rely=0.15,
                                  relwidth=0.1,
                                  relheight=0.05)
        self.history_comment = tk.Text(self.hframe, height=30, width=10)
        self.history_comment.place(relx=0.1,
                                   rely=0.1,
                                   relwidth=0.8,
                                   relheight=0.6)

        self.attending = tk.Label(self.hframe, text='', font=15)
        self.attending.place(relx=0.125,
                             rely=0.75,
                             relwidth=0.8,
                             relheight=0.1)

        self.date_label = tk.Label(self.frame, text='', font=15)
        self.date_label.place(relx=0.5,
                              rely=0.15,
                              relwidth=0.16,
                              relheight=0.05)

        # TODO default date to today's date
        default_date = '09-08-2016'
        self.update_date(default_date)

    def update_date(self, new_date):
        self.rows = database_connection.get_rows_for_date(new_date)
        self.date_label.config(text=new_date)
        self.rowNumber = 0
        self.resetTK()

    def close(self):
        self.root.destroy()

    def next_row(self):
        if self.rowNumber == len(self.rows) - 1:
            return
        self.rowNumber = self.rowNumber + 1
        self.thisRowData = self.rows[self.rowNumber]
        self.var1.set('no')
        self.var2.set('no')
        self.H = 'No'
        self.B = 'No'
        self.updateTK()

    def prev_row(self):
        if self.rowNumber == 0:
            return
        self.rowNumber = self.rowNumber - 1
        self.thisRowData = self.rows[self.rowNumber]
        self.var1.set('no')
        self.var2.set('no')
        self.H = 'No'
        self.B = 'No'
        self.updateTK()

    def resetTK(self):
        self.rowNumber = -1
        self.thisRowData = None
        self.next_row()
        self.updateTK()

    def pickDate(self):
        calendarPopupFrame = tk.Toplevel()
        calendarObject = Calendar(calendarPopupFrame, self)

    def HY(self):
        self.H = 'Yes'
        self.updateTK()

    def HN(self):
        self.H = 'No'
        self.updateTK()

    def BY(self):
        self.B = 'Yes'
        self.updateTK()

    def BN(self):
        self.B = 'No'
        self.updateTK()

    def clicked(self, event):  # Click event callback function.
        self.updateHistoryComment()

    def updateHistoryComment(self):
        currentPatientHistoryRecord = self.getCurrentPatientHistoryRecord()
        if currentPatientHistoryRecord is None:
            return

        self.attending.config(
            text=currentPatientHistoryRecord.signout_pathologist)
        self.history_comment.delete('1.0', tk.END)
        self.history_comment.insert(
            tk.END, str(currentPatientHistoryRecord.interpretation))
        self.table.redrawTable()

    def getCurrentPatientHistoryRecord(self):
        currentTableRecord = self.table.get_currentRecord()
        for ph in self.patient_history:
            if currentTableRecord['1'] == ph.get_formatted_verified_time() and \
                    currentTableRecord['2'] == ph.get_program_description() and \
                    currentTableRecord['3'] == ph.ordering_provider and \
                    currentTableRecord['4'] == ph.band_concentration:
                return ph
        return None

    def updateTK(self):
        # update button text
        self.History.config(text='Case ' + str(self.thisRowData.seq) +
                            ': Does ' + self.thisRowData.patientName +
                            ' have a previous history?')

        # update history comment and attending
        self.attending.config(text='')
        self.history_comment.delete('1.0', tk.END)
        self.history_comment.insert(tk.END, str(''))

        self.table_value.model.setValueAt(self.thisRowData.pt, 0, 0)
        self.table_value.model.setValueAt(self.thisRowData.getAbsAlbuminText(),
                                          0, 1)
        self.table_value.model.setValueAt(self.thisRowData.getAbsAlpha1Text(),
                                          0, 2)
        self.table_value.model.setValueAt(self.thisRowData.getAbsAlpha2Text(),
                                          0, 3)
        self.table_value.model.setValueAt(self.thisRowData.getAbsBetaText(), 0,
                                          4)
        self.table_value.model.setValueAt(self.thisRowData.getAbsGammaText(),
                                          0, 5)

        self.table_value.model.setValueAt(
            str(self.thisRowData.getRelAlbuminText()), 1, 1)
        self.table_value.model.setValueAt(
            str(self.thisRowData.getRelAlpha1Text()), 1, 2)
        self.table_value.model.setValueAt(
            str(self.thisRowData.getRelAlpha2Text()), 1, 3)
        self.table_value.model.setValueAt(
            str(self.thisRowData.getRelBetaText()), 1, 4)
        self.table_value.model.setValueAt(
            str(self.thisRowData.getRelGammaText()), 1, 5)

        self.table_value.redrawTable()
        # update suggested comment
        new_comment = ""
        try:
            new_comment = CommentInterpreter.CM(self.thisRowData, self.H,
                                                self.B)
        except:
            new_comment = "An error occurred when trying to create the comment"
        self.comment.delete('1.0', tk.END)
        self.comment.insert(tk.END, str(new_comment))

        # update historical table
        self.table.model.deleteRows()
        self.table.clearSelected()
        self.table.redrawTable()

        if self.thisRowData.mrn is None:
            return

        self.patient_history = database_connection.get_history(
            str(self.thisRowData.mrn))

        # add a row for each new history element
        for ph in self.patient_history:
            new_row_index = self.table.model.addRow() - 1
            self.table.model.setValueAt(ph.verified_time.strftime("%Y-%m-%d"),
                                        new_row_index, 0)
            self.table.model.setValueAt(ph.get_program_description(),
                                        new_row_index, 1)
            self.table.model.setValueAt(ph.ordering_provider, new_row_index, 2)
            self.table.model.setValueAt(ph.band_concentration, new_row_index,
                                        3)

        self.table.setSelectedRow(0)
        self.updateHistoryComment()

    def mainloop(self):
        self.root.mainloop()


ch_frame = tk.Frame(character_frame, bg='light blue')
ch_frame.place(relx=0.01, rely=0.2, relwidth=0.99, relheight=0.84)

sp_ch_frame = tk.Frame(sp_character_frame, bg='light blue')
sp_ch_frame.place(relx=0.01, rely=0.2, relwidth=0.99, relheight=0.84)

model = TableModel()
table = TableCanvas(ch_frame, model=model)
table.show()

model2 = TableModel()
table2 = TableCanvas(sp_ch_frame, model=model2, read_only=True)
table2.clearSelected()  
table2.show()


def b_show_hex():
    global font_loaded_flag
    if font_loaded_flag == False:
        print("Can't show hex value! Font is not loaded!") 
    else:
        try:
            data = table.model.data
            p_row = table.getSelectedRow()
            p_row_name = model.getRecName(p_row)
            
            p_char = str(data[p_row_name]['Character']) 
            p_char_int = ord(data[p_row_name]['Character'][0])