8000
Skip to content

Repository files navigation

💊 Smart Pharmacy Checker — Drug Price Overpayment Detection System in pharmacies

Empowering Kenyans with drug price transparency at the point of purchase.

Smart Pharmacy Checker is a web-based system that allows users to verify whether they are being overcharged for medication by comparing pharmacy prices against the official Ministry of Health (MOH) Kenya benchmark prices. The system recommends nearby cheaper pharmacies, supports barcode and QR code scanning, and provides a structured overcharge reporting workflow.

Built as a Final Year Project at Multimedia University of Kenya, Faculty of Computing and Information Technology.


📸 Preview

🏠 Dashboard

Main Search Page Dashboard

Dashboard showing "Welcome back, [username] 👋", two animated circular rings (🚩 Reports Made in red, Unsuccessful Reports), the search input with Search and 📷 Scan buttons below


✨ Features

  • 🔍 Drug search — real-time autocomplete from 700+ MOH benchmark drugs
  • 📷 Barcode and QR scanning — scan via webcam or upload an image file
  • 💰 Overpayment calculator — computes KES overcharge amount and percentage vs MOH price
  • 🏪 Pharmacy recommendations — sorted by cheapest price first, then nearest distance
  • 🗺️ Travel time estimates — walking, motorbike, and car for each pharmacy
  • 📍 Pharmacy profiles — photo gallery, Google Maps location bubble, drug price
  • 🚩 Overcharge reporting — multi-drug structured reports backed by receipt photos
  • 🖨️ QR and barcode generation — printable sheet for all drugs, individual downloads
  • ⚙️ Admin pharmacy management — create, edit, delete pharmacies with CSV price upload
  • 📊 User activity tracking — persistent drugs searched and reports made counters
  • 📱 Fully responsive — sidebar on desktop, bottom nav bar on mobile

📸 Screenshots

🔐 Authentication

Sign Up Simple sign up that requires name,password and password confirm field

Sign Up

Login well curated log in page Login

Autocomplete in Action TO eliminate user errors in typing the drug name

Autocomplete in Action


📷 Barcode and QR Scanner

Camera Mode — QR

Camera Mode — QR Camera Mode — Barcode Camera Mode — Barcode

Barcode scanning

Barcode scanning


💊 Drug Check Flow

Overpayment module --select quantity,then see the overpayment

Overpayment module

Overpayment module result dislay --select quantity,Enter the Price charged,Calculates and Displays the price

Overpayment module result dislay


🏪 Pharmacy Recommendations

Recommendations List Recommendations List

Recommendations page showing at least two pharmacy cards each with cover photo, pharmacy name, 📍 location bubble, price badge, distance in km, and the three travel time rows (🚶 Walking / 🏍️ Motorbike / 🚗 Car). Arrow pointing to "Tap for details →"

Pharmacy Detail Modal

Pharmacy Detail Modal Once the pharmacy profile is clicked...it expands to show more pharmacy details and more photo glossary


🚩 Report Overcharge

Report Form REPORT FORM

Report form showing the pharmacy name field with autocomplete, at least two drug entry cards open each with drug name autocomplete, category radio buttons, amount and price fields, and the receipt upload section at the bottom


📷 QR Code Sheet

just click the QR code sheet


⚙️ Admin — Pharmacy Management

ADMIN FEATURES CREATE A SUPER USER IN THE TERMINAL AND THEN LOG IN AS AN ADMIN TO ACCESS THIS FEATURES. USE THE COMMAND: PYTHON MANAGE.PY CREATESUPERUSER

Manage List

Manage Pharmacies page showing pharmacy cards with cover photos, name, location description, drug count, and Edit / Delete buttons. Add Pharmacy button prominent at top right

Create Pharmacy Form

Create pharmacy form showing the location section — coordinates entered, the blue 📍 geocode bubble showing the resolved place name with ✓ badge, and the 🗺️ View on Google Maps button below

Edit Pharmacy

Edit pharmacy form showing the existing photos thumbnails (cover labelled), the location geocode bubble, and the CSV upload warning banner


📱 Mobile View

Mobile Bottom Navigation

Any page viewed on a narrow mobile viewport showing the dark bottom navigation bar with 🔍 Search, 🏪 Pharmacies, 🚩 Report, 📷 QR icons and labels — active icon highlighted in blue


🛠️ Tech Stack

Layer Technology
Backend framework Python 3.12, Django 4.2
Database SQLite via Django ORM
Frontend Bootstrap 5.3, Vanilla JavaScript ES6
Barcode scanning html5-qrcode 2.3.8 (CDN)
QR code generation qrcode[pil]
Barcode generation python-barcode[images]
Reverse geocoding OpenStreetMap Nominatim (free, no API key)
Image processing Pillow

📁 Project Structure

smart_pharmacy/
├── manage.py
├── requirements.txt
├── data/
│   └── moh_benchmark.csv           # MOH drug price seed data (700+ drugs)
│
├── smart_pharmacy/                  # Project config
│   ├── settings.py
│   └── urls.py
│
├── accounts/                        # Authentication app
│   ├── views.py
│   ├── urls.py
│   └── templates/accounts/
│       └── signup.html
│
├── drugs/                           # Core drug logic app
│   ├── models.py                    # Drug, UserActivity
│   ├── views.py
│   ├── utils.py                     # Overpayment formula
│   ├── urls.py
│   ├── management/commands/
│   │   └── import_moh_csv.py
│   └── templates/drugs/
│       ├── search.html
│       ├── quantity_select.html
│       ├── price_entry.html
│       ├── result.html
│       └── qr_sheet.html
│
├── pharmacies/                      # Pharmacy logic app
│   ├── models.py                    # Pharmacy, PharmacyImage, PharmacyDrug,
│   │                                # OverchargeReport, OverchargeReportItem
│   ├── views.py
│   ├── utils.py                     # Haversine + travel time
│   ├── urls.py
│   └── templates/pharmacies/
│       ├── home.html
│       ├── recommendations.html
│       ├── report_form.html
│       ├── report_success.html
│       ├── manage.html
│       ├── create.html
│       ├── edit.html
│       └── delete_confirm.html
│
├── static/
│   └── css/main.css
│
├── media/                           # Uploaded files — gitignored
│   ├── pharmacy_images/
│   └── receipts/
│
└── templates/
    ├── base.html
    └── registration/
        └── login.html

⚙️ Installation

Prerequisites

  • Python 3.10 or higher
  • pip
  • Git

1. Clone the repository

git clone https://github.com/yourusername/smart-pharmacy.git
cd smart-pharmacy

2. Create and activate a virtual environment

# Windows
python -m venv venv
venv\Scripts\activate

# macOS / Linux
python -m venv venv
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Apply migrations

python manage.py makemigrations
python manage.py migrate

5. Create a superuser

python manage.py createsuperuser

6. Import the MOH drug benchmark data

python manage.py import_moh_csv data/moh_benchmark.csv

Expected output:

Done. Created: 113  Updated: 0  Skipped: 0

7. Run the server

python manage.py runserver

Visit http://localhost:8000

⚠️ Always use localhost not 127.0.0.1 — the barcode scanner camera requires a secure context which localhost satisfies automatically.


📷 Barcode and QR Code Scanning

Camera scanning

  1. Go to Search Drug
  2. Click 📷 Scan
  3. Select the Camera tab
  4. Choose QR Code or Barcode mode
  5. Hold the code inside the corner guide frame

Image upload scanning

  1. Click 📷 Scan
  2. Select the Upload tab
  3. Choose a photo of the QR code or barcode
  4. Click 🔍 Scan Uploaded Code

Generating test QR codes

Visit /drugs/qr-sheet/ to see all drugs with their QR codes rendered. Each drug has a unique code in the format SMARTPHARMA_DRUG_{id}. Print the sheet or display it on a second screen for testing.


💰 Overpayment Calculation

MOH Total    = moh_price_per_unit × quantity
Overcharge   = user_total_price − MOH Total
Overcharge % = (Overcharge ÷ MOH Total) × 100

If the result is zero or negative — no overcharge is reported.


🏪 Adding Pharmacies

Only staff users can manage pharmacies.

Via the frontend (recommended)

  1. Log in as staff
  2. Click ⚙️ Manage in the sidebar
  3. Click Add Pharmacy
  4. Fill in name, coordinates (right-click on Google Maps to copy), description, and photos
  5. Upload the pharmacy drug price CSV

Pharmacy price CSV format

drug_name,strength,price_per_unit
Paracetamol,500mg,5.50
Ibuprofen,400mg,8.00
Amoxicillin,500mg,16.00

Drug names must match the MOH benchmark list exactly (case-insensitive). Unmatched rows are skipped and reported.


🔐 User Roles

Role Permissions
Regular User Search drugs, view recommendations, submit overcharge reports, view QR codes
Staff / Admin All of the above plus manage pharmacies, import data, review reports

Promote a user to staff:

python manage.py shell -c "
from django.contrib.auth.models import User
u = User.objects.get(username='yourname')
u.is_staff = True
u.save()
print('Done')
"

📍 Location and Distance

Feature Implementation
Distance calculation Haversine formula (great-circle distance in km)
Pharmacy sorting Cheapest price first, nearest distance as tiebreaker
Reverse geocoding OpenStreetMap Nominatim — no API key required
Map links Google Maps URL with pharmacy coordinates

🗄️ Data Models

Model Purpose
Drug MOH benchmark catalogue — name, category, unit, price, barcode
UserActivity Persistent per-user drugs searched and reports submitted count
Pharmacy Pharmacy profile — name, GPS coordinates, description, location text
PharmacyImage Multiple photos per pharmacy with cover flag
PharmacyDrug Junction table — pharmacy-specific price per drug
OverchargeReport Report header — pharmacy, receipt image, status
OverchargeReportItem One row per drug in a report — name, amount, unit, price charged

📋 Requirements

Django==4.2.13
Pillow==10.3.0
qrcode[pil]
python-barcode[images]

📄 License

This project was developed as an academic final year project at Multimedia University of Kenya. All rights reserved.


👤 Author

DENNIS MUTHAMA
Registration Number: CIT-227-075/2022
Faculty of Computing and Information Technology
Multimedia University of Kenya


🙏 Acknowledgements

  • Ministry of Health Kenya — drug pricing benchmark data
  • OpenStreetMap Nominatim — free reverse geocoding
  • html5-qrcode — open source barcode scanning library
  • Bootstrap — responsive UI components
  • Multimedia University of Kenya — academic supervision and support

Smart Pharmacy — Because every Kenyan deserves to know if they are being overcharged.

About

A smart pharmacy checker system to calculate Overpayment in pharmacy drugs.Uses google maps for pharmacy mapping and directions

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0