← cs
$ cat projects/TeddyCare.md

Dual-Role Healthcare Platform (TeddyCare)

Patient and doctor dashboards with wearable integration and fine-tuned GPT-4o for medical conversations.

2023-09-17
Next.js 14PrismaClerkTerra APIPostgreSQLVercel

TeddyCare: Dual-Role Healthcare Platform

AI-powered healthcare assistant connecting doctors and patients with personalized health insights, wearable integration, and fine-tuned language models.

What I Built

Patient Dashboard:

  • Terra API integration (Fitbit, Apple Watch, Garmin, Oura)
  • Real-time vitals: heart rate, HRV, sleep stages, activity
  • Trend visualization (daily/weekly/monthly)
  • AI chat with personal health context

Doctor Dashboard:

  • Patient list with recent activity
  • Complete health records (vitals, medications, visits)
  • Appointment management
  • AI-assisted diagnosis with patient data access

Fine-Tuned GPT-4o (rohan/tune-gpt-4o):

  • Trained on medical Q&A, clinical notes, patient-doctor dialogues
  • Role-adapted prompts:
    • Patient: accessible language, empathetic, encourages professional consultation
    • Doctor: technical terminology, differential diagnosis, treatment options
  • Automatic context injection (vitals, medications, conditions)

Role-Based Access (Clerk):

  • Patient org: personal dashboard only
  • Doctor org: doctor dashboard + patient records
  • Middleware protection, JWT session management

Architecture

Frontend (Next.js 14):

app/
├── patient/         # Patient dashboard, chat, devices
├── doctor/          # Doctor dashboard, patient list
└── api/
    ├── terra/       # Widget, webhook
    └── chat/        # AI endpoint

Database (Prisma + PostgreSQL):

model User {
  clerkId     String   @unique
  role        Role
  vitals      Vital[]
  medications Medication[]
}

model Vital {
  timestamp   DateTime
  heartRate   Int?
  hrv         Float?
  sleep       Sleep?
}

Terra Webhook:

POST /api/terra/webhook
→ Parse health data → Store in DB → Trigger alerts if abnormal

AI Chat:

POST /api/chat
→ Fetch recent vitals → Construct prompt with context → Call Tune API

Example context injection:

System: Patient has:
- Resting HR: 68 bpm (usually 58, +17%)
- Sleep: 6.5h last night (below usual 7.5h)
- Activity: Marathon training (20→40 mi/week)

User: Why is my resting heart rate higher?

Tech Stack

  • Framework: Next.js 14 (App Router, RSC)
  • Auth: Clerk (org-based roles)
  • DB: Prisma + PostgreSQL
  • Health Data: Terra API
  • AI: Fine-tuned GPT-4o via Tune Studio
  • UI: shadcn/ui + Radix + Tailwind
  • Deploy: Vercel

Results

Award:

  • $1,000 Tune AI Sponsor Award at HackMIT for innovative fine-tuned model application

Key Features Delivered:

  • Role-based dashboards with real auth
  • Live wearable data sync via Terra
  • Context-aware AI conversations
  • Full CRUD for appointments/records

Lessons Learned

Fine-Tuning:

  • Custom medical model more reliable than base GPT-4o
  • Role-adapted system prompts critical for appropriate responses
  • Context injection (vitals, meds) improves relevance significantly

Terra API:

  • Webhook reliability varies by device (Apple Watch > Fitbit)
  • Rate limiting on free tier—batch requests carefully
  • Data normalization needed across devices

Auth:

  • Clerk orgs elegant for role-based access
  • Middleware protection simpler than route-level guards
  • Session tokens expire—handle refresh gracefully

Health Data:

  • Users want trends, not raw numbers
  • Alert thresholds need personalization (baseline varies)
  • Sleep data most requested feature

Future Work

  • Medication reminders with push notifications
  • Doctor-patient secure messaging
  • Lab result integration (blood tests, imaging)
  • Telehealth video consultations
  • Insurance/billing integration