Academic / CourseworkWeb & Full-Stack~3 min read

POS Pharmacy System

Desktop retail pharmacy checkout system with FEFO batch inventory tracking.

RoleSoftware Developer
TimelineNov 2023
DomainWeb & Full-Stack
Core StackJava, Java Swing, Hibernate 5.6

What I Built#

I developed this application as a term project for an enterprise Java course at university. The goal was to build a desktop point-of-sale (POS) and inventory management system for retail pharmacies.

The project was built in Java using Java Swing for the desktop graphical user interface, Hibernate 5.6 ORM for object-relational mapping, and MySQL for persistent database storage.

Core Features#

  • Cashier Checkout: An interactive desktop billing screen where cashiers search for medicines by name or code, add items to an active bill, and calculate totals with taxes.
  • Batch & Expiry Tracking: Medicines are tracked in batches with individual expiry dates and quantities. The system helps cashiers dispense the earliest-expiring batch first (First-Expiring-First-Out / FEFO).
  • Invoice Generation & Printing: Generates itemized billing receipts that can be printed or exported.
  • Stock Management: Inventory levels decrement automatically upon completed sales, with alerts for low-stock items.

Architecture#

architecture-diagram.txt
Java Swing Desktop GUI (Cashier Interface)
                   │
                   ▼
┌───────────────────────────────────────┐
│     SwingWorker Background Threads    │ (Keeps database queries off the UI thread)
└──────────────────┬────────────────────┘
                   │
                   ▼
┌───────────────────────────────────────┐
│      Controller & Business Logic      │ (Cart calculations & batch allocation)
└──────────────────┬────────────────────┘
                   │
                   ▼
┌───────────────────────────────────────┐
│          Hibernate 5.6 ORM            │ (Session management, entities, HQL)
└──────────────────┬────────────────────┘
                   │
                   ▼
┌───────────────────────────────────────┐
│            MySQL Database             │ (Medicines, Batches, Invoices, Sales)
└───────────────────────────────────────┘

Technical Lessons & What I Learned#

1. Keeping the UI Responsive with SwingWorker

In early builds, running database queries directly on the main Java Swing thread caused the desktop window to briefly freeze during product searches and invoice checkouts. In Swing, all UI rendering and user inputs happen on the Event Dispatch Thread (EDT). I moved database reads and writes to background SwingWorker threads, keeping the desktop interface smooth and responsive while queries execute.

2. Entity Mapping and Transactions in Hibernate

Instead of writing raw JDBC queries with manual SQL strings, I used Hibernate 5.6 to map relational tables to Java entity classes (Medicine, MedicineBatch, Invoice, InvoiceItem). Using Hibernate sessions and transaction boundaries ensured that when an invoice was finalized, the sale record and the inventory batch deductions either succeeded together or rolled back safely if an error occurred.

3. Practical Batch Inventory Logic

In retail pharmacies, selling from the newest shipment while older boxes sit on the shelf leads to expired stock waste. Structuring the database to track distinct batches per medicine allowed the checkout logic to automatically select the earliest-expiring batch, solving a real retail problem.

Complete Technology Stack

JavaJava SwingHibernate 5.6MySQL