AI Agent to analyze blood reports and provide detailed health insights.
Features | Tech Stack | Installation | Contributing | Author
- PDF Medical Report Upload: Secure PDF upload with validation (up to 10MB)
- Medical Content Validation: Strict validation ensures only medical-related PDFs are processed
- Intelligent Medical Analysis: AI-powered comprehensive health insights using specialized medical prompts
- Multi-Domain Expertise: Covers CBC, liver function, pancreatic markers, metabolic panels, lipid profiles, and common diseases
- Risk Assessment: Identifies potential health risks with Low/Medium/High risk levels
- Personalized Recommendations: Lifestyle modifications, dietary advice, and follow-up test suggestions
- Offline Analysis: Basic medical analysis when AI services are unavailable
- In-Context Learning: Vector embeddings with pgvector for contextual medical conversations
- Medical-Only Responses: AI strictly responds only to medical and health-related questions
- Contextual Responses: AI responses that reference uploaded medical reports
- Multi-Model Architecture: Groq AI integration with specialized medical analysis prompts
- Offline Fallback: Basic medical guidance when AI services are unavailable
- Knowledge Retention: Maintains conversation context across sessions
- Multi-Provider Authentication: Google OAuth, GitHub OAuth, and email/password
- Secure JWT Token System: Access tokens (15 min) + Refresh tokens (7 days)
- Automatic Token Refresh: Seamless token renewal without user interruption
- File Security: Secure PDF processing with medical content validation
- Session Management: User-specific medical report storage and access control
- Session History: Track all medical report analyses and conversations
- Real-time Processing: Instant PDF analysis and AI response generation
- Modern UI: Responsive design with real-time feedback
- Medical Disclaimer: Proper AI-generated analysis disclaimers
- Logging System: Comprehensive logging for maintenance and debugging
- Frontend: Next.js 15, React 19, TailwindCSS 4
- Backend: Node.js, Express.js 5
- Database: PostgreSQL with UUID support + pgvector extension
- Authentication:
- NextAuth.js 4 (OAuth + JWT)
- Google OAuth 2.0
- GitHub OAuth 2.0
- JWT tokens with automatic refresh
- AI Integration:
- Groq AI with specialized medical analysis prompts and offline fallback
- Multi-tier model architecture with automatic fallback
- Hugging Face Inference API (sentence-transformers/all-MiniLM-L6-v2) - FREE
- Fallback hash-based embeddings (no API key required)
- pgvector for similarity search
- Medical-only question validation and responses
- PDF Processing: pdf-parse for medical report text extraction
- File Upload: Multer with medical content validation
- Security: HTTP-only cookies, CSRF protection, bcrypt hashing
- Node.js 18+
- Clone the repository:
git clone https://github.com/harshhh28/hia-js.git
cd hia-js- Install dependencies:
cd frontend
npm install
cd backend
npm install- Required environment variables:
Backend (backend/.env):
# Server Configuration
PORT=5000
FRONTEND_URL=http://localhost:3000
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=hia_db
DB_USER=postgres
DB_PASSWORD=password
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-here
# AI Integration
GROQ_API_KEY=your-groq-api-key-here
HUGGINGFACE_API_KEY=your-huggingface-api-key-here
# File Upload Configuration
MAX_FILE_SIZE=10485760
UPLOAD_DIR=uploads/medical-reports
# Logging Configuration
LOG_LEVEL=INFO
LOG_DIR=logsFrontend (frontend/.env):
# Backend API URL
NEXT_PUBLIC_BACKEND_URL=http://localhost:5000
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here
# OAuth Provider Credentials (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret- Set up PostgreSQL database with pgvector extension:
# Using Docker (Recommended)
cd backend
docker-compose up -d
# Or manually create database with pgvector
createdb hia_db
psql hia_db -c "CREATE EXTENSION IF NOT EXISTS vector;"- Set up free embedding models (Optional):
Option 1: Hugging Face Inference API (Recommended)
- Get a free API key from Hugging Face
- Add
HUGGINGFACE_API_KEY=your_huggingface_api_key_hereto backend.env - Uses
sentence-transformers/all-MiniLM-L6-v2model (384 dimensions) - Direct API integration with
@huggingface/inferencepackage
Option 2: Fallback Embeddings (No API Key Required)
- If no Hugging Face API key is provided, the system uses hash-based fallback embeddings
- Still provides basic similarity search functionality
- No external API calls required
- Set up OAuth providers (Optional):
For Google OAuth:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add
http://localhost:3000/api/auth/callback/googleto authorized redirect URIs - Copy Client ID and Client Secret to frontend
.env
For GitHub OAuth:
-
Go to GitHub Settings > Developer settings > OAuth Apps
-
Create a new OAuth App
-
Set Authorization callback URL to
http://localhost:3000/api/auth/callback/github -
Copy Client ID and Client Secret to frontend
.env -
Run the application:
# Terminal 1: Start frontend
cd frontend
npm run dev
# Terminal 2: Start backend
cd backend
npm run devhia-js/
βββ backend/ # Express backend with medical analysis
β βββ controllers/ # API controllers
β β βββ medicalReport.js # Medical report upload & analysis
β β βββ chatMessage.js # Contextual chat responses
β β βββ chatSession.js # Session management
β βββ models/ # Database models
β β βββ MedicalReport.js # Medical report storage
β β βββ VectorEmbedding.js # Vector embeddings for AI
β β βββ ChatSession.js # Enhanced session model
β βββ utils/ # Utilities
β β βββ PDFProcessor.js # PDF text extraction
β β βββ VectorService.js # AI embeddings & context
β β βββ Prompt.js # Medical analysis prompts
β βββ middlewares/ # Middleware functions
β β βββ pdfUpload.js # PDF upload validation
β βββ uploads/ # Medical report storage
β βββ logs/ # Application logs
βββ frontend/ # Next.js frontend
βββ README.md # This file
- Create Session: User creates a new chat session
- Upload Report: Upload a PDF medical report (blood test, lab results, etc.)
- AI Analysis: System automatically:
- Validates PDF format and medical content
- Extracts text from the PDF
- Generates comprehensive medical analysis using AI (with offline fallback)
- Stores embeddings for contextual learning
- Interactive Chat: User can ask medical questions about their report
- Contextual Responses: AI provides medical answers based on the uploaded report
- Medical-Only Validation: System ensures only medical questions are answered
- Blood Tests: CBC, Complete Blood Count, Hematology
- Liver Function: ALT, AST, ALP, Bilirubin tests
- Metabolic Panels: Glucose, Cholesterol, Kidney function
- Specialized Tests: Thyroid, Vitamin levels, Inflammatory markers
- Lab Reports: Any medical laboratory test results
- Risk Assessment: Identifies potential health risks (Low/Medium/High)
- Personalized Recommendations: Lifestyle and dietary advice
- Follow-up Suggestions: Recommended additional tests
- Medical Disclaimers: Proper AI-generated analysis warnings
OAuth Authentication Errors:
- Verify OAuth provider credentials are correctly set in frontend
.env - Check that redirect URIs match exactly (including
http://localhost:3000) - Ensure backend is running and accessible from frontend
Database Connection Issues:
- Verify PostgreSQL is running (
docker-compose psfor Docker) - Check database credentials in backend
.env - Ensure database exists (
createdb hia_dbif needed)
Token/Authentication Issues:
- Check JWT_SECRET is set in backend
.env - Verify NEXTAUTH_SECRET is set in frontend
.env - Clear browser cookies and try again
- Check browser console for detailed error messages
CORS Issues:
- Verify FRONTEND_URL in backend
.envmatches your frontend URL - Check that credentials are enabled in CORS configuration
Medical Report Upload Issues:
- Verify PDF file is under 10MB and contains medical content
- Check that PDF contains medical keywords (blood, lab, test, etc.)
- System validates medical content before processing
- Non-medical PDFs are rejected with clear error messages
- Verify pgvector extension is installed in PostgreSQL
- System works with or without Hugging Face API key (uses fallback embeddings)
AI Analysis Issues:
- Check GROQ_API_KEY is set in backend
.env - System includes offline fallback when API is unavailable
- Verify Hugging Face API key is valid (optional - fallback embeddings work without it)
- Ensure medical report contains sufficient medical content
- AI only responds to medical-related questions
- Check logs directory for detailed error messages
Vector Database Issues:
- Verify pgvector extension is enabled:
CREATE EXTENSION IF NOT EXISTS vector; - Use Docker image with pgvector:
pgvector/pgvector:pg15 - Check database connection and permissions
- Ensure vector embeddings table is created properly
Free Embedding Issues:
- Hugging Face API key is optional - system works with fallback embeddings
- If using Hugging Face, verify API key has inference permissions
- Fallback embeddings provide basic similarity search without external API calls
Contributions are welcome! Please read our Contributing Guidelines for details on how to submit pull requests, the development workflow, coding standards, and more.
We appreciate all contributions, from reporting bugs and improving documentation to implementing new features.
Thanks to all the amazing contributors who have helped improve this project!
| Avatar | Name | GitHub | Role | Contributions | PR(s) | Notes |
|---|---|---|---|---|---|---|
![]() |
Harsh Gajjar | harshhh28 | Project Creator & Maintainer | Core implementation, Documentation | N/A | Lead Developer |
This project is licensed under the MIT License - see the LICENSE file for details.
- Strict Medical Validation: Only medical-related PDFs are processed and analyzed
- Medical-Only Chat: AI responds only to medical and health-related questions
- Offline Analysis: Basic medical analysis when AI services are unavailable
- Multi-Tier AI Fallback: Automatic fallback between different AI models
- Enhanced Error Handling: Better connectivity detection and graceful degradation
- β PDF Medical Content Validation: Rejects non-medical PDFs with clear error messages
- β Medical Question Filtering: AI only answers medical questions, redirects others
- β Offline Medical Analysis: Basic analysis when Groq API is unavailable
- β Connectivity Detection: Automatic detection of API connectivity issues
- β Enhanced Prompts: Medical-only response enforcement in all AI interactions
- β Rollback Mechanism: Clean rollback for failed PDF processing
Created by Harsh Gajjar

