# Portfolio Feature - Installation & Verification Checklist

## Pre-Installation Requirements
- [ ] XAMPP running with MySQL
- [ ] logbook_ppds database exists
- [ ] config.php properly configured
- [ ] PHP version >= 7.4
- [ ] Modern web browser (Chrome, Firefox, Safari, Edge)

## Installation Steps

### 1. Database Setup
- [ ] Read `database/migration_portfolio.sql`
- [ ] Execute migration via phpMyAdmin or MySQL CLI
- [ ] Verify tables created: `portfolio`, `portfolio_counter`
- [ ] Verify trigger created: `portfolio_before_insert`

**Command to verify:**
```bash
mysql -h localhost -u root -p logbook_ppds -e "SHOW TABLES LIKE 'portfolio%';"
```

### 2. File Installation
- [ ] `php/portfolio.php` - API handler (11 KB)
- [ ] `js/portfolio.js` - Form logic (20 KB)
- [ ] `index.html` - Updated with portfolio form
- [ ] `js/app.js` - Updated with navigation handlers

### 3. Verify File Sizes (Approximate)
```
php/portfolio.php         ~11 KB
js/portfolio.js           ~20 KB
database/migration_portfolio.sql  ~2.5 KB
index.html updates        +5 KB
```

## Database Verification

### Check Tables
```sql
-- In MySQL, run:
DESCRIBE portfolio;
DESCRIBE portfolio_counter;
SHOW TRIGGERS;
```

### Expected Tables Structure
✅ `portfolio` table:
- 18 columns including id, user_id, divisi, semester, setting_type, nomor, etc.
- Indexes on user_id, divisi, semester

✅ `portfolio_counter` table:
- 5 columns: id, user_id, divisi, semester, setting_type, counter
- UNIQUE key on combination of user/divisi/semester/setting

✅ Trigger `portfolio_before_insert`:
- Auto-generates nomor before insert
- Updates portfolio_counter table

## Functionality Testing

### Test 1: Create Portfolio Entry
1. [ ] Login as trainee user
2. [ ] Navigate to **Portofolio > Kamar Operasi (any semester)**
3. [ ] Click **"Tambah Portofolio Baru"** button
4. [ ] Verify form modal opens
5. [ ] Verify **Nomor field** shows auto-generated number
6. [ ] Fill all required fields
7. [ ] Draw signature in trainee signature canvas
8. [ ] Click **"Simpan Portofolio"**
9. [ ] Verify success message
10. [ ] [ ] Verify entry appears in list view
11. [ ] [ ] Check database: `SELECT * FROM portfolio ORDER BY id DESC LIMIT 1;`

### Test 2: Edit Portfolio Entry
1. [ ] Click **"Edit"** button on portfolio entry
2. [ ] Verify form loads with existing data
3. [ ] Modify one field (e.g., diagnosis)
4. [ ] Click **"Simpan Portofolio"**
5. [ ] Verify update message
6. [ ] Confirm changes in list view
7. [ ] Check database update timestamp

### Test 3: Delete Portfolio Entry
1. [ ] Click **"Hapus"** button on portfolio entry
2. [ ] Confirm deletion dialog
3. [ ] Verify entry removed from list
4. [ ] Check database: entry should not exist

### Test 4: Submit for Verification
1. [ ] Create portfolio entry (Status: Draft)
2. [ ] Click **"Edit"** to re-open
3. [ ] Verify **"Ajukan untuk Verifikasi"** button shows
4. [ ] Click submission button
5. [ ] Confirm submission dialog
6. [ ] Verify status changes to "Menunggu Verifikasi"
7. [ ] Check database: status should be 'submitted'

### Test 5: Signature Capture
1. [ ] Open portfolio form
2. [ ] **Trainee Signature Canvas:**
   - [ ] Mouse drawing works
   - [ ] Touch drawing works (on mobile)
   - [ ] Clear button erases content
   - [ ] Signature saves to hidden field
3. [ ] **DPJP Signature Canvas:**
   - [ ] Visible only when logged in as dosen
   - [ ] Hidden for trainee users
   - [ ] Canvas functions same as trainee

### Test 6: Form Validation
1. [ ] Try submitting empty form
2. [ ] Verify error for missing trainee signature
3. [ ] Verify all required fields marked with *
4. [ ] Try invalid date
5. [ ] Verify proper error handling

### Test 7: Data Filtering
1. [ ] Create portfolios in at least 2 divisions
2. [ ] Create portfolios in at least 2 semesters
3. [ ] Create portfolios in at least 2 settings (OK, Poliklinik, Rawat Inap)
4. [ ] Navigate between different divisions/semesters
5. [ ] Verify list filters correctly
6. [ ] Verify counter increments correctly within each context

### Test 8: Navigation
1. [ ] Use menu to navigate to portfolio sections
2. [ ] Verify hash URL changes correctly
3. [ ] Verify form initializes with correct context
4. [ ] Test on multiple divisions (fertilitas, feto-maternal, etc.)

### Test 9: Responsive Design
1. [ ] Test on desktop (1920x1080)
2. [ ] Test on tablet (768x1024)
3. [ ] Test on mobile (375x667)
4. [ ] Verify form wraps correctly
5. [ ] Verify modal readable on all sizes
6. [ ] Test signature drawing on touch device

### Test 10: Multi-User Scenario
1. [ ] Create portfolio as trainee A
2. [ ] Login as trainee B
3. [ ] Verify B cannot see A's portfolios
4. [ ] Verify B cannot edit A's entries
5. [ ] Verify B's counter starts at 1 (not A's next number)

## API Testing

### Test Endpoints with cURL or Postman

#### 1. Get Next Nomor
```bash
curl "http://localhost/logbook-ppds/php/portfolio.php?action=get_next_nomor&divisi=fertilitas&semester=1&setting_type=OK"
```
Expected: `{"success":true,"nomor":1}`

#### 2. Create Portfolio
```bash
curl -X POST http://localhost/logbook-ppds/php/portfolio.php \
  -H "Content-Type: application/json" \
  -d '{
    "action": "create",
    "divisi": "fertilitas",
    "semester": 1,
    "setting_type": "OK",
    ...
  }'
```

#### 3. List Portfolios
```bash
curl "http://localhost/logbook-ppds/php/portfolio.php?action=list&divisi=fertilitas&semester=1&setting_type=OK"
```

#### 4. Verify Requires Session
```bash
curl -b "PHPSESSID=test" \
  "http://localhost/logbook-ppds/php/portfolio.php?action=list"
```
Should return 401 error without valid session

## Security Verification

- [ ] Cannot access without valid session
- [ ] Cannot edit other user's portfolios
- [ ] DPJP signature requires dosen role
- [ ] Input is properly sanitized
- [ ] Timestamps recorded correctly
- [ ] User attribution works
- [ ] Delete operations cascade properly

## Performance Testing

### Load Testing
1. [ ] Create 100 portfolio entries
2. [ ] List page loads within 1 second
3. [ ] Form opens within 500ms
4. [ ] Signature canvas smooth at 60 FPS
5. [ ] No memory leaks after extended use

### Database Performance
```sql
-- Check query performance
EXPLAIN SELECT * FROM portfolio WHERE user_id = 1 AND semester = 1;
EXPLAIN SELECT * FROM portfolio WHERE setting_type = 'OK';
EXPLAIN SELECT * FROM portfolio WHERE tanggal = '2026-02-25';
```

All should use index and return with low cost

## Browser Compatibility

### Desktop Browsers
- [ ] Chrome latest
- [ ] Firefox latest
- [ ] Safari latest
- [ ] Edge latest

### Mobile Browsers
- [ ] Chrome Mobile
- [ ] Safari iOS
- [ ] Firefox Mobile

### Testing Checklist for Each Browser
- [ ] Form displays correctly
- [ ] Signature canvas works
- [ ] Touch events captured
- [ ] Modal behaves properly
- [ ] No console errors
- [ ] No warnings

## Documentation Verification

- [ ] `PORTFOLIO_GUIDE.md` exists and is readable
- [ ] `PORTFOLIO_SETUP.md` exists and is readable
- [ ] `js/PORTFOLIO_JS_GUIDE.md` exists with code documentation
- [ ] `IMPLEMENTATION_SUMMARY.md` exists with overview
- [ ] All documentation files have good formatting

## Final Checklist

### Before Going Live
- [ ] All database migrations completed
- [ ] All files installed in correct locations
- [ ] All functionality tests passed
- [ ] All API endpoints tested
- [ ] Security measures verified
- [ ] Performance acceptable
- [ ] Documentation complete
- [ ] User training materials prepared

### Post-Deployment
- [ ] Monitor database size
- [ ] Check server logs for errors
- [ ] Monitor API response times
- [ ] Gather user feedback
- [ ] Create backup procedures
- [ ] Document any issues encountered
- [ ] Plan for future enhancements

## Troubleshooting Quick Links

| Issue | Solution | Document |
|-------|----------|----------|
| Database not found | Run migration | PORTFOLIO_SETUP.md |
| API returns 401 | Check session | PORTFOLIO_GUIDE.md |
| Signature not saving | Check canvas context | PORTFOLIO_JS_GUIDE.md |
| Trigger not working | Verify trigger syntax | migration_portfolio.sql |
| DPJP section visible | Check user role | PORTFOLIO_GUIDE.md |

## Contact & Support

- **Database Issues**: DBA / Database Administrator
- **API Issues**: Backend Developer (PHP)
- **Frontend Issues**: Frontend Developer (JavaScript)
- **Installation Issues**: System Administrator
- **Feature Requests**: Project Manager

---

**Checklist Version**: 1.0  
**Last Updated**: February 25, 2026  
**Status**: Ready for Testing
