Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import mysql.connector
  2. import hl7
  3. import hl7apy
  4. import sys
  5. from datetime import date, datetime, timedelta
  6. from mysql.connector import errorcode , Error
  7.  
  8.  
  9. def menu_inicial():
  10. print("HL7 Manager")
  11. print("---------------")
  12. print("1 - Registar")
  13. print("2 - Alterar")
  14. print("3 - Cancelar")
  15. print("0- Sair")
  16.  
  17.  
  18. def registo():
  19. nome_utente = input('Nome:')
  20. morada = input("Morada: ")
  21. telefone = input("Telefone: ")
  22. telefone = int(telefone)
  23. nome_medico = input("Medico: ")
  24. data = input("Data: ")
  25. hora = input("Hora: ")
  26. descricao = input("Descricao: ")
  27. regista_bd(nome_utente, morada , telefone , nome_medico , data, hora , descricao)
  28. return;
  29.  
  30. def regista_bd(nome_utente, morada , telefone , nome_medico , data, hora , descricao):
  31. try:
  32. cnx = mysql.connector.connect(user='root',
  33. password='root',
  34. database='BDhospital')
  35. except mysql.connector.Error as err:
  36. if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
  37. print("Something is wrong with your user name or password")
  38. elif err.errno == errorcode.ER_BAD_DB_ERROR:
  39. print("Database does not exist")
  40. else:
  41. print(err)
  42. else:
  43. cursor = cnx.cursor()
  44. data = datetime.now()
  45. pedido = ("INSERT INTO pedido "
  46. "(utente_name, morada,telefone,nome_medico,data,hora,'0','obs',descricao,'relatorio') "
  47. "VALUES (%s, %s, %d, %s, %s, %s, %s,%s,%s)")
  48. cursor.execute(pedido)
  49. cnx.commit()
  50. print("done")
  51. cursor.close()
  52. cnx.close()
  53. return;
  54.  
  55.  
  56. def main():
  57. op=1
  58. while(op!=0):
  59. menu_inicial()
  60. op=input()
  61. if op==1 :
  62. registo()
  63.  
  64. if __name__ == "__main__":
  65. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement