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
This commit is contained in:
parent
ba9d17d5e6
commit
a572bbabae
|
|
@ -364,7 +364,7 @@ class CaseMaster extends BaseController
|
||||||
(case c.status when 0 then 'Pending' when 1 then 'Ready for submission' when 2 then 'Submitted' when 3 then 'Payment Done' else 'Other' end) as str_status,
|
(case c.status when 0 then 'Pending' when 1 then 'Ready for submission' when 2 then 'Submitted' when 3 then 'Payment Done' else 'Other' end) as str_status,
|
||||||
Date_Format(c.date_registration,'%d-%m-%Y') as date_registration_in
|
Date_Format(c.date_registration,'%d-%m-%Y') as date_registration_in
|
||||||
from (organization_case_master c join patient_master p on c.p_id=p.id )
|
from (organization_case_master c join patient_master p on c.p_id=p.id )
|
||||||
left join opd_master o on (o.insurance_case_id = cast(c.id as char) or o.insurance_case_id = c.case_id_code)
|
left join opd_master o on c.id=o.insurance_case_id
|
||||||
left join invoice_master i on c.id=i.insurance_case_id
|
left join invoice_master i on c.id=i.insurance_case_id
|
||||||
group by c.id ";
|
group by c.id ";
|
||||||
|
|
||||||
|
|
@ -559,13 +559,7 @@ class CaseMaster extends BaseController
|
||||||
from opd_master o
|
from opd_master o
|
||||||
join organization_case_master c on c.id={$caseid}
|
join organization_case_master c on c.id={$caseid}
|
||||||
where o.opd_status in (1,2)
|
where o.opd_status in (1,2)
|
||||||
and o.insurance_case_id is not null
|
and o.insurance_case_id = c.id
|
||||||
and o.insurance_case_id != ''
|
|
||||||
and o.insurance_case_id != '0'
|
|
||||||
and (
|
|
||||||
o.insurance_case_id = cast(c.id as char)
|
|
||||||
or o.insurance_case_id = c.case_id_code
|
|
||||||
)
|
|
||||||
|
|
||||||
union all
|
union all
|
||||||
|
|
||||||
|
|
@ -588,13 +582,7 @@ class CaseMaster extends BaseController
|
||||||
group by hc_items_id, hc_insurance_id
|
group by hc_items_id, hc_insurance_id
|
||||||
) it on t.item_id = it.hc_items_id and i.insurance_id = it.hc_insurance_id
|
) it on t.item_id = it.hc_items_id and i.insurance_id = it.hc_insurance_id
|
||||||
where i.ipd_include = 1 and i.invoice_status = 1
|
where i.ipd_include = 1 and i.invoice_status = 1
|
||||||
and i.insurance_case_id is not null
|
and i.insurance_case_id = c.id
|
||||||
and i.insurance_case_id != ''
|
|
||||||
and i.insurance_case_id != '0'
|
|
||||||
and (
|
|
||||||
i.insurance_case_id = c.id
|
|
||||||
or i.insurance_case_id = c.case_id_code
|
|
||||||
)
|
|
||||||
) v
|
) v
|
||||||
order by v.Charge_type, v.Adate
|
order by v.Charge_type, v.Adate
|
||||||
";
|
";
|
||||||
|
|
@ -632,11 +620,7 @@ class CaseMaster extends BaseController
|
||||||
$opdFeeRow = $this->db->table('opd_master')
|
$opdFeeRow = $this->db->table('opd_master')
|
||||||
->selectSum('opd_fee_amount', 'total')
|
->selectSum('opd_fee_amount', 'total')
|
||||||
->whereIn('opd_status', [1, 2])
|
->whereIn('opd_status', [1, 2])
|
||||||
->whereNotIn('insurance_case_id', [null, '', '0'])
|
->where('insurance_case_id', $caseId)
|
||||||
->groupStart()
|
|
||||||
->where('insurance_case_id', (string) $caseId)
|
|
||||||
->orWhere('insurance_case_id', (string) ($caseRow->case_id_code ?? ''))
|
|
||||||
->groupEnd()
|
|
||||||
->get()
|
->get()
|
||||||
->getRow();
|
->getRow();
|
||||||
$opdFee = (float) ($opdFeeRow->total ?? 0);
|
$opdFee = (float) ($opdFeeRow->total ?? 0);
|
||||||
|
|
@ -651,11 +635,7 @@ class CaseMaster extends BaseController
|
||||||
$chargeRow = $this->db->table('invoice_master')
|
$chargeRow = $this->db->table('invoice_master')
|
||||||
->selectSum('net_amount', 'total')
|
->selectSum('net_amount', 'total')
|
||||||
->where('invoice_status', 1)
|
->where('invoice_status', 1)
|
||||||
->whereNotIn('insurance_case_id', [null, '', '0'])
|
->where('insurance_case_id', $caseId)
|
||||||
->groupStart()
|
|
||||||
->where('insurance_case_id', $caseId)
|
|
||||||
->orWhere('insurance_case_id', (string) ($caseRow->case_id_code ?? ''))
|
|
||||||
->groupEnd()
|
|
||||||
->get()
|
->get()
|
||||||
->getRow();
|
->getRow();
|
||||||
$chargeTotal = (float) ($chargeRow->total ?? 0);
|
$chargeTotal = (float) ($chargeRow->total ?? 0);
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,7 @@ class OrganizationCaseModel extends Model
|
||||||
from opd_master o
|
from opd_master o
|
||||||
join organization_case_master c on c.id={$caseId}
|
join organization_case_master c on c.id={$caseId}
|
||||||
where o.opd_status in (1,2)
|
where o.opd_status in (1,2)
|
||||||
and o.insurance_case_id is not null
|
and o.insurance_case_id = c.id
|
||||||
and o.insurance_case_id != ''
|
|
||||||
and o.insurance_case_id != '0'
|
|
||||||
and (
|
|
||||||
o.insurance_case_id = cast(c.id as char)
|
|
||||||
or o.insurance_case_id = c.case_id_code
|
|
||||||
)
|
|
||||||
|
|
||||||
union all
|
union all
|
||||||
|
|
||||||
|
|
@ -78,13 +72,7 @@ class OrganizationCaseModel extends Model
|
||||||
group by hc_items_id, hc_insurance_id
|
group by hc_items_id, hc_insurance_id
|
||||||
) it on t.item_id = it.hc_items_id and i.insurance_id = it.hc_insurance_id
|
) it on t.item_id = it.hc_items_id and i.insurance_id = it.hc_insurance_id
|
||||||
where i.ipd_include = 1 and i.invoice_status = 1
|
where i.ipd_include = 1 and i.invoice_status = 1
|
||||||
and i.insurance_case_id is not null
|
and i.insurance_case_id = c.id
|
||||||
and i.insurance_case_id != ''
|
|
||||||
and i.insurance_case_id != '0'
|
|
||||||
and (
|
|
||||||
i.insurance_case_id = c.id
|
|
||||||
or i.insurance_case_id = c.case_id_code
|
|
||||||
)
|
|
||||||
) v
|
) v
|
||||||
order by v.Charge_type, v.Adate
|
order by v.Charge_type, v.Adate
|
||||||
";
|
";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user