# CareSterile — deployment & go-live guide

This guide takes CareSterile from the zip to a live hospital. Part A is for Caresoft IT (once per server). Part B is for each new client hospital.

---

## Part A — server set-up (once)

### 1. Requirements

| Item | Minimum |
| --- | --- |
| PHP | 8.1+ (8.3 tested) with `pdo_mysql`, `mbstring`, `openssl`, `zlib`, `json`, `fileinfo`; `zip` recommended (uploaded files in backups) |
| Database | MySQL 8 or MariaDB 10.6+ — a user that can create databases named `cssd_*` |
| Web server | Apache (cPanel) or Nginx + PHP-FPM, HTTPS certificate |
| Cron | Two jobs (worker every 5 minutes, backup nightly) |
| Mail | SMTP account (Amazon SES, own mail server or Gmail Workspace relay) — sign-in codes and alerts depend on it |

Sizing guide: a single 2 vCPU / 4 GB server comfortably runs 20–40 mid-size hospitals. Each client has its own database, so a large group can be moved to its own server later without code changes.

### 2. Install

```bash
unzip caresterile-phase6.zip && cd caresterile
cp config/config.sample.php config/config.php
php -r "echo 'base64:'.base64_encode(random_bytes(32)).PHP_EOL;"   # paste into app_key
```

Edit `config/config.php`:

- `base_url` — `https://cssd.caresoft.co.in` (no trailing slash)
- `env` — `production` (never `dev` on a live server: dev writes sign-in codes to a log file and shows errors)
- `control_db` and `tenant_db_defaults` — database host, user and password; `prefix` stays `cssd_` (on cPanel: `<account>_cssd_`)
- `tenant_domain` — optional, e.g. `cssd.caresoft.co.in` so `shiva.cssd.caresoft.co.in` fills the client code automatically (needs a wildcard DNS record and certificate)
- `mail` — `driver` `smtp` with host, port 587, user, password, from address
- `site` — sales phone, WhatsApp, email and address shown on the marketing site
- `backup.dir` — keep the default (inside `storage/`, not web-reachable) or a separate disk

```bash
php install/install.php --name="Caresoft Admin" --email=admin@caresoft.co.in --password='Strong#Pass1' --demo
chmod -R 775 storage && chown -R www-data:www-data storage      # cPanel: the account user
php install/check.php                                           # every line should be ✓ or !
```

`--demo` also builds the **DEMO** hospital (60 days of sample data, all users password `Demo#2026`) for sales demos. Leave it out on a server that should hold only live hospitals.

### 3. Web server

**cPanel / Apache:** point the domain's document root to `caresterile/public`. If the panel cannot change the document root, upload into `public_html` — the root `.htaccess` forwards everything to `public/` and blocks `config/`, `storage/`, `install/` and `database/`.

**Nginx:**

```nginx
server {
    listen 443 ssl http2;
    server_name cssd.caresoft.co.in *.cssd.caresoft.co.in;
    root /var/www/caresterile/public;
    index index.php;
    client_max_body_size 25m;                 # SOP PDFs, machine printouts, CSV imports
    location / { try_files $uri /index.php?$query_string; }
    location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }
    location ~ /\. { deny all; }
}
```

### 4. Cron jobs

```cron
*/5 * * * * php /var/www/caresterile/install/worker.php >> /var/www/caresterile/storage/logs/worker.log 2>&1
15 2 * * *  php /var/www/caresterile/install/backup.php >> /var/www/caresterile/storage/logs/backup.log 2>&1
```

The worker sends webhooks, retries failures and raises the next day's OT indents. The backup job dumps the control database and every client database (plus each client's uploaded files) to `storage/backups/<CODE>/`, keeping 14 days (the newest 3 are always kept).

**Copy backups off the server.** A backup on the same machine does not survive losing the machine. Sync `storage/backups/` nightly to another region or office storage (for example with `rclone sync` to an S3 bucket, run after the backup job).

### 5. Email deliverability

Sign-in codes must arrive in seconds. For the sending domain set up **SPF**, **DKIM** and a **DMARC** record, and use a dedicated sending address (e.g. `cssd@caresoft.co.in`). Send a test: sign in to `/admin` — the code should arrive within a minute.

### 6. Monitoring

- **Level 1 → System health** shows server, configuration, cron heartbeats and every client database (schema version and last backup).
- Point an uptime monitor at `https://…/health` — it returns `200 {"ok":true}` or `503`, with no internal details.
- Logs: `storage/logs/` — `app-error.log`, `db-error.log`, `tenant-db.log`, `mail-error.log`, `api-error.log`, `integration-error.log`, `webhook-error.log`, plus `worker.log` and `backup.log` from cron.

### 7. Upgrades

1. Back up: `php install/backup.php`
2. Replace the code (keep `config/config.php` and `storage/`)
3. `php install/migrate.php` — applies new database changes to every client (clients also upgrade automatically at their next sign-in)
4. `php install/check.php`

### 8. Restore

```bash
php install/restore.php --code=SHIVA --file=storage/backups/SHIVA/SHIVA-20261112-021500.sql.gz --yes [--files]
```

A safety backup of the current data is taken first. `--files` also restores uploaded files from the matching `-files.zip`. Level 1 can also make and download a backup of any client from the client page.

---

## Part B — go-live for a client hospital

### 1. Create the client (Caresoft Level 1)

Client hospitals → Add: client code, plan, features (multi-site, instrument tracking, RFID, machine data, chargeback), licence date, hospital admin's name and email. The client gets its own database and the admin receives a temporary password.

### 2. Load masters (hospital admin)

**Go-live & import** in the hospital menu:

1. Download each template, fill it in Excel, save as **CSV UTF-8**.
2. Upload in this order: departments → instruments → sets (with the number of physical trays) → set contents → sterilizers → washers → vendors → consumables → surgeons → procedures → preference cards → users.
3. Each upload is checked first; nothing is saved while any line has an error. Re-uploading a corrected file updates rows (matched on code or name; blank cells keep current values).
4. New users get temporary passwords — download the list once, or they receive it by email.

### 3. Confirm clinical settings with infection control

- Pack types and shelf life (time-based or event-related)
- Cycle types against each machine's instructions for use
- Safety rules in Settings: hold implant loads for BI, block steam sterilizers until Bowie-Dick passes, double sign-off for critical sets
- Store temperature / humidity limits and KPI targets

### 4. Hardware

- Barcode scanners (USB keyboard-wedge) at receiving, packing, sterilizer, store and issue
- Label printer for pack labels and tray tags (50 × 38 mm default)
- A TV or monitor in the CSSD for the wall board (Settings → CSSD wall board link)
- Optional: RFID readers, sterilizer data connection

### 5. Dry run (1–2 days)

Take a few test sets through the full cycle — receive, clean, pack, sterilize, release, issue, use on a test patient, return — and run a mock recall on one load. The **Go-live checklist** turns green as each item is done.

### 6. Go-live day

- Tag every tray (set page → Print set tags) and run existing sterile stock through the system so every pack in the store has a label and a load record
- Paper registers stop from a fixed time; keep them for the overlap day only
- Supervisor checks the wall board and indents at each shift change
- Caresoft support login (audited) is available for the first week

### 7. After one week

Review KPIs with the CSSD in-charge, print the first set of registers for the quality team, and confirm nightly backups appear on Level 1 → System health.
