Skip to content

saikrishna-avskr/rtfp-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PharmAssist - Pharmacy Management System

A comprehensive Django-based pharmacy management system with shopping cart functionality and OCR (Optical Character Recognition) capabilities for prescription processing.

πŸš€ Quick Start Demo

Try the demo immediately after setup:

  1. Run the development server: python manage.py runserver
  2. Go to admin panel: http://127.0.0.1:8000/admin/
  3. Login with: Username: admin | Password: 1234
  4. Explore the pharmacy management features!

πŸš€ Features

  • Product Management: Add, view, update, and remove pharmaceutical products
  • Inventory Tracking: Monitor stock levels and expiry dates
  • Shopping Cart: Add products to cart, manage quantities, and checkout
  • OCR Integration: Extract text from prescription images using Tesseract
  • Low Stock Alerts: Identify products with low inventory
  • Expiry Monitoring: Track products nearing expiration
  • Patient Information: Capture customer details during checkout
  • Invoice Generation: Generate invoices for completed orders
  • Admin Panel: Django admin interface for system management

πŸ› οΈ Technology Stack

  • Backend: Django 5.0.6
  • Database: MySQL
  • OCR Engine: Tesseract OCR with pytesseract
  • Image Processing: Pillow (PIL)
  • Server: Gunicorn
  • Frontend: HTML templates with Django templating
  • Environment: Python virtual environment

πŸ“‹ Prerequisites

Before running this project, make sure you have the following installed:

  • Python 3.8+
  • MySQL Server
  • Tesseract OCR
  • pip (Python package manager)

Installing Tesseract OCR

Windows:

  1. Download from: https://github.com/UB-Mannheim/tesseract/wiki
  2. Install and note the installation path
  3. Update the tesseract path in products/views.py if needed

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install tesseract-ocr

macOS:

brew install tesseract

πŸ”§ Installation & Setup

1. Clone the Repository

git clone https://github.com/saikrishna-avskr/rtfp-1.git
cd rtfp-1

2. Create Virtual Environment

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

3. Install Dependencies

cd pharmassit
pip install -r requirements.txt

4. Environment Configuration

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

# Database Configuration
DB_ENGINE=django.db.backends.mysql
DB_NAME=pharmassist
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=3306

# Django Configuration
SECRET_KEY=your_secret_key_here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

5. Database Setup

# Create database migrations
python manage.py makemigrations

# Apply migrations
python manage.py migrate

# Create superuser (admin)
python manage.py createsuperuser

6. Run the Development Server

python manage.py runserver

The application will be available at http://127.0.0.1:8000

οΏ½ Demo Login Credentials

For demonstration purposes, use the following credentials to access the admin panel:

Admin Login:

  • Username: admin
  • Password: Admin@1234

Note: These are demo credentials for testing purposes only. In production, use strong, unique passwords.

οΏ½πŸ“ Project Structure

rtfp-1/
β”œβ”€β”€ .env                    # Environment variables
β”œβ”€β”€ .gitignore             # Git ignore rules
β”œβ”€β”€ README.md              # Project documentation
β”œβ”€β”€ pharmassit/            # Main Django project
β”‚   β”œβ”€β”€ manage.py          # Django management script
β”‚   β”œβ”€β”€ requirements.txt   # Python dependencies
β”‚   β”œβ”€β”€ pharmassit/        # Project configuration
β”‚   β”‚   β”œβ”€β”€ settings.py    # Django settings
β”‚   β”‚   β”œβ”€β”€ urls.py        # Main URL configuration
β”‚   β”‚   β”œβ”€β”€ wsgi.py        # WSGI configuration
β”‚   β”‚   └── asgi.py        # ASGI configuration
β”‚   β”œβ”€β”€ products/          # Products app
β”‚   β”‚   β”œβ”€β”€ models.py      # Product data models
β”‚   β”‚   β”œβ”€β”€ views.py       # Product views & OCR logic
β”‚   β”‚   β”œβ”€β”€ urls.py        # Product URL patterns
β”‚   β”‚   └── templates/     # Product HTML templates
β”‚   └── cart/              # Shopping cart app
β”‚       β”œβ”€β”€ models.py      # Cart data models
β”‚       β”œβ”€β”€ views.py       # Cart functionality
β”‚       β”œβ”€β”€ urls.py        # Cart URL patterns
β”‚       └── templates/     # Cart HTML templates
└── tobeadded/             # Additional OCR scripts
    β”œβ”€β”€ ocr.py             # Camera-based OCR
    β”œβ”€β”€ ocr2.py            # Enhanced OCR functionality
    └── ...                # Other OCR implementations

πŸ“Š Database Models

Product Model

class Product(models.Model):
    pid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)
    generic_name = models.CharField(max_length=255)
    expiry_date = models.DateField()
    price = models.FloatField()
    stock = models.IntegerField()
    storage_loc = models.CharField(max_length=255)
    image = models.CharField(max_length=2083)

Cart Model

class Cart(models.Model):
    product = models.OneToOneField(Product, on_delete=models.CASCADE)
    pid = models.IntegerField(null=True)
    quantity = models.IntegerField(null=True)
    price = models.FloatField(null=True)
    tot_price = models.FloatField(null=True)

πŸ”— API Endpoints

Products

  • / - Home page
  • /products/details/ - Product listing and search
  • /products/find_exp_items/ - Find expiring products
  • /products/find_low_stock/ - Find low stock items
  • /products/remove_product/<int:pid>/ - Remove product
  • /products/show_upload/ - Upload prescription form
  • /products/upload_report/ - Process uploaded prescription

Cart

  • /cart/add/<int:pid>/ - Add product to cart
  • /cart/remove/<int:pid>/ - Remove product from cart
  • /cart/show/ - View cart contents
  • /cart/update/<int:product_id>/ - Update cart quantity
  • /cart/clear/ - Clear entire cart
  • /cart/checkout/ - Checkout process
  • /cart/order/ - Process order

πŸ–ΌοΈ OCR Functionality

The system includes OCR capabilities to process prescription images:

  1. Upload Prescription: Users can upload prescription images
  2. Text Extraction: Tesseract OCR extracts text from images
  3. Product Matching: System matches extracted text with product database
  4. Auto-Add to Cart: Matching products are automatically added to cart

OCR Configuration

Update the Tesseract path in products/views.py:

pytesseract.pytesseract.tesseract_cmd = 'path/to/tesseract.exe'

πŸ‘₯ User Roles

Admin Users

  • Access Django admin panel at /admin/
  • Demo Login: Username: admin, Password: 1234
  • Manage products, inventory, and system settings
  • View reports and analytics

Regular Users

  • Browse products
  • Add items to cart
  • Process orders
  • Upload prescriptions

πŸš€ Deployment

Production Settings

  1. Set DEBUG=False in environment variables
  2. Configure proper ALLOWED_HOSTS
  3. Use production database (PostgreSQL recommended)
  4. Configure static files serving
  5. Use Gunicorn for WSGI server

Example Production Command

gunicorn pharmassit.wsgi:application --bind 0.0.0.0:8000

πŸ§ͺ Testing

Run tests using Django's test framework:

python manage.py test

πŸ“ Contributing

  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

πŸ“„ License

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

πŸ”§ Troubleshooting

Common Issues

  1. Tesseract Not Found

    • Ensure Tesseract is installed and path is correctly set
    • Update the tesseract_cmd path in views.py
  2. Database Connection Error

    • Verify MySQL is running
    • Check database credentials in .env file
    • Ensure database exists
  3. Import Errors

    • Activate virtual environment
    • Install all requirements: pip install -r requirements.txt
  4. Static Files Not Loading

    • Run: python manage.py collectstatic
    • Check STATIC_ROOT and STATIC_URL settings

πŸ“ž Support

For support and questions:

πŸ™ Acknowledgments

  • Django Community for the excellent framework
  • Tesseract OCR team for OCR capabilities
  • Contributors and testers

Note: This is a development version. For production use, please implement proper security measures, error handling, and testing.