Update callbackmanager.py
Browse files- callbackmanager.py +31 -20
callbackmanager.py
CHANGED
@@ -875,7 +875,7 @@ cyberpunk_theme = gr.themes.Monochrome(
|
|
875 |
with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
876 |
gr.Markdown("<h1 style='color:#00FFFF; text-shadow: 0 0 5px #00FFFF;'>Discharge Guard <span style='color:#FF00FF; text-shadow: 0 0 5px #FF00FF;'>Cyber</span></h1>") # Cyberpunk Title
|
877 |
|
878 |
-
with gr.Tab("Authenticate with MeldRx", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
879 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>SMART on FHIR Authentication</h2>") # Neon Tab Header
|
880 |
auth_url_output = gr.Textbox(label="Authorization URL", value=CALLBACK_MANAGER.get_auth_url(), interactive=False)
|
881 |
gr.Markdown("<p style='color:#A9A9A9;'>Copy the URL above, open it in a browser, log in, and paste the <span style='color:#00FFFF;'>entire redirected URL</span> from your browser's address bar below.</p>") # Subdued instructions with neon highlight
|
@@ -891,7 +891,7 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
891 |
patient_data_output = gr.Textbox(label="Patient Data", lines=10)
|
892 |
|
893 |
# Add button to generate PDF from MeldRx data (No AI)
|
894 |
-
meldrx_pdf_button = gr.Button("Generate PDF from MeldRx Data (No AI)", elem_classes="cyberpunk-button") # Renamed button
|
895 |
meldrx_pdf_status = gr.Textbox(label="PDF Generation Status (No AI)") # Renamed status
|
896 |
meldrx_pdf_download = gr.File(label="Download Generated PDF (No AI)") # Renamed download
|
897 |
|
@@ -907,13 +907,15 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
907 |
extract_code_button.click(
|
908 |
fn=process_redirected_url,
|
909 |
inputs=redirected_url_input,
|
910 |
-
outputs=[extracted_code_output, auth_result]
|
|
|
911 |
)
|
912 |
|
913 |
auth_submit.click(
|
914 |
fn=CALLBACK_MANAGER.set_auth_code,
|
915 |
inputs=extracted_code_output, # Using extracted code as input for authentication
|
916 |
outputs=auth_result,
|
|
|
917 |
)
|
918 |
|
919 |
with gr.Tab("Patient Dashboard", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
@@ -973,38 +975,38 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
973 |
return f"<p style='color:#FF6347;'>Error fetching patient data: {str(e)}</p>" # Tomato Error
|
974 |
|
975 |
|
976 |
-
with gr.Tab("Discharge Form", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
977 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Patient Details</h2>") # Neon Tab Header
|
978 |
-
with gr.Row():
|
979 |
first_name = gr.Textbox(label="First Name")
|
980 |
last_name = gr.Textbox(label="Last Name")
|
981 |
middle_initial = gr.Textbox(label="Middle Initial")
|
982 |
-
with gr.Row():
|
983 |
dob = gr.Textbox(label="Date of Birth")
|
984 |
age = gr.Textbox(label="Age")
|
985 |
sex = gr.Textbox(label="Sex")
|
986 |
address = gr.Textbox(label="Address")
|
987 |
-
with gr.Row():
|
988 |
city = gr.Textbox(label="City")
|
989 |
state = gr.Textbox(label="State")
|
990 |
zip_code = gr.Textbox(label="Zip Code")
|
991 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Primary Healthcare Professional Details</h2>") # Neon Sub-header
|
992 |
-
with gr.Row():
|
993 |
doctor_first_name = gr.Textbox(label="Doctor's First Name")
|
994 |
doctor_last_name = gr.Textbox(label="Doctor's Last Name")
|
995 |
doctor_middle_initial = gr.Textbox(label="Doctor's Middle Initial")
|
996 |
hospital_name = gr.Textbox(label="Hospital/Clinic Name")
|
997 |
doctor_address = gr.Textbox(label="Address")
|
998 |
-
with gr.Row():
|
999 |
doctor_city = gr.Textbox(label="City")
|
1000 |
doctor_state = gr.Textbox(label="State")
|
1001 |
doctor_zip = gr.Textbox(label="Zip Code")
|
1002 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Admission and Discharge Details</h2>") # Neon Sub-header
|
1003 |
-
with gr.Row():
|
1004 |
admission_date = gr.Textbox(label="Date of Admission")
|
1005 |
referral_source = gr.Textbox(label="Source of Referral")
|
1006 |
admission_method = gr.Textbox(label="Method of Admission")
|
1007 |
-
with gr.Row():
|
1008 |
discharge_date = gr.Textbox(label="Date of Discharge")
|
1009 |
discharge_reason = gr.Radio(
|
1010 |
["Treated", "Transferred", "Discharge Against Advice", "Patient Died"],
|
@@ -1017,12 +1019,12 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1017 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Medication Details</h2>") # Neon Sub-header
|
1018 |
medications = gr.Textbox(label="Medication on Discharge")
|
1019 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Prepared By</h2>") # Neon Sub-header
|
1020 |
-
with gr.Row():
|
1021 |
preparer_name = gr.Textbox(label="Name")
|
1022 |
preparer_job_title = gr.Textbox(label="Job Title")
|
1023 |
|
1024 |
# Add buttons for both display form and generate PDF
|
1025 |
-
with gr.Row():
|
1026 |
submit_display = gr.Button("Display Form", elem_classes="cyberpunk-button") # Cyberpunk button style
|
1027 |
submit_pdf = gr.Button("Generate PDF (No AI)", elem_classes="cyberpunk-button") # Renamed button to clarify no AI and styled
|
1028 |
|
@@ -1065,6 +1067,7 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1065 |
preparer_job_title,
|
1066 |
],
|
1067 |
outputs=form_output,
|
|
|
1068 |
)
|
1069 |
|
1070 |
# Connect the generate PDF button (No AI version)
|
@@ -1102,11 +1105,12 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1102 |
preparer_job_title,
|
1103 |
],
|
1104 |
outputs=pdf_output,
|
|
|
1105 |
)
|
1106 |
|
1107 |
with gr.Tab("Medical File Analysis", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
1108 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Analyze Medical Files with Discharge Guard AI</h2>") # Neon Tab Header
|
1109 |
-
with gr.Column():
|
1110 |
dicom_file = gr.File(
|
1111 |
file_types=[".dcm"], label="Upload DICOM File (.dcm)"
|
1112 |
)
|
@@ -1156,36 +1160,41 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1156 |
analyze_dicom_file_with_ai, # Call REAL AI function
|
1157 |
inputs=dicom_file,
|
1158 |
outputs=dicom_ai_output,
|
|
|
1159 |
)
|
1160 |
analyze_hl7_button.click(
|
1161 |
analyze_hl7_file_with_ai, # Call REAL AI function
|
1162 |
inputs=hl7_file,
|
1163 |
outputs=hl7_ai_output,
|
|
|
1164 |
)
|
1165 |
analyze_xml_button.click(
|
1166 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1167 |
inputs=xml_file,
|
1168 |
outputs=xml_ai_output,
|
|
|
1169 |
)
|
1170 |
analyze_ccda_button.click(
|
1171 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1172 |
inputs=ccda_file,
|
1173 |
outputs=ccda_ai_output,
|
|
|
1174 |
)
|
1175 |
analyze_ccd_button.click( # Redundant button, but kept for UI if needed
|
1176 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1177 |
inputs=ccd_file,
|
1178 |
outputs=ccd_ai_output,
|
|
|
1179 |
)
|
1180 |
analyze_pdf_button.click(
|
1181 |
-
analyze_pdf_file_with_ai, inputs=pdf_file, outputs=pdf_ai_output
|
1182 |
)
|
1183 |
analyze_csv_button.click(
|
1184 |
-
analyze_csv_file_with_ai, inputs=csv_file, outputs=csv_ai_output
|
1185 |
)
|
1186 |
|
1187 |
with gr.Tab(
|
1188 |
-
"One-Click Discharge Paper (AI)", elem_classes="cyberpunk-tab"
|
1189 |
): # New Tab for One-Click Discharge Paper with AI, styled
|
1190 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>One-Click Medical Discharge Paper Generation with AI Content</h2>") # Neon Tab Header
|
1191 |
one_click_ai_pdf_button = gr.Button(
|
@@ -1209,11 +1218,12 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1209 |
fn=CALLBACK_MANAGER.get_patient_data,
|
1210 |
inputs=None,
|
1211 |
outputs=patient_data_output,
|
|
|
1212 |
)
|
1213 |
|
1214 |
# Connect refresh button to update dashboard
|
1215 |
refresh_btn.click(
|
1216 |
-
fn=update_dashboard, inputs=None, outputs=dashboard_output
|
1217 |
)
|
1218 |
|
1219 |
# Corrected the button click function name here to `generate_pdf_from_meldrx` (No AI PDF)
|
@@ -1221,12 +1231,13 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
1221 |
fn=generate_pdf_from_meldrx,
|
1222 |
inputs=patient_data_output,
|
1223 |
outputs=[meldrx_pdf_download, meldrx_pdf_status],
|
|
|
1224 |
)
|
1225 |
|
1226 |
# Connect patient data updates to dashboard
|
1227 |
patient_data_button.click(
|
1228 |
-
fn=update_dashboard, inputs=None, outputs=dashboard_output
|
1229 |
)
|
1230 |
|
1231 |
# Launch with sharing enabled for public access
|
1232 |
-
demo.launch(
|
|
|
875 |
with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
876 |
gr.Markdown("<h1 style='color:#00FFFF; text-shadow: 0 0 5px #00FFFF;'>Discharge Guard <span style='color:#FF00FF; text-shadow: 0 0 5px #FF00FF;'>Cyber</span></h1>") # Cyberpunk Title
|
877 |
|
878 |
+
with gr.Tab("Authenticate with MeldRx", elem_classes="cyberpunk-tab", js=True): # Optional: Class for tab styling
|
879 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>SMART on FHIR Authentication</h2>") # Neon Tab Header
|
880 |
auth_url_output = gr.Textbox(label="Authorization URL", value=CALLBACK_MANAGER.get_auth_url(), interactive=False)
|
881 |
gr.Markdown("<p style='color:#A9A9A9;'>Copy the URL above, open it in a browser, log in, and paste the <span style='color:#00FFFF;'>entire redirected URL</span> from your browser's address bar below.</p>") # Subdued instructions with neon highlight
|
|
|
891 |
patient_data_output = gr.Textbox(label="Patient Data", lines=10)
|
892 |
|
893 |
# Add button to generate PDF from MeldRx data (No AI)
|
894 |
+
meldrx_pdf_button = gr.Button("Generate PDF from MeldRx Data (No AI)", elem_classes="cyberpunk-button", js=True) # Renamed button
|
895 |
meldrx_pdf_status = gr.Textbox(label="PDF Generation Status (No AI)") # Renamed status
|
896 |
meldrx_pdf_download = gr.File(label="Download Generated PDF (No AI)") # Renamed download
|
897 |
|
|
|
907 |
extract_code_button.click(
|
908 |
fn=process_redirected_url,
|
909 |
inputs=redirected_url_input,
|
910 |
+
outputs=[extracted_code_output, auth_result],
|
911 |
+
js=True# Reusing auth_result for extraction status
|
912 |
)
|
913 |
|
914 |
auth_submit.click(
|
915 |
fn=CALLBACK_MANAGER.set_auth_code,
|
916 |
inputs=extracted_code_output, # Using extracted code as input for authentication
|
917 |
outputs=auth_result,
|
918 |
+
js=True
|
919 |
)
|
920 |
|
921 |
with gr.Tab("Patient Dashboard", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
|
|
975 |
return f"<p style='color:#FF6347;'>Error fetching patient data: {str(e)}</p>" # Tomato Error
|
976 |
|
977 |
|
978 |
+
with gr.Tab("Discharge Form", elem_classes="cyberpunk-tab", js=True): # Optional: Class for tab styling
|
979 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Patient Details</h2>") # Neon Tab Header
|
980 |
+
with gr.Row(js=True):
|
981 |
first_name = gr.Textbox(label="First Name")
|
982 |
last_name = gr.Textbox(label="Last Name")
|
983 |
middle_initial = gr.Textbox(label="Middle Initial")
|
984 |
+
with gr.Row(js=True):
|
985 |
dob = gr.Textbox(label="Date of Birth")
|
986 |
age = gr.Textbox(label="Age")
|
987 |
sex = gr.Textbox(label="Sex")
|
988 |
address = gr.Textbox(label="Address")
|
989 |
+
with gr.Row(js=True):
|
990 |
city = gr.Textbox(label="City")
|
991 |
state = gr.Textbox(label="State")
|
992 |
zip_code = gr.Textbox(label="Zip Code")
|
993 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Primary Healthcare Professional Details</h2>") # Neon Sub-header
|
994 |
+
with gr.Row(js=True):
|
995 |
doctor_first_name = gr.Textbox(label="Doctor's First Name")
|
996 |
doctor_last_name = gr.Textbox(label="Doctor's Last Name")
|
997 |
doctor_middle_initial = gr.Textbox(label="Doctor's Middle Initial")
|
998 |
hospital_name = gr.Textbox(label="Hospital/Clinic Name")
|
999 |
doctor_address = gr.Textbox(label="Address")
|
1000 |
+
with gr.Row(js=True):
|
1001 |
doctor_city = gr.Textbox(label="City")
|
1002 |
doctor_state = gr.Textbox(label="State")
|
1003 |
doctor_zip = gr.Textbox(label="Zip Code")
|
1004 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Admission and Discharge Details</h2>") # Neon Sub-header
|
1005 |
+
with gr.Row(js=True):
|
1006 |
admission_date = gr.Textbox(label="Date of Admission")
|
1007 |
referral_source = gr.Textbox(label="Source of Referral")
|
1008 |
admission_method = gr.Textbox(label="Method of Admission")
|
1009 |
+
with gr.Row(js=True):
|
1010 |
discharge_date = gr.Textbox(label="Date of Discharge")
|
1011 |
discharge_reason = gr.Radio(
|
1012 |
["Treated", "Transferred", "Discharge Against Advice", "Patient Died"],
|
|
|
1019 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Medication Details</h2>") # Neon Sub-header
|
1020 |
medications = gr.Textbox(label="Medication on Discharge")
|
1021 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Prepared By</h2>") # Neon Sub-header
|
1022 |
+
with gr.Row(js=True):
|
1023 |
preparer_name = gr.Textbox(label="Name")
|
1024 |
preparer_job_title = gr.Textbox(label="Job Title")
|
1025 |
|
1026 |
# Add buttons for both display form and generate PDF
|
1027 |
+
with gr.Row(js=True):
|
1028 |
submit_display = gr.Button("Display Form", elem_classes="cyberpunk-button") # Cyberpunk button style
|
1029 |
submit_pdf = gr.Button("Generate PDF (No AI)", elem_classes="cyberpunk-button") # Renamed button to clarify no AI and styled
|
1030 |
|
|
|
1067 |
preparer_job_title,
|
1068 |
],
|
1069 |
outputs=form_output,
|
1070 |
+
js=True
|
1071 |
)
|
1072 |
|
1073 |
# Connect the generate PDF button (No AI version)
|
|
|
1105 |
preparer_job_title,
|
1106 |
],
|
1107 |
outputs=pdf_output,
|
1108 |
+
js=True
|
1109 |
)
|
1110 |
|
1111 |
with gr.Tab("Medical File Analysis", elem_classes="cyberpunk-tab"): # Optional: Class for tab styling
|
1112 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>Analyze Medical Files with Discharge Guard AI</h2>") # Neon Tab Header
|
1113 |
+
with gr.Column(js=True):
|
1114 |
dicom_file = gr.File(
|
1115 |
file_types=[".dcm"], label="Upload DICOM File (.dcm)"
|
1116 |
)
|
|
|
1160 |
analyze_dicom_file_with_ai, # Call REAL AI function
|
1161 |
inputs=dicom_file,
|
1162 |
outputs=dicom_ai_output,
|
1163 |
+
js=True
|
1164 |
)
|
1165 |
analyze_hl7_button.click(
|
1166 |
analyze_hl7_file_with_ai, # Call REAL AI function
|
1167 |
inputs=hl7_file,
|
1168 |
outputs=hl7_ai_output,
|
1169 |
+
js=True
|
1170 |
)
|
1171 |
analyze_xml_button.click(
|
1172 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1173 |
inputs=xml_file,
|
1174 |
outputs=xml_ai_output,
|
1175 |
+
js=True
|
1176 |
)
|
1177 |
analyze_ccda_button.click(
|
1178 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1179 |
inputs=ccda_file,
|
1180 |
outputs=ccda_ai_output,
|
1181 |
+
js=True
|
1182 |
)
|
1183 |
analyze_ccd_button.click( # Redundant button, but kept for UI if needed
|
1184 |
analyze_cda_xml_file_with_ai, # Call REAL AI function
|
1185 |
inputs=ccd_file,
|
1186 |
outputs=ccd_ai_output,
|
1187 |
+
js=True
|
1188 |
)
|
1189 |
analyze_pdf_button.click(
|
1190 |
+
analyze_pdf_file_with_ai, inputs=pdf_file, outputs=pdf_ai_output, js=True
|
1191 |
)
|
1192 |
analyze_csv_button.click(
|
1193 |
+
analyze_csv_file_with_ai, inputs=csv_file, outputs=csv_ai_output, js=True
|
1194 |
)
|
1195 |
|
1196 |
with gr.Tab(
|
1197 |
+
"One-Click Discharge Paper (AI)", elem_classes="cyberpunk-tab", js=True
|
1198 |
): # New Tab for One-Click Discharge Paper with AI, styled
|
1199 |
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>One-Click Medical Discharge Paper Generation with AI Content</h2>") # Neon Tab Header
|
1200 |
one_click_ai_pdf_button = gr.Button(
|
|
|
1218 |
fn=CALLBACK_MANAGER.get_patient_data,
|
1219 |
inputs=None,
|
1220 |
outputs=patient_data_output,
|
1221 |
+
js=True
|
1222 |
)
|
1223 |
|
1224 |
# Connect refresh button to update dashboard
|
1225 |
refresh_btn.click(
|
1226 |
+
fn=update_dashboard, inputs=None, outputs=dashboard_output, js=True
|
1227 |
)
|
1228 |
|
1229 |
# Corrected the button click function name here to `generate_pdf_from_meldrx` (No AI PDF)
|
|
|
1231 |
fn=generate_pdf_from_meldrx,
|
1232 |
inputs=patient_data_output,
|
1233 |
outputs=[meldrx_pdf_download, meldrx_pdf_status],
|
1234 |
+
js=True
|
1235 |
)
|
1236 |
|
1237 |
# Connect patient data updates to dashboard
|
1238 |
patient_data_button.click(
|
1239 |
+
fn=update_dashboard, inputs=None, outputs=dashboard_output, js=True
|
1240 |
)
|
1241 |
|
1242 |
# Launch with sharing enabled for public access
|
1243 |
+
demo.launch(ssr_mode=False)
|