-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
325 lines (284 loc) · 11.8 KB
/
Copy pathapp.py
File metadata and controls
325 lines (284 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import streamlit as st
import anthropic
# --- Page Config ---
st.set_page_config(
page_title="Pre-Op Medication Guide",
page_icon="💊",
layout="centered",
)
# --- Force custom theme (clear localStorage cache that overrides config.toml) ---
st.markdown("""
<script>
// Streamlit caches theme choice in localStorage which overrides config.toml
// Remove cached theme so our config.toml [theme] / [theme.dark] takes effect
const keys = Object.keys(localStorage);
keys.forEach(k => {
if (k.includes('stActiveTheme') || k.includes('theme')) {
localStorage.removeItem(k);
}
});
</script>
""", unsafe_allow_html=True)
# --- Custom Dark Theme CSS ---
st.markdown("""
<style>
/* Force background on all containers */
.stApp {
background-color: #0f1117 !important;
}
[data-testid="stAppViewContainer"],
[data-testid="stAppViewContainer"] > .main,
[data-testid="stAppViewContainer"] > .main > div,
.block-container {
background-color: #0f1117 !important;
color: #e8eaf0 !important;
}
header[data-testid="stHeader"] {
background-color: #0f1117 !important;
}
[data-testid="stBottom"] {
background-color: #0f1117 !important;
}
[data-testid="stBottomBlockContainer"] {
background-color: #0f1117 !important;
}
/* Sidebar */
section[data-testid="stSidebar"],
section[data-testid="stSidebar"] > div {
background-color: #181c26 !important;
}
section[data-testid="stSidebar"] p,
section[data-testid="stSidebar"] li,
section[data-testid="stSidebar"] span {
color: #8b92a5 !important;
}
section[data-testid="stSidebar"] h1,
section[data-testid="stSidebar"] h2,
section[data-testid="stSidebar"] h3,
section[data-testid="stSidebar"] strong {
color: #e8eaf0 !important;
}
/* Chat messages */
.stChatMessage,
[data-testid="stChatMessage"] {
background-color: #181c26 !important;
border: 1px solid #252a38 !important;
border-radius: 12px !important;
}
/* Chat input area */
.stChatInput,
[data-testid="stChatInput"] {
background-color: #0f1117 !important;
}
.stChatInput textarea,
[data-testid="stChatInput"] textarea {
background-color: #181c26 !important;
border: 1px solid #252a38 !important;
color: #e8eaf0 !important;
border-radius: 12px !important;
}
.stChatInput textarea:focus,
[data-testid="stChatInput"] textarea:focus {
border-color: #3dffc0 !important;
box-shadow: 0 0 0 1px #3dffc0 !important;
}
/* Send button accent */
.stChatInput button,
[data-testid="stChatInput"] button {
color: #3dffc0 !important;
background-color: transparent !important;
}
.stChatInput button:hover,
[data-testid="stChatInput"] button:hover {
color: #2de6a8 !important;
}
/* All headings */
h1, h2, h3, h4, h5, h6 {
color: #e8eaf0 !important;
}
/* Body text and paragraphs */
p, li, span, div {
color: #e8eaf0;
}
/* Captions / muted text */
.stCaption p,
[data-testid="stCaption"] p,
[data-testid="stMarkdownContainer"] small,
.stCaption {
color: #8b92a5 !important;
}
/* Links */
a {
color: #3dffc0 !important;
}
a:hover {
color: #2de6a8 !important;
}
/* Dividers */
hr {
border-color: #252a38 !important;
}
/* Alerts/errors */
.stAlert {
background-color: #181c26 !important;
border-radius: 8px !important;
}
/* Spinner */
.stSpinner > div {
border-top-color: #3dffc0 !important;
}
/* Deploy button area */
[data-testid="stToolbar"] {
background-color: #0f1117 !important;
}
/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0f1117; }
::-webkit-scrollbar-thumb { background: #252a38; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #8b92a5; }
</style>
""", unsafe_allow_html=True)
# --- Knowledge Base (extracted from Preop_Med_Guidance.docx) ---
KNOWLEDGE_BASE = """
Pre-Op Medication Safety Guidance
(Sources: ASA 2022, ACC/AHA 2024, Johns Hopkins Pre-op Roadmap, Delray Anesthesia Guidelines)
⚠️ Patients must follow surgeon/physician instructions. The times below reflect usual practice and are for awareness only. Final decision is always at the discretion of anesthesia/surgeon.
---
SGLT2 Inhibitors
• Empagliflozin – Jardiance®
• Dapagliflozin – Farxiga®
• Canagliflozin – Invokana®
• Ertugliflozin – Steglatro®
Combination products:
- Empagliflozin + Metformin – Synjardy®
- Dapagliflozin + Metformin – Xigduo XR®
- Canagliflozin + Metformin – Invokamet®
- Ertugliflozin + Metformin – Segluromet®
- Empagliflozin + Linagliptin – Glyxambi®
- Dapagliflozin + Saxagliptin – Qtern®
- Dapagliflozin + Saxagliptin + Metformin – Qternmet XR®
→ Hold 3 days before surgery (risk: euglycemic DKA)
→ If urgent surgery: alert anesthesia, monitor ketones/acid-base
---
GLP-1 Receptor Agonists — Injectables
• Weekly agents — HOLD 7 days before surgery
– Semaglutide (Ozempic®, Wegovy®)
– Tirzepatide (Mounjaro®, Zepbound®)
– Dulaglutide (Trulicity®)
– Exenatide ER (Bydureon® BCise)
• Combo products (treat per GLP-1 component; coordinate insulin plan)
– Insulin degludec + liraglutide (Xultophy®)
– Insulin glargine + lixisenatide (Soliqua®)
→ If urgent surgery or significant GI symptoms → alert anesthesia; manage as full stomach
---
ACE Inhibitors / ARBs
• ACE Inhibitors: lisinopril, enalapril, captopril, ramipril, benazepril, quinapril, perindopril
• ARBs: losartan, valsartan, irbesartan, candesartan, olmesartan, telmisartan, eprosartan
→ Usual practice: HOLD morning of surgery (reduce risk of refractory hypotension with anesthesia)
---
Antiplatelets / Aspirin / NSAIDs
• Aspirin (low-dose 81 mg) – may sometimes be continued; often stopped 5–7 days before surgery if required
• Aspirin (regular dose ≥325 mg) – usually stop ~7 days before surgery
• NSAIDs (ibuprofen, naproxen, meloxicam, diclofenac, etc.) – often managed like aspirin (5–7 days)
• Clopidogrel (Plavix®) – stop 5 days before surgery
• Prasugrel (Effient®) – stop 7 days before surgery
• Ticagrelor (Brilinta®) – stop 5 days before surgery
• Dipyridamole (Persantine®) – stop 5 days before surgery
• Cilostazol (Pletal®) – stop 5 days before surgery
⚠️ Important Caveat:
Patients with coronary stents must usually continue antiplatelet therapy.
Many vascular surgery patients (e.g., TCAR, TAVR, EVAR/TEVAR) are specifically instructed to remain on antiplatelets. Always confirm with cardiology/vascular surgery.
---
Diuretics
• Loop diuretics: furosemide, bumetanide, torsemide, ethacrynic acid
• Thiazides: HCTZ, chlorthalidone, indapamide, metolazone
• Potassium-sparing: spironolactone, eplerenone, amiloride, triamterene
→ Usual practice: HOLD morning of surgery (avoid hypovolemia/electrolyte imbalance)
→ May continue if specifically needed for CHF or volume control (confirm with physician)
---
Beta Blockers
• Common: metoprolol, atenolol, carvedilol, bisoprolol, propranolol, nadolol, labetalol, nebivolol
→ Usual practice: CONTINUE morning of surgery
→ Beta blockers are cardioprotective and should not be withheld
---
Calcium Channel Blockers (CCBs)
• Dihydropyridines: amlodipine, nifedipine, felodipine, nicardipine, isradipine
• Non-dihydropyridines: diltiazem, verapamil
→ Usual practice: CONTINUE morning of surgery
→ Help maintain blood pressure control perioperatively
---
Anticoagulants
• Warfarin – stop ~5 days before surgery; check INR prior
• DOACs (apixaban, rivaroxaban, edoxaban) – hold 2–3 days; longer if renal impairment/high bleeding risk
• Dabigatran – hold 2–3 days if CrCl ≥50; hold 4–5 days if CrCl <50
• Parenterals (enoxaparin, dalteparin, fondaparinux) – hold ~24 h; longer for high-risk procedures
• Heparin IV infusion – stop 4–6 h before surgery
---
Diabetes Medications (Oral & Insulin)
• Metformin – hold evening before surgery
• Sulfonylureas (glipizide, glyburide, glimepiride) – hold morning of surgery
• DPP-4 inhibitors (sitagliptin, saxagliptin, linagliptin, alogliptin) – hold morning of surgery
• TZDs (pioglitazone, rosiglitazone) – hold morning of surgery
• Meglitinides (repaglinide, nateglinide) – hold morning of surgery
• Insulin (all types: basal, bolus, premixed):
– Confirm perioperative plan with anesthesia
– Do NOT adjust dose without anesthesia guidance
---
⚠️ Disclaimer: This content is for preoperative screening/education. Final decisions must always be confirmed with anesthesia, surgeon, or provider.
""".strip()
SYSTEM_PROMPT = f"""This is a DNP student research and education project demo created solely for departmental and academic evaluation purposes. It must never be used for direct patient care, medical advice, or clinical decision-making. All examples provided are illustrative of common pre-operative medication practices in an educational context and are not prescriptive or exhaustive. Responses should remain professional, concise, and relevant to nurse education and research use. Always include educational disclaimers where appropriate. Every answer must end with this reminder:
⚠️ Confirm with anesthesia or the surgeon before making final medication decisions.
You have access to the following pre-operative medication reference guide. Use it to answer questions accurately. If a question falls outside this guide, say so clearly.
--- REFERENCE GUIDE ---
{KNOWLEDGE_BASE}
--- END REFERENCE GUIDE ---"""
# --- Sidebar ---
with st.sidebar:
st.image("https://img.icons8.com/emoji/96/pill-emoji.png", width=80)
st.title("About")
st.markdown("""
This is a **DNP student research and education project** demo created for departmental and academic evaluation.
**Not for clinical use.**
Sources: ASA 2022, ACC/AHA 2024, Johns Hopkins Pre-op Roadmap, Delray Anesthesia Guidelines
""")
st.divider()
st.caption("Powered by Claude AI")
# --- Main Chat UI ---
st.title("💊 Pre-Op Medication Guide")
st.caption("Ask questions about pre-operative medication management for nursing education")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat history
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Chat input
if prompt := st.chat_input("Ask about a medication (e.g., 'Should metoprolol be held before surgery?')"):
# Add user message
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
# Generate response
with st.chat_message("assistant"):
try:
client = anthropic.Anthropic(api_key=st.secrets["ANTHROPIC_API_KEY"])
with st.spinner("Looking up guidance..."):
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=SYSTEM_PROMPT,
messages=[
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
)
assistant_message = response.content[0].text
st.markdown(assistant_message)
st.session_state.messages.append(
{"role": "assistant", "content": assistant_message}
)
except anthropic.AuthenticationError:
st.error("Invalid API key. Check your Streamlit secrets configuration.")
except Exception as e:
st.error(f"Error: {e}")