Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3, hashlib
- def login(cursor):
- indicator = True
- while indicator:
- username = raw_input("Input username >")
- password = hashlib.sha224(raw_input("Input password >")).hexdigest()
- cursor.execute('''
- SELECT role
- FROM staff
- WHERE login = ?
- AND password = ?;
- ''', (username, password, ))
- result = cursor.fetchall()
- if not result:
- print "Invalid login"
- else:
- break
- return result[0][0]
- def adminMenu(cursor):
- choice = int(raw_input('''Type integer of desired task\n
- 1. Perform task 1\n
- 2. Perform task 2\n
- 3. Perform task 3\n
- 4. Perform task 4\n
- 5. Log out\n'''))
- if choice == 1:
- print "Specify time periods in YYYY-MM-DD"
- start_time = raw_input("Specify starting time >")
- end_time = raw_input("Specify ending time >")
- cursor.execute('''
- SELECT s.name, m.drug_name, sum(m.amount * (julianday(m.end_med) - julianday(m.start_med)))
- FROM medications m, staff s
- WHERE s.staff_id = m.staff_id
- AND julianday(m.start_med) > julianday(?)
- AND julianday(m.end_med) < julianday(?)
- GROUP BY s.name, m.drug_name;''', (start_time, end_time,))
- rows = cursor.fetchall()
- print rows
- elif choice == 2:
- pass
- elif choice == 3:
- pass
- elif choice == 4:
- pass
- else:
- #logout
- pass
- def doctorMenu(cursor):
- pass
- def nurseMenu(cursor):
- choice = int(raw_input('''Type integer of desired task\n
- 1. Create a new chart for a patient\n
- 2. Close the chart when the patient leaves the hospital\n
- 3. For a given patient, list all charts in the system.\n
- 4. For a given patient and an open chart of the patient add an entry for symptoms\n
- 5. Log out\n'''))
- if choice == 1:
- patient_hcno = raw_input("The patient's hcno >")
- cursor.execute('''SELECT *
- FROM patients
- WHERE patients.hcno =:phcno''',{"phcno":patient_hcno})
- data = cursor.fetchall()
- if len(data) == 0:
- #the patient not exists
- print "The patient is a newcomer. Please create a new patient firstly."
- p_name = raw_input("The patient's name >")
- p_age_group = raw_input("The patient's age_group >")
- p_address = raw_input("The patient's address >")
- p_phone = raw_input("The patient's phone >")
- p_emg_phone = raw_input("The patient's emg_phone >")
- cursor.execute('''INSERT INTO patients
- VALUES (?,?,?,?,?,?)
- ''',(patient_hcno,p_name,p_age_group,p_address,p_phone,p_emg_phone))
- conn.commit()
- print "Create a new chart for a patient."
- p_chart_id = raw_input("The chart's id >")
- p_adate = raw_input("The current date and time >")
- cursor.execute('''INSERT INTO charts
- VALUES (?,?,?,NULL)
- ''',(p_chart_id,patient_hcno,p_adate))
- conn.commit()
- nurseMenu(cursor)
- elif choice == 2:
- print "Close a patient's chart when he leaves."
- p_hcno = raw_input("The hcno of the leaving patient >")
- p_edate = raw_input("The leaving date of the patient >")
- cursor.execute('''UPDATE charts
- SET edate = :p_e
- WHERE hcno = :p_h''',{"p_e": p_edate,"p_h":p_hcno})
- conn.commit()
- nurseMenu(cursor)
- elif choice == 3:
- pass
- elif choice ==4:
- pass
- else:
- login(cursor);
- if __name__ == "__main__":
- conn = sqlite3.connect('hospital.db')
- cursor = conn.cursor()
- role = login(cursor)
- if role == 'D':
- print "doctor"
- elif role == 'N':
- print "nurse"
- nurseMenu(cursor);
- elif role == 'A':
- print "admin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement