# Rx Connections - Client Portal

## Overview
This is an external client access portal for the Rx Connections CRM system. It allows external clients to access specific modules for patient management, similar to the pspSync functionality.

## Features
- **Secure Authentication**: OTP-based email authentication for clients
- **Data Entry Module**: Add and manage patient enrollments
- **Welcome Call Module**: Track and update welcome call status
- **Reimbursement Module**: Manage patient reimbursement processes
- **Client-Specific Data**: Each client only sees patients associated with their PSP ID

## Installation

### 1. Database Setup
Run the SQL script to create necessary tables:
```bash
mysql -u root -p rxcrm < client/database_setup.sql
```

### 2. Configure Database Connection
Update `client/connect.php` with your database credentials:
```php
$host = 'localhost';
$db   = 'rxcrm';
$user = 'your_username';
$pass = 'your_password';
```

### 3. Create Client Accounts
Add client users to the `tblclient` table:
```sql
INSERT INTO tblclient (clientName, email, companyName, pspId, isActive) 
VALUES ('Client Name', 'client@example.com', 'Company Name', 1, 'Y');
```

### 4. Set Permissions
Ensure the web server has read/write access to the client folder.

## Directory Structure
```
client/
├── connect.php          # Database connection
├── function.php         # Helper functions
├── login.php           # Client login page
├── logout.php          # Logout handler
├── dashboard.php       # Main dashboard
├── head.php            # Header includes
├── header.php          # Navigation header
├── sidebar.php         # Sidebar navigation
├── footer.php          # Footer includes
├── database_setup.sql  # Database schema
├── de/                 # Data Entry module
│   ├── index.php
│   └── add_patient.php
├── pharmacy/           # Welcome Call module
│   └── index.php
└── reimbursement/      # Reimbursement module
    └── index.php
```

## Access Levels
- Clients can only view/edit patients associated with their assigned PSP ID
- All patient data is filtered by `pspId` in `tblpatientdetails`
- Activity logging tracks all client actions

## Security Features
1. **OTP Authentication**: 4-digit OTP sent via email
2. **Session Management**: Secure session handling with cookies
3. **Data Isolation**: Clients only access their own PSP data
4. **Activity Logging**: All actions logged in `tblclientactivity`
5. **SQL Injection Protection**: Prepared statements throughout

## Usage

### For Administrators
1. Create client accounts in `tblclient` table
2. Assign appropriate PSP ID to each client
3. Monitor client activity via `tblclientactivity` table

### For Clients
1. Navigate to `/client/login.php`
2. Enter registered email address
3. Receive OTP via email
4. Enter OTP to access dashboard
5. Use modules: Data Entry, Welcome Calls, Reimbursement

## Module Details

### Data Entry (DE)
- Add new patients
- Edit patient information
- View patient details
- All patients automatically tagged with client's PSP ID

### Welcome Calls (Pharmacy)
- View patients requiring welcome calls
- Update welcome call status
- Track completion dates
- View call history

### Reimbursement
- Manage reimbursement processes
- Update reimbursement status
- Track enrollment completion
- View treatment start dates

## Customization
To add more features or modify existing ones:
1. Follow the existing code structure
2. Always filter by `$_SESSION['pspId']`
3. Log activities in `tblclientactivity`
4. Use prepared statements for database queries

## Support
For issues or questions, contact the development team.

## Version
1.0.0 - Initial Release
