From c4932601f17fa376895e35769ddc4dfd87d9ae45 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sun, 7 Jun 2026 19:48:33 +0530 Subject: [PATCH] Fix: Re-initialize CKEditor after Save Discharge Advice button ISSUE 2: After clicking 'Save Discharge Advice', CKEditor turns into plain textarea ROOT CAUSE: initInstructionTools() was not re-initializing CKEditor after AJAX section reload - When user clicks button with data-reload-section='section-instructions' - Form submits via AJAX, returns updated HTML - Section content replaced with new HTML - initInstructionTools() called but did NOT restore CKEditor - Fields remain as plain textareas SOLUTION: Added CKEditor re-initialization to initInstructionTools() Changes to discharge_create.php initInstructionTools(): 1. Check if CKEDITOR is available 2. Destroy existing instances first (instruction_other, instruction_remark) 3. Re-create CKEditor for both fields with same config 4. Prevents duplicate instances and ensures editors work after reload TESTING: - Type in instruction_remark or instruction_other - Click 'Save Discharge Advice' - After reload, both fields should still be CKEditor (not textarea) - Can continue editing with toolbar NOTE: Issue 1 (data mixing between fields) requires separate investigation User can test with: php check_instruction_data.php to see actual DB values --- app/Views/billing/ipd/discharge_create.php | 34 ++++++++++++++++++++++ check_instruction_data.php | 22 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 check_instruction_data.php diff --git a/app/Views/billing/ipd/discharge_create.php b/app/Views/billing/ipd/discharge_create.php index 6cc8cfb..1c241c7 100644 --- a/app/Views/billing/ipd/discharge_create.php +++ b/app/Views/billing/ipd/discharge_create.php @@ -3569,6 +3569,40 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller } section.dataset.toolsBound = '1'; + // Re-initialize CKEditor for instruction fields after section reload + if (typeof CKEDITOR !== 'undefined') { + // Destroy existing instances first to avoid duplication + if (CKEDITOR.instances['instruction_other']) { + CKEDITOR.instances['instruction_other'].destroy(true); + } + if (CKEDITOR.instances['instruction_remark']) { + CKEDITOR.instances['instruction_remark'].destroy(true); + } + + // Re-create CKEditor instances + if (document.getElementById('instruction_other')) { + CKEDITOR.replace('instruction_other', { + height: 120, + toolbar: [ + { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline'] }, + { name: 'paragraph', items: ['NumberedList', 'BulletedList'] }, + { name: 'editing', items: ['Undo', 'Redo'] } + ] + }); + } + + if (document.getElementById('instruction_remark')) { + CKEDITOR.replace('instruction_remark', { + height: 150, + toolbar: [ + { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline'] }, + { name: 'paragraph', items: ['NumberedList', 'BulletedList'] }, + { name: 'editing', items: ['Undo', 'Redo'] } + ] + }); + } + } + var addSelectedBtn = section.querySelector('#btn_instruction_add_selected_food'); var clearBtn = section.querySelector('#btn_instruction_clear_food'); var remark = section.querySelector('#instruction_remark'); diff --git a/check_instruction_data.php b/check_instruction_data.php new file mode 100644 index 0000000..337e588 --- /dev/null +++ b/check_instruction_data.php @@ -0,0 +1,22 @@ +initialize(); + +$db = \Config\Database::connect(); +$row = $db->table('ipd_discharge_instructions')->where('ipd_id', 1007141)->get()->getRowArray(); + +if ($row) { + echo "=== IPD 1007141 - ipd_discharge_instructions ===" . PHP_EOL . PHP_EOL; + echo "comp_report (contains other_text JSON): " . PHP_EOL; + echo substr($row['comp_report'] ?? '', 0, 300) . PHP_EOL . PHP_EOL; + echo "comp_remark (Discharge Summary field): " . PHP_EOL; + echo substr($row['comp_remark'] ?? '', 0, 300) . PHP_EOL; +} else { + echo "No record found for IPD 1007141" . PHP_EOL; +}