Fix placeholder tokens: DISCHARGE_SUMMARY, DOCTOR_NAMES, DEPARTMENT
- Add 'Discharge Summary' section to buildAutoDischargeContent with department, doctors, and dates so {{DISCHARGE_SUMMARY}} token extracts properly
- Improve getDischargeDepartmentName to support dept_id, department_id fields and check both hc_department and ipd_department tables
- Improve getDischargeDoctorNames to fallback to doctor_id, doc_id, consultant_id if doc_list is empty
- Update DISCHARGE_TEMPLATE_TOKENS.md to clarify what {{DISCHARGE_SUMMARY}} contains
- Clear cached content for IPD 1 to regenerate with new logic
Fixes issue where {{DISCHARGE_SUMMARY}}, {{DOCTOR_NAMES}}, {{DEPARTMENT}} tokens were not working (replaced with empty values)
This commit is contained in:
parent
1da16a54d6
commit
16348d12db
|
|
@ -67,7 +67,7 @@
|
|||
### 4.2 Section Placeholders for Custom Layout/Order
|
||||
|
||||
```
|
||||
{{DISCHARGE_SUMMARY}} - Discharge summary section
|
||||
{{DISCHARGE_SUMMARY}} - High-level summary (department, treating doctors, dates)
|
||||
{{FINAL_DIAGNOSIS}} - Final diagnosis at discharge
|
||||
{{SURGERY}} - Surgical procedures performed
|
||||
{{PROCEDURE}} - Medical procedures
|
||||
|
|
@ -86,6 +86,12 @@
|
|||
{{SIGNATURE_BLOCK}} - Signature block for consultant
|
||||
```
|
||||
|
||||
**Note:** `{{DISCHARGE_SUMMARY}}` section now includes:
|
||||
- Department name (from `ipd_master.dept_id` or `department_id`)
|
||||
- Treating doctor(s) with specializations (from `ipd_master.doc_list`)
|
||||
- Date of admission
|
||||
- Date of discharge
|
||||
|
||||
### 4.3 Pre-Built Patient Table
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -943,9 +943,16 @@ class Ipd_discharge extends BaseController
|
|||
return '';
|
||||
}
|
||||
|
||||
// Try doc_list field (comma-separated IDs)
|
||||
$docList = trim((string) ($ipd->doc_list ?? ''));
|
||||
if ($docList === '' || $docList === '0') {
|
||||
return '';
|
||||
// Fallback: try single doctor_id or doc_id field
|
||||
$singleDocId = (int) ($ipd->doctor_id ?? $ipd->doc_id ?? $ipd->consultant_id ?? 0);
|
||||
if ($singleDocId > 0) {
|
||||
$docList = (string) $singleDocId;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->db->tableExists('doctor_master')) {
|
||||
|
|
@ -976,6 +983,10 @@ class Ipd_discharge extends BaseController
|
|||
$name = trim((string) ($doc->p_fname ?? ''));
|
||||
$spec = trim((string) ($doc->SpecName ?? ''));
|
||||
|
||||
if ($name === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fullName = ($title !== '' ? $title . ' ' : 'Dr. ') . $name;
|
||||
if ($spec !== '') {
|
||||
$fullName .= ' [' . $spec . ']';
|
||||
|
|
@ -1357,7 +1368,14 @@ class Ipd_discharge extends BaseController
|
|||
|
||||
private function getDischargeDepartmentName(?object $ipd): string
|
||||
{
|
||||
$deptId = (int) ($ipd->dept_id ?? 0);
|
||||
if (! $ipd) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Try dept_id first (common field name)
|
||||
$deptId = (int) ($ipd->dept_id ?? $ipd->department_id ?? 0);
|
||||
|
||||
// Try hc_department table first
|
||||
if ($deptId > 0 && $this->tableHasColumns('hc_department', ['id', 'vName'])) {
|
||||
$row = $this->db->table('hc_department')
|
||||
->select('vName')
|
||||
|
|
@ -1370,6 +1388,25 @@ class Ipd_discharge extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
// Try ipd_department table as fallback
|
||||
if ($deptId > 0 && $this->tableHasColumns('ipd_department', ['id', 'department_name'])) {
|
||||
$row = $this->db->table('ipd_department')
|
||||
->select('department_name')
|
||||
->where('id', $deptId)
|
||||
->get(1)
|
||||
->getRowArray();
|
||||
$name = trim((string) ($row['department_name'] ?? ''));
|
||||
if ($name !== '') {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try direct department field if it exists as a string
|
||||
$directDept = trim((string) ($ipd->department ?? $ipd->department_name ?? ''));
|
||||
if ($directDept !== '') {
|
||||
return $directDept;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
@ -1531,6 +1568,31 @@ class Ipd_discharge extends BaseController
|
|||
// It is available as {{PATIENT_INFO_TABLE}} token for templates to use if needed.
|
||||
// This matches CI3 behavior where template controlled the patient info display.
|
||||
|
||||
// Build Discharge Summary section (high-level overview)
|
||||
$dischargeSummaryParts = [];
|
||||
$admitDate = trim((string) ($ipd->admit_date ?? ''));
|
||||
$dischargeDate = trim((string) ($ipd->discharge_date ?? ''));
|
||||
$deptName = $this->getDischargeDepartmentName($ipd);
|
||||
$doctorNames = $this->getDischargeDoctorNames($ipd);
|
||||
|
||||
if ($deptName !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Department:</b> ' . esc($deptName);
|
||||
}
|
||||
if ($doctorNames !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Treating Doctor(s):</b> ' . esc($doctorNames);
|
||||
}
|
||||
if ($admitDate !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Date of Admission:</b> ' . esc($admitDate);
|
||||
}
|
||||
if ($dischargeDate !== '') {
|
||||
$dischargeSummaryParts[] = '<b>Date of Discharge:</b> ' . esc($dischargeDate);
|
||||
}
|
||||
|
||||
if (! empty($dischargeSummaryParts)) {
|
||||
$sections[] = '<h4 style="margin:16px 0 8px 0;">Discharge Summary</h4>'
|
||||
. '<div>' . implode('<br>', $dischargeSummaryParts) . '</div>';
|
||||
}
|
||||
|
||||
$complaints = $this->byIpdRows('ipd_discharge_complaint', ['comp_report', 'comp_remark'], 'id ASC', $ipdId);
|
||||
$complaintRemark = $this->firstRowByIpd('ipd_discharge_complaint_remark', $ipdId);
|
||||
$complaintRemarkText = $this->normalizeRichText((string) ($complaintRemark['comp_remark'] ?? ''));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user