From a8f09d007dabf22619efa0210a8efaac86f491da Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 6 Jun 2026 12:11:10 +0530 Subject: [PATCH] Add comprehensive discharge template guide (CI3 to CI4 migration) Created detailed guide explaining: - How CI3 template system worked (PHP files, hardcoded patient table) - How CI4 template system works (database tokens, no auto patient table) - Complete list of all available tokens - 5 template examples (blank, minimal, custom, selective, CI3 replica) - Migration steps from CI3 PHP templates to CI4 tokens - Testing procedures and common issues - Best practices and quick reference This explains why blank template now correctly shows NO patient table and how to use {{PATIENT_INFO_TABLE}} token to add it when needed. --- DISCHARGE_TEMPLATE_GUIDE.md | 463 ++++++++++++++++++++++++++++++++++++ 1 file changed, 463 insertions(+) create mode 100644 DISCHARGE_TEMPLATE_GUIDE.md diff --git a/DISCHARGE_TEMPLATE_GUIDE.md b/DISCHARGE_TEMPLATE_GUIDE.md new file mode 100644 index 0000000..a7f8f81 --- /dev/null +++ b/DISCHARGE_TEMPLATE_GUIDE.md @@ -0,0 +1,463 @@ +# IPD Discharge Template System - CI3 to CI4 Migration Guide + +## Overview + +The CI4 discharge template system now **correctly matches** CI3 behavior where: +- **Patient demographic table is NOT auto-generated in content** +- **Content contains ONLY clinical sections** (complaints, diagnosis, medications, etc.) +- **Templates control the entire layout** using tokens + +--- + +## How It Works (CI3 vs CI4) + +### CI3 System (Old - chamunda_discharge_template_html.php) + +```php + + + + + + + + + +
Namep_fname) ?>UHIDp_code ?>
+ + + + + + + + + +``` + +**Key Points:** +- Template was a **PHP file** with hardcoded HTML for patient info +- Content variables (`$FinalDiagnosis`, `$Surgery`, etc.) were **HTML fragments** +- Template decided what to show and in what order + +### CI4 System (New - Database Templates with Tokens) + +```html + + + + + + + + + + +
Name{{PATIENT_NAME}}UHID{{UHID}}
Age/Gender{{AGE_GENDER}}IPD No{{IPD_CODE}}
+ + +{{PATIENT_INFO_TABLE}} + + +{{CONTENT}} + + +{{FINAL_DIAGNOSIS}} +{{SURGERY}} +{{PROCEDURE}} +{{DISCHARGE_MEDICATIONS}} +``` + +**Key Points:** +- Templates are stored in **database** (`discharge_template` table) +- Use **{{TOKEN}}** syntax instead of PHP variables +- Content ({{CONTENT}}) contains **ONLY clinical sections** (NO patient table) +- Patient table available as `{{PATIENT_INFO_TABLE}}` token + +--- + +## Available Tokens + +### Patient Demographic Tokens + +| Token | Description | Example Output | +|-------|-------------|----------------| +| `{{PATIENT_NAME}}` | Full patient name | KAMLA SINGH | +| `{{UHID}}` | Patient UHID/code | P26051000001 | +| `{{IPD_CODE}}` | IPD admission number | A26050000001 | +| `{{AGE_GENDER}}` | Age and gender | 26 Year / Female | +| `{{GUARDIAN}}` | Guardian relation and name | W/O of RAM SINGH | +| `{{PATIENT_ADDRESS}}` | Full address | KASHIPUR, District, State | +| `{{DEPARTMENT}}` | Department name | General Medicine | +| `{{ADMIT_DATE}}` | Admission date | 23-05-2026 | +| `{{DISCHARGE_DATE}}` | Discharge date | 05-06-2026 | +| `{{ADMISSION_TIME}}` | Admission time | 10:30 AM | +| `{{DISCHARGE_TIME}}` | Discharge time | 03:45 PM | + +### Hospital Information Tokens + +| Token | Description | +|-------|-------------| +| `{{H_Name}}` | Hospital name | +| `{{hospital_address}}` | Combined hospital address | +| `{{hospital_phone}}` | Hospital phone number | +| `{{hospital_email}}` | Hospital email | +| `{{H_logo}}` | Logo filename | +| `{{H_logo_abs}}` | Absolute path to logo | + +### Pre-Built Table Token + +| Token | Description | +|-------|-------------| +| `{{PATIENT_INFO_TABLE}}` | Complete patient demographic table (matches CI3 format) | + +### Content Tokens + +| Token | Description | +|-------|-------------| +| `{{CONTENT}}` | **All clinical sections** (complaints, diagnosis, course, medications, etc.) | + +### Individual Section Tokens + +| Token | Description | +|-------|-------------| +| `{{FINAL_DIAGNOSIS}}` | Final diagnosis at discharge | +| `{{SURGERY}}` | Surgical procedures performed | +| `{{PROCEDURE}}` | Medical procedures | +| `{{PRESENTING_COMPLAINTS}}` | Complaints with duration | +| `{{GENERAL_EXAM_ADMISSION}}` | General examination on admission | +| `{{CLINICAL_INVESTIGATION_REPORTS}}` | Lab and imaging reports | +| `{{COURSE_IN_HOSPITAL}}` | Course during hospitalization | +| `{{EXAMINATION_ON_DISCHARGE}}` | Examination findings at discharge | +| `{{DISCHARGE_MEDICATIONS}}` | Medications prescribed | +| `{{DIETARY_ADVICE}}` | Diet instructions | +| `{{DISCHARGE_INSTRUCTIONS}}` | Discharge instructions and advice | +| `{{PAIN_MEASUREMENT_SCALE}}` | Pain assessment | +| `{{DRUG_ALLERGY_ADR}}` | Drug allergies and ADR history | +| `{{CO_MORBIDITIES}}` | Co-morbid conditions | +| `{{PERSONAL_HISTORY}}` | Personal history (smoking, alcohol, etc.) | + +### Meta Tokens + +| Token | Description | +|-------|-------------| +| `{{CURRENT_DATE}}` | Current date (dd-mm-yyyy) | +| `{{PRINT_TIME}}` | Current timestamp | + +--- + +## Template Examples + +### Example 1: Blank Template (CI3-like, Just Content) + +```html + +``` + +**Output:** Only clinical sections (complaints, diagnosis, medications, etc.) +**No patient table** is shown automatically! + +--- + +### Example 2: Minimal Template with Patient Table Token + +```html +{{PATIENT_INFO_TABLE}} +{{CONTENT}} +``` + +**Output:** Patient demographic table + all clinical sections +**Closest to CI3 default behavior** + +--- + +### Example 3: Custom Layout with Individual Tokens + +```html +
+

{{H_Name}}

+

Discharge Summary

+ + + + + + + + + + + + + + + + + + + + +
Name:{{PATIENT_NAME}}UHID:{{UHID}}
Age/Gender:{{AGE_GENDER}}IPD No:{{IPD_CODE}}
Admission:{{ADMIT_DATE}}Discharge:{{DISCHARGE_DATE}}
+ +
+ + {{CONTENT}} +
+``` + +**Output:** Custom-styled discharge with full control over layout + +--- + +### Example 4: Selective Sections (Pick What to Show) + +```html +

Discharge Summary

+ +{{PATIENT_INFO_TABLE}} + +
+ {{FINAL_DIAGNOSIS}} + {{SURGERY}} + {{DISCHARGE_MEDICATIONS}} + {{DISCHARGE_INSTRUCTIONS}} +
+ + +``` + +**Output:** Shows ONLY diagnosis, surgery, medications, and instructions +**Skips** complaints, course, examination, etc. + +--- + +### Example 5: CI3 Chamunda Template Converted to CI4 + +```html + + +

Discharge Summary

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name{{PATIENT_NAME}}UHID{{UHID}}
Age & Gender{{AGE_GENDER}}IPD No.{{IPD_CODE}}
Guardian{{GUARDIAN}}Admission{{ADMIT_DATE}} {{ADMISSION_TIME}}
Phone No.{{hospital_phone}}Discharge{{DISCHARGE_DATE}} {{DISCHARGE_TIME}}
Address{{PATIENT_ADDRESS}}Org. NameDirect
Department{{DEPARTMENT}}
+
+ +{{CONTENT}} +``` + +**Output:** Exact replica of CI3 Chamunda template using CI4 tokens! + +--- + +## Migration Steps from CI3 to CI4 + +### Step 1: Convert PHP Template to Token Template + +**Old CI3 Template:** +```php +

+

Patient: p_fname) ?>

+ + + +``` + +**New CI4 Template:** +```html +

Discharge Summary

+

Patient: {{PATIENT_NAME}}

+{{FINAL_DIAGNOSIS}} +``` + +### Step 2: Replace PHP Variables with Tokens + +| CI3 Variable | CI4 Token | +|--------------|-----------| +| `$ipd_master[0]->p_fname` | `{{PATIENT_NAME}}` | +| `$ipd_master[0]->p_code` | `{{UHID}}` | +| `$ipd_master[0]->ipd_code` | `{{IPD_CODE}}` | +| `$ipd_master[0]->str_age . ' / ' . $xgender` | `{{AGE_GENDER}}` | +| `$FinalDiagnosis` | `{{FINAL_DIAGNOSIS}}` | +| `$Surgery` | `{{SURGERY}}` | +| `$Procedure` | `{{PROCEDURE}}` | +| `$discharge_complaint` | `{{PRESENTING_COMPLAINTS}}` | +| `$Course_in_the_hospital` | `{{COURSE_IN_HOSPITAL}}` | +| `$Discharge_Medications` | `{{DISCHARGE_MEDICATIONS}}` | +| `$Discharge_Instructions` | `{{DISCHARGE_INSTRUCTIONS}}` | + +### Step 3: Remove PHP Conditionals + +**Before:** +```php + + + +``` + +**After:** +```html +{{SURGERY}} +``` + +Tokens automatically handle empty values (nothing shown if no data). + +### Step 4: Save to Database + +1. Go to Template Management UI (if available) +2. **OR** Insert directly into `discharge_template` table: + +```sql +INSERT INTO discharge_template (template_name, template_html, is_default, page_size) +VALUES ('Chamunda Template', '', 1, 'A4'); +``` + +--- + +## Testing Your Template + +### Test Case 1: Blank Template +1. Create template with NO content (empty string) +2. View discharge: `http://localhost:8080/Ipd_discharge/show_discharge/1/1?tpl=1` +3. **Expected:** ONLY clinical sections (no patient table) + +### Test Case 2: Just {{CONTENT}} +1. Create template with: `{{CONTENT}}` +2. View discharge +3. **Expected:** ONLY clinical sections (no patient table) + +### Test Case 3: Patient Table + Content +1. Create template with: `{{PATIENT_INFO_TABLE}}{{CONTENT}}` +2. View discharge +3. **Expected:** Patient table + clinical sections + +### Test Case 4: Custom Layout +1. Create template with individual tokens +2. View discharge +3. **Expected:** Your custom layout with data filled in + +--- + +## Common Issues and Solutions + +### Issue 1: Patient table still showing when template is blank + +**Cause:** Old cached discharge content in database +**Solution:** Clear cached content: +```bash +php clear_discharge_content.php [ipd_id] +``` + +### Issue 2: Token not replaced (shows {{TOKEN_NAME}}) + +**Cause:** Token name is misspelled or doesn't exist +**Solution:** Check available tokens list above (case-insensitive) + +### Issue 3: Want old CI3 behavior exactly + +**Solution:** Use this template: +```html +{{PATIENT_INFO_TABLE}} +{{CONTENT}} +``` + +### Issue 4: Need to show patient table in some templates but not others + +**Solution:** +- Template A: Include `{{PATIENT_INFO_TABLE}}` +- Template B: Omit it (blank or just `{{CONTENT}}`) + +--- + +## Best Practices + +### ✅ DO: +- Use `{{PATIENT_INFO_TABLE}}` for quick CI3-style patient demographics +- Use individual tokens for custom layouts +- Use `{{CONTENT}}` to show all clinical sections at once +- Clear cached content after template changes +- Test with different IPD cases (with/without surgery, delivery, etc.) + +### ❌ DON'T: +- Don't expect patient table to auto-appear (it's a token now!) +- Don't use PHP code in templates (use tokens instead) +- Don't manually edit `ipd_discharge.content` column (use regenerate button) +- Don't forget to set `is_default=1` for your primary template + +--- + +## Quick Reference + +### Viewing Options + +| URL | Description | +|-----|-------------| +| `/Ipd_discharge/show_discharge/{id}/1` | PDF with default template | +| `/Ipd_discharge/show_discharge/{id}/1?tpl=5` | PDF with template ID 5 | +| `/Ipd_discharge/preview_discharge_report/{id}` | Preview in browser | +| `/Ipd_discharge/preview_discharge_report/{id}?tpl=5` | Preview with template ID 5 | +| `/Ipd_discharge/preview_discharge_report/{id}?regen=1` | Force regenerate content | + +### Database Tables + +- `discharge_template` - Template definitions +- `ipd_discharge` - Generated content (cached) +- `ipd_discharge_complaint` - Complaints data +- `ipd_discharge_diagnosis` - Diagnosis data +- `ipd_discharge_drug` - Medications data +- etc. + +--- + +## Summary + +**CI3 Way:** +- Template = PHP file with hardcoded patient table +- Content = Variables injected into template + +**CI4 Way (Corrected):** +- Template = Database record with {{TOKENS}} +- Content = ONLY clinical sections (no patient table by default) +- Patient table = Available as `{{PATIENT_INFO_TABLE}}` token + +**Result:** Full control over layout, matches CI3 flexibility! 🎉