From 3c430fa386841709f101010c8031e07e71ebc980 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sun, 7 Jun 2026 07:42:38 +0530 Subject: [PATCH] Fix discharge status header in auto-generated content and remove Date of Discharge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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:

status_details_value

instead of

Discharge Summary

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

Discharge Summary

to

status_value

- 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:

Discharge Summary

Department: General Surgery
Treating Doctor(s): Dr. Name
Date of Admission: 04-06-2026
Date of Discharge: 07-06-2026
Content Structure After:

Leave Against Medical Advice

Department: General Surgery
Treating Doctor(s): Dr. Name
Date of Admission: 04-06-2026
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 --- app/Controllers/Ipd_discharge.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 213ffeb..04ee3e8 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -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 '

Discharge Summary

' + // Get discharge status header + $statusHeader = $this->getDischargeStatusText($ipd); + + return '

' . esc($statusHeader) . '

' . '
' . '' . '' @@ -1683,12 +1692,13 @@ class Ipd_discharge extends BaseController if ($admitDate !== '') { $dischargeSummaryParts[] = 'Date of Admission: ' . esc($admitDate); } - if ($dischargeDate !== '') { - $dischargeSummaryParts[] = 'Date of Discharge: ' . esc($dischargeDate); - } + // NOTE: Date of Discharge removed per user request if (! empty($dischargeSummaryParts)) { - $sections[] = '

Discharge Summary

' + // Get discharge status text based on ipd_status + $dischargeStatusHeader = $this->getDischargeStatusText($ipd); + + $sections[] = '

' . esc($dischargeStatusHeader) . '

' . '
' . implode('
', $dischargeSummaryParts) . '
'; }
Name' . esc($patientName) . 'UHID' . esc($patientCode) . '