Files · Prior-Auth Automation Agent for Dental and Optometry Clinics
90 (1 binary, 774.6 kB total)attempt 1
README.md·3464 B·markdown
markdown
# Prior-Auth Automation Agent for Dental and Optometry Clinics
> Cut prior-auth processing from 25 minutes to under 2 minutes per request.
A tutorialized reference solution from [reaatech.com](https://reaatech.com) demonstrating how to build production-grade AI systems with the `@reaatech/*` package family.
## Architecture
The system processes prior-authorization requests through an 8-step pipeline:
1. **Input Validation** — validates the incoming request against `IncomingRequestSchema`
2. **Guardrail Check** — runs input through sanitization guardrails
3. **PDF Extraction** — extracts text from uploaded EHR documents using `unpdf`
4. **Payer Lookup** — resolves the payer-specific form definition
5. **LLM Field Mapping** — uses an agnostic LLM client to map EHR data to payer form fields
6. **Form Filling** — fills the PDF form using `pdf-lib`
7. **Output Validation** — validates the filled form data through guardrails
8. **Memory & Response** — stores the interaction in `AgentMemory` and returns the result
## Getting Started
```bash
pnpm install
# Copy and configure environment variables
cp .env.example .env.local
# Edit .env.local with your API keys
pnpm dev # Start Next.js dev server
pnpm test # Run vitest suite with coverage
pnpm typecheck # TypeScript type checking
pnpm lint # ESLint
```
## API Reference
### GET /api/health
Health check endpoint. Returns service status, name, and timestamp.
### POST /api/prior-auth/submit
Submit a prior-authorization request. Expects JSON body with `requestId`, `patientName`, `patientDob`, `payerId`, `procedureCode`, `diagnosisCode`, and optional `ehrDocumentUrl`.
### GET /api/prior-auth/status?requestId=<id>
Check the status of a prior-authorization request. Returns 200 with status object or 404 if not found.
### GET /api/prior-auth/forms
List all available payer form definitions. Returns array of payers with their required fields.
## Configuration
| Variable | Description |
|----------|-------------|
| `LLM_API_KEY` | API key for the agnostic LLM provider |
| `LLM_BASE_URL` | Base URL for the OpenAI-compatible endpoint |
| `LLM_MODEL` | Model identifier string |
| `LLM_MAX_TOKENS` | Default max tokens (default: 4096) |
| `LLM_TEMPERATURE` | Default temperature (default: 0.1) |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key for observability |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key |
| `LANGFUSE_HOST` | Langfuse host URL |
| `AGENT_MEMORY_STORAGE_PROVIDER` | Storage backend: `memory` or `postgres` |
| `LOG_LEVEL` | Logging level |
| `NEXT_PUBLIC_APP_NAME` | Application display name |
## Testing
```bash
pnpm test # vitest run with coverage (threshold: 90% lines/branches/functions/statements)
```
Tests mock all external APIs via MSW and vi.mock. No live HTTP calls are made during test runs.
## REAA Packages
- `@reaatech/agent-mesh` — domain types, Zod schemas, environment config, and constants
- `@reaatech/agent-memory` — long-term memory layer with LLM extraction and semantic search
- `@reaatech/llm-router-core` — routing types and Zod schemas for model selection
- `@reaatech/guardrail-chain` — composable guardrail pipeline with budget management
- `@reaatech/mcp-server-tools` — tool registry and definition helpers for MCP servers
- `@reaatech/structured-repair-core` — repair engine for malformed LLM structured outputs
## License
MIT — see [LICENSE](./LICENSE).