# Next Step - Feature Implementation Guide ## Overview This guide explains how to integrate the 5 new features into the main Next Step codebase. ## Features Implemented ### 1. Treatment Milestone Tracker ✅ **Files:** - `prisma/schema.prisma` - Add TreatmentPlan and TreatmentMilestone models - `src/app/(app)/treatment/page.tsx` - Main treatment page - `src/app/(app)/treatment/new/page.tsx` - Create treatment plan - `src/components/treatment/TreatmentProgress.tsx` - Progress widget - `src/components/treatment/TreatmentPlanForm.tsx` - Form component - `src/app/api/workspaces/[id]/treatment-plan/route.ts` - API routes - `src/app/api/workspaces/[id]/treatment-plan/complete-cycle/route.ts` - Complete cycle **Integration Steps:** 1. Add models to schema.prisma 2. Run `npm run db:migrate` 3. Copy page files to app directory 4. Copy component files 5. Copy API routes 6. Add navigation link to treatment page ### 2. Enhanced Symptom Tracking ✅ **Files:** - `src/app/(app)/symptoms/page.tsx` - Enhanced symptoms page (overwrite) - `src/components/symptoms/SymptomTrendChart.tsx` - Trend visualization - `src/components/symptoms/SymptomReportGenerator.tsx` - PDF export **Integration Steps:** 1. Replace existing symptoms page with enhanced version 2. Add new components 3. Update SymptomQuickLog to include medication correlation 4. Add API route for PDF generation ### 3. Caregiver Coordination ✅ **Files:** - `prisma/schema.prisma` - Add CareTask and HandoffNote models - `src/app/(app)/care/page.tsx` - Care coordination page - `src/app/(app)/care/new-task/page.tsx` - Create task - `src/app/(app)/care/new-note/page.tsx` - Create handoff note - `src/app/api/workspaces/[id]/care-tasks/route.ts` - Task API - `src/app/api/workspaces/[id]/handoff-notes/route.ts` - Notes API **Integration Steps:** 1. Add models to schema 2. Migrate database 3. Copy page and component files 4. Copy API routes 5. Add navigation link ### 4. Emergency Quick Access Widget ✅ **Files:** - `src/components/emergency/EmergencyWidget.tsx` - Floating widget - `src/app/(app)/layout.tsx` - Add widget to layout **Integration Steps:** 1. Copy widget component 2. Import and add to main app layout 3. Ensure it appears on all pages ### 5. Calendar Integration ✅ **Files:** - `prisma/schema.prisma` - Add CalendarFeed model - `src/components/calendar/CalendarIntegration.tsx` - Settings component - `src/app/api/workspaces/[id]/calendar-feed/route.ts` - ICS feed API - `src/app/(app)/settings/calendar/page.tsx` - Settings page **Integration Steps:** 1. Add model to schema 2. Migrate database 3. Copy components and API routes 4. Add to settings navigation --- ## Database Schema Additions Add these models to `prisma/schema.prisma`: ```prisma // ============================================ // TREATMENT MILESTONE TRACKER // ============================================ model TreatmentPlan { id String @id @default(cuid()) workspaceId String @unique title String totalCycles Int currentCycle Int @default(0) startDate DateTime? estimatedEnd DateTime? status String @default("ACTIVE") cycleType String @default("WEEKLY") cycleDays Int @default(7) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt createdById String workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) createdBy User @relation(fields: [createdById], references: [id]) milestones TreatmentMilestone[] @@index([workspaceId]) } model TreatmentMilestone { id String @id @default(cuid()) planId String cycleNumber Int date DateTime status String @default("UPCOMING") notes String? sideEffects String? celebratedAt DateTime? createdAt DateTime @default(now()) plan TreatmentPlan @relation(fields: [planId], references: [id], onDelete: Cascade) @@index([planId]) @@index([planId, cycleNumber]) } // ============================================ // CAREGIVER COORDINATION // ============================================ model CareTask { id String @id @default(cuid()) workspaceId String title String description String? assignedToId String? dueAt DateTime? completedAt DateTime? completedById String? priority String @default("MEDIUM") category String @default("GENERAL") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt createdById String workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) assignedTo User? @relation("AssignedTasks", fields: [assignedToId], references: [id]) completedBy User? @relation("CompletedTasks", fields: [completedById], references: [id]) createdBy User @relation(fields: [createdById], references: [id]) @@index([workspaceId]) @@index([workspaceId, assignedToId]) @@index([workspaceId, completedAt]) } model HandoffNote { id String @id @default(cuid()) workspaceId String content String category String @default("GENERAL") priority String @default("NORMAL") expiresAt DateTime createdById String createdAt DateTime @default(now()) acknowledgedBy String[] workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) createdBy User @relation(fields: [createdById], references: [id]) @@index([workspaceId]) @@index([workspaceId, expiresAt]) } // ============================================ // CALENDAR INTEGRATION // ============================================ model CalendarFeed { id String @id @default(cuid()) workspaceId String token String @unique includeMeds Boolean @default(false) includeAppointments Boolean @default(true) daysAhead Int @default(90) createdAt DateTime @default(now()) lastAccessedAt DateTime? workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) @@index([token]) @@index([workspaceId]) } ``` Run migration: ```bash npm run db:migrate ``` --- ## Navigation Updates ### Add to Today Page Dashboard Add this section to `src/app/(app)/today/page.tsx`: ```tsx {/* Treatment Progress */}

Treatment Progress

``` ### Add to Settings Navigation Add to `src/app/(app)/settings/page.tsx`: ```tsx } label="Calendar Integration" description="Sync appointments to your calendar" href="/settings/calendar" /> ``` --- ## Dexie DB Updates Add to `src/lib/sync/db.ts`: ```typescript export interface LocalTreatmentPlan { id: string workspaceId: string title: string totalCycles: number currentCycle: number startDate: string | null estimatedEnd: string | null status: string cycleType: string cycleDays: number version: number syncedAt: string } export interface LocalTreatmentMilestone { id: string planId: string cycleNumber: number date: string status: string notes?: string sideEffects?: string celebratedAt?: string syncedAt: string } export interface LocalCareTask { id: string workspaceId: string title: string description?: string assignedToId?: string dueAt?: string completedAt?: string completedById?: string priority: string category: string createdAt: string updatedAt: string } export interface LocalHandoffNote { id: string workspaceId: string content: string category: string priority: string expiresAt: string createdAt: string acknowledgedBy: string[] } ``` And add tables to NextStepDB: ```typescript treatmentPlans!: Table treatmentMilestones!: Table careTasks!: Table handoffNotes!: Table calendarFeeds!: Table ``` Update version: ```typescript this.version(3).stores({ // ... existing tables ... treatmentPlans: 'id, workspaceId', treatmentMilestones: 'id, planId, cycleNumber', careTasks: 'id, workspaceId, assignedToId, completedAt', handoffNotes: 'id, workspaceId, expiresAt', calendarFeeds: 'id, workspaceId, token', }) ``` --- ## Testing Checklist ### Treatment Milestone Tracker - [ ] Create treatment plan - [ ] View progress widget - [ ] Complete a cycle - [ ] See celebration modal - [ ] Check milestone details ### Enhanced Symptom Tracking - [ ] Log symptom with details - [ ] View trend charts - [ ] Filter by symptom type - [ ] Export PDF report - [ ] Copy text summary ### Caregiver Coordination - [ ] Create care task - [ ] Assign to caregiver - [ ] Mark task complete - [ ] Add handoff note - [ ] Acknowledge note ### Emergency Widget - [ ] See floating button - [ ] Click to open modal - [ ] Quick dial buttons work - [ ] Medical info displays ### Calendar Integration - [ ] Create calendar feed - [ ] Copy feed URL - [ ] Subscribe in calendar app - [ ] Verify appointments sync --- ## Notes - All features maintain offline-first capability - Follow existing patterns for auth and workspace access - Use existing UI components and styling - Add appropriate audit logging - Handle VIEWER role restrictions