Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. import sqlite3, hashlib
  2.  
  3. def login(cursor):
  4.  
  5. indicator = True
  6.  
  7. while indicator:
  8.  
  9. username = raw_input("Input username >")
  10. password = hashlib.sha224(raw_input("Input password >")).hexdigest()
  11.  
  12. cursor.execute('''
  13. SELECT role
  14. FROM staff
  15. WHERE login = ?
  16. AND password = ?;
  17. ''', (username, password, ))
  18.  
  19. result = cursor.fetchall()
  20.  
  21. if not result:
  22. print "Invalid login"
  23. else:
  24. break
  25.  
  26. return result[0][0]
  27.  
  28. def adminMenu(cursor):
  29.  
  30. choice = int(raw_input('''Type integer of desired task\n
  31. 1. Perform task 1\n
  32. 2. Perform task 2\n
  33. 3. Perform task 3\n
  34. 4. Perform task 4\n
  35. 5. Log out\n'''))
  36.  
  37. if choice == 1:
  38. print "Specify time periods in YYYY-MM-DD"
  39. start_time = raw_input("Specify starting time >")
  40. end_time = raw_input("Specify ending time >")
  41.  
  42. cursor.execute('''
  43. SELECT s.name, m.drug_name, sum(m.amount * (julianday(m.end_med) - julianday(m.start_med)))
  44. FROM medications m, staff s
  45. WHERE s.staff_id = m.staff_id
  46. AND julianday(m.start_med) > julianday(?)
  47. AND julianday(m.end_med) < julianday(?)
  48. GROUP BY s.name, m.drug_name;''', (start_time, end_time,))
  49. rows = cursor.fetchall()
  50. print rows
  51.  
  52. elif choice == 2:
  53. pass
  54. elif choice == 3:
  55. pass
  56. elif choice == 4:
  57. pass
  58. else:
  59. #logout
  60. pass
  61.  
  62. def doctorMenu(cursor):
  63. pass
  64.  
  65. def nurseMenu(cursor):
  66. choice = int(raw_input('''Type integer of desired task\n
  67. 1. Create a new chart for a patient\n
  68. 2. Close the chart when the patient leaves the hospital\n
  69. 3. For a given patient, list all charts in the system.\n
  70. 4. For a given patient and an open chart of the patient add an entry for symptoms\n
  71. 5. Log out\n'''))
  72. if choice == 1:
  73. patient_hcno = raw_input("The patient's hcno >")
  74. cursor.execute('''SELECT *
  75. FROM patients
  76. WHERE patients.hcno =:phcno''',{"phcno":patient_hcno})
  77. data = cursor.fetchall()
  78. if len(data) == 0:
  79. #the patient not exists
  80. print "The patient is a newcomer. Please create a new patient firstly."
  81. p_name = raw_input("The patient's name >")
  82. p_age_group = raw_input("The patient's age_group >")
  83. p_address = raw_input("The patient's address >")
  84. p_phone = raw_input("The patient's phone >")
  85. p_emg_phone = raw_input("The patient's emg_phone >")
  86. cursor.execute('''INSERT INTO patients
  87. VALUES (?,?,?,?,?,?)
  88. ''',(patient_hcno,p_name,p_age_group,p_address,p_phone,p_emg_phone))
  89. conn.commit()
  90.  
  91. print "Create a new chart for a patient."
  92. p_chart_id = raw_input("The chart's id >")
  93. p_adate = raw_input("The current date and time >")
  94. cursor.execute('''INSERT INTO charts
  95. VALUES (?,?,?,NULL)
  96. ''',(p_chart_id,patient_hcno,p_adate))
  97. conn.commit()
  98. nurseMenu(cursor)
  99.  
  100.  
  101. elif choice == 2:
  102. print "Close a patient's chart when he leaves."
  103. p_hcno = raw_input("The hcno of the leaving patient >")
  104. p_edate = raw_input("The leaving date of the patient >")
  105. cursor.execute('''UPDATE charts
  106. SET edate = :p_e
  107. WHERE hcno = :p_h''',{"p_e": p_edate,"p_h":p_hcno})
  108. conn.commit()
  109. nurseMenu(cursor)
  110. elif choice == 3:
  111. pass
  112. elif choice ==4:
  113. pass
  114. else:
  115. login(cursor);
  116.  
  117. if __name__ == "__main__":
  118.  
  119. conn = sqlite3.connect('hospital.db')
  120. cursor = conn.cursor()
  121.  
  122. role = login(cursor)
  123.  
  124. if role == 'D':
  125. print "doctor"
  126. elif role == 'N':
  127. print "nurse"
  128. nurseMenu(cursor);
  129. elif role == 'A':
  130. print "admin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement