# Dialysis Management System

A web application for searching patient records for Ayushman Bharat PMJAY processing and managing daily dialysis patient records.

## Features

- Secure login with database authentication
- Patient search by name or ID
- Integration with Ayushman Bharat PMJAY
- **Daily Dialysis Records Management** - Track patient biometrics for dialysis sessions
- **Time-based Validation** - Automatic validation for dialysis duration (min 3hrs, max 24hrs)
- **Patient Data Fetching** - Auto-populate patient details using PMJAY ID
- **Admin & User Panels** - Daily records feature available for both admin and user roles
- Responsive design using Bootstrap
- Secure database connectivity with PDO
- Sample data for testing
- Aadhaar number masking for privacy

## Technologies Used

- **Frontend**: HTML, CSS, JavaScript, Bootstrap 4, AdminLTE 3
- **Backend**: PHP
- **Database**: MySQL
- **Security**: PDO prepared statements, password hashing, session management

## Installation

1. Clone or download this repository to your web server directory (e.g., `www` folder for WAMP)
2. Create a MySQL database named `dialysis_db`
3. Execute the SQL script in `includes/setup.sql` to create the database tables and sample data
4. Update the database credentials in `includes/db_connect.php` if needed
5. Access the application through your web browser at `http://localhost/dialysis/login.php`

## Default Login

- **Username**: admin
- **Password**: admin123

> **Important**: Change the default password immediately after first login in a production environment.

## Database Setup

Run the following commands in your MySQL client:

```sql
CREATE DATABASE IF NOT EXISTS dialysis_db;
USE dialysis_db;

CREATE TABLE IF NOT EXISTS patients (
    id INT AUTO_INCREMENT PRIMARY KEY,
    patient_name VARCHAR(100) NOT NULL,
    patient_id VARCHAR(50) UNIQUE NOT NULL,
    aadhaar_number VARCHAR(12),
    age INT,
    gender ENUM('Male', 'Female', 'Other'),
    address TEXT,
    phone VARCHAR(15),
    registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    name VARCHAR(100) DEFAULT 'Admin User',
    role ENUM('admin', 'staff') DEFAULT 'admin',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```

## File Structure

```
dialysis/
│
├── admin/
│   ├── index.php              # Admin dashboard
│   └── daily_records.php      # Daily dialysis records form (Admin)
├── api/
│   └── dialysis_records.php   # API endpoint for dialysis records
├── css/
│   └── style.css              # Custom styles
├── includes/
│   ├── db_connect.php         # Database connection
│   ├── setup.sql              # Database setup script
│   └── dialysis_records_setup.sql  # Dialysis records table setup
├── js/
│   └── app.js                 # Custom JavaScript
├── index.php                  # Main entry point (patient search)
├── login.php                  # Login page
├── logout.php                 # Logout handler
├── search.php                 # Search functionality
├── user_panel.php             # User panel - Patient records
├── user_daily_records.php     # Daily dialysis records form (User)
├── migrate_dialysis_records.php  # Migration script for dialysis records table
└── README.md                  # This file
```

## Usage

1. Navigate to `http://localhost/dialysis/login.php` in your web browser
2. Login with the default credentials
3. Search for patients by name or ID
4. View the patient details in the search results
5. Process patients for PMJAY benefits

### Daily Dialysis Records

1. **Run Migration**: First, visit `http://localhost/dialysis/migrate_dialysis_records.php` to create the dialysis records table
2. **Admin Panel**: Navigate to Admin Dashboard > Daily Dialysis Records or directly to `admin/daily_records.php`
3. **User Panel**: Navigate to User Panel > Daily Dialysis Records or directly to `user_daily_records.php`
4. **Enter Patient PMJAY ID**: Type the patient's PMJAY ID and click Search to auto-populate patient details
5. **Select Date and Time**: Choose the record date and dialysis start/end times
6. **Enter Biometrics**: Fill in pre and post dialysis biometrics (weight, blood pressure, pulse, temperature)
7. **Treatment Details**: Enter ultrafiltration, heparin dose, and saline used
8. **Save Record**: The system validates duration (3-24 hours) before saving

## Security Features

- Uses PDO prepared statements to prevent SQL injection
- Password hashing with `password_hash()` and `password_verify()`
- Session-based authentication
- Input validation for search terms
- Secure database connection handling
- Aadhaar number masking to protect sensitive PII
- Error messages logged internally (not displayed to users)

## Contributing

This is a simplified demonstration application. In a production environment, additional security measures and features would be implemented, such as:
- CSRF protection
- Rate limiting for login attempts
- HTTPS enforcement
- Role-based access control
- Audit logging

## Daily Dialysis Records Feature

### Biometrics Captured

| Field | Description |
|-------|-------------|
| Weight (Before/After) | Patient weight in kg |
| Blood Pressure (Before/After) | BP reading (e.g., 120/80) |
| Pulse (Before/After) | Heart rate in bpm |
| Temperature (Before/After) | Body temperature in °F |

### Treatment Details

| Field | Description |
|-------|-------------|
| Ultrafiltration | Fluid removed during dialysis (ml) |
| Heparin Dose | Heparin administered (units) |
| Saline Used | Saline volume used (ml) |
| Duration | Calculated automatically (3-24 hrs) |

### Time Validation Rules

- **Minimum Duration**: 3 hours
- **Maximum Duration**: 24 hours
- **Auto-calculation**: Duration is calculated based on Time In and Time Out
- **Cross-midnight Support**: If Time Out is before Time In, it assumes next day

## License

This project is for educational purposes and demonstrates a patient search system for healthcare applications.
