Skip to content

Instantly share code, notes, and snippets.

@decagondev
Last active April 28, 2026 18:33
Show Gist options
  • Select an option

  • Save decagondev/fb0b20f2ea5ffb5db8de5e7c4daa3768 to your computer and use it in GitHub Desktop.

Select an option

Save decagondev/fb0b20f2ea5ffb5db8de5e7c4daa3768 to your computer and use it in GitHub Desktop.
flowchart TB
    subgraph OpenEMR ["OpenEMR (PHP Frontend)"]
        ChartOpen[Chart Open\npid, user_id]
        PHP[PHP Module]
        JWT[JWT Minting\nHMAC-signed\nuser_id, pid\n15-min expiry]
    end

    subgraph UI ["Physician UI Surfaces"]
        SummaryCard[Pre-computed\nSummary Card\nZero LLM latency]
        ChatUI[Multi-turn Chat\nEmbedded in Chart]
    end

    subgraph Agent ["Python Agent Service"]
        Auth[JWT Verifier\nTrust Token Only]
        Tools[Tool Functions\n10 Typed SQL Tools]
        SQL[Parameterized SQL\nRead-only DB User\nAUDIT-encoded]
        LLM[Primary LLM\nFact Generation\nWith src:table.id Citations]
        PostProc[Deterministic Post-Processor\nCitation Validator\nBans Inference Phrases]
        Verifier[Independent Verifier LLM\nDifferent Family\nGrounding + No-Inference Check]
        Fallback[Safe Fallback\nEnumerated Facts Only]
        Output[Output to UI]
    end

    subgraph DB ["OpenEMR MySQL Database"]
        Data[(Patient Data\nMeds, Labs, Notes\nAUDIT columns)]
    end

    %% Logic Flows
    ChartOpen --> PHP
    PHP --> JWT
    JWT --> Auth
    
    SummaryCard -. "Pre-computed\n(8-10 min earlier)" .-> Agent
    ChatUI <--> Auth
    Auth --> Tools
    Tools --> SQL
    SQL <--> Data
    SQL --> Tools
    Tools --> LLM
    LLM --> PostProc
    PostProc --> Verifier
    
    Verifier -->|Pass| Output
    Verifier -->|Fail| Fallback
    Fallback --> Output

    %% UI Connections
    SummaryCard <--> ChatUI
    Output --> SummaryCard
    Output --> ChatUI


    class SummaryCard,ChatUI ui
    class Agent,LLM,PostProc,Verifier,Tools,Output,Fallback backend
    class DB,Data db
    class JWT,Auth security
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment