File size: 2,073 Bytes
f57ec27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import re

def evaluate_pa(drug, diagnosis, notes):
    text = (drug + " " + diagnosis + " " + notes).lower()

    # Simple rule-based checks
    approved_keywords = ["medically necessary", "failed therapy", "step therapy completed"]
    denial_keywords = ["cosmetic", "experimental", "not indicated"]
    needinfo_keywords = ["missing", "need labs", "need documentation"]

    # Decision logic
    if any(k in text for k in approved_keywords):
        decision = "Approved"
        reason = "Meets medical necessity criteria."
    elif any(k in text for k in denial_keywords):
        decision = "Denied"
        reason = "Does not meet required clinical criteria."
    elif any(k in text for k in needinfo_keywords):
        decision = "Needs More Information"
        reason = "Additional documentation is required."
    else:
        decision = "Needs Manual Review"
        reason = "Criteria unclear based on provided information."

    df = pd.DataFrame({
        "Drug": [drug],
        "Diagnosis": [diagnosis],
        "Decision": [decision],
        "Reason": [reason]
    })

    return df, f"### Decision: **{decision}**\nReason: {reason}"

# --- Interface ---
with gr.Blocks(title="Prior Authorization Decision Helper") as demo:
    gr.Markdown("## 📝 Prior Authorization Helper")
    gr.Markdown("Enter drug, diagnosis, and clinical notes to generate a mock PA decision.")

    with gr.Row():
        drug = gr.Textbox(label="Drug Name", placeholder="Example: Ozempic")
        diagnosis = gr.Textbox(label="Diagnosis", placeholder="Example: Type 2 Diabetes")

    notes = gr.Textbox(
        label="Clinical Notes",
        placeholder="Example: Patient completed step therapy and met medically necessary criteria.",
        lines=6
    )

    submit = gr.Button("Evaluate PA Request")

    output_table = gr.Dataframe(label="PA Evaluation Summary")
    output_text = gr.Markdown(label="Decision Result")

    submit.click(evaluate_pa, [drug, diagnosis, notes], [output_table, output_text])

demo.launch(share=True)