Ingen beskrivning

enfermeriaver.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # coding=utf-8
  2. # from sqlalchemy import metadata
  3. import sqlalchemy as db
  4. # connect to server
  5. engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
  6. connection = engine.connect()
  7. # estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
  8. # usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
  9. def visitas():
  10. query ='SELECT t1.id, t2.nombres e_nombre, t2.apellidos e_apellido,\
  11. t1.nombres p_nombre, t1.apellidos p_apellido, t1.razon, t1.acciones\
  12. FROM (SELECT v.id, u.nombres, u.apellidos,v.razon, v.acciones\
  13. FROM visitas_enfermeria v, usuarios u\
  14. WHERE v.estudiante_id = u.id) t1,\
  15. (SELECT v.id, u.nombres, u.apellidos\
  16. FROM visitas_enfermeria v, usuarios u\
  17. WHERE v.enfermera_id = u.id) t2\
  18. WHERE t1.id=t2.id'
  19. result_db = connection.execute(query).fetchall()
  20. ###### headers
  21. headers = '['
  22. headers += '{"nombre":"Nombre Enfermera"}'
  23. headers += ','
  24. headers += '{"nombre":"Nombre Estudiante"}'
  25. headers += ','
  26. headers += '{"nombre":"Razon"}'
  27. headers += ','
  28. headers += '{"nombre":"Informacion"}'
  29. headers += ','
  30. headers += '{"nombre":"Editar"}'
  31. headers += ']'
  32. ###### tabla
  33. modal_content = '['
  34. tabla = '['
  35. i = 0
  36. len_result = len(result_db)
  37. for q in result_db:
  38. i = i+1
  39. tabla += '{'
  40. modal_content += '{'
  41. tabla += '"Nombre Enfermera":"'+(q[1])+' '+(q[2])+'"'
  42. modal_content += '"Nombre Enfermera":"'+(q[1])+' '+(q[2])+'"'
  43. tabla += ','
  44. modal_content += ','
  45. tabla += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"'
  46. modal_content += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"'
  47. tabla += ','
  48. modal_content += ','
  49. tabla += '"Razon":"'+(q[5])+'"'
  50. modal_content += '"Razon":"'+(q[5])+'"'
  51. modal_content += ','
  52. modal_content += '"Explicación":"'+(q[6])+'"'
  53. tabla += ','
  54. modal_content += ','
  55. tabla += '"user_id":"'+str(q[0])+'"'
  56. modal_content += '"user_id":"'+str(q[0])+'"'
  57. tabla += '}'
  58. modal_content += '}'
  59. if i < len_result:
  60. tabla += ','
  61. modal_content+= ','
  62. tabla += ']'
  63. modal_content += ']'
  64. ###### info
  65. info = '{'
  66. info += '"dash_name":"Enfermeria- Manejar Visitas"'
  67. info += ','
  68. info += '"dash_link":"/enfermeria/ver/"'
  69. info += ','
  70. info += '"dash_sub_name":"Visitas hechas"'
  71. info += ','
  72. info += '"add":"Anadir Visita"'
  73. info += ','
  74. info += '"add_link":"/enfermeria/forma/add/visitas_enfermeria/"'
  75. info += ','
  76. info += '"dir1":"#"'
  77. info += ','
  78. info += '"dir2":"/enfermeria/forma/edit/visitas_enfermeria/"'
  79. info += '}'
  80. ###### modal
  81. modal = '{'
  82. modal += '"infoName":"Ver informacion"'
  83. modal += ','
  84. modal += '"editName":"#"'
  85. modal += '}'
  86. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  87. # print(result)
  88. return(result)