varshakolanu commited on
Commit
c91e888
·
verified ·
1 Parent(s): 6b046bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -106
app.py CHANGED
@@ -240,13 +240,35 @@ calendly_client = CalendlyClient(CALENDLY_API_TOKEN)
240
  # State to store patient phone number
241
  patient_phone_state = gr.State(value=None)
242
 
243
- def register_patient(phone, email, language, consent_status):
244
- if not phone or not email or not language or not consent_status:
 
 
 
 
 
245
  return "All fields are required.", gr.State(value=None)
246
  try:
247
  patient_data = {
 
 
 
 
 
 
 
248
  "Phone__c": phone,
249
  "Email__c": email,
 
 
 
 
 
 
 
 
 
 
250
  "Language__c": language,
251
  "ConsentGiven__c": consent_status
252
  }
@@ -445,110 +467,64 @@ def escalate_case(patient_id, response_text):
445
  with gr.Blocks(theme=gr.themes.Soft(), title="AI-Powered Patient Follow-up Agent") as demo:
446
  gr.Markdown("# AI-Powered Patient Follow-up Agent for Clinics")
447
 
448
- with gr.Tab("Patient Registration"):
449
- with gr.Row():
450
- with gr.Column():
451
- name_first = gr.Textbox(label="First Name", placeholder="First Name")
452
- name_last = gr.Textbox(label="Last Name", placeholder="Last Name")
453
- with gr.Column():
454
- dob_input = gr.Textbox(label="Date of Birth", placeholder="MM-DD-YYYY")
455
- sex_input = gr.Dropdown(label="Sex", choices=["Please Select", "Male", "Female", "Other"], value="Please Select")
456
- with gr.Row():
457
- height_input = gr.Textbox(label="Height (inches)", placeholder="e.g., 65")
458
- weight_input = gr.Textbox(label="Weight (pounds)", placeholder="e.g., 150")
459
- marital_input = gr.Dropdown(label="Marital Status", choices=["Please Select", "Single", "Married", "Divorced", "Widowed"], value="Please Select")
460
- with gr.Row():
461
- phone_input = gr.Textbox(label="Contact Number", placeholder="(000) 000-0000")
462
- email_input = gr.Textbox(label="Email", placeholder="patient@example.com")
463
- with gr.Row():
464
- with gr.Column():
465
- address_street1 = gr.Textbox(label="Street Address", placeholder="Street Address")
466
- address_street2 = gr.Textbox(label="Street Address Line 2", placeholder="Apt, Suite, etc.")
467
- with gr.Column():
468
- address_city = gr.Textbox(label="City", placeholder="City")
469
- address_state = gr.Textbox(label="State/Province", placeholder="State/Province")
470
- postal_input = gr.Textbox(label="Postal/Zip Code", placeholder="Postal/Zip Code")
471
- with gr.Row():
472
- med_yes_no = gr.Radio(label="Taking any medications, currently?", choices=["Yes", "No"], value="No")
473
- med_list = gr.Textbox(label="Please list it here", placeholder="List medications here", lines=2, visible=False)
474
- with gr.Accordion("In case of emergency", open=False):
475
- with gr.Row():
476
- with gr.Column():
477
- emergency_first = gr.Textbox(label="First Name", placeholder="First Name")
478
- emergency_last = gr.Textbox(label="Last Name", placeholder="Last Name")
479
- with gr.Column():
480
- emergency_relation = gr.Textbox(label="Relationship", placeholder="e.g., Spouse")
481
- emergency_number = gr.Textbox(label="Contact Number", placeholder="(000) 000-0000")
482
- language_input = gr.Dropdown(["English", "Telugu", "Hindi"], label="Language")
483
- consent_input = gr.Dropdown(["SMS", "WhatsApp", "Awaiting"], label="Consent Method")
484
- register_button = gr.Button("Submit")
485
- register_output = gr.Textbox(label="Result")
486
-
487
- # Update visibility of medication list based on radio selection
488
- def toggle_med_list(med_choice):
489
- return gr.update(visible=med_choice == "Yes")
490
-
491
- med_yes_no.change(
492
- fn=toggle_med_list,
493
- inputs=med_yes_no,
494
- outputs=med_list
495
- )
496
-
497
- # Update the registration function to handle new fields
498
- def register_patient(name_first, name_last, dob, sex, height, weight, marital, phone, email,
499
- address_street1, address_street2, address_city, address_state, postal,
500
- med_yes_no, med_list, emergency_first, emergency_last, emergency_relation,
501
- emergency_number, language, consent_status):
502
- if not all([name_first, name_last, dob, sex, height, weight, marital, phone, email,
503
- address_street1, address_city, address_state, postal, language, consent_status]) or \
504
- (med_yes_no == "Yes" and not med_list):
505
- return "All fields are required.", gr.State(value=None)
506
- try:
507
- patient_data = {
508
- "First_Name__c": name_first,
509
- "Last_Name__c": name_last,
510
- "Date_of_Birth__c": dob,
511
- "Sex__c": sex,
512
- "Height__c": height,
513
- "Weight__c": weight,
514
- "Marital_Status__c": marital,
515
- "Phone__c": phone,
516
- "Email__c": email,
517
- "Address_Street1__c": address_street1,
518
- "Address_Street2__c": address_street2 or "",
519
- "City__c": address_city,
520
- "State__c": address_state,
521
- "Postal_Code__c": postal,
522
- "Medications__c": med_list if med_yes_no == "Yes" else "",
523
- "Emergency_First_Name__c": emergency_first or "",
524
- "Emergency_Last_Name__c": emergency_last or "",
525
- "Emergency_Relation__c": emergency_relation or "",
526
- "Emergency_Number__c": emergency_number or "",
527
- "Language__c": language,
528
- "ConsentGiven__c": consent_status
529
- }
530
- result = sf_client.create_record("Patient__c", patient_data)
531
- if isinstance(result, str): # Error message returned
532
- return result, gr.State(value=None)
533
- if result:
534
- logging.info(f"Registered patient: {result}")
535
- message = f"Welcome! You are registered. Your patient ID is {result}."
536
- if consent_status in ["Approved", "Awaiting"]:
537
- twilio_client.send_message(phone, message, method=consent_status.lower().replace(" ", "")[:3] if consent_status == "Awaiting" else "sms")
538
- return f"Patient registered successfully! Your patient ID is {result}. You can use this ID for future actions.", gr.State(value=phone)
539
- return "Failed to register patient. Please try again or contact support.", gr.State(value=None)
540
- except Exception as e:
541
- logging.error(f"Error registering patient: {str(e)}")
542
- return f"Error registering patient: {str(e)}. Please try again or contact support.", gr.State(value=None)
543
-
544
- register_button.click(
545
- fn=register_patient,
546
- inputs=[name_first, name_last, dob_input, sex_input, height_input, weight_input, marital_input,
547
- phone_input, email_input, address_street1, address_street2, address_city, address_state,
548
- postal_input, med_yes_no, med_list, emergency_first, emergency_last, emergency_relation,
549
- emergency_number, language_input, consent_input],
550
- outputs=[register_output, patient_phone_state]
551
- )
552
 
553
  with gr.Tab("Consent Form"):
554
  consent_phone_input = gr.Textbox(label="Patient Phone Number", value=lambda x: x, interactive=False) if patient_phone_state.value else gr.Textbox(label="Patient Phone Number", placeholder="+1234567890")
 
240
  # State to store patient phone number
241
  patient_phone_state = gr.State(value=None)
242
 
243
+ def register_patient(name_first, name_last, dob, sex, height, weight, marital, phone, email,
244
+ address_street1, address_street2, address_city, address_state, postal,
245
+ med_yes_no, med_list, emergency_first, emergency_last, emergency_relation,
246
+ emergency_number, language, consent_status):
247
+ if not all([name_first, name_last, dob, sex, height, weight, marital, phone, email,
248
+ address_street1, address_city, address_state, postal, language, consent_status]) or \
249
+ (med_yes_no == "Yes" and not med_list):
250
  return "All fields are required.", gr.State(value=None)
251
  try:
252
  patient_data = {
253
+ "First_Name__c": name_first,
254
+ "Last_Name__c": name_last,
255
+ "Date_of_Birth__c": dob,
256
+ "Sex__c": sex,
257
+ "Height__c": height,
258
+ "Weight__c": weight,
259
+ "Marital_Status__c": marital,
260
  "Phone__c": phone,
261
  "Email__c": email,
262
+ "Address_Street1__c": address_street1,
263
+ "Address_Street2__c": address_street2 or "",
264
+ "City__c": address_city,
265
+ "State__c": address_state,
266
+ "Postal_Code__c": postal,
267
+ "Medications__c": med_list if med_yes_no == "Yes" else "",
268
+ "Emergency_First_Name__c": emergency_first or "",
269
+ "Emergency_Last_Name__c": emergency_last or "",
270
+ "Emergency_Relation__c": emergency_relation or "",
271
+ "Emergency_Number__c": emergency_number or "",
272
  "Language__c": language,
273
  "ConsentGiven__c": consent_status
274
  }
 
467
  with gr.Blocks(theme=gr.themes.Soft(), title="AI-Powered Patient Follow-up Agent") as demo:
468
  gr.Markdown("# AI-Powered Patient Follow-up Agent for Clinics")
469
 
470
+ with gr.Tabs():
471
+ with gr.Tab("Patient Registration"):
472
+ with gr.Row():
473
+ with gr.Column():
474
+ name_first = gr.Textbox(label="First Name", placeholder="First Name")
475
+ name_last = gr.Textbox(label="Last Name", placeholder="Last Name")
476
+ with gr.Column():
477
+ dob_input = gr.Textbox(label="Date of Birth", placeholder="MM-DD-YYYY")
478
+ sex_input = gr.Dropdown(label="Sex", choices=["Please Select", "Male", "Female", "Other"], value="Please Select")
479
+ with gr.Row():
480
+ height_input = gr.Textbox(label="Height (inches)", placeholder="e.g., 65")
481
+ weight_input = gr.Textbox(label="Weight (pounds)", placeholder="e.g., 150")
482
+ marital_input = gr.Dropdown(label="Marital Status", choices=["Please Select", "Single", "Married", "Divorced", "Widowed"], value="Please Select")
483
+ with gr.Row():
484
+ phone_input = gr.Textbox(label="Contact Number", placeholder="(000) 000-0000")
485
+ email_input = gr.Textbox(label="Email", placeholder="patient@example.com")
486
+ with gr.Row():
487
+ with gr.Column():
488
+ address_street1 = gr.Textbox(label="Street Address", placeholder="Street Address")
489
+ address_street2 = gr.Textbox(label="Street Address Line 2", placeholder="Apt, Suite, etc.")
490
+ with gr.Column():
491
+ address_city = gr.Textbox(label="City", placeholder="City")
492
+ address_state = gr.Textbox(label="State/Province", placeholder="State/Province")
493
+ postal_input = gr.Textbox(label="Postal/Zip Code", placeholder="Postal/Zip Code")
494
+ with gr.Row():
495
+ med_yes_no = gr.Radio(label="Taking any medications, currently?", choices=["Yes", "No"], value="No")
496
+ med_list = gr.Textbox(label="Please list it here", placeholder="List medications here", lines=2, visible=False)
497
+ with gr.Accordion("In case of emergency", open=False):
498
+ with gr.Row():
499
+ with gr.Column():
500
+ emergency_first = gr.Textbox(label="First Name", placeholder="First Name")
501
+ emergency_last = gr.Textbox(label="Last Name", placeholder="Last Name")
502
+ with gr.Column():
503
+ emergency_relation = gr.Textbox(label="Relationship", placeholder="e.g., Spouse")
504
+ emergency_number = gr.Textbox(label="Contact Number", placeholder="(000) 000-0000")
505
+ language_input = gr.Dropdown(["English", "Telugu", "Hindi"], label="Language")
506
+ consent_input = gr.Dropdown(["SMS", "WhatsApp", "Awaiting"], label="Consent Method")
507
+ register_button = gr.Button("Submit")
508
+ register_output = gr.Textbox(label="Result")
509
+
510
+ # Update visibility of medication list based on radio selection
511
+ def toggle_med_list(med_choice):
512
+ return gr.update(visible=med_choice == "Yes")
513
+
514
+ med_yes_no.change(
515
+ fn=toggle_med_list,
516
+ inputs=med_yes_no,
517
+ outputs=med_list
518
+ )
519
+
520
+ register_button.click(
521
+ fn=register_patient,
522
+ inputs=[name_first, name_last, dob_input, sex_input, height_input, weight_input, marital_input,
523
+ phone_input, email_input, address_street1, address_street2, address_city, address_state,
524
+ postal_input, med_yes_no, med_list, emergency_first, emergency_last, emergency_relation,
525
+ emergency_number, language_input, consent_input],
526
+ outputs=[register_output, patient_phone_state]
527
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
  with gr.Tab("Consent Form"):
530
  consent_phone_input = gr.Textbox(label="Patient Phone Number", value=lambda x: x, interactive=False) if patient_phone_state.value else gr.Textbox(label="Patient Phone Number", placeholder="+1234567890")