Modernized PHP/MySQL hospital management demo with secure uploads, prepared statements, reports, and basic authentication.
- Patients: add and manage patient records
- Doctors: manage doctors (UI scaffold present)
- HR: upload contract PDFs, store metadata, and track staff
- Lab: tests catalog, inventory usage, issued tests, and follow-ups
- Finance: fees configuration and accounts (in/out) entries
- Reports: overview dashboard, accounts report, lab usage report, printable fees report
- File uploads: hardened PDF-only uploads with random filenames and secure download endpoint
- Security: centralized DB config via env, prepared statements across pages, CSRF-ready structure
- Auth: users table with password hashing, session login/logout, admin seeding, admin-only Users page
- Requirements
- PHP 8.x with mysqli, fileinfo extensions enabled
- MySQL 5.7+ / MariaDB 10+
- Database
- Create a database (default:
moala_hospital). - Import schema/data from
database/(.sql files) if needed.
- Configuration (Environment Variables)
Create a
.envfile in the project root (same folder as this README) with:
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=moala_hospital
DB_USER=root
DB_PASS=your_password
# Optional (macOS/Homebrew socket path example):
# DB_SOCKET=/tmp/mysql.sock
Notes:
- If
.envis missing, the app falls back toDB_HOST=127.0.0.1,DB_NAME=moala_hospital,DB_USER=root,DB_PASS=oracleoracle(change this in production). - You can override any value via real environment variables as well.
- Run locally
- Serve the
code/directory with PHP or a local web server (Apache/Nginx). - Example (PHP dev server):
cd codephp -S 127.0.0.1:8080
- Open
http://127.0.0.1:8080/index.php
- Login
- A default admin user is auto-created on first visit to the sign-in page:
- Username:
admin - Password:
admin
- Username:
- Change this immediately after logging in.
code/basefiles/– layout, connection, auth helpers, componentscode/*.php– pages (patients, hr, lab, reports, etc.)code/uploads/– uploaded PDFs (gitignored)database/– SQL dumps and migration helper
- Do NOT commit
.envwith real credentials. - Change the fallback DB password in
code/basefiles/connection.phpor use.env. - Uploaded files are stored under
code/uploads/and served viacode/filedownload.php?id=.... - Most raw SQL has been migrated to prepared statements; new code should follow the same.
- MySQL socket on macOS: set
DB_HOST=127.0.0.1or specifyDB_SOCKET=/tmp/mysql.sockin.env. - Headers already sent: ensure redirects occur before any HTML output (login flow already fixed).
- Role-based permissions per page/action
- CSRF tokens on all forms
- Pagination and search on long lists
- Unit/integration tests
This project is provided as-is for educational/demo purposes.