From 64e34678ec5914790005fcc9623dd9d60db99d9e Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Wed, 16 Sep 2026 15:53:53 +0530 Subject: [PATCH] feat: close related organization case on IPD discharge --- app/Controllers/Billing/Ipd.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Billing/Ipd.php b/app/Controllers/Billing/Ipd.php index ef22eaa..72032fe 100644 --- a/app/Controllers/Billing/Ipd.php +++ b/app/Controllers/Billing/Ipd.php @@ -872,9 +872,17 @@ class Ipd extends BaseController $this->ipdEditModel->updateIpd($update, $ipdId); $this->ipdEditModel->calculateIPD($ipdId); - // Release bed when discharging patient + // Release bed and close org case when discharging patient if (isset($update['ipd_status']) && $update['ipd_status'] == 1) { $this->ipdEditModel->releaseBed($ipdId); + + $currentIpd = $this->ipdEditModel->find($ipdId); + $caseId = (int) ($currentIpd['case_id'] ?? 0); + if ($caseId > 0) { + \Config\Database::connect()->table('organization_case_master') + ->where('id', $caseId) + ->update(['status' => 1]); + } } return $this->buildDischargeProcessResponse($ipdId, 'Discharge status updated.'); @@ -921,9 +929,16 @@ class Ipd extends BaseController $update = ['ipd_status' => $newStatus]; $this->ipdEditModel->updateIpd($update, $ipdId); - // Release bed when setting to discharged (status = 1) + // Release bed and close org case when setting to discharged (status = 1) if ($newStatus === 1 && $currentStatus === 0) { $this->ipdEditModel->releaseBed($ipdId); + + $caseId = (int) ($currentIpd['case_id'] ?? 0); + if ($caseId > 0) { + \Config\Database::connect()->table('organization_case_master') + ->where('id', $caseId) + ->update(['status' => 1]); + } } $statusText = $newStatus === 0 ? 'Active (Bills unlocked)' : 'Discharged (Bills locked)';