We are Presurgical Optimization Platform, a hackathon prototype focused on backend system design, LLM-assisted structured extraction, and real-time clinical workflow updates.
This document is written by Carrie Chang.
Scope note: This is a hackathon prototype. It focuses on backend data modeling + system workflows rather than production-grade compliance/security.
- Carrie Chang @Tsu-Yu
- Carol Yeh @Carolyehhh
- Shih-Yuan Huang @shihyunhuang
- I-Hsuan Chiang @J-ihsuan
- Pete Chen @petechentw
- Our Team
- Table of Contents
- Project Overview
- System Architecture
- Project Structure
- Core Technical Design
- How to Run Locally
- For Developers
- Future Improvements
Presurgical Optimization Platform is a full-stack web application designed to explore how perioperative clinical workflows can be modeled as:
- Versioned backend data
- Structured, machine-readable rules
- Event-driven UI updates
Instead of treating guidelines as static text, this system treats them as versioned JSON-based instructions that can be:
- audited
- updated
- published
- consumed by both humans and machines
┌──────────────┐
│ Doctor UI │◀──── WebSocket (guideline:updated)
└──────┬───────┘
│ REST APIs
┌──────▼───────┐
│ Next.js API │
│ (Node.js) │
├──────┬───────┤
│ Prisma ORM │
│ PostgreSQL │
└──────┬───────┘
│
┌──────▼────────────────┐
│ OpenAI + LangChain │
│ Structured JSON Output│
└───────────────────────┘
(Without: node_modules, .env, *.lock)
prisma/
└─ schema.prisma # Data model & versioning
src/
├─ app/
│ ├─ api/
│ │ ├─ guidelines/ # Guideline CRUD + socket emit
│ │ ├─ doctor/ # Doctor data aggregation API
│ │ ├─ patients/ # Patient-facing APIs
│ │ ├─ openAI/ # LLM structured extraction
│ │
│ ├─ doctor/page.tsx # Doctor dashboard (client)
│ ├─ patient/page.tsx # Patient view
│
├─ lib/
│ ├─ prisma.ts # Prisma client singleton
│ ├─ auth.ts # Role-based auth helpers
│ ├─ session.ts # In-memory session store
│ ├─ socket.ts # Socket.IO server singleton
│ ├─ useGuidelineSocket.ts # Client WebSocket hook
│
├─ pages/
│ └─ api/socket.ts # Socket.IO server initialization
- Each Surgery can have multiple SurgeryPlanVersions
- Only one version is marked as published and exposed to patients
- Historical versions are preserved for traceability
Key ideas:
currentPublishedVersionIdacts as a single source of truth- Instructions are stored as JSON, not rigid tables, to support evolving clinical logic
This project intentionally avoids free-form AI responses.
Why LangChain?
- Enforces schema-validated outputs
- Enables automation and downstream processing
- Prevents “hallucinated” fields
Flow:
- Aggregate patient medication instructions from DB
- Accept pill image + user hints
- Send to OpenAI via LangChain
- Validate output against strict JSON schema
- Persist run metadata for auditability
All LLM runs are logged with:
- input metadata
- output JSON
- success / error state
- Socket.IO is used for event-driven updates
- When a guideline is created or updated:
- backend emits
guideline:updated - doctor dashboard automatically refreshes data
- backend emits
This avoids manual refresh and demonstrates:
- backend-driven UI synchronization
- decoupled, event-based system design
Clone the repository:
git clone <this-repo-url>
cd presurgInstall dependencies:
npm installCreate .env:
DATABASE_URL=postgresql://user:password@localhost:5432/db
OPENAI_API_KEY=your_openai_keyRun database migration:
npx prisma migrate devStart development server:
npm run devOpen: http://localhost:3000
| Category | Tool |
|---|---|
| Runtime | Node.js 18+ |
| Backend | Next.js API Routes |
| Database | PostgreSQL |
| ORM | Prisma |
| AI | OpenAI, LangChain |
| Realtime | Socket.IO |
- Visual Studio Code
- Prisma Studio
- Postman / curl
- pgAdmin / TablePlus
Recommended VSCode extensions:
- Prisma
- ESLint
- Prettier
- GitLens
- Replace in-memory sessions with Redis
- Add API contract tests