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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Define the letter types and their corresponding definitions and fields
|
4 |
+
letter_types = {
|
5 |
+
"Referral Letters": {
|
6 |
+
"Definition": "Letters asking for more help or treatment",
|
7 |
+
"Fields": ["Patient info", "Referral details"]
|
8 |
+
},
|
9 |
+
"Medical Certificate Letters": {
|
10 |
+
"Definition": "Letters about a patient's health problem or limits",
|
11 |
+
"Fields": ["Patient info", "Health problem details"]
|
12 |
+
},
|
13 |
+
"Prescription Letters": {
|
14 |
+
"Definition": "Letters allowing medicine",
|
15 |
+
"Fields": ["Patient info", "Medicine details"]
|
16 |
+
},
|
17 |
+
"Diagnosis Letters": {
|
18 |
+
"Definition": "Letters explaining a patient's health problem",
|
19 |
+
"Fields": ["Patient info", "Health problem details"]
|
20 |
+
},
|
21 |
+
"Treatment Plan Letters": {
|
22 |
+
"Definition": "Letters with a plan for getting better",
|
23 |
+
"Fields": ["Patient info", "Treatment details"]
|
24 |
+
},
|
25 |
+
"Surgery Recommendation Letters": {
|
26 |
+
"Definition": "Letters saying a patient needs surgery",
|
27 |
+
"Fields": ["Patient info", "Surgery details"]
|
28 |
+
},
|
29 |
+
"Medical Clearance Letters": {
|
30 |
+
"Definition": "Letters saying a patient can do activities",
|
31 |
+
"Fields": ["Patient info", "Activity details"]
|
32 |
+
},
|
33 |
+
"Follow-up Appointment Letters": {
|
34 |
+
"Definition": "Letters reminding about appointments",
|
35 |
+
"Fields": ["Patient info", "Appointment details"]
|
36 |
+
},
|
37 |
+
"Disability Support Letters": {
|
38 |
+
"Definition": "Letters about a patient's disability",
|
39 |
+
"Fields": ["Patient info", "Disability details"]
|
40 |
+
},
|
41 |
+
"Health Education Letters": {
|
42 |
+
"Definition": "Letters teaching about health",
|
43 |
+
"Fields": ["Patient info", "Education topic"]
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
# Streamlit UI
|
48 |
+
st.title("AI Letter Generation")
|
49 |
+
|
50 |
+
# User selects the letter type
|
51 |
+
selected_letter_type = st.selectbox("Select Letter Type", list(letter_types.keys()))
|
52 |
+
|
53 |
+
# Display the definition and fields for the selected letter type
|
54 |
+
st.write("Definition:", letter_types[selected_letter_type]["Definition"])
|
55 |
+
st.write("Fields Usually Needed:")
|
56 |
+
for field in letter_types[selected_letter_type]["Fields"]:
|
57 |
+
st.button(field)
|
58 |
+
|
59 |
+
def generate_referral_letters_ui():
|
60 |
+
st.title("π€ Referral Letters")
|
61 |
+
|
62 |
+
# Search-style text box
|
63 |
+
search_query = st.text_input("Search Referral Letters")
|
64 |
+
|
65 |
+
# Buttons with emojis and boldface text
|
66 |
+
st.button("π **First**")
|
67 |
+
st.button("π **Middle**")
|
68 |
+
st.button("π **Last**")
|
69 |
+
|
70 |
+
# Text areas with default values based on letter examples
|
71 |
+
first_default = "Urgent need for further diagnostic testing for Mrs. Smith, who has persistent stomach issues\n" \
|
72 |
+
"Request for an audiological assessment for Mr. Johnson, aged 60"
|
73 |
+
middle_default = "The patient has symptoms that suggest a more comprehensive review is required\n" \
|
74 |
+
"The patientβs issue requires specialized care beyond the scope of the referring physician"
|
75 |
+
last_default = "Patient demographics, Referral details\n" \
|
76 |
+
"Diagnostic test reports, Medication details"
|
77 |
+
|
78 |
+
first_text = st.text_area("First: State the request for consultation/treatment", value=first_default, max_chars=None, height=None)
|
79 |
+
middle_text = st.text_area("Middle: Explain the reason for referral", value=middle_default, max_chars=None, height=None)
|
80 |
+
last_text = st.text_area("Last: Provide patient info needed for the referred service", value=last_default, max_chars=None, height=None)
|
81 |
+
|
82 |
+
# Username field with an emoji
|
83 |
+
username = st.text_input("π€ Username")
|
84 |
+
|
85 |
+
|
86 |
+
def generate_medical_certificate_letters_ui():
|
87 |
+
st.title("π Medical Certificate Letters")
|
88 |
+
|
89 |
+
# Search-style text box
|
90 |
+
search_query = st.text_input("Search Medical Certificate Letters")
|
91 |
+
|
92 |
+
# Buttons with emojis and boldface text
|
93 |
+
st.button("π **First**")
|
94 |
+
st.button("π **Middle**")
|
95 |
+
st.button("π **Last**")
|
96 |
+
|
97 |
+
# Text areas with default values based on letter examples
|
98 |
+
first_default = "To certify Mr. Brownβs condition and advise on work restrictions\n" \
|
99 |
+
"To certify Ms. Leeβs health status for her impending travel."
|
100 |
+
middle_default = "Mr. Brown has suffered from a heart attack and is under medication\n" \
|
101 |
+
"Ms. Lee has a chronic back pain condition that requires special accommodations during her travel"
|
102 |
+
last_default = "No driving should be allowed for 6 months\n" \
|
103 |
+
"Ms. Lee must have an aisle seat and use cushions for lumbar support"
|
104 |
+
|
105 |
+
first_text = st.text_area("First: State the reason for certification", value=first_default, max_chars=None, height=None)
|
106 |
+
middle_text = st.text_area("Middle: Explain the patientβs medical condition", value=middle_default, max_chars=None, height=None)
|
107 |
+
last_text = st.text_area("Last: Outline any necessary work/travel adjustments", value=last_default, max_chars=None, height=None)
|
108 |
+
|
109 |
+
# Username field with an emoji
|
110 |
+
username = st.text_input("π€ Username")
|
111 |
+
|
112 |
+
|
113 |
+
def generate_prescription_letters_ui():
|
114 |
+
st.title("π Prescription Letters")
|
115 |
+
|
116 |
+
# Search-style text box
|
117 |
+
search_query = st.text_input("Search Prescription Letters")
|
118 |
+
|
119 |
+
# Buttons with emojis and boldface text
|
120 |
+
st.button("π **First**")
|
121 |
+
st.button("π **Middle**")
|
122 |
+
st.button("π **Last**")
|
123 |
+
|
124 |
+
# Text areas with default values based on letter examples
|
125 |
+
first_default = "Request for prescription for Mr. Clarke\n" \
|
126 |
+
"Prescription authorization for Mrs. Davis"
|
127 |
+
middle_default = "Mr. Clarke requires medication for hypertension - Lisinopril 10mg BD with food\n" \
|
128 |
+
"Mrs. Davis is required to take two 500mg penicillin V tablets every 6 hours"
|
129 |
+
last_default = "Medication details, allergies and any known side effects"
|
130 |
+
|
131 |
+
first_text = st.text_area("First: Introduce prescription request", value=first_default, max_chars=None, height=None)
|
132 |
+
middle_text = st.text_area("Middle: List dosage and frequency of medication", value=middle_default, max_chars=None, height=None)
|
133 |
+
last_text = st.text_area("Last: Provide medication details", value=last_default, max_chars=None, height=None)
|
134 |
+
|
135 |
+
# Username field with an emoji
|
136 |
+
username = st.text_input("π€ Username")
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
import streamlit as st
|
142 |
+
|
143 |
+
def generate_prescription_letters_ui():
|
144 |
+
st.title("π Prescription Letters")
|
145 |
+
|
146 |
+
# Search-style text box
|
147 |
+
search_query = st.text_input("Search Prescription Letters")
|
148 |
+
|
149 |
+
# Buttons with emojis and boldface text
|
150 |
+
st.button("π **First**")
|
151 |
+
st.button("π **Middle**")
|
152 |
+
st.button("π **Last**")
|
153 |
+
|
154 |
+
# Text areas with default values based on letter examples
|
155 |
+
first_default = "Request for prescription for Mr. Clarke\n" \
|
156 |
+
"Prescription authorization for Mrs. Davis"
|
157 |
+
middle_default = "Mr. Clarke requires medication for hypertension - Lisinopril 10mg BD with food\n" \
|
158 |
+
"Mrs. Davis is required to take two 500mg penicillin V tablets every 6 hours"
|
159 |
+
last_default = "Medication details, allergies and any known side effects"
|
160 |
+
|
161 |
+
first_text = st.text_area("First: Introduce prescription request", value=first_default, max_chars=None, height=None)
|
162 |
+
middle_text = st.text_area("Middle: List dosage and frequency of medication", value=middle_default, max_chars=None, height=None)
|
163 |
+
last_text = st.text_area("Last: Provide medication details", value=last_default, max_chars=None, height=None)
|
164 |
+
|
165 |
+
# Username field with an emoji
|
166 |
+
username = st.text_input("π€ Username")
|
167 |
+
|
168 |
+
|
169 |
+
|
170 |
+
def generate_treatment_plan_letters_ui():
|
171 |
+
st.title("π©Ή Treatment Plan Letters")
|
172 |
+
|
173 |
+
# Search-style text box
|
174 |
+
search_query = st.text_input("Search Treatment Plan Letters")
|
175 |
+
|
176 |
+
# Buttons with emojis and boldface text
|
177 |
+
st.button("π **First**")
|
178 |
+
st.button("π **Middle**")
|
179 |
+
st.button("π **Last**")
|
180 |
+
|
181 |
+
# Text areas with default values based on letter examples
|
182 |
+
first_default = "Outline treatment and testing plan for Mr.Smith\n" \
|
183 |
+
"Suggest handling chronic asthma for Mrs.White"
|
184 |
+
middle_default = "Mr. Smithβs treatment will involve IV medication and chest x-ray\n" \
|
185 |
+
"Mrs. Whiteβs asthma management plan requires frequent use of recommended inhaler and daily monitoring"
|
186 |
+
last_default = "Recommend follow-up visits for monitoring and periodic testing\n" \
|
187 |
+
"Provide contact information in case of any emergencies"
|
188 |
+
|
189 |
+
first_text = st.text_area("First: Introduce treatment plan", value=first_default, max_chars=None, height=None)
|
190 |
+
middle_text = st.text_area("Middle: Explain treatment plan specifics", value=middle_default, max_chars=None, height=None)
|
191 |
+
last_text = st.text_area("Last: Detail any follow-up needed", value=last_default, max_chars=None, height=None)
|
192 |
+
|
193 |
+
# Username field with an emoji
|
194 |
+
username = st.text_input("π€ Username")
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
def generate_surgery_recommendation_letters_ui():
|
200 |
+
st.title("π₯ Surgery Recommendation Letters")
|
201 |
+
|
202 |
+
# Search-style text box
|
203 |
+
search_query = st.text_input("Search Surgery Recommendation Letters")
|
204 |
+
|
205 |
+
# Buttons with emojis and boldface text
|
206 |
+
st.button("π **First**")
|
207 |
+
st.button("π **Middle**")
|
208 |
+
st.button("π **Last**")
|
209 |
+
|
210 |
+
# Text areas with default values based on letter examples
|
211 |
+
first_default = "Recommend endoscopy procedure for Mr.Baker\n" \
|
212 |
+
"Recommend an angiography for Mrs.Taylor"
|
213 |
+
middle_default = "Mr. Baker needs endoscopy for the diagnosis of GI tract abnormalities\n" \
|
214 |
+
"Mrs. Taylor needs angiography to locate any arterial blockages"
|
215 |
+
last_default = "Suggest to take extra measures regarding allergies or post-procedural appointments\n" \
|
216 |
+
"Provide details on necessary pre and post-hospitalization guidance"
|
217 |
+
|
218 |
+
first_text = st.text_area("First: Introduce surgical procedure", value=first_default, max_chars=None, height=None)
|
219 |
+
middle_text = st.text_area("Middle: Explain surgical procedure specifics", value=middle_default, max_chars=None, height=None)
|
220 |
+
last_text = st.text_area("Last: Detail any adjustment needed before/after surgery", value=last_default, max_chars=None, height=None)
|
221 |
+
|
222 |
+
# Username field with an emoji
|
223 |
+
username = st.text_input("π€ Username")
|
224 |
+
|
225 |
+
|
226 |
+
def generate_follow_up_appointment_letters_ui():
|
227 |
+
st.title("π
Follow-up Appointment Letters")
|
228 |
+
|
229 |
+
# Search-style text box
|
230 |
+
search_query = st.text_input("Search Follow-up Appointment Letters")
|
231 |
+
|
232 |
+
# Buttons with emojis and boldface text
|
233 |
+
st.button("π **First**")
|
234 |
+
st.button("π **Middle**")
|
235 |
+
st.button("π **Last**")
|
236 |
+
|
237 |
+
# Text areas with default values based on letter examples
|
238 |
+
first_default = "This is a reminder for Mrs. Rodriguezβs appointment on Friday, 17th September, at 11:00 am\n" \
|
239 |
+
"This letter is to confirm Mr. Johnsonβs appointment on Monday, 20th September, at 1:00 pm"
|
240 |
+
middle_default = "Review the date, time, and location of appointment\n" \
|
241 |
+
"Detail any necessary preparations for the appointment"
|
242 |
+
last_default = "Provide contact information and phone numbers in case of schedule change or emergency\n" \
|
243 |
+
"Encourage to reach out if an appointment must be canceled, or if there are any questions or concerns"
|
244 |
+
|
245 |
+
first_text = st.text_area("First: Remind of the appointment", value=first_default, max_chars=None, height=None)
|
246 |
+
middle_text = st.text_area("Middle: Confirm appointment details", value=middle_default, max_chars=None, height=None)
|
247 |
+
last_text = st.text_area("Last: Provide contact details", value=last_default, max_chars=None, height=None)
|
248 |
+
|
249 |
+
# Username field with an emoji
|
250 |
+
username = st.text_input("π€ Username")
|
251 |
+
|
252 |
+
# Run the Streamlit UI function
|
253 |
+
generate_follow_up_appointment_letters_ui()
|
254 |
+
|
255 |
+
def generate_health_education_letters_ui():
|
256 |
+
st.title("π Health Education Letters")
|
257 |
+
|
258 |
+
# Search-style text box
|
259 |
+
search_query = st.text_input("Search Health Education Letters")
|
260 |
+
|
261 |
+
# Buttons with emojis and boldface text
|
262 |
+
st.button("π **First**")
|
263 |
+
st.button("π **Middle**")
|
264 |
+
st.button("π **Last**")
|
265 |
+
|
266 |
+
# Text areas with default values based on letter examples
|
267 |
+
first_default = "This letter is to provide Ms. Prince with information on healthy eating habits\n" \
|
268 |
+
"This letter offers suggestions for stress management to Mr. Martin"
|
269 |
+
middle_default = "Outline the benefits of specific health practices for overall health\n" \
|
270 |
+
"Detail steps that can be taken to manage specific health conditions properly"
|
271 |
+
last_default = "Provide handouts, online resources, or any relevant materials to supplement the information\n" \
|
272 |
+
"Encourage patients to schedule follow-up appointments to discuss any questions or concerns."
|
273 |
+
|
274 |
+
first_text = st.text_area("First: Introduce the health education topic", value=first_default, max_chars=None, height=None)
|
275 |
+
middle_text = st.text_area("Middle: Explain the recommended practices", value=middle_default, max_chars=None, height=None)
|
276 |
+
last_text = st.text_area("Last: Provide Resources", value=last_default, max_chars=None, height=None)
|
277 |
+
|
278 |
+
# Username field with an emoji
|
279 |
+
username = st.text_input("π€ Username")
|
280 |
+
|
281 |
+
|
282 |
+
|
283 |
+
|
284 |
+
def generate_letter_grid_ui():
|
285 |
+
st.title("π₯ Letter Type Selection")
|
286 |
+
|
287 |
+
# Define the data for the table
|
288 |
+
letter_types = [
|
289 |
+
("1οΈβ£ Referral Letters", "π€ Letters asking for more help or treatment", "π Patient info, Referral details", generate_referral_letters_ui),
|
290 |
+
("2οΈβ£ Medical Certificate Letters", "πΌ Letters about a patient's health problem or limits", "π Patient info, Health problem details", generate_medical_certificate_letters_ui),
|
291 |
+
("3οΈβ£ Prescription Letters", "π Letters allowing medicine", "π Patient info, Medicine details", generate_prescription_letters_ui),
|
292 |
+
("4οΈβ£ Diagnosis Letters", "π Letters explaining a patient's health problem", "π Patient info, Health problem details", generate_diagnosis_letters_ui),
|
293 |
+
("5οΈβ£ Treatment Plan Letters", "π Letters with a plan for getting better", "π Patient info, Treatment details", generate_treatment_plan_letters_ui),
|
294 |
+
("6οΈβ£ Surgery Recommendation Letters", "π₯ Letters saying a patient needs surgery", "π Patient info, Surgery details", generate_surgery_recommendation_letters_ui),
|
295 |
+
("7οΈβ£ Medical Clearance Letters", "π Letters saying a patient can do activities", "π Patient info, Activity details", generate_medical_clearance_letters_ui),
|
296 |
+
("8οΈβ£ Follow-up Appointment Letters", "π
Letters reminding about appointments", "π Patient info, Appointment details", generate_follow_up_appointment_letters_ui),
|
297 |
+
("9οΈβ£ Disability Support Letters", "βΏ Letters about a patient's disability", "π Patient info, Disability details", generate_disability_support_letters_ui),
|
298 |
+
("π Health Education Letters", "π Letters teaching about health", "π Patient info, Education topic", generate_health_education_letters_ui)
|
299 |
+
]
|
300 |
+
|
301 |
+
# Create the table with buttons
|
302 |
+
for letter_type, definition, fields, letter_function in letter_types:
|
303 |
+
col1, col2, col3, col4 = st.columns(4)
|
304 |
+
with col1:
|
305 |
+
if st.button(letter_type):
|
306 |
+
letter_function()
|
307 |
+
with col2:
|
308 |
+
st.write(definition)
|
309 |
+
with col3:
|
310 |
+
st.write(fields)
|
311 |
+
|
312 |
+
# Run the Streamlit UI function
|
313 |
+
generate_letter_grid_ui()
|
314 |
+
|
315 |
+
|
316 |
+
# Run the Streamlit UI function
|
317 |
+
#generate_referral_letters_ui()
|
318 |
+
# Run the Streamlit UI function
|
319 |
+
#generate_medical_certificate_letters_ui()
|
320 |
+
# Run the Streamlit UI function
|
321 |
+
#generate_prescription_letters_ui()
|
322 |
+
# Run the Streamlit UI function
|
323 |
+
#generate_prescription_letters_ui()
|
324 |
+
# Run the Streamlit UI function
|
325 |
+
#generate_treatment_plan_letters_ui()
|
326 |
+
# Run the Streamlit UI function
|
327 |
+
#generate_surgery_recommendation_letters_ui()
|
328 |
+
# Run the Streamlit UI function
|
329 |
+
#generate_health_education_letters_ui()
|
330 |
+
# Run the Streamlit UI function
|
331 |
+
#generate_letter_grid_ui()
|
332 |
+
|
333 |
+
# Define the functions for generating the letter UIs (examples)
|
334 |
+
#def generate_referral_letters_ui():
|
335 |
+
# UI code for referral letters
|
336 |
+
# pass
|
337 |
+
|
338 |
+
#def generate_medical_certificate_letters_ui():
|
339 |
+
# UI code for medical certificate letters
|
340 |
+
# pass
|