File size: 6,277 Bytes
e6cbc4d
 
 
 
 
 
 
 
 
 
 
9d2c1c5
506685d
e6cbc4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d2c1c5
 
e6cbc4d
 
9d2c1c5
e6cbc4d
9d2c1c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6cbc4d
9d2c1c5
 
 
 
 
 
e6cbc4d
9d2c1c5
 
 
e6cbc4d
9d2c1c5
506685d
9d2c1c5
 
506685d
9d2c1c5
506685d
9d2c1c5
 
e6cbc4d
9d2c1c5
 
e6cbc4d
 
 
 
 
 
 
 
 
 
 
 
 
9d2c1c5
506685d
e6cbc4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506685d
 
 
e6cbc4d
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import gradio as gr
from scoring_service import IOTNScoringService
from constants import SOURCE_NOTE

# Global service instance
service = IOTNScoringService()

def get_dhc_score(*args):
    keys = [
        "overjet_mm", "lip_competence", "reverse_overjet_mm", 
        "mastication_difficulty", "speech_difficulty",
        "anterior_crossbite_mm", "posterior_crossbite_mm", "posterior_lingual_crossbite_no_contact",
        "max_contact_displacement_mm", "overbite_mm", "open_bite_mm", "overbite_complete",
        "gingival_trauma", "palatal_trauma",
        "missing_teeth_UR", "missing_teeth_UL", "missing_teeth_LR", "missing_teeth_LL",
        "space_closure_required", "restorative_implications",
        "impeded_eruption", "cleft_lip_palate", "submerged_deciduous", "supplemental_teeth"
    ]
    # Ensure all numerical args are handled safely (Gradio Number handles numeric enforcement)
    payload = dict(zip(keys, args))
    result = service.score(payload)
    
    findings_list = [f"- **{f.code}**: {f.summary} ({f.evidence})" for f in result.findings]
    findings_md = "### Matched Criteria\n" + "\n".join(findings_list) if findings_list else "No Grade 2+ criteria matched."
        
    return (
        f"## Grade {result.grade}",
        f"**{result.classification}**: {result.subcode_label}",
        result.summary,
        findings_md
    )

with gr.Blocks(title="IOTN Assistant", theme=gr.themes.Soft()) as demo:
    gr.Markdown("# IOTN DHC Assessment Form")
    gr.Markdown("Please enter the patient's findings below. The system will calculate the highest IOTN Grade based on the MOCDO hierarchy.")
    
    with gr.Row():
        # Unified Form Section (Left)
        with gr.Column(scale=3):
            gr.Markdown("### 1. Missing Teeth / Specials (M)")
            with gr.Row():
                m_ur = gr.Number(label="UR Missing", value=0, precision=0, minimum=0)
                m_ul = gr.Number(label="UL Missing", value=0, precision=0, minimum=0)
                m_lr = gr.Number(label="LR Missing", value=0, precision=0, minimum=0)
                m_ll = gr.Number(label="LL Missing", value=0, precision=0, minimum=0)
            
            with gr.Row():
                sp_cl = gr.Checkbox(label="Space Closure Required")
                rest_imp = gr.Checkbox(label="Restorative Needs")
                imp_er = gr.Checkbox(label="Impeded Eruption")
            
            with gr.Row():
                cleft = gr.Checkbox(label="Cleft Lip/Palate")
                subm = gr.Checkbox(label="Submerged Deciduous")
                supp = gr.Checkbox(label="Supplemental Teeth")

            gr.Markdown("---")
            gr.Markdown("### 2. Overjet (O)")
            with gr.Row():
                oj_mm = gr.Number(label="Overjet (mm)", value=0.0, precision=1, minimum=0)
                lips = gr.Radio(
                    choices=["competent", "incompetent"], 
                    value="competent", 
                    label="Lip Competence"
                )
            with gr.Row():
                roj_mm = gr.Number(label="Reverse Overjet (mm)", value=0.0, precision=1, minimum=0)
                mast = gr.Checkbox(label="Masticatory Difficulty")
                speech = gr.Checkbox(label="Speech Difficulty")

            gr.Markdown("---")
            gr.Markdown("### 3. Crossbite (C)")
            with gr.Row():
                ant_cb = gr.Number(label="Anterior Crossbite Discrepancy (mm)", value=0.0, precision=1, minimum=0)
                post_cb = gr.Number(label="Posterior Crossbite Discrepancy (mm)", value=0.0, precision=1, minimum=0)
                scissor = gr.Checkbox(label="Posterior lingual crossbite (No contact)")

            gr.Markdown("---")
            gr.Markdown("### 4. Displacement (D)")
            disp_mm = gr.Number(label="Max Contact Displacement (mm)", value=0.0, precision=1, minimum=0)

            gr.Markdown("---")
            gr.Markdown("### 5. Overbite / Open Bite (O)")
            with gr.Row():
                ob_mm = gr.Number(label="Overbite Depth (mm)", value=0.0, precision=1, minimum=0)
                open_bite_mm = gr.Number(label="Open Bite (mm)", value=0.0, precision=1, minimum=0)
            with gr.Row():
                ob_comp = gr.Checkbox(label="Complete Overbite")
                ging_tr = gr.Checkbox(label="Gingival Trauma")
                pal_tr = gr.Checkbox(label="Palatal Trauma")
            
            gr.Markdown("---")
            score_btn = gr.Button("Calculate IOTN Grade", variant="primary", size="lg")

        # Results Section (Right)
        with gr.Column(scale=2):
            with gr.Group():
                gr.Markdown("### Assessment Result")
                res_grade = gr.Markdown("## Grade -")
                res_class = gr.Markdown("**Classification -**")
                res_summary = gr.Textbox(label="Summary", interactive=False, lines=2)
                res_findings = gr.Markdown("### Matched Criteria")

    # Wire up events
    all_inputs = [
        oj_mm, lips, roj_mm, mast, speech,
        ant_cb, post_cb, scissor,
        disp_mm, ob_mm, open_bite_mm, ob_comp, ging_tr, pal_tr,
        m_ur, m_ul, m_lr, m_ll, sp_cl, rest_imp,
        imp_er, cleft, subm, supp
    ]
    
    score_btn.click(
        get_dhc_score,
        inputs=all_inputs,
        outputs=[res_grade, res_class, res_summary, res_findings],
        show_progress="minimal"
    )

    gr.Markdown(f"\n\n---  \n{SOURCE_NOTE}")

    gr.Examples(
        examples=[
            [10.0, "competent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
            [5.0, "incompetent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, False, False, False, False],
            [0.0, "competent", 0.0, False, False, 0.0, 0.0, False, 0.0, 0.0, 0.0, False, False, False, 0, 0, 0, 0, False, False, True, False, False, False],
        ],
        inputs=all_inputs,
        label="Quick Samples"
    )

if __name__ == "__main__":
    demo.queue().launch(server_name="0.0.0.0", server_port=7860)