A Clinical Decision Support System (CDSS) for analyzing chest X-ray images to detect pneumonia and aid COVID-19 diagnosis. Built with a Convolutional Neural Network (CNN) trained on the Kaggle Chest X-ray Pneumonia Dataset (~5,000 images), achieving 89.9% accuracy. Features a full-stack architecture with Next.js, Django, TensorFlow, and PostgreSQL, supporting drag-and-drop uploads, patient vitals input, and detailed diagnostic reports. Includes demo and integrated BE modes for seamless UX. Developed as a course project at Cairo University, rivaling graduation project quality.
This semi-graduation project demonstrates a clean architecture approach with three distinct service layers (Frontend, Backend, and AI Analysis) that work together to provide a comprehensive medical diagnostic tool.
- Features
- Tech Stack
- Architecture
- Getting Started
- Clinical Workflow
- UI & UX Highlights
- Backend API Documentation
- Deployment
- Development Notes
- License
- Contributing
- Author
- πΌοΈ X-ray Image Upload: Drag and drop interface for easy chest X-ray upload
- π€ AI-powered Analysis: Advanced machine learning models for accurate diagnostic suggestions
- π Heatmap Visualization: Visual highlighting of regions of interest in X-ray images
- π Detailed Results: Comprehensive diagnostic suggestions with confidence scores
- π Rule-Based Fallback: Intelligent fallback mechanisms when ML inference is uncertain
- π Patient Vitals Integration: Form for capturing patient temperature, blood pressure, heart rate, and symptoms
- π₯ Enhanced Diagnosis: Combined analysis of imaging findings with clinical parameters
- βοΈ Treatment Recommendations: Tailored treatment suggestions based on imaging and vitals
β οΈ Severity Classification: Automatic categorization of cases as Low, Moderate, or High severity- π Light & Dark Mode: Toggle between themes for comfortable viewing in any environment
- π± Responsive Design: Optimized user experience across all device sizes
- π User Authentication: Secure login and registration system
- π Interactive Data Visualization: Display of prediction results using Recharts
- β»οΈ Component Architecture: Clean, modular design with reusable components
- π Downloadable Reports: Generate comprehensive diagnostic reports (coming soon)
- Next.js 15.3: React framework with App Router architecture
- TypeScript: Type-safe code development
- React 19: Component-based UI library
- Tailwind CSS: Utility-first CSS framework for styling
- React Dropzone: For drag-and-drop file uploads
- Recharts: For data visualization
- Lucide React: Icon library
- Python 3.12: Core backend language
- Django 4.2: Backend web framework
- Django REST Framework: API development toolkit
- PyTorch/TensorFlow: ML model implementation
- Pillow/OpenCV: Image processing libraries
- NumPy/Pandas: Data handling
- SQLite: Development database (PostgreSQL in production)
The application follows a modern client-server architecture with a clean separation of three distinct service layers:
-
Frontend Service:
- Built with Next.js 15.3, React 19, TypeScript, and Tailwind CSS
- Handles user interface, interactions, and data visualization
- Provides responsive design for various devices and clinical settings
- Features interactive heatmap visualization of X-ray regions of interest
- Includes light/dark mode for different working environments
- Implements comprehensive form validation and error handling
- Supports downloadable diagnostic reports in PDF format
-
Backend Service:
- Developed with Django 4.2, Python 3.12, and Django REST Framework
- Manages API endpoints, authentication (JWT-based), and user management
- Handles image processing and metadata extraction
- Provides secure data storage and retrieval
- Implements clinical data validation and processing
- Offers comprehensive error handling and logging
-
AI Analysis Service:
- Integrates deep learning models for chest X-ray pathology detection
- Analyzes images for conditions like pneumonia, COVID-19, cardiomegaly, etc.
- Incorporates rule-based systems for diagnostic refinement using patient vitals
- Generates heatmaps highlighting regions of interest in X-rays
- Provides severity classification (Low, Moderate, High) based on findings
- Delivers evidence-based treatment recommendations
- Supports multiple diagnosis possibilities with confidence scores
Each layer has clear responsibilities and communicates through well-defined interfaces:
π cdss-xray-app/ # Frontend application
βββ app/ # Next.js App Router pages
β βββ layout.tsx # Root layout with providers
β βββ page.tsx # Homepage
β βββ analyze/ # X-ray upload & analysis
β βββ result/ # Analysis results display with vitals form
β βββ login/ # Authentication
β βββ register/ # New user registration
βββ components/ # Reusable React components
β βββ ui/ # UI components
β β βββ ImageUploader.tsx
β β βββ HeatmapViewer.tsx
β β βββ PatientVitalsForm.tsx
β β βββ FinalDiagnosisCard.tsx
β β βββ ...
βββ hooks/ # Custom React hooks
βββ utils/ # Helper functions
β βββ predictionService.ts
β βββ imageUploadService.ts
βββ types/ # TypeScript type definitions
βββ public/ # Static assets
π backend/ # Backend services
βββ core/ # Django project
β βββ settings.py # Project configuration
β βββ urls.py # URL routing
βββ auth_service/ # Authentication API
β βββ models.py # User model
β βββ views.py # Auth endpoints
β βββ ...
βββ imaging_service/ # X-ray processing service
β βββ models.py # X-ray and diagnosis models
β βββ views.py # Image analysis endpoints
β βββ ...
βββ requirements.txt # Python dependencies
- Node.js 18.x or higher
- npm or yarn
- Python 3.8+ (for backend services)
- Git
git clone https://github.com/MMansy19/cdss-xray-app.git
cd cdss-xray-app
# Navigate to frontend directory
cd cdss-xray-app
# Install dependencies
npm install
# or
yarn install
# Run the development server
npm run dev
# or
yarn dev
The application will be available at http://localhost:3000.
# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run database migrations
cd core
python manage.py migrate
# Start the Django development server
python manage.py runserver
The backend API will be available at http://localhost:8000.
The application can run in "demo mode" without a backend:
Our application follows a structured clinical workflow designed to enhance diagnostic accuracy:
- Healthcare provider uploads a chest X-ray image
- AI model processes the image and generates initial diagnostic suggestions
- Heatmap visualization highlights regions of interest
- Provider enters patient vital signs:
- Temperature (Β°C)
- Blood Pressure (mmHg)
- Heart Rate (bpm)
- Provider records relevant symptoms:
- Presence of cough
- Presence of headaches
- Ability to smell/taste food
- System combines imaging findings with clinical parameters
- Provides refined diagnostic assessment
- Generates severity classification (Low, Moderate, High)
- Based on the comprehensive assessment, the system suggests:
- Appropriate treatment approaches
- Testing recommendations
- Follow-up considerations
- All information is presented in an intuitive interface
- Provider makes final clinical judgment with AI assistance
- Full diagnostic report can be downloaded for the medical record
- Responsive Design: Adapts seamlessly to mobile, tablet, and desktop views
- Theme Switching: Elegant transition between light and dark modes for varied clinical environments
- Intuitive Upload: Simple drag-and-drop interface with progress indicators
- Interactive Results: Dynamic visualization of diagnostic findings with confidence metrics
- Clinical Form Design: Professional medical input forms with validation
- Accessibility: WCAG-compliant design elements
- Guided User Flow: Clear navigation path from upload to results
- Professional Medical Aesthetics: Clean design focused on clinical utility
- Information Architecture: Organized presentation of complex medical data
- Visual Feedback: Clear status indicators throughout the analysis process
POST /api/auth/register/
: Create new user accountPOST /api/auth/login/
: Obtain authentication tokensPOST /api/auth/refresh/
: Refresh access tokenPOST /api/auth/logout/
: Invalidate refresh token
POST /api/imaging/analyze/
: Submit X-ray for initial analysisPOST /api/imaging/analyze-with-vitals/
: Submit X-ray with vitals for comprehensive analysisGET /api/imaging/history/
: Retrieve user's analysis history
// Example response from /api/imaging/analyze-with-vitals/
{
"success": true,
"data": {
"topPrediction": {
"label": "Pneumonia",
"confidence": 0.89
},
"predictions": [
{"label": "Pneumonia", "confidence": 0.89},
{"label": "COVID-19", "confidence": 0.45},
{"label": "Normal", "confidence": 0.12}
],
"heatmapUrl": "data:image/png;base64,iVBOR...",
"severity": "Moderate",
"diagnosisWithVitals": "Consistent with bacterial pneumonia given the presence of fever (38.5Β°C). Productive cough supports this diagnosis.",
"treatmentSuggestions": [
"Consider empiric antibiotic therapy pending culture results",
"Antipyretics for fever management",
"Monitor oxygen saturation"
]
}
}
# Build the Next.js application
npm run build
# or
yarn build
# Start the production server
npm start
# or
yarn start
# Collect static files
python manage.py collectstatic
# Run with a production WSGI server
gunicorn core.wsgi:application
- Vercel: Recommended for the Next.js frontend
- Railway/Render: Good options for the Django backend
- Docker: Container-based deployment for consistent environments
- Code Organization: Following Next.js and Django best practices with modular components
- State Management: Using React hooks for local state management
- Type Safety: Comprehensive TypeScript types for better code reliability
- Performance Optimization: Efficient rendering with React best practices
- API Integration: Clean separation between frontend and backend services
- Security: Proper authentication flow with refresh tokens
- Testing: Component and API endpoint tests
- Dual Operation Modes:
- Demo mode for standalone frontend operation
- Backend integration mode for production use
- Error Handling: Comprehensive error handling and fallback mechanisms
- Development Time: Completed in less than a week as a semi-graduation project
This project is licensed under the MIT License - see the LICENSE file for details.
Important: This application is designed for educational and demonstration purposes only. All medical predictions should be reviewed by qualified healthcare professionals before clinical use.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Mahmoud Mansy
GitHub Profile
This semi-graduation project was completed in less than one week, showcasing the ability to rapidly develop a complex medical application with clean architecture principles and comprehensive features.
Created with β€οΈ for improving chest X-ray diagnostics and supporting healthcare professionals