Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- README.md +21 -13
- app.py +126 -0
- constants.py +46 -0
- interfaces.py +11 -0
- models.py +22 -0
- requirements.txt +7 -0
- scoring_service.py +115 -0
README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version:
|
| 9 |
-
app_file: app.py
|
| 10 |
-
pinned: false
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: IOTN Assistant
|
| 3 |
+
emoji: 🦷
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.1
|
| 8 |
+
python_version: 3.12
|
| 9 |
+
app_file: app.py
|
| 10 |
+
pinned: false
|
| 11 |
+
license: mit
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
+
|
| 16 |
+
# IOTN Assistant (Dental Health Component)
|
| 17 |
+
|
| 18 |
+
A professional-grade medical scoring application for calculating the Index of Orthodontic Treatment Need (IOTN).
|
| 19 |
+
|
| 20 |
+
## 🚀 Deployment
|
| 21 |
+
This app runs on Hugging Face Spaces using the Gradio SDK.
|
app.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from scoring_service import IOTNScoringService
|
| 3 |
+
from constants import SOURCE_NOTE
|
| 4 |
+
|
| 5 |
+
# Global service instance
|
| 6 |
+
service = IOTNScoringService()
|
| 7 |
+
|
| 8 |
+
def get_dhc_score(*args):
|
| 9 |
+
keys = [
|
| 10 |
+
"overjet_mm", "lip_competence", "reverse_overjet_mm",
|
| 11 |
+
"mastication_difficulty", "speech_difficulty",
|
| 12 |
+
"crossbite_present", "rcp_icp_discrepancy_mm", "posterior_lingual_crossbite_no_contact",
|
| 13 |
+
"max_contact_displacement_mm", "overbite_mm", "overbite_complete",
|
| 14 |
+
"gingival_trauma", "palatal_trauma",
|
| 15 |
+
"missing_teeth_UR", "missing_teeth_UL", "missing_teeth_LR", "missing_teeth_LL",
|
| 16 |
+
"space_closure_required", "restorative_implications",
|
| 17 |
+
"impeded_eruption", "cleft_lip_palate", "submerged_deciduous", "supplemental_teeth"
|
| 18 |
+
]
|
| 19 |
+
# Ensure all numerical args are handled safely (Gradio Number handles numeric enforcement)
|
| 20 |
+
payload = dict(zip(keys, args))
|
| 21 |
+
result = service.score(payload)
|
| 22 |
+
|
| 23 |
+
findings_list = [f"- **{f.code}**: {f.summary} ({f.evidence})" for f in result.findings]
|
| 24 |
+
findings_md = "### Matched Criteria\n" + "\n".join(findings_list) if findings_list else "No Grade 2+ criteria matched."
|
| 25 |
+
|
| 26 |
+
return (
|
| 27 |
+
f"## Grade {result.grade}",
|
| 28 |
+
f"**{result.classification}**: {result.subcode_label}",
|
| 29 |
+
result.summary,
|
| 30 |
+
findings_md
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
with gr.Blocks(title="IOTN Assistant", theme=gr.themes.Soft()) as demo:
|
| 34 |
+
gr.Markdown("# IOTN DHC Assistant")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
# Input Section (Left)
|
| 38 |
+
with gr.Column(scale=3):
|
| 39 |
+
with gr.Tabs() as tabs:
|
| 40 |
+
with gr.TabItem("Overjet", id=0):
|
| 41 |
+
gr.Markdown("#### Anterior Horizontal Relationship")
|
| 42 |
+
with gr.Row():
|
| 43 |
+
oj_mm = gr.Number(label="Increased Overjet (mm)", value=0.0, precision=1, minimum=0)
|
| 44 |
+
lips = gr.Radio(
|
| 45 |
+
choices=["competent", "incompetent"],
|
| 46 |
+
value="competent",
|
| 47 |
+
label="Lip Competence"
|
| 48 |
+
)
|
| 49 |
+
with gr.Row():
|
| 50 |
+
roj_mm = gr.Number(label="Reverse Overjet (mm)", value=0.0, precision=1, minimum=0)
|
| 51 |
+
mast = gr.Checkbox(label="Masticatory Difficulty")
|
| 52 |
+
speech = gr.Checkbox(label="Speech Difficulty")
|
| 53 |
+
|
| 54 |
+
with gr.TabItem("Crossbite", id=1):
|
| 55 |
+
gr.Markdown("#### Transverse Relationship")
|
| 56 |
+
cb_present = gr.Checkbox(label="Crossbite Present")
|
| 57 |
+
rcp_icp = gr.Number(label="RCP-ICP Discrepancy (mm)", value=0.0, precision=1, minimum=0)
|
| 58 |
+
scissor = gr.Checkbox(label="Posterior lingual crossbite (No contact)")
|
| 59 |
+
|
| 60 |
+
with gr.TabItem("Displacement / Overbite", id=2):
|
| 61 |
+
gr.Markdown("#### Vertical & Crowding")
|
| 62 |
+
with gr.Row():
|
| 63 |
+
disp_mm = gr.Number(label="Max Displacement (mm)", value=0.0, precision=1, minimum=0)
|
| 64 |
+
ob_mm = gr.Number(label="Overbite Depth (mm)", value=0.0, precision=1, minimum=0)
|
| 65 |
+
with gr.Row():
|
| 66 |
+
ob_comp = gr.Checkbox(label="Complete Overbite")
|
| 67 |
+
ging_tr = gr.Checkbox(label="Gingival Trauma")
|
| 68 |
+
pal_tr = gr.Checkbox(label="Palatal Trauma")
|
| 69 |
+
|
| 70 |
+
with gr.TabItem("Missing / Special", id=3):
|
| 71 |
+
gr.Markdown("#### Hypodontia & Other Categories")
|
| 72 |
+
with gr.Row():
|
| 73 |
+
m_ur = gr.Number(label="UR Missing", value=0, precision=0, minimum=0)
|
| 74 |
+
m_ul = gr.Number(label="UL Missing", value=0, precision=0, minimum=0)
|
| 75 |
+
m_lr = gr.Number(label="LR Missing", value=0, precision=0, minimum=0)
|
| 76 |
+
m_ll = gr.Number(label="LL Missing", value=0, precision=0, minimum=0)
|
| 77 |
+
with gr.Row():
|
| 78 |
+
sp_cl = gr.Checkbox(label="Space Closure Required")
|
| 79 |
+
rest_imp = gr.Checkbox(label="Restorative Needs")
|
| 80 |
+
with gr.Row():
|
| 81 |
+
imp_er = gr.Checkbox(label="Impeded Eruption")
|
| 82 |
+
cleft = gr.Checkbox(label="Cleft Lip/Palate")
|
| 83 |
+
subm = gr.Checkbox(label="Submerged Deciduous")
|
| 84 |
+
supp = gr.Checkbox(label="Supplemental Teeth")
|
| 85 |
+
|
| 86 |
+
score_btn = gr.Button("Score Assessment", variant="primary", size="lg")
|
| 87 |
+
|
| 88 |
+
# Results Section (Right)
|
| 89 |
+
with gr.Column(scale=2):
|
| 90 |
+
with gr.Group():
|
| 91 |
+
gr.Markdown("### Assessment Result")
|
| 92 |
+
res_grade = gr.Markdown("## Grade -")
|
| 93 |
+
res_class = gr.Markdown("**Classification -**")
|
| 94 |
+
res_summary = gr.Textbox(label="Summary", interactive=False, lines=2)
|
| 95 |
+
res_findings = gr.Markdown("### Matched Criteria")
|
| 96 |
+
|
| 97 |
+
# Wire up events
|
| 98 |
+
all_inputs = [
|
| 99 |
+
oj_mm, lips, roj_mm, mast, speech,
|
| 100 |
+
cb_present, rcp_icp, scissor,
|
| 101 |
+
disp_mm, ob_mm, ob_comp, ging_tr, pal_tr,
|
| 102 |
+
m_ur, m_ul, m_lr, m_ll, sp_cl, rest_imp,
|
| 103 |
+
imp_er, cleft, subm, supp
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
score_btn.click(
|
| 107 |
+
get_dhc_score,
|
| 108 |
+
inputs=all_inputs,
|
| 109 |
+
outputs=[res_grade, res_class, res_summary, res_findings],
|
| 110 |
+
show_progress="minimal"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
gr.Markdown(f"\n\n--- \n{SOURCE_NOTE}")
|
| 114 |
+
|
| 115 |
+
gr.Examples(
|
| 116 |
+
examples=[
|
| 117 |
+
[10.0, "competent", 0.0, False, False, False, 0.0, False, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
|
| 118 |
+
[5.0, "incompetent", 0.0, False, False, False, 0.0, False, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
|
| 119 |
+
[0.0, "competent", 0.0, False, False, False, 0.0, False, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, True, False, False, False],
|
| 120 |
+
],
|
| 121 |
+
inputs=all_inputs,
|
| 122 |
+
label="Quick Samples"
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|
constants.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IOTN DHC Grade Definitions
|
| 2 |
+
GRADE_LABELS = {
|
| 3 |
+
1: "No need",
|
| 4 |
+
2: "Little need",
|
| 5 |
+
3: "Moderate need",
|
| 6 |
+
4: "Great need",
|
| 7 |
+
5: "Very great need",
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
# Detailed Subcode Descriptions (Box 2.4)
|
| 11 |
+
SUBCODE_LABELS = {
|
| 12 |
+
"5a": "Increased overjet greater than 9 mm",
|
| 13 |
+
"5h": "Extensive hypodontia or multiple missing teeth",
|
| 14 |
+
"5i": "Impeded eruption of teeth",
|
| 15 |
+
"5m": "Reverse overjet greater than 3.5 mm with functional difficulty",
|
| 16 |
+
"5p": "Cleft lip, cleft palate, or craniofacial anomaly",
|
| 17 |
+
"5s": "Submerged deciduous teeth",
|
| 18 |
+
"4a": "Increased overjet greater than 6 mm and up to 9 mm",
|
| 19 |
+
"4b": "Reverse overjet greater than 3.5 mm without reported functional difficulty",
|
| 20 |
+
"4c": "Crossbite with discrepancy greater than 2 mm",
|
| 21 |
+
"4l": "Posterior lingual crossbite with no functional occlusal contact",
|
| 22 |
+
"4m": "Reverse overjet greater than 1 mm and up to 3.5 mm with functional difficulty",
|
| 23 |
+
"4t": "Partially erupted, tipped, or impacted teeth against adjacent teeth",
|
| 24 |
+
"4x": "Presence of supernumerary teeth",
|
| 25 |
+
"3a": "Increased overjet greater than 3.5 mm and up to 6 mm with incompetent lips",
|
| 26 |
+
"3b": "Reverse overjet greater than 1 mm and up to 3.5 mm without reported functional difficulty",
|
| 27 |
+
"3c": "Crossbite with discrepancy greater than 1 mm and up to 2 mm",
|
| 28 |
+
"3d": "Contact point displacement greater than 2 mm and up to 4 mm",
|
| 29 |
+
"3e": "Anterior or lateral open bite greater than 2 mm and up to 4 mm",
|
| 30 |
+
"3f": "Complete deep overbite without trauma",
|
| 31 |
+
"2a": "Increased overjet greater than 3.5 mm and up to 6 mm with competent lips",
|
| 32 |
+
"2b": "Reverse overjet greater than 0 mm and up to 1 mm",
|
| 33 |
+
"2c": "Crossbite with discrepancy up to 1 mm",
|
| 34 |
+
"2d": "Contact point displacement greater than 1 mm and up to 2 mm",
|
| 35 |
+
"2e": "Anterior or lateral open bite greater than 1 mm and up to 2 mm",
|
| 36 |
+
"2f": "Increased overbite without trauma",
|
| 37 |
+
"2g": "Pre-normal or post-normal occlusion with no other anomaly",
|
| 38 |
+
"1": "No need for treatment",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# Source Metadata
|
| 42 |
+
SOURCE_NOTE = (
|
| 43 |
+
"Based on Littlewood & Mitchell, An Introduction to Orthodontics (5th ed., 2019). "
|
| 44 |
+
"The Index of Orthodontic Treatment Need (IOTN) is copyrighted by The University of Manchester. "
|
| 45 |
+
"This tool is for educational and clinical decision support purposes only."
|
| 46 |
+
)
|
interfaces.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Protocol, runtime_checkable, Dict, Any
|
| 2 |
+
from models import DHCResult
|
| 3 |
+
|
| 4 |
+
@runtime_checkable
|
| 5 |
+
class IScoringEngine(Protocol):
|
| 6 |
+
"""
|
| 7 |
+
Interface for the IOTN Scoring Engine.
|
| 8 |
+
Enforces a strict contract for scoring implementations.
|
| 9 |
+
"""
|
| 10 |
+
def score(self, payload: Dict[str, Any]) -> DHCResult:
|
| 11 |
+
...
|
models.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass, field
|
| 2 |
+
from typing import List, Optional
|
| 3 |
+
|
| 4 |
+
@dataclass(frozen=True)
|
| 5 |
+
class Finding:
|
| 6 |
+
code: str
|
| 7 |
+
category: str
|
| 8 |
+
grade: int
|
| 9 |
+
summary: str
|
| 10 |
+
evidence: str
|
| 11 |
+
|
| 12 |
+
@dataclass(frozen=True)
|
| 13 |
+
class DHCResult:
|
| 14 |
+
grade: int
|
| 15 |
+
classification: str
|
| 16 |
+
grade_label: str
|
| 17 |
+
subcode_label: str
|
| 18 |
+
summary: str
|
| 19 |
+
justification: str
|
| 20 |
+
findings: List[Finding] = field(default_factory=list)
|
| 21 |
+
review_notes: List[str] = field(default_factory=list)
|
| 22 |
+
source_note: str = ""
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
+
fastapi==0.112.2
|
| 3 |
+
starlette==0.38.2
|
| 4 |
+
jinja2==3.1.4
|
| 5 |
+
uvicorn
|
| 6 |
+
pydantic
|
| 7 |
+
huggingface-hub==0.24.0
|
scoring_service.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any, List
|
| 2 |
+
from models import Finding, DHCResult
|
| 3 |
+
from interfaces import IScoringEngine
|
| 4 |
+
from constants import GRADE_LABELS, SUBCODE_LABELS, SOURCE_NOTE
|
| 5 |
+
|
| 6 |
+
class IOTNScoringService(IScoringEngine):
|
| 7 |
+
"""
|
| 8 |
+
Service Layer: Implements the business logic for IOTN DHC scoring.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
def score(self, payload: Dict[str, Any]) -> DHCResult:
|
| 12 |
+
findings: List[Finding] = []
|
| 13 |
+
review_notes: List[str] = []
|
| 14 |
+
|
| 15 |
+
# Logic helpers
|
| 16 |
+
def get_f(k): return float(payload.get(k, 0) or 0)
|
| 17 |
+
def get_b(k): return bool(payload.get(k, False))
|
| 18 |
+
def get_i(k): return int(get_f(k))
|
| 19 |
+
def get_t(k): return str(payload.get(k, "")).strip().lower()
|
| 20 |
+
|
| 21 |
+
# 1. Overjet (MOCDO: O)
|
| 22 |
+
oj = get_f("overjet_mm")
|
| 23 |
+
lips = get_t("lip_competence")
|
| 24 |
+
if oj > 9:
|
| 25 |
+
findings.append(self._create_finding("5a", "overjet", f"Overjet {oj:g} mm"))
|
| 26 |
+
elif oj > 6:
|
| 27 |
+
findings.append(self._create_finding("4a", "overjet", f"Overjet {oj:g} mm"))
|
| 28 |
+
elif oj > 3.5:
|
| 29 |
+
if lips == "incompetent":
|
| 30 |
+
findings.append(self._create_finding("3a", "overjet", f"Overjet {oj:g} mm + Incompetent lips"))
|
| 31 |
+
elif lips == "competent":
|
| 32 |
+
findings.append(self._create_finding("2a", "overjet", f"Overjet {oj:g} mm + Competent lips"))
|
| 33 |
+
else:
|
| 34 |
+
findings.append(self._create_finding("3a", "overjet", f"Overjet {oj:g} mm (No lip data)"))
|
| 35 |
+
review_notes.append("Lip competence required for 3.6-6mm overjet.")
|
| 36 |
+
|
| 37 |
+
# 2. Reverse Overjet
|
| 38 |
+
roj = get_f("reverse_overjet_mm")
|
| 39 |
+
func = get_b("mastication_difficulty") or get_b("speech_difficulty")
|
| 40 |
+
if roj > 3.5:
|
| 41 |
+
findings.append(self._create_finding("5m" if func else "4b", "reverse_overjet", f"Reverse overjet {roj:g} mm"))
|
| 42 |
+
elif roj > 1:
|
| 43 |
+
findings.append(self._create_finding("4m" if func else "3b", "reverse_overjet", f"Reverse overjet {roj:g} mm"))
|
| 44 |
+
elif roj > 0:
|
| 45 |
+
findings.append(self._create_finding("2b", "reverse_overjet", f"Reverse overjet {roj:g} mm"))
|
| 46 |
+
|
| 47 |
+
# 3. Crossbites (MOCDO: C)
|
| 48 |
+
if get_b("posterior_lingual_crossbite_no_contact"):
|
| 49 |
+
findings.append(self._create_finding("4l", "crossbite", "Scissor bite (no contact)"))
|
| 50 |
+
if get_b("crossbite_present"):
|
| 51 |
+
ds = get_f("rcp_icp_discrepancy_mm")
|
| 52 |
+
code = "4c" if ds > 2 else ("3c" if ds > 1 else "2c")
|
| 53 |
+
findings.append(self._create_finding(code, "crossbite", f"Discrepancy {ds:g} mm"))
|
| 54 |
+
|
| 55 |
+
# 4. Displacement (MOCDO: D)
|
| 56 |
+
disp = get_f("max_contact_displacement_mm")
|
| 57 |
+
if disp > 4: findings.append(self._create_finding("4d", "displacement", f"Displacement {disp:g} mm"))
|
| 58 |
+
elif disp > 2: findings.append(self._create_finding("3d", "displacement", f"Displacement {disp:g} mm"))
|
| 59 |
+
elif disp > 1: findings.append(self._create_finding("2d", "displacement", f"Displacement {disp:g} mm"))
|
| 60 |
+
|
| 61 |
+
# 5. Overbite (MOCDO: O)
|
| 62 |
+
ob = get_f("overbite_mm")
|
| 63 |
+
comp = get_b("overbite_complete")
|
| 64 |
+
trauma = get_b("gingival_trauma") or get_b("palatal_trauma")
|
| 65 |
+
if comp and trauma: findings.append(self._create_finding("4f", "overbite", "Deep bite + trauma"))
|
| 66 |
+
elif comp: findings.append(self._create_finding("3f", "overbite", "Complete deep bite"))
|
| 67 |
+
elif ob >= 3.5: findings.append(self._create_finding("2f", "overbite", f"Overbite {ob:g} mm"))
|
| 68 |
+
|
| 69 |
+
# 6. Hypodontia (MOCDO: M - Missing)
|
| 70 |
+
m_counts = [get_i(f"missing_teeth_{q}") for q in ["UR", "UL", "LR", "LL"]]
|
| 71 |
+
mx = max(m_counts)
|
| 72 |
+
rest = get_b("restorative_implications") or get_b("space_opening_required")
|
| 73 |
+
if mx > 1 and rest:
|
| 74 |
+
findings.append(self._create_finding("5h", "missing", "Extensive hypodontia"))
|
| 75 |
+
elif (mx > 0 or any(m_counts)) and get_b("space_closure_required"):
|
| 76 |
+
findings.append(self._create_finding("4h", "missing", "Hypodontia (space closure)"))
|
| 77 |
+
|
| 78 |
+
# 7. Specials
|
| 79 |
+
if get_b("impeded_eruption"): findings.append(self._create_finding("5i", "eruption", "Impeded eruption"))
|
| 80 |
+
if get_b("cleft_lip_palate"): findings.append(self._create_finding("5p", "cleft", "Cleft lip/palate"))
|
| 81 |
+
if get_b("submerged_deciduous"): findings.append(self._create_finding("5s", "eruption", "Submerged deciduous"))
|
| 82 |
+
if get_b("supplemental_teeth"): findings.append(self._create_finding("4x", "supplemental", "Supplemental teeth"))
|
| 83 |
+
|
| 84 |
+
# Resolution: Highest grade wins
|
| 85 |
+
findings = sorted(self._unique(findings), key=lambda x: (-x.grade, x.code))
|
| 86 |
+
top = findings[0] if findings else None
|
| 87 |
+
|
| 88 |
+
return DHCResult(
|
| 89 |
+
grade=top.grade if top else 1,
|
| 90 |
+
classification=top.code if top else "1",
|
| 91 |
+
grade_label=GRADE_LABELS.get(top.grade if top else 1, "No need"),
|
| 92 |
+
subcode_label=SUBCODE_LABELS.get(top.code if top else "1", "No need"),
|
| 93 |
+
summary=top.summary if top else "No Grade 2+ criteria met.",
|
| 94 |
+
justification=top.evidence if top else "No qualifying feature.",
|
| 95 |
+
findings=findings,
|
| 96 |
+
review_notes=list(set(review_notes)),
|
| 97 |
+
source_note=SOURCE_NOTE
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
def _create_finding(self, code: str, cat: str, evidence: str) -> Finding:
|
| 101 |
+
return Finding(
|
| 102 |
+
code=code,
|
| 103 |
+
category=cat,
|
| 104 |
+
grade=int(code[0]),
|
| 105 |
+
summary=SUBCODE_LABELS.get(code, "Unknown"),
|
| 106 |
+
evidence=evidence
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
def _unique(self, findings: List[Finding]) -> List[Finding]:
|
| 110 |
+
res, seen = [], set()
|
| 111 |
+
for f in findings:
|
| 112 |
+
if f.code not in seen:
|
| 113 |
+
res.append(f)
|
| 114 |
+
seen.add(f.code)
|
| 115 |
+
return res
|