Commit Graph

14 Commits

Author SHA1 Message Date
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
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
700741ab9b Fix billing case creation reusing old records 2026-06-04 15:55:08 +05:30
addef91468 Fix legacy billing prints and pathology template compatibility 2026-03-21 02:23:31 +05:30
aa845ac5ff Add report panel updates and related billing/discharge enhancements 2026-03-10 02:43:35 +05:30
614713f76b Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30