Skip to content

itzsouravkumar/mediSense-HMS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MediSense Hospital Management System

A comprehensive desktop application for managing hospital operations including patient records, doctor management, appointments, and medical checkups. Built with Java Swing and MySQL database.

Table of Contents

Overview

MediSense HMS is a role-based hospital management system that provides separate interfaces for three types of users:

  • Administrators - Manage doctors and patients
  • Doctors - View patients, add checkups, and manage appointments
  • Patients - View appointments, medical records, and personal profile

The system implements a complete CRUD (Create, Read, Update, Delete) functionality for managing hospital data with a modern graphical user interface.

Features

Authentication System

  • Role-based login (Admin, Doctor, Patient)
  • Secure password authentication
  • User session management
  • Logout functionality with confirmation

Admin Dashboard

  • Doctor Management

    • Add new doctors with auto-generated IDs (DR000001 format)
    • Update doctor information (name, specialization, email, phone)
    • Delete doctors with cascade deletion
    • View all doctors in tabular format
    • Default password: DOC@1234
  • Patient Management

    • Add new patients with auto-generated IDs (PT000001 format)
    • Update patient information (name, age, email, phone)
    • Delete patients with cascade deletion
    • View all patients in tabular format
    • Default password: PAT@1234

Doctor Dashboard

  • Dashboard View

    • Statistics cards showing today's appointments, total patients, and pending checkups
    • Today's appointment list
    • Welcome message with doctor's name
  • My Patients

    • View all patients assigned to the doctor
    • Patient details in tabular format
  • Add Checkup

    • Record medical checkups for patients
    • Add diagnosis, prescription, and notes
  • Appointments

    • View scheduled appointments
    • Manage appointment status

Patient Dashboard

  • Dashboard View

    • Statistics cards showing total visits, upcoming appointments, and medical records
    • Recent appointments list
    • Welcome message with patient's name
  • My Appointments

    • View all scheduled appointments
    • Appointment details and status
  • Medical Records

    • Access complete medical history
    • View checkup details, diagnoses, and prescriptions
  • Profile

    • View personal information
    • Contact details

System Architecture

The application follows a modular architecture with clear separation of concerns:

mediSense-HMS/
├── src/hospital/management/system/
│   ├── Login.java                 # Main entry point and authentication
│   ├── loginDB.java              # Database connection and authentication logic
│   ├── adminDashboard.java       # Admin interface and operations
│   ├── doctorDashboard.java      # Doctor interface and operations
│   └── patientDashboard.java     # Patient interface and operations
├── assets/
│   ├── logo.png                  # Application logo
│   ├── admin.png                 # Admin icon
│   └── doctor.png                # Doctor icon
└── Hospital Management System.iml

Technology Stack

  • Language: Java
  • GUI Framework: Java Swing
  • Database: MySQL 8.0
  • JDBC Driver: MySQL Connector/J (com.mysql.cj.jdbc.Driver)
  • Development Environment: IntelliJ IDEA
  • Java Version: Java 8 or higher

Database Schema

Required Tables

login

Stores authentication credentials for all users.

CREATE TABLE login (
    id VARCHAR(20) PRIMARY KEY,
    pass VARCHAR(100) NOT NULL,
    user_type ENUM('Admin', 'Doctor', 'Patient') NOT NULL
);

doctor_details

Stores detailed information about doctors.

CREATE TABLE doctor_details (
    doctor_id VARCHAR(20) PRIMARY KEY,
    full_name VARCHAR(100) NOT NULL,
    specialization VARCHAR(100),
    email VARCHAR(100),
    phone VARCHAR(20),
    join_date DATE,
    FOREIGN KEY (doctor_id) REFERENCES login(id) ON DELETE CASCADE
);

patient_details

Stores detailed information about patients.

CREATE TABLE patient_details (
    patient_id VARCHAR(20) PRIMARY KEY,
    full_name VARCHAR(100) NOT NULL,
    age INT,
    email VARCHAR(100),
    phone VARCHAR(20),
    registration_date DATE,
    FOREIGN KEY (patient_id) REFERENCES login(id) ON DELETE CASCADE
);

Installation and Setup

Prerequisites

  1. Java Development Kit (JDK) 8 or higher
  2. MySQL Server 8.0 or higher
  3. MySQL Connector/J JDBC driver
  4. IDE (IntelliJ IDEA recommended)

Database Setup

  1. Install MySQL Server and start the service.

  2. Create the database:

CREATE DATABASE medisense;
USE medisense;
  1. Create the required tables using the SQL schema provided above.

  2. Create an admin user for initial access:

INSERT INTO login (id, pass, user_type) VALUES ('admin', 'admin123', 'Admin');
  1. Update database credentials in loginDB.java:
connection = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/medisense",
    "your_mysql_username",
    "your_mysql_password"
);

Application Setup

  1. Clone the repository:
git clone https://github.com/itzsouravkumar/mediSense-HMS.git
cd mediSense-HMS
  1. Add MySQL Connector/J to your project classpath:

    • Download MySQL Connector/J from the official MySQL website
    • Add the JAR file to your project's library path
  2. Ensure the assets folder is in the project root directory with all image files.

  3. Compile and run the application:

javac src/hospital/management/system/*.java
java -cp .:mysql-connector-java.jar src.hospital.management.system.Login

Or run directly from your IDE:

  • Open the project in IntelliJ IDEA
  • Configure the MySQL JDBC driver in project dependencies
  • Run Login.java

Usage Guide

First Time Setup

  1. Start the application by running Login.java
  2. Log in with the admin credentials (id: admin, pass: admin123)
  3. Add doctors and patients through the Admin Dashboard
  4. Use the generated IDs and default passwords for doctor/patient login

Admin Operations

  1. Adding a Doctor:

    • Navigate to "Doctors" tab
    • Fill in the form (Name, Specialization, Email, Phone)
    • Click "Add" button
    • System generates unique ID (e.g., DR000001)
    • Default password: DOC@1234
  2. Adding a Patient:

    • Navigate to "Patients" tab
    • Fill in the form (Name, Age, Email, Phone)
    • Click "Add" button
    • System generates unique ID (e.g., PT000001)
    • Default password: PAT@1234
  3. Updating Records:

    • Select a row in the table
    • Form auto-populates with selected data
    • Modify the fields
    • Click "Update" button
  4. Deleting Records:

    • Select a row in the table
    • Click "Delete" button
    • Confirm the deletion
    • Related login credentials are removed automatically

Doctor Operations

  1. View Dashboard:

    • Shows statistics: today's appointments, total patients, pending checkups
    • Displays today's appointment schedule
  2. Manage Patients:

    • Navigate to "My Patients"
    • View complete patient list
    • Access patient details
  3. Add Checkup:

    • Navigate to "Add Checkup"
    • Select patient
    • Enter diagnosis, prescription, and notes
    • Save checkup record
  4. View Appointments:

    • Navigate to "Appointments"
    • View all scheduled appointments
    • Check appointment details and status

Patient Operations

  1. View Dashboard:

    • Shows statistics: total visits, upcoming appointments, medical records count
    • Displays recent appointments
  2. Check Appointments:

    • Navigate to "My Appointments"
    • View all scheduled appointments
    • Check date, time, and doctor information
  3. Access Medical Records:

    • Navigate to "Medical Records"
    • View complete medical history
    • Access checkup details, diagnoses, and prescriptions
  4. View Profile:

    • Navigate to "Profile"
    • View personal information
    • Check contact details

Code Structure

Login.java

Main application entry point that handles user authentication and dashboard routing.

Key Components:

  • JTextField textField - Username input field
  • JPasswordField passwordField - Password input field
  • JRadioButton - Role selection (Admin, Doctor, Patient)
  • JButton loginButton - Custom styled login button with hover effects

Key Methods:

  • Login() - Constructor that initializes the login UI with custom styling
  • getJPanel() - Creates the rounded panel container with shadow effects
  • actionPerformed(ActionEvent e) - Handles login button click, validates credentials, and routes to appropriate dashboard
  • showLoginScreen() - Restores login screen after logout, recreates all UI components

Authentication Flow:

  1. Validates role selection and input fields
  2. Queries database using loginDB connection
  3. On success, replaces login panel with role-specific dashboard
  4. On failure, shows error dialog

loginDB.java

Database connection manager and authentication service.

Key Components:

  • Connection connection - MySQL database connection instance
  • Database URL: jdbc:mysql://localhost:3306/medisense

Key Methods:

  • loginDB() - Constructor that establishes database connection using MySQL Connector/J
  • getConnection() - Returns the active database connection
  • authenticateUser(String id, String password, String role) - Validates user credentials against login table

Database Configuration:

  • Driver: com.mysql.cj.jdbc.Driver
  • Connection pooling: Single connection instance per loginDB object
  • Error handling: Prints stack trace on connection failure

adminDashboard.java

Administrator interface with comprehensive CRUD operations for managing doctors and patients.

Key Components:

  • DefaultTableModel doctorModel - Table model for doctor data
  • DefaultTableModel patientModel - Table model for patient data
  • JTable doctorTable - Doctor records table
  • JTable patientTable - Patient records table
  • Input fields for doctor and patient information

Key Methods:

  • adminDashboard(String username, String role, Login loginFrame) - Constructor that initializes tabbed interface
  • getConnection() - Retrieves database connection via loginDB
  • getNextId(Connection con, String table, String idColumn, String prefix) - Generates sequential IDs (DR000001, PT000001)

Doctor Management Methods:

  • loadDoctors() - Fetches all doctors from database and populates table
  • populateDoctorFormFromSelection() - Fills form when table row is selected
  • addDoctor() - Inserts new doctor with transaction management (login + doctor_details)
  • updateSelectedDoctor() - Updates existing doctor information
  • deleteSelectedDoctor() - Removes doctor with cascade deletion confirmation
  • clearDoctorForm() - Resets all form fields

Patient Management Methods:

  • loadPatients() - Fetches all patients from database and populates table
  • populatePatientFormFromSelection() - Fills form when table row is selected
  • addPatient() - Inserts new patient with transaction management (login + patient_details)
  • updateSelectedPatient() - Updates existing patient information
  • deleteSelectedPatient() - Removes patient with cascade deletion confirmation
  • clearPatientForm() - Resets all form fields

Transaction Management:

  • Uses setAutoCommit(false) for atomic operations
  • Commits on success, rolls back on failure
  • Ensures data consistency between login and details tables

doctorDashboard.java

Doctor interface for patient management, checkups, and appointments.

Key Components:

  • String loggedInUserName - Stores logged-in doctor's username
  • String loggedInUserRole - Stores user role (Doctor)
  • Login loginFrame - Reference to main login frame for navigation
  • JPanel contentPanel - Dynamic content area that changes based on navigation

Key Methods:

  • doctorDashboard(String username, String role, Login loginFrame) - Constructor that initializes sidebar and content area
  • createSidebar() - Builds navigation sidebar with menu items (Dashboard, My Patients, Add Checkup, Appointments)
  • createContentPanel() - Initializes the main content display area
  • handleNavigation(String item) - Routes to appropriate view based on menu selection

Dashboard Views:

  • loadDashboardView() - Displays statistics cards and today's appointments

    • Fetches: today's appointment count, total patient count, pending checkups
    • Shows: welcome message with doctor's name, quick stats, appointment list
  • loadMyPatientsView() - Shows all patients assigned to the doctor

    • Displays patient table with ID, name, age, contact information
  • loadAddCheckupView() - Provides form for recording medical checkups

    • Fields: patient selection, diagnosis, prescription, notes
    • Saves checkup data with timestamp
  • loadAppointmentsView() - Lists all scheduled appointments

    • Shows: appointment date, time, patient name, status

Helper Methods:

  • getDoctorName(loginDB db) - Retrieves doctor's full name from database
  • getTodayAppointments(loginDB db) - Counts appointments for current date
  • getMyPatientCount(loginDB db) - Returns total number of patients
  • getPendingCheckups(loginDB db) - Counts incomplete checkups
  • createStatCard(String title, int value, Color color, int x, int y) - Creates visual statistic cards

UI Features:

  • Custom avatar circles with initials
  • Hover effects on navigation buttons
  • Logout confirmation dialog
  • Profile panel showing doctor name and role

patientDashboard.java

Patient interface for viewing appointments, medical records, and personal profile.

Key Components:

  • String loggedInUserName - Stores logged-in patient's username
  • String loggedInUserRole - Stores user role (Patient)
  • Login loginFrame - Reference to main login frame for navigation
  • JPanel contentPanel - Dynamic content area for different views

Key Methods:

  • patientDashboard(String username, String role, Login loginFrame) - Constructor that sets up patient interface
  • createSidebar() - Builds navigation sidebar with menu items (Dashboard, My Appointments, Medical Records, Profile)
  • createContentPanel() - Initializes the main display area
  • handleNavigation(String item) - Switches between different patient views

Dashboard Views:

  • loadDashboardView() - Shows patient statistics and recent activity

    • Displays: total visits, upcoming appointments, medical records count
    • Shows: welcome message, quick stats, recent appointments
  • loadAppointmentsView() - Lists all patient appointments

    • Shows: date, time, doctor name, appointment status
    • Allows viewing appointment details
  • loadMedicalRecordsView() - Displays complete medical history

    • Shows: checkup date, doctor name, diagnosis, prescription
    • Provides access to historical medical data
  • loadProfileView() - Shows patient personal information

    • Displays: full name, age, email, phone, registration date
    • Read-only view of patient details

Helper Methods:

  • getPatientName(loginDB db) - Retrieves patient's full name from database
  • getTotalVisits(loginDB db) - Counts total hospital visits
  • getUpcomingAppointments(loginDB db) - Returns count of future appointments
  • getMedicalRecordsCount(loginDB db) - Counts total medical records
  • createStatCard(String title, int value, Color color, int x, int y) - Creates visual statistic displays

UI Features:

  • Custom avatar with patient's initial
  • Smooth navigation transitions
  • Logout confirmation dialog
  • Profile section with patient info
  • Color-coded statistics cards (blue, green, purple themes)

Security Considerations

Current Implementation

  • Basic password authentication
  • Role-based access control
  • SQL injection vulnerability in Login.java (concatenated queries)
  • Plain text password storage
  • Default passwords for new users

Recommended Improvements

  1. Password Security:

    • Implement password hashing (BCrypt, PBKDF2)
    • Enforce strong password policies
    • Add password change functionality
    • Implement password reset mechanism
  2. SQL Injection Prevention:

    • Replace concatenated SQL queries with PreparedStatements
    • Current vulnerable code in Login.java line 206:
    // VULNERABLE
    String query = "SELECT * FROM login WHERE id='" + username + "' AND pass='" + password + "' AND user_type='" + role + "'";
    
    // SECURE ALTERNATIVE
    String query = "SELECT * FROM login WHERE id=? AND pass=? AND user_type=?";
    PreparedStatement ps = connection.prepareStatement(query);
    ps.setString(1, username);
    ps.setString(2, password);
    ps.setString(3, role);
  3. Session Management:

    • Implement session timeouts
    • Add session invalidation on logout
    • Track active sessions
  4. Access Control:

    • Add authorization checks for sensitive operations
    • Implement audit logging
    • Track user actions
  5. Data Validation:

    • Validate all user inputs
    • Sanitize data before database operations
    • Implement input length restrictions
  6. Database Security:

    • Use environment variables for database credentials
    • Implement connection pooling
    • Use SSL/TLS for database connections
    • Regular database backups

Contributing

Contributions are welcome! Please follow these guidelines:

  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 Java naming conventions
  • Add comments for complex logic
  • Write unit tests for new features
  • Update documentation as needed

License

This project is part of an educational initiative. Please check with the repository owner for specific licensing terms.

Contact

Project Repository: https://github.com/itzsouravkumar/mediSense-HMS

Acknowledgments

  • Java Swing documentation
  • MySQL community
  • IntelliJ IDEA
  • All contributors to this project

Future Enhancements

MediSense HMS is built with scalability in mind. Future updates aim to introduce:

Appointment Notifications via email or SMS for doctors and patients

E-Prescription System with downloadable PDFs

Billing & Invoicing Module for patient payments and hospital accounting

Inventory Management for medicines and medical supplies

Data Analytics Dashboard to monitor hospital performance metric

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages