diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 991c5a9..d035579 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -63,14 +63,18 @@ class Home extends BaseController $user = service('auth')->user(); $today = date('Y-m-d'); $monthStart = date('Y-m-01'); + $todayStart = $today . ' 00:00:00'; + $tomorrowStart = date('Y-m-d', strtotime('+1 day')) . ' 00:00:00'; + $monthStartDateTime = $monthStart . ' 00:00:00'; $opdToday = $this->db->table('opd_master') - ->where('apointment_date', $today) + ->where('apointment_date >=', $todayStart) + ->where('apointment_date <', $tomorrowStart) ->countAllResults(); $opdLast7Days = $this->db->table('opd_master') - ->where('apointment_date >=', date('Y-m-d', strtotime('-7 days'))) - ->where('apointment_date <=', $today) + ->where('apointment_date >=', date('Y-m-d', strtotime('-7 days')) . ' 00:00:00') + ->where('apointment_date <', $tomorrowStart) ->countAllResults(); $admitToday = $this->db->table('ipd_master') @@ -96,8 +100,8 @@ class Home extends BaseController ->select('ins.short_name as org_name') ->select('COUNT(o.opd_id) as total_cases', false) ->join('hc_insurance ins', 'ins.id = o.insurance_id', 'left') - ->where('o.apointment_date >=', $monthStart) - ->where('o.apointment_date <=', $today) + ->where('o.apointment_date >=', $monthStartDateTime) + ->where('o.apointment_date <', $tomorrowStart) ->groupBy('ins.short_name') ->orderBy('total_cases', 'DESC') ->limit(10) @@ -109,7 +113,8 @@ class Home extends BaseController ->select('COUNT(o.opd_id) as total_cases', false) ->select("SUM(CASE WHEN (o.insurance_id IS NULL OR o.insurance_id <= 1) THEN 1 ELSE 0 END) as direct_cases", false) ->select("SUM(CASE WHEN (o.insurance_id IS NULL OR o.insurance_id <= 1) THEN 0 ELSE 1 END) as org_cases", false) - ->where('o.apointment_date', $today) + ->where('o.apointment_date >=', $todayStart) + ->where('o.apointment_date <', $tomorrowStart) ->where('o.doc_name IS NOT NULL', null, false) ->where("o.doc_name != ''", null, false) ->groupBy('o.doc_name') @@ -160,8 +165,8 @@ class Home extends BaseController $opdTrendRaw = $this->db->table('opd_master') ->select("DATE_FORMAT(apointment_date, '%Y-%m-%d') as yd", false) ->select('COUNT(opd_id) as total', false) - ->where('apointment_date >=', $trendStart) - ->where('apointment_date <=', $trendEnd) + ->where('apointment_date >=', $trendStart . ' 00:00:00') + ->where('apointment_date <', $tomorrowStart) ->groupBy('yd') ->get() ->getResult(); diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 4f96eef..d089bf8 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -382,7 +382,7 @@ class Patient extends BaseController } $sql = "select o.opd_id,o.opd_code,o.doc_name,o.apointment_date,o.p_id, - p.p_fname,if(o.apointment_date=curdate(),1,0) as new_opd, + p.p_fname,if(date(o.apointment_date)=curdate(),1,0) as new_opd, date_format(o.apointment_date,'%d-%m-%Y') as str_apointment_date from opd_master o join patient_master p on o.p_id=p.id where o.p_id=$pno diff --git a/app/Models/OpdModel.php b/app/Models/OpdModel.php index fe981a9..7897268 100644 --- a/app/Models/OpdModel.php +++ b/app/Models/OpdModel.php @@ -17,13 +17,16 @@ class OpdModel { $pId = (int) ($data['p_id'] ?? 0); $docId = (int) ($data['doc_id'] ?? 0); + $todayStart = date('Y-m-d') . ' 00:00:00'; + $tomorrowStart = date('Y-m-d', strtotime('+1 day')) . ' 00:00:00'; if ($pId <= 0 || $docId <= 0) { return 0; } $duplicate = $this->db->table('opd_master') - ->where('apointment_date', date('Y-m-d')) + ->where('apointment_date >=', $todayStart) + ->where('apointment_date <', $tomorrowStart) ->where('p_id', $pId) ->where('doc_id', $docId) ->groupStart() @@ -44,7 +47,8 @@ class OpdModel $opdNoRow = $this->db->table('opd_master') ->select('count(*) as no_max') - ->where('apointment_date', date('Y-m-d')) + ->where('apointment_date >=', $todayStart) + ->where('apointment_date <', $tomorrowStart) ->where('doc_id', $docId) ->get() ->getRow(); @@ -66,8 +70,8 @@ class OpdModel $lastOpdRow = $this->db->table('opd_master') ->select('max(opd_id) as last_opd_id') - ->where('apointment_date >=', $this->resolveRunningLookupDate($docId)) - ->where('apointment_date <=', date('Y-m-d')) + ->where('apointment_date >=', $this->resolveRunningLookupDate($docId) . ' 00:00:00') + ->where('apointment_date <', $tomorrowStart) ->where('running_opd', 0) ->where('opd_fee_type <>', 3) ->where('coalesce(opd_fee_amount,0) >', 0, false)