Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Š MediGuard - Smart Medication Management System

Python Flask License Status

MediGuard is a comprehensive, secure medication management platform designed to help individuals, families, and caregivers track medications, manage prescriptions, set reminders, and ensure medication safety with AI-powered assistance.


🌟 Key Features

πŸ“‹ Medication Management

  • Complete Medicine Tracking - Add, edit, and organize medications with detailed information
  • Expiry Date Monitoring - Automatic alerts for expiring medications
  • Stock Level Management - Track quantities and get low stock notifications
  • Barcode/QR Code Support - Quick medicine entry via scanning
  • Batch Operations - Manage multiple medications efficiently

πŸ‘₯ Multi-User & Family Support

  • Role-Based Access Control - Admin and User roles with granular permissions
  • Family Member Management - Add and manage family members' medications
  • Caregiver Permissions - Grant controlled access to caregivers
  • Emergency Contacts - Quick access to emergency contact information

πŸ”” Smart Notifications

  • Email Notifications - Expiry alerts, low stock warnings, and reminders
  • SMS Alerts - Critical notifications via Twilio integration
  • Customizable Reminders - Set medication reminders with flexible schedules
  • Daily/Weekly Digests - Summary reports of medication status

πŸ€– AI-Powered Assistant

  • Medication Information - Get instant answers about medications
  • Drug Interactions - Check for potential interactions
  • Dosage Guidance - AI-powered dosage recommendations
  • Health Tips - Personalized medication management advice
  • Powered by Google Gemini - Advanced natural language processing

🏒 Manufacturer & Category Management

  • Manufacturer Database - Track medication manufacturers with contact details
  • Category Organization - Organize medicines by therapeutic categories
  • Verification System - Verify manufacturer authenticity
  • Detailed Profiles - Store licenses, websites, and descriptions

πŸ”’ Security & Compliance

  • CSRF Protection - Secure forms with Flask-WTF
  • Rate Limiting - Prevent abuse with Flask-Limiter
  • Secure Headers - Enhanced security with Flask-Talisman
  • Password Hashing - Werkzeug secure password storage
  • Session Management - Secure session handling
  • Audit Logging - Complete activity tracking for compliance

πŸ“Š Admin Dashboard

  • System Overview - Real-time statistics and metrics
  • User Management - Promote, demote, activate/deactivate users
  • Audit Logs - Comprehensive activity monitoring
  • System Health - Monitor application performance
  • Bulk Operations - Efficient management of large datasets

πŸ“± Modern UI/UX

  • Responsive Design - Works seamlessly on desktop, tablet, and mobile
  • Bootstrap 5 - Modern, clean interface
  • Font Awesome Icons - Beautiful iconography
  • Gradient Themes - Eye-catching visual design
  • Dark Mode Ready - Comfortable viewing in any lighting

πŸš€ Quick Start

Prerequisites

  • Python 3.9 or higher
  • MySQL 8.0 or higher
  • Redis (optional, for caching)
  • Gmail account (for email notifications)
  • Twilio account (optional, for SMS)
  • Google Gemini API key (for AI assistant)

Installation

  1. Clone the repository
git clone https://github.com/yourusername/mediguard.git
cd mediguard
  1. Create virtual environment
python -m venv .venv
  1. Activate virtual environment

Windows:

.venv\Scripts\activate

Linux/Mac:

source .venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up MySQL database
# Login to MySQL
mysql -u root -p

# Create database
CREATE DATABASE medication_navigator;
  1. Configure environment variables
# Copy example environment file
cp .env.example .env

# Edit .env with your configuration
# Required: SECRET_KEY, MYSQL credentials, MAIL settings
  1. Initialize database
python
>>> from app import app, db
>>> with app.app_context():
>>>     db.create_all()
>>> exit()
  1. Run the application
python app.py
  1. Access the application
http://127.0.0.1:5000

βš™οΈ Configuration

Environment Variables

Create a .env file in the root directory with the following variables:

# Application
SECRET_KEY=your-secret-key-here
FLASK_ENV=development
DEBUG=True

# Database
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your-password
MYSQL_DATABASE=medication_navigator

# Email (Gmail)
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_DEFAULT_SENDER=your-email@gmail.com
EMAIL_NOTIFICATIONS_ENABLED=True

# SMS (Twilio - Optional)
TWILIO_ACCOUNT_SID=your-account-sid
TWILIO_AUTH_TOKEN=your-auth-token
TWILIO_PHONE_NUMBER=+1234567890
SMS_NOTIFICATIONS_ENABLED=False

# AI Assistant (Google Gemini)
GEMINI_API_KEY=your-gemini-api-key

# Scheduler
SCHEDULER_ENABLED=True
REMINDER_CHECK_INTERVAL=60

Getting API Keys

Gmail App Password:

  1. Enable 2-Factor Authentication on your Google account
  2. Go to Google Account > Security > App Passwords
  3. Generate a new app password for "Mail"

Twilio (Optional):

  1. Sign up at https://www.twilio.com
  2. Get your Account SID and Auth Token from the dashboard
  3. Purchase a phone number for SMS

Google Gemini API:

  1. Visit https://makersuite.google.com/app/apikey
  2. Create a new API key
  3. Copy the key to your .env file

πŸ“– Usage Guide

First Time Setup

  1. Create Admin Account

    • Navigate to /signup
    • Register with your details
    • First user is automatically assigned admin role
  2. Add Categories

    • Go to Admin Dashboard > Manage Categories
    • Add medication categories (e.g., Antibiotics, Pain Relief)
  3. Add Manufacturers

    • Go to Admin Dashboard > Manage Manufacturers
    • Add pharmaceutical manufacturers with contact details
  4. Add Medications

    • Go to Dashboard > Add Medicine
    • Fill in medication details
    • Set expiry dates and stock levels
  5. Set Up Reminders

    • Go to Reminders section
    • Create medication reminders with schedules

User Roles

Admin:

  • Full system access
  • User management
  • View all medications across users
  • System configuration
  • Audit log access

User:

  • Manage own medications
  • Add family members
  • Set reminders
  • View personal dashboard
  • Use AI assistant

πŸ—οΈ Project Structure

mediguard/
β”‚
β”œβ”€β”€ app.py                      # Main application file
β”œβ”€β”€ forms.py                    # WTForms form definitions
β”œβ”€β”€ sms_templates.py            # SMS notification templates
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ .env.example               # Environment variables template
β”œβ”€β”€ .gitignore                 # Git ignore rules
β”‚
β”œβ”€β”€ config/
β”‚   └── secure_config.py       # Application configuration
β”‚
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ ai_assistant_service.py    # AI assistant logic
β”‚   β”œβ”€β”€ medicine_service.py        # Medicine business logic
β”‚   └── notification_service.py    # Notification handling
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ mysql_schema.sql           # Database schema
β”‚   β”œβ”€β”€ setup_mysql_database.py    # Database setup script
β”‚   └── mysql_backup.py            # Backup utility
β”‚
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html                  # Base template
β”‚   β”œβ”€β”€ index.html                 # Landing page
β”‚   β”œβ”€β”€ dashboard.html             # User dashboard
β”‚   β”œβ”€β”€ admin_dashboard.html       # Admin dashboard
β”‚   β”œβ”€β”€ medicines.html             # Medicine list
β”‚   β”œβ”€β”€ add_medicine.html          # Add medicine form
β”‚   β”œβ”€β”€ edit_medicine.html         # Edit medicine form
β”‚   β”œβ”€β”€ reminders.html             # Reminders page
β”‚   β”œβ”€β”€ manage_users.html          # User management
β”‚   β”œβ”€β”€ manage_manufacturers.html  # Manufacturer management
β”‚   β”œβ”€β”€ manage_categories.html     # Category management
β”‚   β”œβ”€β”€ medication_assistant.html  # AI assistant interface
β”‚   β”œβ”€β”€ profile.html               # User profile
β”‚   β”œβ”€β”€ login.html                 # Login page
β”‚   β”œβ”€β”€ signup.html                # Registration page
β”‚   β”œβ”€β”€ emails/                    # Email templates
β”‚   └── errors/                    # Error pages
β”‚
β”œβ”€β”€ static/
β”‚   └── uploads/                   # User uploaded files
β”‚
└── backups/                       # Database backups

πŸ”§ Database Schema

Core Tables

  • users - User accounts and authentication
  • medicines - Medication records
  • categories - Medication categories
  • manufacturers - Pharmaceutical manufacturers
  • reminders - Medication reminders
  • family_members - Family member profiles
  • caregiver_permissions - Access control for caregivers
  • emergency_contacts - Emergency contact information
  • audit_logs - System activity tracking
  • notifications - Notification queue

πŸ” Security Features

  • Password Hashing - Werkzeug PBKDF2 with salt
  • CSRF Protection - Token-based form protection
  • Rate Limiting - Prevent brute force attacks
  • Secure Headers - CSP, HSTS, X-Frame-Options
  • Session Security - HTTPOnly, Secure, SameSite cookies
  • Input Validation - WTForms validators
  • SQL Injection Prevention - SQLAlchemy ORM
  • XSS Protection - Jinja2 auto-escaping
  • Audit Logging - Complete activity tracking

πŸ“Š API Endpoints

Authentication

  • POST /login - User login
  • POST /signup - User registration
  • GET /logout - User logout
  • POST /forgot-password - Password reset request
  • POST /reset-password - Password reset

Medicines

  • GET /medicines/ - List user medicines
  • POST /medicines/add - Add new medicine
  • GET /medicines/edit/<id> - Edit medicine
  • POST /medicines/delete/<id> - Delete medicine
  • GET /api/medicines - API endpoint for medicines

Admin

  • GET /admin/dashboard - Admin dashboard
  • GET /admin/users - User management
  • GET /admin/medicines - All medicines view
  • GET /admin/manufacturers - Manufacturer management
  • GET /admin/categories - Category management
  • GET /admin/audit-logs - Audit logs
  • GET /admin/system-status - System health

AI Assistant

  • POST /medication-assistant - AI chat endpoint

πŸ§ͺ Testing

# Run tests (when implemented)
pytest

# Check code coverage
pytest --cov=app

# Lint code
flake8 app.py

πŸ“¦ Deployment

Production Checklist

  1. Set FLASK_ENV=production in .env
  2. Set DEBUG=False
  3. Use strong SECRET_KEY
  4. Enable SESSION_COOKIE_SECURE=True (HTTPS only)
  5. Configure production database
  6. Set up Redis for caching
  7. Configure email/SMS services
  8. Enable HTTPS with SSL certificate
  9. Set up automated backups
  10. Configure monitoring and logging

Deployment Options

Option 1: Traditional Server

# Install gunicorn
pip install gunicorn

# Run with gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app

Option 2: Docker

# Create Dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"]

Option 3: Cloud Platforms

  • Heroku
  • AWS Elastic Beanstalk
  • Google Cloud Run
  • Azure App Service
  • DigitalOcean App Platform

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Coding Standards

  • Follow PEP 8 style guide
  • Write descriptive commit messages
  • Add comments for complex logic
  • Update documentation
  • Test your changes

πŸ› Troubleshooting

Common Issues

Database Connection Error:

Solution: Check MySQL is running and credentials in .env are correct

Email Not Sending:

Solution: Verify Gmail app password and enable "Less secure app access"

Redis Connection Failed:

Solution: Application falls back to SimpleCache automatically

AI Assistant Not Working:

Solution: Verify GEMINI_API_KEY is set correctly in .env

Port Already in Use:

# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F

# Linux/Mac
lsof -ti:5000 | xargs kill -9

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Your Name


πŸ™ Acknowledgments

  • Flask framework and community
  • Bootstrap for UI components
  • Font Awesome for icons
  • Google Gemini for AI capabilities
  • Twilio for SMS services
  • All contributors and users

πŸ“ž Support

For support, email support@mediguard.com or open an issue on GitHub.


πŸ—ΊοΈ Roadmap

Version 2.0 (Planned)

  • Mobile app (iOS/Android)
  • Prescription scanning with OCR
  • Pharmacy integration
  • Insurance claim tracking
  • Multi-language support
  • Voice reminders
  • Wearable device integration
  • Telemedicine integration
  • Advanced analytics dashboard
  • Export to PDF/Excel

Version 1.5 (In Progress)

  • AI-powered medication assistant
  • Family member management
  • Caregiver permissions
  • Medication interaction checker
  • Refill reminders
  • Doctor appointment tracking

Made with ❀️ for better medication management

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages