Commit Graph

287 Commits

Author SHA1 Message Date
a1fbf50f3f Change {{Tadvise_test_list}} to comma-separated format (not bullet list)
Changed placeholder behavior to match user requirements:
- {{investigation}} = textarea content (advise_investigation_notes) only
- {{Tadvise_test_list}} = comma-separated test names from table

Removed HTML bullet list formatting. Now outputs plain comma-separated text.

Example output:
CBC (Complete Blood Count), ECG (Electrocardiogram), HBA1C, HBSAG, HCV,
HIV I & II (Elisa), Liver Function Test (LFT), PT/INR, Renal Function Test (RFT),
Urine Routine & Microscopy, X-Ray Chest (PA View)

Both placeholders are independent and can show content simultaneously.
2026-06-05 15:59:16 +05:30
0b865f41cd Add textarea fallback for {{Tadvise_test_list}} placeholder
When opd_prescription_investigation table is empty but investigation
textarea has content, parse textarea content (split by newlines) to
populate the test list.

This handles cases where tests are entered as free-text in the
"Advise Investigation" textarea instead of selecting from master list.

Parsing logic:
- Try rx_investigations table first
- If empty, split investigation textarea by newlines
- Filter out empty lines and 'null' values
- Build HTML bullet list from either source

Example textarea content:
USG WHOLE ABDOMEN
CECT ABDOMEN
PAC
COMPLETE CARDIAC CHECK UP
PAP SMEAR

Will render as:
• USG WHOLE ABDOMEN
• CECT ABDOMEN
• PAC
• COMPLETE CARDIAC CHECK UP
• PAP SMEAR
2026-06-05 15:55:34 +05:30
1ca2dbce4c Add error handling and debug mode for OPD PDF rendering
Added try-catch around mPDF WriteHTML to catch rendering errors.
Changed debug_html mode to output as text/html for better preview.
Logs mPDF errors and returns user-friendly error message.

This will help diagnose blank page issues with {{Tadvise_test_list}} placeholder.
2026-06-05 15:38:26 +05:30
a540581bf9 Fix {{Tadvise_test_list}} to always populate from rx_investigations
Previous implementation only built test list when investigation textarea
was empty, preventing {{Tadvise_test_list}} from showing when textarea
had content.

Changes:
- Separated test list building from textarea population logic
- {{Tadvise_test_list}} now always populates when rx_investigations exists
- {{investigation}} still gets comma-separated fallback when textarea empty
- Both placeholders now work independently

Test list HTML output format:
<ul style="margin:3px 0 0 16px;padding:0;list-style-type:disc;">
  <li>CBC (Complete Blood Count)</li>
  <li>ECG (Electrocardiogram)</li>
  <li>HBA1C</li>
</ul>
2026-06-05 15:28:01 +05:30
6f6286f427 Add {{Tadvise_test_list}} placeholder for investigation test names
Created new OPD template placeholder to display investigation test names
as a formatted HTML list, separate from the textarea {{investigation}}.

Changes:
- app/Controllers/Opd.php:
  * Added $rxInvestigationTestList variable in buildLegacyDashboardTemplateVars()
  * Builds HTML <ul> list from rx_investigations test names
  * Added 'Tadvise_test_list' token to return array

- app/Views/billing/opd_template_builder.php:
  * Added 'Tadvise_test_list' to $opdConsultSet placeholder list
  * Now appears in "OPD Consult" group in template builder

Usage in OPD templates:
- {{investigation}} = comma-separated test names (for textarea)
- {{Tadvise_test_list}} = formatted HTML bullet list of test names (for print/display)

Example output:
<ul style="margin:3px 0 0 16px;padding:0;list-style-type:disc;">
  <li>CBC (Complete Blood Count)</li>
  <li>USG WHOLE ABDOMEN</li>
  <li>ECG (Electrocardiogram)</li>
</ul>
2026-06-05 15:15:15 +05:30
a572bbabae Simplify org-case queries to match CI3 pattern
Changed from complex string comparisons to simple integer comparisons matching legacy CI3 code:

OPD query (CI3 pattern):
- OLD: o.insurance_case_id = cast(c.id as char) OR o.insurance_case_id = c.case_id_code
- NEW: o.insurance_case_id = c.id (integer comparison)

Invoice query (CI3 pattern):
- OLD: i.insurance_case_id = c.id OR i.insurance_case_id = c.case_id_code (with NULL/0 checks)
- NEW: i.insurance_case_id = c.id (integer comparison)

Schema notes:
- opd_master.insurance_case_id: int(11)
- invoice_master.insurance_case_id: varchar(50) (but stores numeric IDs)

MySQL varchar→int conversion handles this correctly:
- '4997' → 4997 (matches)
- '0' → 0 (doesn't match 4997)
- 'C26060004997' → 0 (doesn't match 4997)

Applied to:
- getOrganizationCaseInvoiceRows() union query
- updateOrgTotals() aggregate queries
- search() case list query
2026-06-05 14:14:22 +05:30
ba9d17d5e6 Fix org-case invoice query: exclude empty insurance_case_id
Root cause: 50k+ invoices had insurance_case_id='0', and MySQL string comparison '0'='C26060004997' matched (both convert to numeric 0).

Fix: Exclude NULL/empty/'0' insurance_case_id before comparison in:
- getOrganizationCaseInvoiceRows() union query
- updateOrgTotals() aggregate queries

Result: Case C26060004997 now returns 9 rows instead of 56,786 (memory crash fixed)
2026-06-05 14:09:26 +05:30
4c5e0748bb Revert patient ID fallback - use insurance_case_id only 2026-06-05 13:55:50 +05:30
e80e18600d Fix org-case invoice scoping 2026-06-05 13:49:58 +05:30
6e3a355e03 Fix org case invoice and discharge PDF rendering 2026-06-05 13:43:19 +05:30
9c295c55c8 fix(discharge): enforce pdf response and sanitize template html 2026-06-05 12:03:47 +05:30
499a9bea31 fix(orgcase): fallback invoice linkage by patient and case 2026-06-05 11:45:01 +05:30
bd820a7939 fix(orgcase): use insurance amount1 in union invoice query 2026-06-05 11:37:23 +05:30
e7d6dd88d2 fix(orgcase): avoid missing discount column in union query 2026-06-05 11:34:52 +05:30
9f1d5b93e6 fix(orgcase): restore legacy union invoice rows 2026-06-05 11:32:01 +05:30
48222bb689 fix(orgcase): include OPD rows linked by case code 2026-06-05 11:27:24 +05:30
561adb9647 feat(discharge): add department and time placeholders 2026-06-05 11:05:00 +05:30
23fd1bf73f fix(discharge): render html fragments and reorder sections 2026-06-05 10:42:14 +05:30
0b05d7284c feat(discharge): support section placeholders 2026-06-05 10:24:31 +05:30
472b8367d9 fix(discharge): remove blank-header fallback and improve auto summary 2026-06-05 09:50:58 +05:30
3666875782 fix(discharge-pdf): suppress borders for border=0 tables 2026-06-05 08:39:48 +05:30
a076d48859 fix(discharge): apply latest controller adjustments 2026-06-05 08:31:02 +05:30
8f57288d2a fix(discharge): apply latest Ipd_discharge updates 2026-06-05 08:29:11 +05:30
c9c70a9ce5 fix(discharge): support borderless medication table in preview and PDF 2026-06-05 08:15:33 +05:30
7527fc315a fix(discharge): apply latest controller updates 2026-06-05 08:04:31 +05:30
b47b41ce8a fix(discharge-pdf): remove auto title/template block from body 2026-06-05 07:40:43 +05:30
f341e8e76e fix(discharge-template): make delete endpoint reliable for URL and AJAX 2026-06-05 07:37:39 +05:30
a169ab174b fix(discharge): render header/footer hospital placeholders in PDF 2026-06-05 07:33:07 +05:30
171ff50155 fix(template): backfill discharge template columns for legacy schemas 2026-06-05 07:20:43 +05:30
fdb7c15f85 Fix discharge template page edit flow and AJAX save/delete 2026-06-05 07:12:58 +05:30
e6ffebb96d Render discharge PDF with content-only body and remove duplicate top meta blocks 2026-06-05 07:05:25 +05:30
21e662a0e6 Fix duplicate discharge summary header when using content placeholder 2026-06-05 06:47:39 +05:30
ecb55e7329 Add page settings and header footer support to discharge templates 2026-06-05 06:22:13 +05:30
b6a2e956d8 Remove heading from combined NABH panel placeholder 2026-06-05 06:05:06 +05:30
806044ff93 Add single conditional NABH panel placeholder 2026-06-05 06:00:43 +05:30
8bfd11ccda Persist consult NABH fields via remarks fallback 2026-06-05 05:53:24 +05:30
c4a6e95933 Add explicit OPD NABH allergy raw and block placeholders 2026-06-05 05:47:16 +05:30
14fb1fd400 Fix OPD placeholder collisions for vitals and allergy blocks 2026-06-05 05:29:58 +05:30
51daaa989a Fix OPD pain/allergy placeholders and hide No Pain block 2026-06-05 04:51:05 +05:30
dc2a0da1ee Use mPDF-safe mm spacer blocks for OPD section gaps 2026-06-05 04:26:23 +05:30
dbda578d68 Harden OPD block spacing and add debug_html output mode 2026-06-05 04:18:48 +05:30
f358bbd66c More spacing between OPD print blocks; add margin around medicine table 2026-06-05 04:13:21 +05:30
3a06c32dc5 Increase spacing between OPD print placeholder blocks 2026-06-05 04:08:20 +05:30
6bdef9bb9d Improve OPD print block typography for professional output 2026-06-05 03:54:52 +05:30
a1ba8f0e6b Enhance OPD template placeholders and list rendering 2026-06-05 03:48:24 +05:30
700741ab9b Fix billing case creation reusing old records 2026-06-04 15:55:08 +05:30
c692340bb2 Store ABDM bundles in health records 2026-06-03 11:05:40 +05:30
45abd3ca76 Store ABHA ID and ABHA address separately 2026-06-02 06:00:35 +05:30
510d121478 Normalize OPD preview bundle_type from profile 2026-06-01 14:04:44 +05:30
c68816ce57 Upgrade regenerated OPD bundle_type to OPConsultRecord 2026-06-01 14:02:23 +05:30