Update app.py
Browse files
app.py
CHANGED
@@ -231,11 +231,11 @@ def clean_response(text: str) -> str:
|
|
231 |
# Pre-compiled regex patterns for cleaning
|
232 |
patterns = [
|
233 |
(re.compile(r"\[.*?\]|\bNone\b", re.IGNORECASE), ""),
|
234 |
-
(re.compile(r"To analyze
|
235 |
(re.compile(r"Since the previous attempts.*?\.", re.IGNORECASE), ""),
|
236 |
-
(re.compile(r"I need to.*?
|
237 |
-
(re.compile(r"
|
238 |
-
(re.compile(r"
|
239 |
(re.compile(r"This requires reviewing.*?\.", re.IGNORECASE), ""),
|
240 |
(re.compile(r"Given the context, it is important to review.*?\.", re.IGNORECASE), ""),
|
241 |
(re.compile(r"\s+"), " "),
|
@@ -286,8 +286,8 @@ def summarize_findings(combined_response: str) -> str:
|
|
286 |
if diagnosis:
|
287 |
diagnoses.append(diagnosis)
|
288 |
|
289 |
-
# Extract findings from non-sectioned text
|
290 |
-
medication_pattern = re.compile(r"medications
|
291 |
evaluation_pattern = re.compile(r"psychiatric evaluation.*?mention of ([^\.]+)", re.IGNORECASE)
|
292 |
|
293 |
for line in combined_response.splitlines():
|
@@ -298,12 +298,12 @@ def summarize_findings(combined_response: str) -> str:
|
|
298 |
med_match = medication_pattern.search(line)
|
299 |
if med_match:
|
300 |
meds = med_match.group(1).strip()
|
301 |
-
diagnoses.append(f"use of medications ({meds}),
|
302 |
|
303 |
eval_match = evaluation_pattern.search(line)
|
304 |
if eval_match:
|
305 |
details = eval_match.group(1).strip()
|
306 |
-
diagnoses.append(f"psychiatric evaluation noting {details},
|
307 |
|
308 |
if not diagnoses:
|
309 |
return "No missed diagnoses were identified in the provided records."
|
@@ -316,7 +316,7 @@ def summarize_findings(combined_response: str) -> str:
|
|
316 |
summary = "The patient record indicates missed diagnoses including "
|
317 |
summary += ", ".join(unique_diagnoses[:-1])
|
318 |
summary += f", and {unique_diagnoses[-1]}" if len(unique_diagnoses) > 1 else unique_diagnoses[0]
|
319 |
-
summary += ". These findings
|
320 |
|
321 |
return summary
|
322 |
|
@@ -352,7 +352,7 @@ def init_agent():
|
|
352 |
def create_ui(agent):
|
353 |
"""Optimized UI creation with pre-compiled templates"""
|
354 |
PROMPT_TEMPLATE = """
|
355 |
-
Analyze the patient record excerpt for missed diagnoses
|
356 |
Patient Record Excerpt (Chunk {0} of {1}):
|
357 |
{chunk}
|
358 |
"""
|
|
|
231 |
# Pre-compiled regex patterns for cleaning
|
232 |
patterns = [
|
233 |
(re.compile(r"\[.*?\]|\bNone\b", re.IGNORECASE), ""),
|
234 |
+
(re.compile(r"To (analyze|proceed).*?medications\.", re.IGNORECASE), ""),
|
235 |
(re.compile(r"Since the previous attempts.*?\.", re.IGNORECASE), ""),
|
236 |
+
(re.compile(r"I need to.*?results\.", re.IGNORECASE), ""),
|
237 |
+
(re.compile(r"(Therefore, )?I will start by retrieving.*?\.", re.IGNORECASE), ""),
|
238 |
+
(re.compile(r"(Therefore, )?Retrieving tools.*?\.", re.IGNORECASE), ""),
|
239 |
(re.compile(r"This requires reviewing.*?\.", re.IGNORECASE), ""),
|
240 |
(re.compile(r"Given the context, it is important to review.*?\.", re.IGNORECASE), ""),
|
241 |
(re.compile(r"\s+"), " "),
|
|
|
286 |
if diagnosis:
|
287 |
diagnoses.append(diagnosis)
|
288 |
|
289 |
+
# Extract findings from non-sectioned text
|
290 |
+
medication_pattern = re.compile(r"medications includ(?:e|ing|ed) ([^\.]+)", re.IGNORECASE)
|
291 |
evaluation_pattern = re.compile(r"psychiatric evaluation.*?mention of ([^\.]+)", re.IGNORECASE)
|
292 |
|
293 |
for line in combined_response.splitlines():
|
|
|
298 |
med_match = medication_pattern.search(line)
|
299 |
if med_match:
|
300 |
meds = med_match.group(1).strip()
|
301 |
+
diagnoses.append(f"use of medications ({meds}), suggesting an undiagnosed psychiatric condition requiring urgent review")
|
302 |
|
303 |
eval_match = evaluation_pattern.search(line)
|
304 |
if eval_match:
|
305 |
details = eval_match.group(1).strip()
|
306 |
+
diagnoses.append(f"psychiatric evaluation noting {details}, indicating a potential missed psychiatric diagnosis requiring urgent review")
|
307 |
|
308 |
if not diagnoses:
|
309 |
return "No missed diagnoses were identified in the provided records."
|
|
|
316 |
summary = "The patient record indicates missed diagnoses including "
|
317 |
summary += ", ".join(unique_diagnoses[:-1])
|
318 |
summary += f", and {unique_diagnoses[-1]}" if len(unique_diagnoses) > 1 else unique_diagnoses[0]
|
319 |
+
summary += ". These findings suggest potential oversights in the patient's medical evaluation and require urgent clinical review to prevent adverse outcomes."
|
320 |
|
321 |
return summary
|
322 |
|
|
|
352 |
def create_ui(agent):
|
353 |
"""Optimized UI creation with pre-compiled templates"""
|
354 |
PROMPT_TEMPLATE = """
|
355 |
+
Analyze the patient record excerpt for missed diagnoses, focusing only on clinical findings such as symptoms, medications, or evaluation results provided in the excerpt. Provide a concise, evidence-based summary in one paragraph without headings or bullet points. Include specific findings (e.g., 'elevated blood pressure (160/95) on page 10'), their implications (e.g., 'may indicate untreated hypertension'), and recommend urgent review. Do NOT use external tools or retrieve additional data. If no missed diagnoses are found, state 'No missed diagnoses identified' in one sentence. Ignore non-clinical data (e.g., name, date of birth) and other oversight categories (e.g., medication conflicts).
|
356 |
Patient Record Excerpt (Chunk {0} of {1}):
|
357 |
{chunk}
|
358 |
"""
|