| # PRESAGE Next.js Frontend - Quick Start Guide |
|
|
| ## π Project Status |
|
|
| **β
COMPLETE** - Modern React/Next.js frontend with TypeScript, Tailwind CSS, and Framer Motion animations. |
|
|
| ### Completed Components |
|
|
| #### 1. **PresageDashboard** (`components/PresageDashboard.tsx`) |
| Main dashboard with 3-column layout: |
| - **Left Column**: Patient profile form (16 fields) |
| - **Right Columns**: Results display (health score, risk assessment, interventions) |
| - Features: |
| - Real-time API health check on load |
| - Form state management for all patient metrics |
| - Loading states with spinners |
| - Error handling with helpful messages |
| - Animated health index ring (0-100 scale) |
|
|
| #### 2. **RiskVisualization** (`components/RiskVisualization.tsx`) |
| Disease risk assessment display: |
| - SVG circular progress indicators with dynamic colors |
| - Animated entrance and progress transitions |
| - Risk level badges (High/Elevated/Moderate/Low) |
| - Displays: Diabetes, Hypertension, Cardiovascular risk percentages |
|
|
| #### 3. **ImageDropzone** (`components/ImageDropzone.tsx`) |
| Medical document upload interface: |
| - Drag-and-drop file upload (images, PDFs) |
| - File preview list |
| - Framer Motion animations |
| - Loading state support |
|
|
| #### 4. **API Client** (`lib/api.ts`) |
| Axios HTTP client with: |
| - Type-safe interfaces for PatientData and HealthAnalysisResponse |
| - 3-minute timeout for long-running analyses |
| - Health check endpoint |
| - Analysis endpoint POST handler |
|
|
| ## π Configuration |
|
|
| ### Environment Variables |
| Created `.env.local`: |
| ``` |
| NEXT_PUBLIC_API_URL=http://127.0.0.1:8000 |
| ``` |
|
|
| ### Package Dependencies Installed |
| ``` |
| react-dropzone - File upload handling |
| axios - HTTP client |
| recharts - Charting library |
| framer-motion - Animations |
| lucide-react - Icon library |
| ``` |
| **Total: 418 npm packages installed** |
|
|
| ## π― How to Run |
|
|
| ### Terminal 1: Start the FastAPI Backend |
| ```bash |
| cd e:\New folder (2)\future |
| python main.py |
| ``` |
| - API runs on: http://127.0.0.1:8000 |
| - Health check: http://127.0.0.1:8000/health |
| - Analysis endpoint: http://127.0.0.1:8000/analyze (POST) |
|
|
| ### Terminal 2: Start the Next.js Frontend |
| ```bash |
| cd "e:\New folder (2)\future\client" |
| npm run dev |
| ``` |
| - Frontend runs on: http://localhost:3000 |
| - Hot reload enabled for development |
| - TypeScript type-checking during development |
|
|
| ## π Using the Dashboard |
|
|
| 1. **Fill Patient Profile** (Left Column) |
| - Age, Sex |
| - Blood pressure (systolic/diastolic) |
| - Fasting blood sugar |
| - BMI |
| - Lifestyle metrics (sleep, exercise, smoking, alcohol) |
|
|
| 2. **Click "π Run Health Analysis"** |
| - Form validates data |
| - Sends POST request to FastAPI backend |
| - Shows loading spinner during processing |
|
|
| 3. **View Results** (Right Columns) |
| - **Overall Health Index**: 0-100 score with animated ring |
| - **Disease Risk Assessment**: Diabetes/Hypertension/Cardiovascular percentages |
| - **Risk Explanations**: Clinical factors driving the assessment |
| - **90-Day Prevention Plan**: Personalized interventions and timeline |
|
|
| ## π API Integration |
|
|
| ### Request Flow |
| ``` |
| Browser Form β POST /analyze |
| β |
| FastAPI Backend (main.py) |
| β |
| Multi-Agent Orchestrator |
| ββ Data Agent (validation) |
| ββ Risk Agent (clinical calculator) |
| ββ Literature Agent (PubMed search) |
| ββ Intervention Agent (90-day plan) |
| β |
| HealthAnalysisResponse (JSON) |
| β |
| Display Results with Animations |
| ``` |
|
|
| ### Request/Response Format |
| **Request (PatientData):** |
| ```typescript |
| { |
| age: number, |
| sex: "male" | "female" | "other", |
| blood_pressure_systolic: number, |
| blood_pressure_diastolic: number, |
| blood_sugar_fasting: number, |
| cholesterol_total: number, |
| hdl_cholesterol: number, |
| bmi: number, |
| sleep_hours: number, |
| stress_level: "low" | "medium" | "high", |
| smoking: boolean, |
| alcohol: "none" | "moderate" | "heavy", |
| exercise_days_per_week: number, |
| iron_level: number, |
| cortisol: number, |
| family_history: string[] |
| } |
| ``` |
|
|
| **Response (HealthAnalysisResponse):** |
| ```typescript |
| { |
| overall_health_score: 75, |
| risk_scores: { |
| diabetes: 35, |
| hypertension: 42, |
| cardiovascular: 48 |
| }, |
| risk_explanations: "...", |
| profile_summary: "...", |
| evidence: "...", |
| intervention_plan: "..." |
| } |
| ``` |
|
|
| ## π¨ Theme & Styling |
|
|
| ### Color Scheme |
| - **Background**: Slate-950 to slate-900 gradient |
| - **Accents**: Cyan-400/500 and blue-400/500 |
| - **Cards**: Slate-900 with 50% opacity + backdrop blur |
| - **Borders**: Cyan-500 with 20% opacity |
|
|
| ### Typography |
| - **Headings**: Cyan-400 gradient text |
| - **Primary Text**: White |
| - **Secondary Text**: Slate-300 to slate-400 |
| - **Disabled**: Reduced opacity |
|
|
| ## βοΈ Development Tips |
|
|
| ### Add New Form Fields |
| Edit `PresageDashboard.tsx`: |
| 1. Add field to `PatientData` interface in `lib/api.ts` |
| 2. Add input element in left column |
| 3. Add to `handleInputChange()` state management |
| 4. Update form submission |
|
|
| ### Customize Risk Colors |
| Edit `RiskVisualization.tsx`: |
| ```typescript |
| const getRiskColor = (risk: number) => { |
| if (risk >= 80) return '#ef4444'; // red |
| if (risk >= 60) return '#f97316'; // orange |
| if (risk >= 40) return '#eab308'; // yellow |
| return '#22c55e'; // green |
| }; |
| ``` |
|
|
| ### Extend Result Display |
| Add new sections to `PresageDashboard.tsx` right column (after `intervention_plan`): |
| ```tsx |
| <motion.div className="rounded-xl bg-slate-900/50 border border-cyan-500/20 p-6"> |
| <h3>New Section</h3> |
| <p>{result.new_field}</p> |
| </motion.div> |
| ``` |
|
|
| ## π Troubleshooting |
|
|
| | Issue | Solution | |
| |-------|----------| |
| | "Cannot connect to API server" | Ensure FastAPI is running on port 8000 | |
| | CORS errors in console | Backend has CORSMiddleware enabled | |
| | Form not submitting | Check browser console for validation errors | |
| | Slow analysis | Analysis takes 30-120s depending on system | |
| | Images not uploading | ImageDropzone component created but not yet integrated | |
|
|
| ## π Project Structure |
|
|
| ``` |
| client/ |
| βββ app/ |
| β βββ layout.tsx β Root layout (dark theme) |
| β βββ page.tsx β Entry point (renders PresageDashboard) |
| β βββ globals.css β Tailwind directives |
| βββ components/ |
| β βββ PresageDashboard.tsx β Main dashboard (3-column layout) |
| β βββ RiskVisualization.tsx β Risk ring animations |
| β βββ ImageDropzone.tsx β File upload interface |
| βββ lib/ |
| β βββ api.ts β Axios client & TypeScript interfaces |
| βββ .env.local β API endpoint configuration |
| βββ next.config.ts β Next.js configuration |
| βββ tailwind.config.ts β Tailwind CSS configuration |
| βββ tsconfig.json β TypeScript configuration |
| βββ package.json β Dependencies |
| ``` |
|
|
| ## β¨ Features Implemented |
|
|
| β
Dark theme with neon accents |
| β
Responsive grid layout (mobile-friendly) |
| β
16-field patient profile form |
| β
Real-time API connectivity check |
| β
Animated health score visualization |
| β
Disease risk assessment display |
| β
Clinical risk explanations |
| β
90-day intervention plan |
| β
Loading states with spinners |
| β
Error handling with helpful messages |
| β
Framer Motion animations throughout |
| β
Full TypeScript type safety |
| β
Tailwind CSS styling |
| β
Responsive design |
|
|
| ## π’ Deployment (Future) |
|
|
| To deploy to production: |
| 1. Build: `npm run build` |
| 2. Deploy to Vercel: `vercel deploy` |
| 3. Or containerize with Docker |
|
|
| ## π Support |
|
|
| For issues or questions: |
| 1. Check API logs: `python main.py` terminal output |
| 2. Check browser console: F12 β Console tab |
| 3. Verify environment variables: `.env.local` contains correct API URL |
| 4. Ensure both services running on correct ports (3000 for Next.js, 8000 for API) |
|
|