diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 47f7ab1..1eba0f0 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -845,6 +845,7 @@ class Opd extends BaseController $opdList0 = []; $opdList1 = []; + $opdListWaitingAll = []; $opdList2 = []; $opdList3 = []; @@ -863,11 +864,13 @@ class Opd extends BaseController if ($status === 1 && ! $hasPrescription) { $opdList0[] = $row; + $opdListWaitingAll[] = $row; continue; } if ($status === 1 && $hasPrescription) { $opdList1[] = $row; + $opdListWaitingAll[] = $row; continue; } @@ -903,6 +906,36 @@ class Opd extends BaseController return ((int) ($left->opd_id ?? 0)) <=> ((int) ($right->opd_id ?? 0)); }); + usort($opdListWaitingAll, static function ($left, $right): int { + $leftHasPrescription = (int) ($left->has_prescription ?? 0); + $rightHasPrescription = (int) ($right->has_prescription ?? 0); + if ($leftHasPrescription !== $rightHasPrescription) { + return $rightHasPrescription <=> $leftHasPrescription; + } + + if ($leftHasPrescription === 1) { + $leftVitals = (int) ($left->has_vitals ?? 0); + $rightVitals = (int) ($right->has_vitals ?? 0); + if ($leftVitals !== $rightVitals) { + return $leftVitals <=> $rightVitals; + } + + $leftQueue = (int) ($left->queue_no ?? 0); + $rightQueue = (int) ($right->queue_no ?? 0); + if ($leftQueue !== $rightQueue) { + return $leftQueue <=> $rightQueue; + } + } + + $leftConfirmed = (int) ($left->is_confirmed_for_queue ?? 0); + $rightConfirmed = (int) ($right->is_confirmed_for_queue ?? 0); + if ($leftConfirmed !== $rightConfirmed) { + return $rightConfirmed <=> $leftConfirmed; + } + + return ((int) ($left->opd_id ?? 0)) <=> ((int) ($right->opd_id ?? 0)); + }); + usort($opdList2, static function ($left, $right): int { return ((int) ($left->opd_id ?? 0)) <=> ((int) ($right->opd_id ?? 0)); }); @@ -923,6 +956,7 @@ class Opd extends BaseController 'doc_master' => $docMaster, 'opd_list_0' => $opdList0, 'opd_list_1' => $opdList1, + 'opd_list_waiting_all' => $opdListWaitingAll, 'opd_list_2' => $opdList2, 'opd_list_3' => $opdList3, ]); diff --git a/app/Views/billing/opd_appointment_list.php b/app/Views/billing/opd_appointment_list.php index 6f71ea3..fb95369 100644 --- a/app/Views/billing/opd_appointment_list.php +++ b/app/Views/billing/opd_appointment_list.php @@ -33,7 +33,7 @@ - = view('billing/opd_appointment_list_table', ['rows' => $opd_list_1, 'showQueue' => true, 'tabType' => 'waiting', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?> + = view('billing/opd_appointment_list_table', ['rows' => $opd_list_waiting_all ?? $opd_list_1, 'showQueue' => true, 'tabType' => 'waiting', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>