devsofttech_hms_ci4/app/Controllers/Setting
DevSoftTech Server 328de6279d Fix: Disable auto-generation of discharge templates + add manual creation button
ISSUE: Templates auto-regenerate when deleted
User deletes template ID 3, page reload creates template ID 4 automatically

ROOT CAUSE: ensureDefaultDischargeTemplateSeeded() called on EVERY page load
- discharge_templates() method called it on every view
- getDischargeTemplateRows() called it on every discharge PDF generation
- When count=0, it auto-inserted default templates
- Made it impossible to delete all templates

SOLUTION: Changed to manual opt-in template creation

1. Removed auto-seeding calls:
   - Setting/Template::discharge_templates() - removed ensureDefaultDischargeTemplateSeeded()
   - Ipd_discharge::getDischargeTemplateRows() - removed ensureDefaultDischargeTemplateSeeded()
   - Both now only call ensureDischargeTemplateTable() (structure check only)

2. Added manual template creation:
   - New 'Create Default Templates' button shown when table is empty
   - New endpoint: discharge_templates_seed() - creates defaults on demand
   - Route: POST /setting/template/discharge_templates_seed
   - Button confirms before creating, shows success message, reloads page

3. Preserved seeding functions:
   - ensureDefaultDischargeTemplateSeeded() kept but not auto-called
   - Can be manually triggered via new button
   - Creates 'Default Discharge Template' and 'NABH Compliant Discharge Summary'

BEHAVIOR NOW:
- Users can delete ALL templates - they stay deleted
- Empty table shows helpful message with creation button
- Templates only created when user explicitly requests them
- No more surprise template regeneration

TESTING:
- Delete all templates
- Page reloads showing empty table with button
- Click 'Create Default Templates'
- 2 templates created (ID 1 and 2)
2026-06-07 11:38:18 +05:30
..
AbdmGatewaySettings.php feat(abdm): proper FHIR bundles for lab reports and IPD discharge 2026-05-23 04:41:59 +05:30
AbdmReportDoctorSettings.php Align ABDM bridge workflow APIs and add report doctor mapping 2026-06-01 07:02:34 +05:30
Admin.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
AiSettings.php feat(abdm): proper FHIR bundles for lab reports and IPD discharge 2026-05-23 04:41:59 +05:30
Bank.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
BedManagement.php Fix BedManagement controller header to restore bed-status route 2026-04-02 06:27:52 +05:30
Charges.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
Doctor.php Make HealthPlix Doctor Identifier field optional in Doctor Master 2026-04-28 08:22:00 +05:30
HealthplixSettings.php Reflect actual HealthPlix fetch secret save state 2026-04-28 07:40:22 +05:30
HospitalProfile.php feat: add configurable sidebar auto-hide in hospital settings 2026-04-27 14:32:31 +05:30
HospitalStock.php feat(stock): add modular hospital stock management with dashboard, masters, indents, purchase and reports 2026-04-02 10:28:38 +05:30
Insurance.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
MedicalBank.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
NursingBedsideItems.php Add nursing scan-to-structured workflow and discharge UI polish 2026-03-09 00:12:04 +05:30
Reffer.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
Template.php Fix: Disable auto-generation of discharge templates + add manual creation button 2026-06-07 11:38:18 +05:30
UserManagement.php Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30