Generate standardized Digital Share PDFs for invoice and diagnostic records, strengthen FHIR document validation and sync handling, and keep task-board submissions AJAX-only.
Integrate Final Diagnosis with canonical disease master data and add reusable My/Master template CRUD for discharge narrative sections, including summary investigations, course, other advice, and discharge summary.
Restore surgery and procedure bindings after SPA updates, validate procedure dates without SQL errors, and prevent medicine autocomplete Enter from submitting while preserving layout and autofill.
Serialize the full repaired body instead of only the temporary wrapper contents so DOMDocument recovery does not drop later discharge sections before mPDF rendering.
- Add ?html=1 parameter to show_discharge to output HTML directly
- Shows debug info: IPD ID, template name, content lengths
- Bypass PDF generation to see rendered HTML content
- Helps diagnose PHP/rendering errors before PDF conversion
Usage: /Ipd_discharge/show_discharge/1007168/1?html=1&tpl=3
- Restore "Discharge Summary" heading for template extraction to work
- Show status as strong text below heading (not as replacement)
- Include discharge summary HTML editor content (instruction_remark)
- Section extraction requires consistent heading names
Previous fix broke section extraction by changing heading text
- Include ipd_discharge_instructions.comp_remark in discharge summary section
- Previously only showed status header, missing actual discharge narrative
- Reuse existing instructionRowForMeta query to avoid duplicate DB calls
- Apply renderRichText() to properly display HTML editor content
Fixes missing discharge summary text for IPD 1007168 and similar cases
- Enhanced normalizeRichText() to detect and preserve HTML from HTML editors
- Added renderRichText() helper to safely render HTML vs plain text content
- Updated 4 rendering locations (narrative sections, systemic exams, investigations)
- Backward compatible: plain textarea fields still work correctly
- Fixes issue where strip_tags() removed all HTML formatting from editor content
Resolves blank discharge summaries in PDF when content saved from TinyMCE/HTML editors
- Fix dose columns showing IDs instead of labels (OD, BID, TDS, etc.)
- Add Rx-Group functionality with modal, search, and bulk add
- Add substitute medicine suggestions with one-click use
- Improve medicine autocomplete with debouncing and scope=all
- Load dose master maps in controller and pass to view
- Match OPD Consult UI/UX patterns for consistency
- Clear all output buffers before sending PDF binary to prevent corruption
- Add X-Content-Type-Options: nosniff to force Chrome to treat response as PDF
- Apply fixes to main, fallback, and ultimate fallback PDF response paths
- Fixes issue where Chrome fails to open PDF while Firefox/Edge work
- Critical for PDFs with Hindi/UTF-8 content where output buffering can corrupt binary data
ISSUE 1: {{SIGNATURE_BLOCK}} placeholder not working
- Signature extraction was using wrong end markers
- Start: 'Signature of Consultant'
- End: 'Signature of Medical Officer', 'Signature of Receiver / Date'
- Problem: All three texts are in SAME table row
- Extraction cut off too early (found end marker immediately after start)
FIX: Remove end markers for signature block extraction
- Signature table is LAST element in content
- Extract from 'Signature of Consultant' to end of content
- Now captures entire signature table correctly
ISSUE 2: Other Advice not showing in PDF
- Cached content was generated BEFORE 'Other Advice:' label was added
- Database has data but cached HTML doesn't include label
FIX: Created cache clearing utility
- clear_discharge_cache.php script
- Clears cached content for specified IPD
- Forces regeneration with new labels
DEBUG TOOLS ADDED:
- debug_discharge_content.php - Check what's in cached content
- clear_discharge_cache.php - Clear cache to force regeneration
TESTING:
1. php clear_discharge_cache.php 1
2. Visit /Ipd_discharge/preview_discharge_report/1?regen=1
3. Verify PDF shows Other Advice: and Discharge Summary: labels
4. Verify {{SIGNATURE_BLOCK}} placeholder works in templates
ISSUE 1: Discharge Summary showing in PDF but without label
ISSUE 2: Need separate placeholders for Other Advice and Discharge Summary
FIX 1: Added label to instruction_remark in PDF
- Added Discharge Summary: label before instruction_remark content
FIX 2: Added new placeholders for template flexibility
- OTHER_ADVICE - Shows only Other Advice field
- INSTRUCTION_REMARK or DISCHARGE_ADVICE - Shows only Discharge Summary field
- DISCHARGE_INSTRUCTIONS - Shows full section with all advice
Now templates can control what appears where using specific placeholders.
CHANGES:
1. Line 2248 - Added Discharge Summary: label
2. Line 574-575 - Extract new tokens from content
3. Line 579-581 - Add tokens to vars array
4. Line 520-522 - Add markers to extraction list
TESTING: Go to discharge PDF and verify labels show correctly
ISSUE: instruction_remark (Discharge Summary) data appearing in instruction_other (Other Advice) field after save
ROOT CAUSE: Legacy table sync was writing wrong variable
- Save handler at line 5478 was writing \ to legacy food_text
- Should have been writing \
- When legacy fallback loads (if food_ids empty), wrong data copied to instruction_other
FIX: Changed line 5478 in Ipd_discharge.php
- Before: \['food_text'] = \;
- After: \['food_text'] = \;
FILES MODIFIED:
1. app/Controllers/Ipd_discharge.php - Fixed legacy save handler
2. app/Views/billing/ipd/discharge_create.php - Removed debug comments
TESTING STEPS:
1. Clear corrupt legacy data: php clear_legacy_food.php 1
2. Go to /Ipd_discharge/ipd_select/1
3. Clear both fields
4. Type 'Hello Other' in Other Advice
5. Type 'Hello Discharge' in Discharge Summary
6. Click 'Save Discharge Advice'
7. After reload: Other Advice should show 'Hello Other', NOT 'Hello Discharge'
SCRIPTS ADDED:
- check_instruction_db.php - Check database values
- check_legacy_food.php - Check legacy table
- clear_legacy_food.php - Clean corrupt legacy data
- list_instruction_records.php - List all records
Added sanitizeCKEditorSpecialChars() method to handle smart quotes, zero-width spaces, em/en dashes, and other special characters that can break mPDF.
Removes invisible Unicode chars, replaces special punctuation with ASCII equivalents, cleans HTML comments.
ISSUE: Templates auto-regenerate when deleted
User deletes template ID 3, page reload creates template ID 4 automatically
ROOT CAUSE: ensureDefaultDischargeTemplateSeeded() called on EVERY page load
- discharge_templates() method called it on every view
- getDischargeTemplateRows() called it on every discharge PDF generation
- When count=0, it auto-inserted default templates
- Made it impossible to delete all templates
SOLUTION: Changed to manual opt-in template creation
1. Removed auto-seeding calls:
- Setting/Template::discharge_templates() - removed ensureDefaultDischargeTemplateSeeded()
- Ipd_discharge::getDischargeTemplateRows() - removed ensureDefaultDischargeTemplateSeeded()
- Both now only call ensureDischargeTemplateTable() (structure check only)
2. Added manual template creation:
- New 'Create Default Templates' button shown when table is empty
- New endpoint: discharge_templates_seed() - creates defaults on demand
- Route: POST /setting/template/discharge_templates_seed
- Button confirms before creating, shows success message, reloads page
3. Preserved seeding functions:
- ensureDefaultDischargeTemplateSeeded() kept but not auto-called
- Can be manually triggered via new button
- Creates 'Default Discharge Template' and 'NABH Compliant Discharge Summary'
BEHAVIOR NOW:
- Users can delete ALL templates - they stay deleted
- Empty table shows helpful message with creation button
- Templates only created when user explicitly requests them
- No more surprise template regeneration
TESTING:
- Delete all templates
- Page reloads showing empty table with button
- Click 'Create Default Templates'
- 2 templates created (ID 1 and 2)
ISSUE: Medicines were being saved twice - once via Add button AJAX, and again when clicking 'Save Discharge Advice' button.
ROOT CAUSE:
1. Legacy code in save_main handler (lines 5489-5538) read 'discharge_medicine_json' POST field
2. JavaScript serializeDischargeMedicineTable() collected all medicine table rows into JSON
3. On form submit (Save Discharge Advice), JSON was sent and controller re-inserted all medicines
4. Result: duplicate entries in ipd_discharge_prescrption_prescribed table
SOLUTION:
- DISABLED controller code that processes discharge_medicine_json in save_main handler
- DISABLED JavaScript call to serializeDischargeMedicineTable() on form submit
- Medicines now saved ONLY via Add button AJAX (action='add_drug')
- Save Discharge Advice button now only saves dietary advice, instructions, review after, etc.
TESTING:
1. Add medicines via Add button (saves immediately)
2. Click Save Discharge Advice (does NOT save medicines again)
3. No duplicate entries in database