cnn_redcap_update.updateList()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.95
c 0
b 0
f 0
cc 2
nop 0
1
from tkinter import *
2
import sqlite3
3
import pyodbc
4
from array import *
5
import time
6
import sys
7
8
from tkinter.messagebox import *
9
fenetre = Tk()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Tk does not seem to be defined.
Loading history...
10
liste = []
11
12
 # this creates x as a new label to the GUI
13
label = Label(fenetre, text="CNN/CNFUN to REDCap - Data update")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Label does not seem to be defined.
Loading history...
14
label.pack()
15
16
17
def printList():
18
    i=0
19
    db = sqlite3.connect ('cnbp_mnr.sqlite')
20
    cursor = db.cursor()
21
    cursor.execute('select cnbp, mnr from cnbpmnr')
22
23
    all_rows = cursor.fetchall()
24
    for row in all_rows:
25
    # row[0] returns the first column in the query (name), row[1] returns email column.
26
        #  print('{0} , {1}'.format(row[0], row[1]))
27
        label = Label(fenetre, text= '{0} , {1}'.format(row[0], row[1]))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Label does not seem to be defined.
Loading history...
28
        liste.append(row[1])
29
        i=i+1
30
        label.pack()
31
        cursor.close
32
        db.close
33
def updateList():
34
           label = Label(fenetre, text='Process began ..')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Label does not seem to be defined.
Loading history...
35
           # this creates x as a new label to the GUI
36
           label.pack()
37
           # Connect to the distant cnn database
38
           conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=Q:\CNN\CNN2010_DB\CNNQueryDb.mdb;' r'PWD=sqlcnn;')
39
           cursor = conn.cursor()
40
##   trouver le moyen d'executer la macro
41
           
42
           # label = Label(fenetre, text= liste[0])
43
           # label.pack()
44
           cursor.execute("select DateOfAdmission from Admission where HospitalRecordNumber=?", 2358228 )
45
           ##Draw a liste of 
46
           for row in cursor.fetchall():
47
                    print (row)
48
                    toolbar_width = 40
49
50
# setup toolbar
51
toolbar_width = 40
52
sys.stdout.write("[%s]" % (" " * toolbar_width))
53
sys.stdout.flush()
54
sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
55
56
for i in range(toolbar_width):
57
    time.sleep(0.1) # do real work here
58
    # update the bar
59
    sys.stdout.write("-")
60
    sys.stdout.flush()
61
62
sys.stdout.write("\n")
63
64
65
##Buttons
66
button = Button(fenetre, text="Study participant's list", command=printList,height = 1, width = 25) 
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Button does not seem to be defined.
Loading history...
67
button.pack()
68
button = Button(fenetre, text="Update REDCap Data", command=updateList,height = 1, width = 25) 
69
button.pack()
70
button = Button(fenetre, text="Import participant's list (csv)", command=updateList,height = 1, width = 25) 
71
button.pack()
72
button = Button(fenetre, text="Add New participant", command=updateList,height = 1, width = 25) 
73
button.pack()
74
75
76
# Make window 300x150 and place at position (50,50)
77
fenetre.geometry("500x400+350+350")
78
fenetre.title("CNN/CNFUN REDCap Data update")
79
80
81
82
83
fenetre.mainloop()
84