FastAPI • PostgreSQL • Chatbot • MCP • CrewAI
A modern backend system designed to help clinics manage patients, appointments, and health data — with a future-ready architecture for AI agents and automation.
The Patient Health Management System is a real-world healthcare backend that enables clinics to:
- Manage patient records
- Store and retrieve medical history
- Automatically calculate BMI
- Handle doctor schedules and appointment slots
- Book appointments seamlessly
- Provide a chatbot interface for patient queries
- Prepare for AI automation using CrewAI + MCP
This project is built with scalability and AI integration in mind.
Frontend (HTML/JS)
↓
FastAPI Backend
↓
PostgreSQL Database
↓
Business Logic (Slots, Booking, BMI)
↓
Chatbot Layer
↓
MCP Server (Tools)
↓
CrewAI Agents (Automation & AI)
- Add new patients
- Update patient details
- Delete patients
- View all patients
- View medical history
- Automatic BMI calculation
- Health verdict:
- Underweight
- Normal
- Overweight
- Obese
- Provider schedules
- Slot generation
- Slot availability check
- Appointment booking
- Overlap prevention
Patients can ask about:
- BMI
- Allergies
- Last visit
- Available slots
- Booking instructions
- MCP server exposes backend tools
- CrewAI agents automate workflows
- LLM-ready for natural language operations
| Layer | Technology |
|---|---|
| Backend | FastAPI |
| Database | PostgreSQL |
| Frontend | HTML, CSS, JavaScript |
| AI Framework | CrewAI |
| Tool Protocol | MCP |
| ORM / Driver | psycopg2 |
| Server | Uvicorn |
FastApi Project/
│
├── main.py # FastAPI application
├── db.py # Database connection
├── migrate.py # Patient table migration
├── migrate_slots.py # Slot tables migration
├── mcp_server.py # MCP tool server
├── crew_runner.py # CrewAI agent runner
├── index.html # Frontend UI
├── requirements.txt
└── myenv/ # Virtual environment
- User opens
index.html - UI sends requests to FastAPI
- FastAPI:
- Reads/writes to PostgreSQL
- Handles slot logic & booking
- Chatbot endpoint:
- Understands intent
- Fetches patient data
- MCP server:
- Exposes booking & info tools
- CrewAI:
- Uses MCP tools
- Automates scheduling tasks
.\myenv\Scripts\activateMake sure PostgreSQL is running on port 5432.
python migrate.py
python migrate_slots.pyuvicorn main:app --reloadOpen:
python mcp_server.pypython crew_runner.pyShow available slots for D001 on 2025-12-30
Book D001 for patient P001 on 2025-12-30 10:00 to 10:30
What allergies does patient P001 have?
.\myenv\Scripts\activate
pip install -r requirements.txtCheck:
- PostgreSQL is running
DATABASE_URLis correct- Port 5432 is free
Make sure:
- Slot time is valid
- No overlapping appointment exists
If you see:
OPENAI_API_KEY is required
or
insufficient_quota
That means:
- API key is missing or
- Quota is exhausted
✅ Solution:
- Add API credits
- Set
OPENAI_API_KEYin environment variables
- 📧 Email: sidchavan6557@gmail.com
- 💼 LinkedIn: https://www.linkedin.com/in/siddhesh-chavan-36718622b/
- 🐞 Issues: Open an issue in this repository
You can ask about:
- FastAPI
- PostgreSQL
- Booking logic
- Chatbot flow
- MCP / CrewAI
- Full CrewAI agent for appointment scheduling
- MCP tools for billing & reports
- Smarter LLM chatbot
- Login system
- Role-based access (Admin / Doctor / Patient)
- Doctor dashboard
- Appointment calendar
- Patient self-service portal
- Alembic migrations
- Redis caching
- Email/SMS reminders
- Docker support
- Cloud hosting (AWS / Azure / GCP / Render)
Siddhesh Chavan
Data Engineer | Backend Developer | AI Enthusiast
This project demonstrates real-world backend engineering combined with modern agentic AI architecture using FastAPI, PostgreSQL, MCP, and CrewAI.