# TGICS (The Great Indian Cough Study) Doctor magic-link patient questionnaire for LifeMankind / Rapport. - Frontend: `https://tgics.cttr.in/{user_id}/{contact_id}` - Backend: Hapi + MySQL - Rapport partition: `rapport-lifemankind` ## Structure ``` tgics/ backend/ # Node.js Hapi API frontend/ # Vite + React ``` ## Backend ```bash cd backend cp .env.example .env # set DB_* and RAPPORT_ACCESS_TOKEN npm install npm run dev ``` API defaults to `http://localhost:3050`. | Method | Path | Purpose | |--------|------|---------| | GET | `/health` | Health | | GET | `/api/doctors/{userId}/{contactId}` | Resolve enrolled doctor | | POST | `/api/surveys` | Save patient survey | | GET | `/api/surveys/counts?contact_ids=a,b` | Batch counts for Rapport | | GET | `/api/surveys/count?contact_id=` | Single count | | POST | `/api/auth/login` | Dashboard login | | GET | `/api/auth/me` | Current user (Bearer token) | | GET | `/api/dashboard/stats` | Survey stats (auth) | | GET | `/api/dashboard/surveys` | Recent surveys (auth) | ### Dashboard users On startup the API ensures a `users` table and seeds the first admin if missing: - Email: `ravi@stratawiz.com` - Password: `qwerty` Login UI: `/login` → `/dashboard` ## Frontend ```bash cd frontend cp .env.example .env npm install npm run dev ``` Set `VITE_API_BASE=http://localhost:3050`. ## Deploy (EC2) ```bash cd /Applications/MAMP/htdocs/shabby/tgics ./deploy.sh ``` Defaults: | Setting | Value | |---------|--------| | SSH | `ssh -i ~/Documents/Keys/VirtualEngage.pem ubuntu@15.207.15.52` | | Path | `/var/www/tgics` | | Site | `https://tgics.cttr.in` | | PM2 | `tgics-api` on `127.0.0.1:3050` | The script builds the frontend locally (same-origin `/api`), rsyncs to the server, installs nginx (`deploy/nginx-tgics.conf`), and reloads PM2. Remote `backend/.env` is never overwritten. First-time after deploy: 1. DNS: `tgics.cttr.in` → `15.207.15.52` 2. Edit `/var/www/tgics/backend/.env` (`DB_*`, `RAPPORT_ACCESS_TOKEN`, `JWT_SECRET`) 3. `pm2 restart tgics-api --update-env` 4. `sudo certbot --nginx -d tgics.cttr.in` ## Rapport Laravel Set `TGICS_API_BASE` in Laravel `.env` (e.g. `https://tgics.cttr.in` or `http://localhost:3050`). The enrolment form uses `App\Helpers\TgicsHelper` for survey counts.