File size: 2,003 Bytes
f1d86e0
 
98f489e
1ff595b
f1d86e0
 
 
98f489e
 
 
 
 
 
 
1601a64
 
 
98f489e
 
f1d86e0
 
 
 
 
98f489e
 
 
 
 
 
88d4b37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1601a64
88d4b37
1601a64
 
98f489e
1601a64
88d4b37
 
 
1601a64
98f489e
88d4b37
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
from fastapi import FastAPI
from pydantic import BaseModel
import os
from openai import OpenAI

app = FastAPI()

#class PARequest(BaseModel):
#    procedure_code: str
#    summary: str
#    dysphagia: bool
#    weight_loss: bool
#    ppi_weeks: int

# Make sure you add 'OPENAI_API_KEY' to your Payer Space Secrets
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

class AgentMessage(BaseModel):
    message: str

@app.get("/")
def read_root():
    return {"status": "Payer API is Live"}

class AgentMessage(BaseModel):
    message: str

# This would ideally call an LLM (OpenAI/Mistral) to 'think' like a Payer
@app.post("/agent-chat")
async def agent_chat(payload: AgentMessage):
    # DYNAMIC POLICY DATABASE (Mirroring your Provider side)
    POLICIES = {
        "22558": "Policy LCD-L341 (Spinal Fusion): Requires Physical Therapy (6+ weeks), Instability, or Spondylolisthesis.",
        "43239": "Policy MED-772 (EGD): Requires Weight Loss, Dysphagia, or 8-week PPI failure."
    }

    # Step 1: Tell the Payer to identify the code first
    system_instruction = (
        "You are an Oracle Health Payer Adjudication Agent. "
        "Your goal is to verify medical necessity based on the following policies: \n"
        f"1. {POLICIES['22558']}\n"
        f"2. {POLICIES['43239']}\n\n"
        "INSTRUCTIONS:\n"
        "- Identify which CPT code the Provider is requesting.\n"
        "- ONLY apply the criteria for THAT specific code.\n"
        "- If evidence for THAT code is found, reply 'APPROVED'.\n"
        "- If evidence is missing, ask for the specific missing documentation for THAT policy."
    )

    prompt = [
        {"role": "system", "content": system_instruction},
        {"role": "user", "content": payload.message}
    ]
    
    response = client.chat.completions.create(
        model="gpt-4o", # Recommended for better logic than 3.5
        messages=prompt,
        temperature=0
    )
    
    return {"agent_response": response.choices[0].message.content}