CRITICAL FIX - User Requirement:
- If ipd_status = 0: Show 'Discharge Summary' only
- If ipd_status != 0: Show value from ipd_discharge_status.status_details
- Remove 'Date of Discharge' line completely
Problem:
- {{DISCHARGE_SUMMARY}} still showed 'Discharge Summary' header regardless of status
- 'Date of Discharge: YYYY-MM-DD' line was appearing
- Previous fix only worked on saved content via regex, not on auto-generated content
Root Cause:
- buildAutoDischargeContent() method had hardcoded 'Discharge Summary' header
- getDischargeStatusText() was querying database but header wasn't being used
- Date of Discharge was being added to dischargeSummaryParts array
Solution:
1. Updated buildAutoDischargeContent() method (line ~1670):
- Removed 'Date of Discharge' from dischargeSummaryParts array
- Added comment: 'NOTE: Date of Discharge removed per user request'
- Call getDischargeStatusText() to get dynamic header
- Use status-based header instead of hardcoded 'Discharge Summary'
- Now generates: <h4>status_details_value</h4> instead of <h4>Discharge Summary</h4>
2. Updated getDischargeStatusText() method (line ~1047):
- Added early return for ipd_status = 0: returns 'Discharge Summary'
- For ipd_status != 0: queries ipd_discharge_status table
- Returns status_details field (primary)
- Falls back to status_desc if status_details is empty
- Final fallback: 'Discharge Summary'
3. Updated buildAutoDischargeSummaryTable() method (line ~1517):
- Used for {{PATIENT_INFO_TABLE}} token
- Now uses getDischargeStatusText() for header
- Changes <h2>Discharge Summary</h2> to <h2>status_value</h2>
- Keeps patient info table structure unchanged
Status Mapping Logic:
- ipd_status = 0 → 'Discharge Summary' (special case, no DB lookup)
- ipd_status = 1 → Query DB → 'Discharge Summary' (from status_details)
- ipd_status = 2 → Query DB → 'Leave Against Medical Advice'
- ipd_status = 3 → Query DB → 'Refer To Higher Centre'
- ipd_status = 5 → Query DB → 'Dead Summary'
- ipd_status = 7 → Query DB → 'Discharge on Request'
Content Structure Before:
<h4>Discharge Summary</h4>
<div>
<b>Department:</b> General Surgery<br>
<b>Treating Doctor(s):</b> Dr. Name<br>
<b>Date of Admission:</b> 04-06-2026<br>
<b>Date of Discharge:</b> 07-06-2026
</div>
Content Structure After:
<h4>Leave Against Medical Advice</h4>
<div>
<b>Department:</b> General Surgery<br>
<b>Treating Doctor(s):</b> Dr. Name<br>
<b>Date of Admission:</b> 04-06-2026
</div>
Testing:
1. Set ipd_master.ipd_status = 0 → regenerate → should show 'Discharge Summary'
2. Set ipd_master.ipd_status = 1 → regenerate → should show 'Discharge Summary'
3. Set ipd_master.ipd_status = 2 → regenerate → should show 'Leave Against Medical Advice'
4. Set ipd_master.ipd_status = 5 → regenerate → should show 'Dead Summary'
5. 'Date of Discharge' line should NOT appear in any case
Files Modified:
- app/Controllers/Ipd_discharge.php:
- getDischargeStatusText() - Added ipd_status = 0 check
- buildAutoDischargeContent() - Removed Date of Discharge, use dynamic header
- buildAutoDischargeSummaryTable() - Use dynamic header
IMPORTANT: User must REGENERATE discharge summary after pulling code
- Click 'Regenerate' button on discharge preview page
- Or delete existing discharge content and reload form
- Old saved content will still have old header until regenerated