fix(pipeline): strictly route uncoded conditions to abstentions on primary-fix
This commit is contained in:
@@ -1038,6 +1038,7 @@ def finalize_output_node(state: PipelineGraphState) -> dict[str, Any]:
|
|||||||
|
|
||||||
# SEPARATION OF CLINICAL DIAGNOSIS AND ICD CODE MAPPING (Sections 4 & 11)
|
# SEPARATION OF CLINICAL DIAGNOSIS AND ICD CODE MAPPING (Sections 4 & 11)
|
||||||
# If primary diagnosis was clinically confirmed and established, but ICD mapping abstained or failed:
|
# If primary diagnosis was clinically confirmed and established, but ICD mapping abstained or failed:
|
||||||
|
# If primary diagnosis was clinically confirmed and established, but ICD mapping abstained or failed:
|
||||||
if primary_response is None:
|
if primary_response is None:
|
||||||
clin_primary = None
|
clin_primary = None
|
||||||
for c in classified:
|
for c in classified:
|
||||||
@@ -1049,57 +1050,22 @@ def finalize_output_node(state: PipelineGraphState) -> dict[str, Any]:
|
|||||||
|
|
||||||
if clin_primary:
|
if clin_primary:
|
||||||
term = getattr(clin_primary, "normalized_diagnosis", None) or getattr(clin_primary, "raw_term", "")
|
term = getattr(clin_primary, "normalized_diagnosis", None) or getattr(clin_primary, "raw_term", "")
|
||||||
quote = (
|
if not any(a.reason == AbstentionReason.NO_MATCHING_ICD_CANDIDATE and a.raw_term and a.raw_term.lower() == term.lower() for a in abstentions):
|
||||||
getattr(clin_primary, "primary_evidence_quote", None)
|
|
||||||
or (
|
|
||||||
clin_primary.context.evidence.quote
|
|
||||||
if hasattr(clin_primary, "context") and hasattr(clin_primary.context, "evidence")
|
|
||||||
else ""
|
|
||||||
)
|
|
||||||
or getattr(clin_primary, "evidence_quote", "")
|
|
||||||
)
|
|
||||||
# Diagnosis is clinically ACCEPTED as primary; only ICD mapping is abstained
|
|
||||||
primary_response = CodedDiagnosisResponse(
|
|
||||||
raw_term=getattr(clin_primary, "raw_term", term),
|
|
||||||
normalized_diagnosis=term,
|
|
||||||
description=term,
|
|
||||||
database_code=None,
|
|
||||||
database_description=None,
|
|
||||||
matching_status="NO_DATABASE_MATCH",
|
|
||||||
source_section=getattr(clin_primary, "source_section", "") or "DISCHARGE_DIAGNOSES",
|
|
||||||
source_span=getattr(clin_primary, "source_span", None),
|
|
||||||
role=DiagnosisRole.PRIMARY,
|
|
||||||
acuity=Acuity.ACUTE
|
|
||||||
if "acute" in term.lower()
|
|
||||||
else Acuity.CHRONIC
|
|
||||||
if "chronic" in term.lower()
|
|
||||||
else Acuity.UNSPECIFIED,
|
|
||||||
certainty=Certainty.CONFIRMED,
|
|
||||||
evidence_quote=quote,
|
|
||||||
evidence=[{
|
|
||||||
"quote": quote,
|
|
||||||
"section": "DISCHARGE_DIAGNOSES",
|
|
||||||
"evidence_type": "PRIMARY_DIAGNOSIS",
|
|
||||||
}],
|
|
||||||
confidence_score=getattr(clin_primary, "evidence_strength", 1.0),
|
|
||||||
is_terminal_billable=False,
|
|
||||||
icd10cm=None, # ICD code abstained
|
|
||||||
icdo=None,
|
|
||||||
cpt=None,
|
|
||||||
)
|
|
||||||
if not any(a.reason == AbstentionReason.NO_MATCHING_ICD_CANDIDATE for a in abstentions):
|
|
||||||
abstentions.append(
|
abstentions.append(
|
||||||
AbstentionRecord(
|
AbstentionRecord(
|
||||||
diagnosis_id=getattr(clin_primary, "diagnosis_id", "primary"),
|
diagnosis_id=getattr(clin_primary, "diagnosis_id", "primary"),
|
||||||
raw_term=term,
|
raw_term=term,
|
||||||
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
||||||
detail=f"Clinical diagnosis '{term}' is accepted as primary, but ICD-10-CM mapping is abstained.",
|
detail=f"Clinical primary diagnosis '{term}' lacked verified local code match; strictly abstained under coding rules.",
|
||||||
stage=PipelineStage.RANKING,
|
stage=PipelineStage.VALIDATION,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if secondary_responses:
|
||||||
|
# Promote top coded secondary to primary role
|
||||||
|
primary_response = secondary_responses.pop(0)
|
||||||
|
primary_response.role = DiagnosisRole.PRIMARY
|
||||||
|
|
||||||
# SEPARATION OF CLINICAL DIAGNOSIS AND ICD CODE MAPPING FOR SECONDARIES
|
# SEPARATION OF CLINICAL DIAGNOSIS AND ICD CODE MAPPING FOR SECONDARIES
|
||||||
# Ensure every active secondary diagnosis clinically confirmed is retained in secondary_responses
|
|
||||||
seen_sec_terms = set()
|
seen_sec_terms = set()
|
||||||
if primary_response:
|
if primary_response:
|
||||||
if primary_response.normalized_diagnosis:
|
if primary_response.normalized_diagnosis:
|
||||||
@@ -1174,44 +1140,17 @@ def finalize_output_node(state: PipelineGraphState) -> dict[str, Any]:
|
|||||||
if not is_valid_cand:
|
if not is_valid_cand:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Clinical condition had no matching code in authoritative database; explicitly abstain ICD code mapping
|
# Clinical condition has no matching code in authoritative database; put strictly in abstain
|
||||||
if not any(a.raw_term and a.raw_term.lower() == c_term.lower() for a in abstentions):
|
if not any(a.raw_term and a.raw_term.lower() == c_term.lower() for a in abstentions):
|
||||||
abstentions.append(
|
abstentions.append(
|
||||||
AbstentionRecord(
|
AbstentionRecord(
|
||||||
diagnosis_id=getattr(c, "diagnosis_id", "secondary"),
|
diagnosis_id=getattr(c, "diagnosis_id", "secondary"),
|
||||||
raw_term=c_term,
|
raw_term=c_term,
|
||||||
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
||||||
detail=f"Condition '{c_term}' lacked verified ICD database match; abstained.",
|
detail=f"Condition '{c_term}' lacked verified local code match; strictly abstained under coding rules.",
|
||||||
stage=PipelineStage.RANKING,
|
stage=PipelineStage.VALIDATION,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Preserve clinically confirmed secondary diagnosis in secondary_responses
|
|
||||||
sec_resp = CodedDiagnosisResponse(
|
|
||||||
raw_term=getattr(c, "raw_term", c_term),
|
|
||||||
normalized_diagnosis=c_term,
|
|
||||||
description=c_term,
|
|
||||||
database_code=None,
|
|
||||||
database_description=None,
|
|
||||||
matching_status="NO_DATABASE_MATCH",
|
|
||||||
source_section=getattr(c, "source_section", "") or (c.context.evidence.source_section if hasattr(c, "context") and hasattr(c.context, "evidence") and c.context.evidence else "CLINICAL_DOCUMENTATION"),
|
|
||||||
source_span=getattr(c, "source_span", None),
|
|
||||||
role=DiagnosisRole.SECONDARY,
|
|
||||||
acuity=getattr(c, "acuity", Acuity.UNSPECIFIED),
|
|
||||||
certainty=getattr(c, "certainty", Certainty.CONFIRMED),
|
|
||||||
evidence_quote=c_quote,
|
|
||||||
evidence=[{
|
|
||||||
"quote": c_quote,
|
|
||||||
"section": getattr(c, "source_section", "") or "CLINICAL_DOCUMENTATION",
|
|
||||||
"evidence_type": "SECONDARY_DIAGNOSIS",
|
|
||||||
}] if c_quote else [],
|
|
||||||
confidence_score=getattr(c, "evidence_strength", 1.0),
|
|
||||||
is_terminal_billable=False,
|
|
||||||
icd10cm=None,
|
|
||||||
icdo=None,
|
|
||||||
cpt=None,
|
|
||||||
)
|
|
||||||
secondary_responses.append(sec_resp)
|
|
||||||
seen_sec_terms.add(c_norm)
|
seen_sec_terms.add(c_norm)
|
||||||
|
|
||||||
# Suppress Z71.1 ("feared health complaint in whom no diagnosis is made") when real clinical conditions exist
|
# Suppress Z71.1 ("feared health complaint in whom no diagnosis is made") when real clinical conditions exist
|
||||||
@@ -1220,6 +1159,47 @@ def finalize_output_node(state: PipelineGraphState) -> dict[str, Any]:
|
|||||||
primary_response.role = DiagnosisRole.PRIMARY
|
primary_response.role = DiagnosisRole.PRIMARY
|
||||||
secondary_responses = [s for s in secondary_responses if s.code != "Z71.1"]
|
secondary_responses = [s for s in secondary_responses if s.code != "Z71.1"]
|
||||||
|
|
||||||
|
# Filter secondary_responses so ONLY items with verified local codes are retained; uncoded items are strictly abstained
|
||||||
|
coded_secondaries: list[CodedDiagnosisResponse] = []
|
||||||
|
for s in secondary_responses:
|
||||||
|
s_code = s.code or getattr(s, "database_code", None)
|
||||||
|
if s_code and s_code != "None" and s.matching_status != "NO_DATABASE_MATCH":
|
||||||
|
coded_secondaries.append(s)
|
||||||
|
else:
|
||||||
|
s_name = s.normalized_diagnosis or s.raw_term or s.description or ""
|
||||||
|
if s_name and not any(a.raw_term and a.raw_term.lower() == s_name.lower() for a in abstentions):
|
||||||
|
abstentions.append(
|
||||||
|
AbstentionRecord(
|
||||||
|
diagnosis_id=getattr(s, "diagnosis_id", "secondary-abstained"),
|
||||||
|
raw_term=s_name,
|
||||||
|
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
||||||
|
detail=f"Condition '{s_name}' lacked verified local code match; strictly abstained under coding rules.",
|
||||||
|
stage=PipelineStage.VALIDATION,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
secondary_responses = coded_secondaries
|
||||||
|
|
||||||
|
# Check primary_response for local code match: if missing, abstain and promote coded secondary if available
|
||||||
|
if primary_response:
|
||||||
|
p_code = primary_response.code or getattr(primary_response, "database_code", None)
|
||||||
|
if not p_code or p_code == "None" or primary_response.matching_status == "NO_DATABASE_MATCH":
|
||||||
|
p_name = primary_response.normalized_diagnosis or primary_response.raw_term or primary_response.description or ""
|
||||||
|
if p_name and not any(a.raw_term and a.raw_term.lower() == p_name.lower() for a in abstentions):
|
||||||
|
abstentions.append(
|
||||||
|
AbstentionRecord(
|
||||||
|
diagnosis_id=getattr(primary_response, "diagnosis_id", "primary-abstained"),
|
||||||
|
raw_term=p_name,
|
||||||
|
reason=AbstentionReason.NO_MATCHING_ICD_CANDIDATE,
|
||||||
|
detail=f"Primary condition '{p_name}' lacked verified local code match; strictly abstained under coding rules.",
|
||||||
|
stage=PipelineStage.VALIDATION,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if secondary_responses:
|
||||||
|
primary_response = secondary_responses.pop(0)
|
||||||
|
primary_response.role = DiagnosisRole.PRIMARY
|
||||||
|
else:
|
||||||
|
primary_response = None
|
||||||
|
|
||||||
# Enforce clean role separation: secondary section must NEVER duplicate the primary diagnosis
|
# Enforce clean role separation: secondary section must NEVER duplicate the primary diagnosis
|
||||||
if primary_response:
|
if primary_response:
|
||||||
pri_code = primary_response.code
|
pri_code = primary_response.code
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ class CodingResult(BaseModel):
|
|||||||
return "None"
|
return "None"
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
if self.primary_diagnosis:
|
if self.primary_diagnosis and self.primary_diagnosis.code and self.primary_diagnosis.code != "None" and self.primary_diagnosis.matching_status != "NO_DATABASE_MATCH":
|
||||||
p = self.primary_diagnosis
|
p = self.primary_diagnosis
|
||||||
p_name = p.normalized_diagnosis or p.raw_term or p.description
|
p_name = p.normalized_diagnosis or p.raw_term or p.description
|
||||||
p_code = _get_formatted_code(p)
|
p_code = _get_formatted_code(p)
|
||||||
@@ -238,9 +238,13 @@ class CodingResult(BaseModel):
|
|||||||
else:
|
else:
|
||||||
lines.append("primary diagnosis: None, code: None, evidence: None")
|
lines.append("primary diagnosis: None, code: None, evidence: None")
|
||||||
|
|
||||||
if self.secondary_diagnoses:
|
coded_secondaries = [
|
||||||
|
s for s in (self.secondary_diagnoses or [])
|
||||||
|
if s.code and s.code != "None" and s.matching_status != "NO_DATABASE_MATCH"
|
||||||
|
]
|
||||||
|
if coded_secondaries:
|
||||||
lines.append("secondary diagnosises:")
|
lines.append("secondary diagnosises:")
|
||||||
for s in self.secondary_diagnoses:
|
for s in coded_secondaries:
|
||||||
s_name = s.normalized_diagnosis or s.raw_term or s.description
|
s_name = s.normalized_diagnosis or s.raw_term or s.description
|
||||||
s_code = _get_formatted_code(s)
|
s_code = _get_formatted_code(s)
|
||||||
s_ev = _get_cand_ev(s)
|
s_ev = _get_cand_ev(s)
|
||||||
|
|||||||
@@ -158,19 +158,16 @@ def _clean_audit_from_evidence(ev: str) -> str:
|
|||||||
def render_primary_diagnosis(primary: CodedDiagnosisResponse | None) -> None:
|
def render_primary_diagnosis(primary: CodedDiagnosisResponse | None) -> None:
|
||||||
"""Render the primary diagnosis card with evidence and specificity confirmation."""
|
"""Render the primary diagnosis card with evidence and specificity confirmation."""
|
||||||
st.markdown("### 🎯 Primary Diagnosis")
|
st.markdown("### 🎯 Primary Diagnosis")
|
||||||
if not primary:
|
if not primary or not primary.code or primary.code in ("None", "[NO LOCAL CODE]") or primary.matching_status == "NO_DATABASE_MATCH":
|
||||||
st.info("ℹ️ No primary diagnosis assigned for this document (abstained or undetermined).")
|
st.info("ℹ️ No primary diagnosis assigned for this document (abstained or undetermined).")
|
||||||
return
|
return
|
||||||
|
|
||||||
code_display = html.escape(primary.code or "[NO LOCAL CODE]")
|
code_display = html.escape(primary.code)
|
||||||
if primary.matching_status == "NO_DATABASE_MATCH" or not primary.code:
|
billable_badge = (
|
||||||
billable_badge = '<span class="pill-badge badge-warning">No Database Match</span>'
|
'<span class="pill-badge badge-success">✓ HIPAA Billable Leaf</span>'
|
||||||
else:
|
if primary.is_terminal_billable
|
||||||
billable_badge = (
|
else '<span class="pill-badge badge-danger">⚠ Non-Billable Header</span>'
|
||||||
'<span class="pill-badge badge-success">✓ HIPAA Billable Leaf</span>'
|
)
|
||||||
if primary.is_terminal_billable
|
|
||||||
else '<span class="pill-badge badge-danger">⚠ Non-Billable Header</span>'
|
|
||||||
)
|
|
||||||
acuity_badge = f'<span class="pill-badge badge-info">{html.escape(primary.acuity.value if hasattr(primary.acuity, "value") else str(primary.acuity))}</span>'
|
acuity_badge = f'<span class="pill-badge badge-info">{html.escape(primary.acuity.value if hasattr(primary.acuity, "value") else str(primary.acuity))}</span>'
|
||||||
certainty_badge = f'<span class="pill-badge badge-secondary">{html.escape(primary.certainty.value if hasattr(primary.certainty, "value") else str(primary.certainty))}</span>'
|
certainty_badge = f'<span class="pill-badge badge-secondary">{html.escape(primary.certainty.value if hasattr(primary.certainty, "value") else str(primary.certainty))}</span>'
|
||||||
|
|
||||||
@@ -236,21 +233,22 @@ def render_primary_diagnosis(primary: CodedDiagnosisResponse | None) -> None:
|
|||||||
|
|
||||||
def render_secondary_diagnoses(secondaries: list[CodedDiagnosisResponse]) -> None:
|
def render_secondary_diagnoses(secondaries: list[CodedDiagnosisResponse]) -> None:
|
||||||
"""Render the list of validated secondary comorbid diagnoses."""
|
"""Render the list of validated secondary comorbid diagnoses."""
|
||||||
st.markdown(f"### 📋 Secondary Diagnoses ({len(secondaries)})")
|
valid_secondaries = [
|
||||||
if not secondaries:
|
s for s in (secondaries or [])
|
||||||
|
if s.code and s.code not in ("None", "[NO LOCAL CODE]") and s.matching_status != "NO_DATABASE_MATCH"
|
||||||
|
]
|
||||||
|
st.markdown(f"### 📋 Secondary Diagnoses ({len(valid_secondaries)})")
|
||||||
|
if not valid_secondaries:
|
||||||
st.write("No secondary comorbid diagnoses identified.")
|
st.write("No secondary comorbid diagnoses identified.")
|
||||||
return
|
return
|
||||||
|
|
||||||
for idx, diag in enumerate(secondaries, start=1):
|
for idx, diag in enumerate(valid_secondaries, start=1):
|
||||||
sec_code_display = html.escape(diag.code or "[NO LOCAL CODE]")
|
sec_code_display = html.escape(diag.code)
|
||||||
if diag.matching_status == "NO_DATABASE_MATCH" or not diag.code:
|
billable_badge = (
|
||||||
billable_badge = '<span class="pill-badge badge-warning">No Database Match</span>'
|
'<span class="pill-badge badge-success">✓ Billable</span>'
|
||||||
else:
|
if diag.is_terminal_billable
|
||||||
billable_badge = (
|
else '<span class="pill-badge badge-danger">⚠ Non-Billable</span>'
|
||||||
'<span class="pill-badge badge-success">✓ Billable</span>'
|
)
|
||||||
if diag.is_terminal_billable
|
|
||||||
else '<span class="pill-badge badge-danger">⚠ Non-Billable</span>'
|
|
||||||
)
|
|
||||||
acuity_str = html.escape(diag.acuity.value if hasattr(diag.acuity, "value") else str(diag.acuity))
|
acuity_str = html.escape(diag.acuity.value if hasattr(diag.acuity, "value") else str(diag.acuity))
|
||||||
certainty_str = html.escape(diag.certainty.value if hasattr(diag.certainty, "value") else str(diag.certainty))
|
certainty_str = html.escape(diag.certainty.value if hasattr(diag.certainty, "value") else str(diag.certainty))
|
||||||
|
|
||||||
@@ -317,13 +315,23 @@ def render_abstentions(abstentions: list[AbstentionRecord]) -> None:
|
|||||||
stage_str = abst.stage.value if hasattr(abst.stage, "value") else str(abst.stage)
|
stage_str = abst.stage.value if hasattr(abst.stage, "value") else str(abst.stage)
|
||||||
raw_term = abst.raw_term or "Unspecified Entity"
|
raw_term = abst.raw_term or "Unspecified Entity"
|
||||||
|
|
||||||
|
if (
|
||||||
|
abst.reason == AbstentionReason.NO_MATCHING_ICD_CANDIDATE
|
||||||
|
or reason_str in ("NO_MATCHING_ICD_CANDIDATE", "NO_CANDIDATE_FOUND")
|
||||||
|
or "No local code" in (abst.detail or "")
|
||||||
|
or "lacked verified local code" in (abst.detail or "")
|
||||||
|
):
|
||||||
|
badge_html = '<span class="pill-badge badge-warning">No Local Code (Abstained)</span>'
|
||||||
|
else:
|
||||||
|
badge_html = f'<span class="pill-badge badge-danger">{reason_str}</span>'
|
||||||
|
|
||||||
st.markdown(
|
st.markdown(
|
||||||
clean_html(
|
clean_html(
|
||||||
f"""
|
f"""
|
||||||
<div class="abstention-card">
|
<div class="abstention-card">
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;">
|
||||||
<strong style="color: #f87171; font-size: 14px;">Condition: {raw_term}</strong>
|
<strong style="color: #f87171; font-size: 14px;">Condition: {raw_term}</strong>
|
||||||
<span class="pill-badge badge-danger">{reason_str}</span>
|
{badge_html}
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: 13px; color: #e2e8f0;">{abst.detail}</div>
|
<div style="font-size: 13px; color: #e2e8f0;">{abst.detail}</div>
|
||||||
<div style="font-size: 11px; color: #94a3b8; margin-top: 4px;">Enforced at stage: <code>{stage_str}</code></div>
|
<div style="font-size: 11px; color: #94a3b8; margin-top: 4px;">Enforced at stage: <code>{stage_str}</code></div>
|
||||||
|
|||||||
@@ -144,14 +144,51 @@ async def test_full_pipeline_multi_condition_formatting() -> None:
|
|||||||
assert final_result.primary_diagnosis.role == DiagnosisRole.PRIMARY
|
assert final_result.primary_diagnosis.role == DiagnosisRole.PRIMARY
|
||||||
assert "cholecystitis" in final_result.primary_diagnosis.description.lower()
|
assert "cholecystitis" in final_result.primary_diagnosis.description.lower()
|
||||||
|
|
||||||
# All other valid active conditions must be in secondary diagnoses
|
# All valid conditions with local code are in secondary diagnoses
|
||||||
assert len(final_result.secondary_diagnoses) >= 2
|
assert len(final_result.secondary_diagnoses) >= 2
|
||||||
sec_names = [s.description.lower() for s in final_result.secondary_diagnoses]
|
sec_names = [s.description.lower() for s in final_result.secondary_diagnoses]
|
||||||
assert any("choledocholithiasis" in n or "calculus" in n for n in sec_names)
|
|
||||||
assert any("diabetes" in n for n in sec_names)
|
assert any("diabetes" in n for n in sec_names)
|
||||||
|
assert any("hypertension" in n for n in sec_names)
|
||||||
|
|
||||||
|
# Conditions without local code match are strictly put into abstentions
|
||||||
|
abst_terms = [(a.raw_term or "").lower() for a in final_result.abstentions]
|
||||||
|
assert any("choledocholithiasis" in t for t in abst_terms)
|
||||||
|
|
||||||
output = final_result.format_output()
|
output = final_result.format_output()
|
||||||
assert "primary diagnosis: " in output
|
assert "primary diagnosis: " in output
|
||||||
assert "secondary diagnosises:" in output
|
assert "secondary diagnosises:" in output
|
||||||
assert "code: " in output
|
assert "code: " in output
|
||||||
assert "evidence: " in output
|
assert "evidence: " in output
|
||||||
|
assert "[NO LOCAL CODE]" not in output
|
||||||
|
assert "code: None" not in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_no_local_code_abstention_guarantee() -> None:
|
||||||
|
"""Verify that any clinical condition without a valid local database code is strictly abstained."""
|
||||||
|
note = """
|
||||||
|
DISCHARGE SUMMARY
|
||||||
|
PRIMARY DIAGNOSIS: Deviated nasal septum
|
||||||
|
SECONDARY DIAGNOSES: Nasal obstruction, Chronic sinusitis
|
||||||
|
HOSPITAL COURSE: Patient presented for septoplasty due to deviated nasal septum.
|
||||||
|
Also noted nasal obstruction and chronic sinusitis.
|
||||||
|
"""
|
||||||
|
final_result = await process_clinical_document(
|
||||||
|
source=note,
|
||||||
|
document_id="doc-uncoded-abstain-test",
|
||||||
|
)
|
||||||
|
assert final_result is not None
|
||||||
|
# For every item in secondary diagnoses, code must not be empty or NO_DATABASE_MATCH
|
||||||
|
for s in final_result.secondary_diagnoses:
|
||||||
|
assert s.code and s.code != "None" and s.code != "[NO LOCAL CODE]"
|
||||||
|
assert s.matching_status != "NO_DATABASE_MATCH"
|
||||||
|
|
||||||
|
if final_result.primary_diagnosis:
|
||||||
|
assert final_result.primary_diagnosis.code
|
||||||
|
assert final_result.primary_diagnosis.code not in ("None", "[NO LOCAL CODE]")
|
||||||
|
assert final_result.primary_diagnosis.matching_status != "NO_DATABASE_MATCH"
|
||||||
|
|
||||||
|
output = final_result.format_output()
|
||||||
|
assert "[NO LOCAL CODE]" not in output
|
||||||
|
assert "code: None" not in output
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user