fix(pipeline): heal diagnosis extraction, role classification, and ICD mapping invariants

- Architecture Audit & Root Cause Analysis: Documented full 10-node runtime architecture, 8 failure root causes, and target architecture in ARCHITECTURE_AUDIT.md, ROOT_CAUSE_ANALYSIS.md, and TARGET_ARCHITECTURE.md.
- Strict Separation of Clinical Extraction and Retrieval: Clinical extraction establishes candidate entities prior to retrieval; retrieval never invents diagnoses.
- Generalized Clinical Entity Extraction: Added unstructured narrative fallback parser in ClinicalExtractor for single-sentence and unstructured discharge text; stripped structural role prefixes ('Primary:', 'Secondary:'); constrained procedural corroboration to entity-relevant keywords.
- UHDDS Role Classification & Admitting Significance: Restored section-aware scoring hierarchy prioritizing discharge diagnoses (+5.0) and admission reasons (+3.5); resolved whole-word regex monitoring checks preventing PMH leaks; added clinical admission synonyms for tie-breaking; prioritized acute conditions and definitive etiologies over non-specific symptoms.
- Subtype Specificity & Etiology Alignment: Guarded against hallucinated and unsupported etiologies (transplant, rheumatic, hypertensive) and subtypes in CandidateRanker and DeterministicValidator; expanded retrieval candidate window (top_k=25) ensuring general leaf codes (e.g. I50.9) remain in candidate pool for realignment.
- Test Suite: 100% pass rate achieved across all 125 repository unit, integration, guardrail, and end-to-end tests.
This commit is contained in:
Abhinav Gupta
2026-10-05 10:56:32 +05:30
parent fc5eb7aaab
commit 1b09529534
15 changed files with 2347 additions and 220 deletions
+28 -12
View File
@@ -453,18 +453,34 @@ class CandidateRankingAgent(BaseAgent):
elif is_acute_doc and not is_chronic_doc:
score -= 0.25
# 4. Specificity penalty for unsupported subtypes
# Heart failure: systolic / diastolic
if "systolic" in desc_lower and not any(
w in full_context for w in ["systolic", "hfref", "reduced ejection"]
):
score = 0.05
rationale_parts.append("unsupported systolic specificity")
if "diastolic" in desc_lower and not any(
w in full_context for w in ["diastolic", "hfpef", "preserved ejection"]
):
score = 0.05
rationale_parts.append("unsupported diastolic specificity")
# 4. Specificity penalty for unsupported subtypes and etiologies
# Etiology support check: transplant, rheumatic, hypertensive, postprocedural, congenital, etc.
etiologies = {
"transplant": ["transplant", "allograft", "graft"],
"rheumatic": ["rheumatic"],
"hypertensive": ["hypertension", "hypertensive", "htn", "high blood pressure"],
"postprocedural": ["postprocedural", "postoperative", "post-op", "complication of surgery"],
"congenital": ["congenital", "birth defect", "anomaly"],
"toxic": ["toxic", "toxicity", "poisoning"],
"alcoholic": ["alcoholic", "alcohol", "etoh"],
}
has_unsupported_etiology = False
for etio_word, doc_cues in etiologies.items():
if etio_word in desc_lower and not any(w in full_context for w in doc_cues):
score = 0.05
rationale_parts.append(f"unsupported {etio_word} etiology")
has_unsupported_etiology = True
break
# Heart failure: systolic / diastolic / right / left / end stage
if not has_unsupported_etiology and ("heart" in desc_lower and "failure" in desc_lower):
for sub in ["systolic", "diastolic", "right", "left", "high output", "end stage", "biventricular", "other"]:
if sub in desc_lower and not any(
w in full_context for w in [sub, "hfref", "hfpef", "reduced ejection", "preserved ejection"]
):
score = 0.05
rationale_parts.append(f"unsupported {sub} specificity")
break
# Diabetes complications
if any(