Update app.py
Browse files
app.py
CHANGED
@@ -147,7 +147,6 @@ def search_text_list(text_list: Optional[List[str]], search_terms: List[str]) ->
|
|
147 |
break
|
148 |
return found_snippets
|
149 |
|
150 |
-
|
151 |
# --- Other Helper Functions (parse_bp, check_red_flags, format_patient_data_for_prompt) ---
|
152 |
def parse_bp(bp_string: str) -> Optional[tuple[int, int]]:
|
153 |
if not isinstance(bp_string, str):
|
@@ -235,7 +234,6 @@ def format_patient_data_for_prompt(data: dict) -> str:
|
|
235 |
prompt_str += f"**{section_title}:** {value}\n"
|
236 |
return prompt_str.strip()
|
237 |
|
238 |
-
|
239 |
# --- Tool Definitions ---
|
240 |
class LabOrderInput(BaseModel):
|
241 |
test_name: str = Field(...)
|
@@ -261,6 +259,9 @@ class FlagRiskInput(BaseModel):
|
|
261 |
|
262 |
@tool("order_lab_test", args_schema=LabOrderInput)
|
263 |
def order_lab_test(test_name: str, reason: str, priority: str = "Routine") -> str:
|
|
|
|
|
|
|
264 |
print(f"Executing order_lab_test: {test_name}, Reason: {reason}, Priority: {priority}")
|
265 |
return json.dumps({
|
266 |
"status": "success",
|
@@ -270,6 +271,9 @@ def order_lab_test(test_name: str, reason: str, priority: str = "Routine") -> st
|
|
270 |
|
271 |
@tool("prescribe_medication", args_schema=PrescriptionInput)
|
272 |
def prescribe_medication(medication_name: str, dosage: str, route: str, frequency: str, duration: str, reason: str) -> str:
|
|
|
|
|
|
|
273 |
print(f"Executing prescribe_medication: {medication_name} {dosage}...")
|
274 |
return json.dumps({
|
275 |
"status": "success",
|
@@ -279,6 +283,9 @@ def prescribe_medication(medication_name: str, dosage: str, route: str, frequenc
|
|
279 |
|
280 |
@tool("check_drug_interactions", args_schema=InteractionCheckInput)
|
281 |
def check_drug_interactions(potential_prescription: str, current_medications: Optional[List[str]] = None, allergies: Optional[List[str]] = None) -> str:
|
|
|
|
|
|
|
282 |
print(f"\n--- Executing REAL check_drug_interactions ---")
|
283 |
print(f"Checking potential prescription: '{potential_prescription}'")
|
284 |
warnings = []
|
@@ -359,6 +366,9 @@ def check_drug_interactions(potential_prescription: str, current_medications: Op
|
|
359 |
|
360 |
@tool("flag_risk", args_schema=FlagRiskInput)
|
361 |
def flag_risk(risk_description: str, urgency: str) -> str:
|
|
|
|
|
|
|
362 |
print(f"Executing flag_risk: {risk_description}, Urgency: {urgency}")
|
363 |
st.error(f"π¨ **{urgency.upper()} RISK FLAGGED by AI:** {risk_description}", icon="π¨")
|
364 |
return json.dumps({
|
|
|
147 |
break
|
148 |
return found_snippets
|
149 |
|
|
|
150 |
# --- Other Helper Functions (parse_bp, check_red_flags, format_patient_data_for_prompt) ---
|
151 |
def parse_bp(bp_string: str) -> Optional[tuple[int, int]]:
|
152 |
if not isinstance(bp_string, str):
|
|
|
234 |
prompt_str += f"**{section_title}:** {value}\n"
|
235 |
return prompt_str.strip()
|
236 |
|
|
|
237 |
# --- Tool Definitions ---
|
238 |
class LabOrderInput(BaseModel):
|
239 |
test_name: str = Field(...)
|
|
|
259 |
|
260 |
@tool("order_lab_test", args_schema=LabOrderInput)
|
261 |
def order_lab_test(test_name: str, reason: str, priority: str = "Routine") -> str:
|
262 |
+
"""
|
263 |
+
Orders a lab test with the specified test name, reason, and priority.
|
264 |
+
"""
|
265 |
print(f"Executing order_lab_test: {test_name}, Reason: {reason}, Priority: {priority}")
|
266 |
return json.dumps({
|
267 |
"status": "success",
|
|
|
271 |
|
272 |
@tool("prescribe_medication", args_schema=PrescriptionInput)
|
273 |
def prescribe_medication(medication_name: str, dosage: str, route: str, frequency: str, duration: str, reason: str) -> str:
|
274 |
+
"""
|
275 |
+
Prepares a prescription for the specified medication including dosage, route, frequency, and duration.
|
276 |
+
"""
|
277 |
print(f"Executing prescribe_medication: {medication_name} {dosage}...")
|
278 |
return json.dumps({
|
279 |
"status": "success",
|
|
|
283 |
|
284 |
@tool("check_drug_interactions", args_schema=InteractionCheckInput)
|
285 |
def check_drug_interactions(potential_prescription: str, current_medications: Optional[List[str]] = None, allergies: Optional[List[str]] = None) -> str:
|
286 |
+
"""
|
287 |
+
Checks for potential drug interactions and allergy risks for the given prescription.
|
288 |
+
"""
|
289 |
print(f"\n--- Executing REAL check_drug_interactions ---")
|
290 |
print(f"Checking potential prescription: '{potential_prescription}'")
|
291 |
warnings = []
|
|
|
366 |
|
367 |
@tool("flag_risk", args_schema=FlagRiskInput)
|
368 |
def flag_risk(risk_description: str, urgency: str) -> str:
|
369 |
+
"""
|
370 |
+
Flags a clinical risk with the provided description and urgency.
|
371 |
+
"""
|
372 |
print(f"Executing flag_risk: {risk_description}, Urgency: {urgency}")
|
373 |
st.error(f"π¨ **{urgency.upper()} RISK FLAGGED by AI:** {risk_description}", icon="π¨")
|
374 |
return json.dumps({
|