diff --git a/DISCHARGE_PLACEHOLDERS_REFERENCE.md b/DISCHARGE_PLACEHOLDERS_REFERENCE.md new file mode 100644 index 0000000..3256bd5 --- /dev/null +++ b/DISCHARGE_PLACEHOLDERS_REFERENCE.md @@ -0,0 +1,255 @@ +# Discharge Summary Template Placeholders Reference + +## Overview +This document explains all available placeholders for discharge summary templates. Use these placeholders in your template HTML to insert dynamic content. + +--- + +## šŸ”“ MAIN DISCHARGE SUMMARY + +### `{{CLINICAL_SUMMARY}}` ⭐ RECOMMENDED +**Content:** The main discharge summary text from the HTML editor (instruction_remark field) +**Source:** "Discharge Summary" section in the discharge form +**Use this for:** The primary clinical narrative written by doctors + +**Example:** +```html +

Discharge Summary

+{{CLINICAL_SUMMARY}} +``` + +### `{{DISCHARGE_SUMMARY}}` (Legacy) +**Content:** Same as `{{CLINICAL_SUMMARY}}` +**Note:** Kept for backward compatibility. Use `{{CLINICAL_SUMMARY}}` for clarity. + +--- + +## šŸ”µ CLINICAL SECTIONS + +### `{{FINAL_DIAGNOSIS}}` +**Content:** Final diagnosis section +**Source:** "Final Diagnosis" section + +### `{{SURGERY}}` +**Content:** Surgery details section +**Source:** "Surgery" section + +### `{{PROCEDURE}}` +**Content:** Procedure details section +**Source:** "Procedure" section + +### `{{PRESENTING_COMPLAINTS}}` +**Content:** Presenting complaints and reason for admission +**Source:** "Presenting Complaints and Reason for Admission" section + +### `{{PERSONAL_HISTORY}}` +**Content:** Patient personal history +**Source:** "Personal History" section + +### `{{GENERAL_EXAM_ADMISSION}}` +**Content:** General examination findings at admission +**Source:** "General Examination on Admission" section + +### `{{CLINICAL_INVESTIGATION_REPORTS}}` +**Content:** Clinical investigation and lab test reports +**Source:** "Clinical Investigation Reports" section + +### `{{COURSE_IN_HOSPITAL}}` +**Content:** Course/progress during hospitalization +**Source:** "Course in the hospital" section + +### `{{EXAMINATION_ON_DISCHARGE}}` +**Content:** Examination findings at discharge +**Source:** "Examination on Discharge" section + +### `{{PAIN_MEASUREMENT_SCALE}}` +**Content:** Pain assessment scale details +**Source:** "Pain Measurement Scale" section + +### `{{DRUG_ALLERGY_ADR}}` +**Content:** Drug allergies and adverse drug reactions +**Source:** "Drug Allergy / ADR" section + +### `{{CO_MORBIDITIES}}` +**Content:** Co-existing medical conditions +**Source:** "Co-Morbidities" section + +--- + +## 🟢 DISCHARGE INSTRUCTIONS & ADVICE + +### `{{DISCHARGE_MEDICATIONS}}` +**Content:** Medications prescribed at discharge +**Source:** "Discharge Medications" section + +### `{{DIETARY_ADVICE}}` +**Content:** Dietary recommendations +**Source:** "Dietary Advice" section + +### `{{DISCHARGE_INSTRUCTIONS}}` +**Content:** General discharge advice and instructions +**Source:** "Discharge Advice/Instructions/Summary" section + +### `{{OTHER_ADVICE}}` +**Content:** Other miscellaneous advice +**Source:** "Other Advice:" section + +### `{{FOLLOW_UP_INSTRUCTIONS}}` +**Content:** Follow-up appointment instructions +**Source:** "Discharge Summary:" subsection (note the colon) + +--- + +## 🟔 OTHER SECTIONS + +### `{{SIGNATURE_BLOCK}}` +**Content:** Signature table with consultant details +**Source:** "Signature of Consultant" section + +--- + +## šŸ“‹ PATIENT INFO PLACEHOLDERS + +Use `{{PATIENT_INFO_TABLE}}` for the complete patient information header table. + +--- + +## šŸ’” RECOMMENDED TEMPLATE STRUCTURE + +```html + +{{PATIENT_INFO_TABLE}} + + +

Clinical Summary

+{{CLINICAL_SUMMARY}} + + +{{PRESENTING_COMPLAINTS}} +{{PAIN_MEASUREMENT_SCALE}} +{{DRUG_ALLERGY_ADR}} +{{CO_MORBIDITIES}} +{{GENERAL_EXAM_ADMISSION}} +{{PERSONAL_HISTORY}} +{{CLINICAL_INVESTIGATION_REPORTS}} + + +{{FINAL_DIAGNOSIS}} +{{SURGERY}} +{{PROCEDURE}} +{{COURSE_IN_HOSPITAL}} +{{EXAMINATION_ON_DISCHARGE}} + + +{{DISCHARGE_MEDICATIONS}} +{{DIETARY_ADVICE}} +{{OTHER_ADVICE}} +{{DISCHARGE_INSTRUCTIONS}} +{{FOLLOW_UP_INSTRUCTIONS}} + + +{{SIGNATURE_BLOCK}} +``` + +--- + +## āš ļø IMPORTANT NOTES + +1. **Empty Sections:** If a section has no data, the placeholder will be replaced with empty string (won't show in PDF) + +2. **HTML Formatting:** Content from HTML editors (like `{{CLINICAL_SUMMARY}}`) preserves formatting (bold, lists, etc.) + +3. **Placeholder Case:** Placeholders are case-sensitive. Use UPPERCASE with underscores. + +4. **Missing Placeholders:** If you forget a placeholder, that content simply won't appear in the PDF + +5. **Duplicate Placeholders:** You can use the same placeholder multiple times in a template if needed + +--- + +## šŸ”„ MIGRATION GUIDE + +### Old Placeholder → New Placeholder + +| Old (Confusing) | New (Clear) | Notes | +|----------------|-------------|-------| +| `{{DISCHARGE_SUMMARY}}` | `{{CLINICAL_SUMMARY}}` | Both work, but use `{{CLINICAL_SUMMARY}}` for clarity | +| `{{INSTRUCTION_REMARK}}` | `{{FOLLOW_UP_INSTRUCTIONS}}` | Old placeholder removed | +| `{{DISCHARGE_ADVICE}}` | `{{FOLLOW_UP_INSTRUCTIONS}}` | More descriptive name | + +### What Changed? + +**Before (Confusing):** +- `{{DISCHARGE_SUMMARY}}` - Main clinical summary +- `{{DISCHARGE_ADVICE}}` - Follow-up instructions +- `{{INSTRUCTION_REMARK}}` - Same as DISCHARGE_ADVICE + +**After (Clear):** +- `{{CLINICAL_SUMMARY}}` - Main clinical summary ⭐ Use this! +- `{{FOLLOW_UP_INSTRUCTIONS}}` - Follow-up instructions +- `{{DISCHARGE_INSTRUCTIONS}}` - General discharge advice + +--- + +## šŸ“ EXAMPLE TEMPLATES + +### Minimal Template +```html +{{PATIENT_INFO_TABLE}} +{{CLINICAL_SUMMARY}} +{{FINAL_DIAGNOSIS}} +{{DISCHARGE_MEDICATIONS}} +{{SIGNATURE_BLOCK}} +``` + +### Comprehensive Template +```html +{{PATIENT_INFO_TABLE}} + +

Clinical Summary

+{{CLINICAL_SUMMARY}} + +{{PRESENTING_COMPLAINTS}} +{{GENERAL_EXAM_ADMISSION}} +{{CLINICAL_INVESTIGATION_REPORTS}} +{{FINAL_DIAGNOSIS}} +{{SURGERY}} +{{PROCEDURE}} +{{COURSE_IN_HOSPITAL}} +{{EXAMINATION_ON_DISCHARGE}} + +

Discharge Instructions

+{{DISCHARGE_MEDICATIONS}} +{{DIETARY_ADVICE}} +{{OTHER_ADVICE}} +{{FOLLOW_UP_INSTRUCTIONS}} + +{{SIGNATURE_BLOCK}} +``` + +--- + +## šŸ†˜ TROUBLESHOOTING + +**Problem:** Discharge summary text not appearing in PDF +**Solution:** Make sure you have `{{CLINICAL_SUMMARY}}` or `{{DISCHARGE_SUMMARY}}` in your template + +**Problem:** Section appears empty in PDF +**Solution:** Check if that section was filled in the discharge form. Empty sections = empty output. + +**Problem:** Formatting looks wrong +**Solution:** Check your template HTML structure. Each placeholder inserts its content with existing HTML tags. + +--- + +## šŸ“ž SUPPORT + +For template editing issues, check: +1. Template management page (ensure placeholders are spelled correctly) +2. HTML debug mode: `/Ipd_discharge/show_discharge/{ipdId}/1?html=1&tpl=3` +3. Content debug: `/Ipd_discharge/debug_discharge_html/{ipdId}` + +--- + +**Last Updated:** 2026-06-11 +**Version:** 2.0 (Simplified naming) diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index f56a6e2..4086f15 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -523,31 +523,32 @@ class Ipd_discharge extends BaseController return $this->extractDischargeSectionByMarkers($full, $starts, array_merge($allMarkers, $extraEnds)); }; - $summary = $section(['Discharge Summary']); + // Main clinical discharge summary from HTML editor + $clinicalSummary = $section(['Discharge Summary']); // Replace "Discharge Summary" header with discharge status - if ($dischargeStatus !== '' && $summary !== '') { - $summary = preg_replace( + if ($dischargeStatus !== '' && $clinicalSummary !== '') { + $clinicalSummary = preg_replace( '/]*>\s*Discharge\s+Summary\s*<\/h[1-6]>/i', '

' . esc($dischargeStatus) . '

', - $summary + $clinicalSummary ); // Also handle bold/strong tags - $summary = preg_replace( + $clinicalSummary = preg_replace( '/<(b|strong)>\s*Discharge\s+Summary\s*<\/\1>/i', '' . esc($dischargeStatus) . '', - $summary + $clinicalSummary ); // Remove "Date of Discharge" line - $summary = preg_replace( + $clinicalSummary = preg_replace( '/Date\s+of\s+Discharge\s*:\s*[0-9\-\/]+\s*/i', '', - $summary + $clinicalSummary ); - $summary = preg_replace( + $clinicalSummary = preg_replace( '/]*>\s*Date\s+of\s+Discharge\s*:\s*[0-9\-\/]+\s*<\/p>/i', '', - $summary + $clinicalSummary ); } @@ -571,10 +572,15 @@ class Ipd_discharge extends BaseController // Extract individual instruction fields for template flexibility $otherAdvice = $section(['Other Advice:']); - $dischargeSummaryAdvice = $section(['Discharge Summary:']); + $followUpInstructions = $section(['Discharge Summary:']); $vars = [ - 'DISCHARGE_SUMMARY' => $summary, + // Main discharge summary from HTML editor (instruction_remark field) + 'CLINICAL_SUMMARY' => $clinicalSummary, + // Legacy alias for backward compatibility + 'DISCHARGE_SUMMARY' => $clinicalSummary, + + // Clinical sections 'FINAL_DIAGNOSIS' => $finalDiagnosis, 'SURGERY' => $surgery, 'PROCEDURE' => $procedure, @@ -584,16 +590,19 @@ class Ipd_discharge extends BaseController 'CLINICAL_INVESTIGATION_REPORTS' => $clinicalInvestigations, 'COURSE_IN_HOSPITAL' => $courseInHospital, 'EXAMINATION_ON_DISCHARGE' => $examOnDischarge, + + // Discharge instructions and advice 'DISCHARGE_MEDICATIONS' => $dischargeMedications, 'DIETARY_ADVICE' => $dietaryAdvice, 'DISCHARGE_INSTRUCTIONS' => $dischargeInstructions, + 'OTHER_ADVICE' => $otherAdvice, + 'FOLLOW_UP_INSTRUCTIONS' => $followUpInstructions, + + // Other sections 'PAIN_MEASUREMENT_SCALE' => $painMeasurement, 'DRUG_ALLERGY_ADR' => $drugAllergyAdr, 'CO_MORBIDITIES' => $coMorbidities, 'SIGNATURE_BLOCK' => $signatureBlock, - 'OTHER_ADVICE' => $otherAdvice, - 'INSTRUCTION_REMARK' => $dischargeSummaryAdvice, - 'DISCHARGE_ADVICE' => $dischargeSummaryAdvice, // Legacy style aliases to ease migration from CI3-style template variables. 'FinalDiagnosis' => $finalDiagnosis, 'Surgery' => $surgery, diff --git a/check_bed_history.php b/check_bed_history.php new file mode 100644 index 0000000..50ba114 --- /dev/null +++ b/check_bed_history.php @@ -0,0 +1,39 @@ +query(" + SELECT + bah.id, + bah.ipd_id, + bah.bed_id, + bm.bed_number, + bm.bed_code, + bm.bed_status, + bm.current_ipd_id, + DATE_FORMAT(bah.assigned_date, '%d-%m-%Y %H:%i') as assigned_date, + bah.released_date + FROM bed_assignment_history bah + LEFT JOIN bed_master bm ON bm.id = bah.bed_id + WHERE bah.ipd_id = 1 + ORDER BY bah.assigned_date DESC +"); + +if ($result->num_rows > 0) { + while($row = $result->fetch_assoc()) { + echo "Assignment ID: {$row['id']}\n"; + echo "Bed: {$row['bed_number']} ({$row['bed_code']})\n"; + echo "Assigned Date: {$row['assigned_date']}\n"; + echo "Released Date: " . ($row['released_date'] ?? 'NOT RELEASED') . "\n"; + echo "Bed Status in master: {$row['bed_status']}\n"; + echo "Current IPD ID in bed: " . ($row['current_ipd_id'] ?? 'NULL') . "\n"; + echo "---\n"; + } +} else { + echo "No bed assignment history found for this patient.\n"; + echo "This patient may need a bed assigned manually.\n"; +} + +$db->close(); diff --git a/check_current_admission.php b/check_current_admission.php new file mode 100644 index 0000000..864151a --- /dev/null +++ b/check_current_admission.php @@ -0,0 +1,36 @@ +query(" + SELECT + i.id, + i.ipd_code, + DATE_FORMAT(i.register_date, '%d-%m-%Y') as register_date, + p.p_fname, + p.p_lname, + bm.bed_number, + bm.current_ipd_id + FROM ipd_master i + LEFT JOIN patient_master p ON p.id = i.p_id + LEFT JOIN bed_master bm ON bm.current_ipd_id = i.id + WHERE i.ipd_status = 0 + ORDER BY i.register_date DESC +"); + +if ($result->num_rows > 0) { + while($row = $result->fetch_assoc()) { + echo "IPD ID: {$row['id']}\n"; + echo "IPD Code: {$row['ipd_code']}\n"; + echo "Patient: {$row['p_fname']} {$row['p_lname']}\n"; + echo "Register Date: {$row['register_date']}\n"; + echo "Bed Assigned: " . ($row['bed_number'] ?? 'NOT ASSIGNED') . "\n"; + echo "---\n"; + } +} else { + echo "No current admissions found.\n"; +} + +$db->close(); diff --git a/check_ipd2_bed.php b/check_ipd2_bed.php new file mode 100644 index 0000000..f07a472 --- /dev/null +++ b/check_ipd2_bed.php @@ -0,0 +1,90 @@ +query(" + SELECT + i.id, + i.ipd_code, + i.ipd_status, + DATE_FORMAT(i.register_date, '%d-%m-%Y') as register_date, + p.p_fname, + p.p_lname + FROM ipd_master i + LEFT JOIN patient_master p ON p.id = i.p_id + WHERE i.id = 2 +"); +if ($result && $result->num_rows > 0) { + $row = $result->fetch_assoc(); + echo "IPD Code: {$row['ipd_code']}\n"; + echo "Patient: {$row['p_fname']} {$row['p_lname']}\n"; + echo "Status: " . ($row['ipd_status'] == 0 ? 'Admitted' : 'Discharged') . "\n"; + echo "Register Date: {$row['register_date']}\n\n"; +} else { + echo "IPD ID 2 not found!\n\n"; +} + +// Check bed_assignment_history +echo "Bed Assignment History:\n"; +$result = $db->query(" + SELECT + bah.id, + bah.ipd_id, + bah.bed_id, + bm.bed_number, + bm.bed_code, + w.ward_name, + DATE_FORMAT(bah.assigned_date, '%d-%m-%Y %H:%i') as assigned_date, + DATE_FORMAT(bah.released_date, '%d-%m-%Y %H:%i') as released_date, + bah.assignment_type, + bah.remarks + FROM bed_assignment_history bah + LEFT JOIN bed_master bm ON bm.id = bah.bed_id + LEFT JOIN ward_master w ON w.id = bah.ward_id + WHERE bah.ipd_id = 2 + ORDER BY bah.id DESC +"); +if ($result && $result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + echo "Assignment ID: {$row['id']}\n"; + echo "Bed: {$row['bed_number']} ({$row['bed_code']})\n"; + echo "Ward: {$row['ward_name']}\n"; + echo "Assigned: {$row['assigned_date']}\n"; + echo "Released: " . ($row['released_date'] ?? 'NOT RELEASED') . "\n"; + echo "Type: {$row['assignment_type']}\n"; + echo "Remarks: {$row['remarks']}\n"; + echo "---\n"; + } +} else { + echo "No bed assignment history found for IPD ID 2\n\n"; +} + +// Check current bed assignment in bed_master +echo "Current Bed in bed_master:\n"; +$result = $db->query(" + SELECT + bm.id, + bm.bed_number, + bm.bed_code, + bm.bed_status, + bm.current_ipd_id, + w.ward_name + FROM bed_master bm + LEFT JOIN ward_master w ON w.id = bm.ward_id + WHERE bm.current_ipd_id = 2 +"); +if ($result && $result->num_rows > 0) { + $row = $result->fetch_assoc(); + echo "Bed ID: {$row['id']}\n"; + echo "Bed: {$row['bed_number']} ({$row['bed_code']})\n"; + echo "Ward: {$row['ward_name']}\n"; + echo "Status: {$row['bed_status']}\n"; +} else { + echo "No bed currently assigned in bed_master.current_ipd_id for IPD ID 2\n"; +} + +$db->close(); diff --git a/debug_bed_query.php b/debug_bed_query.php new file mode 100644 index 0000000..833831a --- /dev/null +++ b/debug_bed_query.php @@ -0,0 +1,45 @@ +query($query); + +echo "Query executed\n"; +echo "Rows found: " . $result->num_rows . "\n\n"; + +if ($result->num_rows > 0) { + while ($row = $result->fetch_object()) { + echo "Record ID: {$row->id}\n"; + echo "bed_code: " . ($row->bed_code ?? 'NULL') . "\n"; + echo "bed_number: " . ($row->bed_number ?? 'NULL') . "\n"; + echo "ward_name: " . ($row->ward_name ?? 'NULL') . "\n"; + echo "assigned_date: " . ($row->assigned_date ?? 'NULL') . "\n"; + echo "released_date: " . ($row->released_date ?? 'NULL') . "\n"; + echo "assignment_type: " . ($row->assignment_type ?? 'NULL') . "\n"; + echo "remarks: " . ($row->remarks ?? 'NULL') . "\n"; + echo "---\n"; + } +} else { + echo "No records found\n"; +} + +$db->close(); diff --git a/test_panel_tab.php b/test_panel_tab.php new file mode 100644 index 0000000..625f5b1 --- /dev/null +++ b/test_panel_tab.php @@ -0,0 +1,69 @@ +query($query); +if ($result && $result->num_rows > 0) { + echo "āœ“ IPD data found\n\n"; +} else { + echo "āœ— IPD not found\n"; + exit; +} + +// Step 2: Get bed assignments +echo "Step 2: Get bed assignments...\n"; +$query = " + SELECT + bed_assignment_history.*, + bed_master.bed_code, + bed_master.bed_number, + ward_master.ward_name + FROM bed_assignment_history + LEFT JOIN bed_master ON bed_master.id = bed_assignment_history.bed_id + LEFT JOIN ward_master ON ward_master.id = bed_assignment_history.ward_id + WHERE bed_assignment_history.ipd_id = {$ipdId} + ORDER BY bed_assignment_history.id DESC +"; +$result = $db->query($query); +echo "āœ“ Query executed\n"; +echo "āœ“ Rows found: {$result->num_rows}\n\n"; + +if ($result->num_rows > 0) { + echo "Step 3: Render view with data...\n"; + $bed_assignments = []; + while ($row = $result->fetch_object()) { + $bed_assignments[] = $row; + } + + echo "āœ“ Data prepared\n"; + echo "āœ“ Array count: " . count($bed_assignments) . "\n\n"; + + echo "Step 4: Check if view can access data...\n"; + echo "Sample data from first record:\n"; + if (!empty($bed_assignments)) { + $first = $bed_assignments[0]; + echo " bed_code: " . ($first->bed_code ?? 'NULL') . "\n"; + echo " bed_number: " . ($first->bed_number ?? 'NULL') . "\n"; + echo " ward_name: " . ($first->ward_name ?? 'NULL') . "\n"; + echo " assigned_date: " . ($first->assigned_date ?? 'NULL') . "\n"; + echo " assignment_type: " . ($first->assignment_type ?? 'NULL') . "\n"; + } + + echo "\nāœ“ View should display this data\n"; +} else { + echo "āœ— No bed assignments found - view will show empty message\n"; +} + +$db->close();