Fix discharge status header in auto-generated content and remove Date of Discharge
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
This commit is contained in:
parent
09570e0793
commit
3c430fa386
|
|
@ -1054,6 +1054,11 @@ class Ipd_discharge extends BaseController
|
|||
|
||||
$ipdStatus = (int) ($ipd->ipd_status ?? 0);
|
||||
|
||||
// If status is 0 (Status Pending), show "Discharge Summary" only
|
||||
if ($ipdStatus === 0) {
|
||||
return 'Discharge Summary';
|
||||
}
|
||||
|
||||
// Check if ipd_discharge_status table exists
|
||||
if (! $this->db->tableExists('ipd_discharge_status')) {
|
||||
return 'Discharge Summary';
|
||||
|
|
@ -1069,9 +1074,10 @@ class Ipd_discharge extends BaseController
|
|||
return 'Discharge Summary';
|
||||
}
|
||||
|
||||
// Prefer status_details if available, otherwise use status_desc
|
||||
// Use status_details field (e.g., "Discharge Summary", "Leave Against Medical Advice", "Dead Summary")
|
||||
$statusText = trim((string) ($row['status_details'] ?? ''));
|
||||
if ($statusText === '') {
|
||||
// Fallback to status_desc if status_details is empty
|
||||
$statusText = trim((string) ($row['status_desc'] ?? ''));
|
||||
}
|
||||
|
||||
|
|
@ -1532,7 +1538,10 @@ class Ipd_discharge extends BaseController
|
|||
$admitDate = $this->safeDate((string) ($ipd->str_register_date ?? $ipd->register_date ?? ''));
|
||||
$dischargeDate = $this->safeDate((string) ($ipd->str_discharge_date ?? $ipd->discharge_date ?? ''));
|
||||
|
||||
return '<h2 style="text-align:center;margin:1px;padding:0px;">Discharge Summary</h2>'
|
||||
// Get discharge status header
|
||||
$statusHeader = $this->getDischargeStatusText($ipd);
|
||||
|
||||
return '<h2 style="text-align:center;margin:1px;padding:0px;">' . esc($statusHeader) . '</h2>'
|
||||
. '<hr style="margin:1px;padding:0px;" />'
|
||||
. '<table width="100%" cellpadding="0" cellspacing="0">'
|
||||
. '<tr><td width="150px"><b>Name</b></td><td width="250px">' . esc($patientName) . '</td><td width="150px"><b>UHID</b></td><td width="250px">' . esc($patientCode) . '</td></tr>'
|
||||
|
|
@ -1683,12 +1692,13 @@ class Ipd_discharge extends BaseController
|
|||
if ($admitDate !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Date of Admission:</b> ' . esc($admitDate);
|
||||
}
|
||||
if ($dischargeDate !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Date of Discharge:</b> ' . esc($dischargeDate);
|
||||
}
|
||||
// NOTE: Date of Discharge removed per user request
|
||||
|
||||
if (! empty($dischargeSummaryParts)) {
|
||||
$sections[] = '<h4 style="margin:16px 0 8px 0;">Discharge Summary</h4>'
|
||||
// Get discharge status text based on ipd_status
|
||||
$dischargeStatusHeader = $this->getDischargeStatusText($ipd);
|
||||
|
||||
$sections[] = '<h4 style="margin:16px 0 8px 0;">' . esc($dischargeStatusHeader) . '</h4>'
|
||||
. '<div>' . implode('<br>', $dischargeSummaryParts) . '</div>';
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user