yougandar commited on
Commit
20d5351
·
verified ·
1 Parent(s): bdb1b2b

Update connect_doctor.py

Browse files
Files changed (1) hide show
  1. connect_doctor.py +18 -7
connect_doctor.py CHANGED
@@ -39,15 +39,15 @@ def handle_connection(patient_id):
39
  """Generate connection link based on the assigned doctor and confirm appointment."""
40
  patient_name = get_patient_details(patient_id)
41
  if patient_name in ["Patient ID not found", "Patients file not found."]:
42
- return f"Error: {patient_name}", ""
43
 
44
  doctor_name = get_assigned_doctor(patient_id)
45
  if doctor_name in ["Doctor not found for this Patient ID.", "No appointments found."]:
46
- return f"Error: {doctor_name}", ""
47
 
48
  connection_link = generate_jitsi_link(doctor_name)
49
 
50
- return f"Connecting {patient_name} with {doctor_name}.", connection_link
51
 
52
  def generate_jitsi_link(doctor_name):
53
  """Generate a Jitsi link to connect to the selected doctor."""
@@ -71,6 +71,7 @@ def create_gradio_interface():
71
 
72
  doctor_name_output = gr.Textbox(label="Assigned Doctor", placeholder="Doctor will auto-populate", interactive=False)
73
  connect_button = gr.Button("Connect to Doctor")
 
74
  connection_text = gr.Markdown("Connection Link will appear here")
75
  connection_iframe = gr.HTML() # To display the iframe
76
 
@@ -88,17 +89,27 @@ def create_gradio_interface():
88
 
89
  # Action to connect to doctor
90
  def connect_to_doctor(patient_id):
91
- message, connection_link = handle_connection(patient_id)
92
  if connection_link:
93
  iframe_html = f'<iframe src="{connection_link}" width="800" height="600" allow="camera; microphone; fullscreen; display-capture" style="border:none;"></iframe>'
94
- return message, iframe_html
95
  else:
96
- return message, ""
 
 
 
 
97
 
98
  connect_button.click(
99
  fn=connect_to_doctor,
100
  inputs=patient_id_input,
101
- outputs=[connection_text, connection_iframe]
 
 
 
 
 
 
102
  )
103
 
104
  return demo
 
39
  """Generate connection link based on the assigned doctor and confirm appointment."""
40
  patient_name = get_patient_details(patient_id)
41
  if patient_name in ["Patient ID not found", "Patients file not found."]:
42
+ return f"Error: {patient_name}", "", ""
43
 
44
  doctor_name = get_assigned_doctor(patient_id)
45
  if doctor_name in ["Doctor not found for this Patient ID.", "No appointments found."]:
46
+ return f"Error: {doctor_name}", "", ""
47
 
48
  connection_link = generate_jitsi_link(doctor_name)
49
 
50
+ return f"Connecting {patient_name} with {doctor_name}.", connection_link, doctor_name
51
 
52
  def generate_jitsi_link(doctor_name):
53
  """Generate a Jitsi link to connect to the selected doctor."""
 
71
 
72
  doctor_name_output = gr.Textbox(label="Assigned Doctor", placeholder="Doctor will auto-populate", interactive=False)
73
  connect_button = gr.Button("Connect to Doctor")
74
+ disconnect_button = gr.Button("Disconnect")
75
  connection_text = gr.Markdown("Connection Link will appear here")
76
  connection_iframe = gr.HTML() # To display the iframe
77
 
 
89
 
90
  # Action to connect to doctor
91
  def connect_to_doctor(patient_id):
92
+ message, connection_link, doctor_name = handle_connection(patient_id)
93
  if connection_link:
94
  iframe_html = f'<iframe src="{connection_link}" width="800" height="600" allow="camera; microphone; fullscreen; display-capture" style="border:none;"></iframe>'
95
+ return message, iframe_html, gr.update(visible=True), gr.update(visible=False)
96
  else:
97
+ return message, "", gr.update(visible=False), gr.update(visible=True)
98
+
99
+ # Action to disconnect
100
+ def disconnect_meeting():
101
+ return "", "", gr.update(visible=False), gr.update(visible=True)
102
 
103
  connect_button.click(
104
  fn=connect_to_doctor,
105
  inputs=patient_id_input,
106
+ outputs=[connection_text, connection_iframe, disconnect_button, connect_button]
107
+ )
108
+
109
+ disconnect_button.click(
110
+ fn=disconnect_meeting,
111
+ inputs=[],
112
+ outputs=[connection_text, connection_iframe, disconnect_button, connect_button]
113
  )
114
 
115
  return demo