From 67664ab8ff6dc101c44eabfc6ec7f7bdd371930d Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Mon, 6 Apr 2026 13:11:46 +0530 Subject: [PATCH] fix: move confirmed opd appointments into waiting --- app/Controllers/Opd.php | 10 +- app/Views/billing/opd_appointment_list.php | 149 ++++++++++++++++-- .../billing/opd_appointment_list_table.php | 32 ++-- 3 files changed, 163 insertions(+), 28 deletions(-) diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 47f7ab1..dece6ef 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -861,12 +861,12 @@ class Opd extends BaseController $isConfirmedForQueue = $paymentStatus === 1 || $isConfirmedZeroAmount || !empty($row->confirm_pay_opd); $row->is_confirmed_for_queue = $isConfirmedForQueue ? 1 : 0; - if ($status === 1 && ! $hasPrescription) { + if ($status === 1 && ! $hasPrescription && ! $isConfirmedForQueue) { $opdList0[] = $row; continue; } - if ($status === 1 && $hasPrescription) { + if ($status === 1 && ($hasPrescription || $isConfirmedForQueue)) { $opdList1[] = $row; continue; } @@ -886,6 +886,12 @@ class Opd extends BaseController }); usort($opdList1, static function ($left, $right): int { + $leftHasPrescription = (int) ($left->has_prescription ?? 0); + $rightHasPrescription = (int) ($right->has_prescription ?? 0); + if ($leftHasPrescription !== $rightHasPrescription) { + return $leftHasPrescription <=> $rightHasPrescription; + } + $leftVitals = (int) ($left->has_vitals ?? 0); $rightVitals = (int) ($right->has_vitals ?? 0); if ($leftVitals !== $rightVitals) { diff --git a/app/Views/billing/opd_appointment_list.php b/app/Views/billing/opd_appointment_list.php index 6f71ea3..e3a6c93 100644 --- a/app/Views/billing/opd_appointment_list.php +++ b/app/Views/billing/opd_appointment_list.php @@ -33,11 +33,11 @@ - $opd_list_1, 'showQueue' => true, 'tabType' => 'waiting', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?> + $opd_list_1, 'showQueue' => true, 'tabType' => 'waiting', 'tableId' => 'opdWaitingTable', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>
All waiting patients already have vitals.
- $opd_list_2, 'showQueue' => true, 'tabType' => 'visited', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?> + $opd_list_2, 'showQueue' => true, 'tabType' => 'visited', 'tableId' => 'opdVisitedTable', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>
$opd_list_3, 'showQueue' => true, 'tabType' => 'cancelled', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?> @@ -101,6 +101,8 @@ var modalObj = modalEl ? new bootstrap.Modal(modalEl) : null; var vitalsModalEl = document.getElementById('vitalsModal'); var vitalsModalObj = vitalsModalEl ? new bootstrap.Modal(vitalsModalEl) : null; + var waitingDataTable = null; + var visitedDataTable = null; function getCsrfPair() { var input = document.querySelector('input[name=""]'); @@ -120,6 +122,128 @@ } } + function destroyDataTable(selector) { + if (!window.jQuery || !$.fn || !$.fn.DataTable || !$.fn.DataTable.isDataTable(selector)) { + return null; + } + + return $(selector).DataTable().destroy(); + } + + function hasActualRows(selector) { + var $table = $(selector); + if ($table.length === 0) { + return false; + } + + var $rows = $table.find('tbody tr'); + if ($rows.length === 0) { + return false; + } + + return $table.find('tbody tr td:not([colspan])').length > 0; + } + + function registerWaitingVitalsFilter() { + if (!window.jQuery || !$.fn || !$.fn.dataTable) { + return; + } + + if (window.opdWaitingVitalsFilter) { + var existingIndex = $.fn.dataTable.ext.search.indexOf(window.opdWaitingVitalsFilter); + if (existingIndex >= 0) { + $.fn.dataTable.ext.search.splice(existingIndex, 1); + } + } + + window.opdWaitingVitalsFilter = function(settings, data, dataIndex) { + if (!settings || !settings.nTable || settings.nTable.id !== 'opdWaitingTable') { + return true; + } + + if (!$('#toggle_missing_vitals_only').is(':checked')) { + return true; + } + + var rowNode = settings.aoData && settings.aoData[dataIndex] ? settings.aoData[dataIndex].nTr : null; + if (!rowNode) { + return true; + } + + if (parseInt($(rowNode).attr('data-has-prescription') || '0', 10) !== 1) { + return false; + } + + return parseInt($(rowNode).attr('data-has-vitals') || '0', 10) !== 1; + }; + + $.fn.dataTable.ext.search.push(window.opdWaitingVitalsFilter); + } + + function initializeOpdTable(selector, options) { + if (!window.jQuery || !$.fn || !$.fn.DataTable) { + return null; + } + + destroyDataTable(selector); + + if (!hasActualRows(selector)) { + return null; + } + + return $(selector).DataTable($.extend({ + paging: true, + lengthChange: false, + searching: true, + ordering: true, + info: true, + autoWidth: false, + responsive: true, + pageLength: 25 + }, options || {})); + } + + function syncWaitingHintAndBadge() { + var $rows = $('#tab_waiting tbody tr[data-opd-id]'); + var missingCount = 0; + var visibleCount = 0; + + $rows.each(function() { + var hasVitals = parseInt($(this).attr('data-has-vitals') || '0', 10) === 1; + var hasPrescription = parseInt($(this).attr('data-has-prescription') || '0', 10) === 1; + if (hasPrescription && !hasVitals) { + missingCount++; + } + + if ($(this).is(':visible')) { + visibleCount++; + } + }); + + var $badge = $('#waitingMissingBadge'); + $badge.text(String(missingCount)); + $badge.toggleClass('d-none', missingCount <= 0); + + $('#waitingNoRowsHint').toggleClass('d-none', !($('#toggle_missing_vitals_only').is(':checked') && $rows.length > 0 && visibleCount === 0)); + } + + function initializeOpdTables() { + registerWaitingVitalsFilter(); + + waitingDataTable = initializeOpdTable('#opdWaitingTable', { + order: [[2, 'asc']], + drawCallback: function() { + syncWaitingHintAndBadge(); + } + }); + + visitedDataTable = initializeOpdTable('#opdVisitedTable', { + order: [[2, 'asc']] + }); + + syncWaitingHintAndBadge(); + } + function reloadAppointmentList() { load_form('/Opd/get_appointment_list//', 'OPD Appointment List'); } @@ -152,6 +276,11 @@ function applyMissingVitalsFilter() { // Filter waiting rows to optionally show only patients whose vitals are still missing. + if (waitingDataTable) { + waitingDataTable.draw(); + return; + } + var onlyMissing = $('#toggle_missing_vitals_only').is(':checked'); var $rows = $('#tab_waiting tbody tr[data-opd-id]'); var visibleCount = 0; @@ -170,17 +299,7 @@ function updateMissingVitalsBadge() { // Count waiting rows missing vitals and show badge only when count > 0. - var missingCount = 0; - $('#tab_waiting tbody tr[data-opd-id]').each(function() { - var hasVitals = parseInt($(this).attr('data-has-vitals') || '0', 10) === 1; - if (!hasVitals) { - missingCount++; - } - }); - - var $badge = $('#waitingMissingBadge'); - $badge.text(String(missingCount)); - $badge.toggleClass('d-none', missingCount <= 0); + syncWaitingHintAndBadge(); } $(document).off('click.opdscanopen', '.btn-opd-scan').on('click.opdscanopen', '.btn-opd-scan', function() { @@ -372,6 +491,9 @@ $vitalBtn.removeClass('btn-warning text-dark btn-outline-warning').addClass('btn-success'); $vitalBtn.attr('title', 'Vitals Filled'); } + if (waitingDataTable) { + waitingDataTable.rows().invalidate().draw(false); + } updateMissingVitalsBadge(); applyMissingVitalsFilter(); } @@ -401,6 +523,7 @@ } }); + initializeOpdTables(); updateMissingVitalsBadge(); applyMissingVitalsFilter(); })(); diff --git a/app/Views/billing/opd_appointment_list_table.php b/app/Views/billing/opd_appointment_list_table.php index fa3dba6..7f73e27 100644 --- a/app/Views/billing/opd_appointment_list_table.php +++ b/app/Views/billing/opd_appointment_list_table.php @@ -8,7 +8,7 @@ if ($authUser) { } ?>
- +
> @@ -22,18 +22,17 @@ if ($authUser) { - + has_vitals) && (int) $row->has_vitals === 1; ?> + + is_confirmed_for_queue ?? 0) === 1; ?> + has_prescription ?? 0) === 1; ?> + - +
OPD No.
opd_code ?? '') ?> P_name ?? '') . ' { ' . ($row->p_rname ?? '') . ' }') ?>queue_no ?? 0)) ?>queue_no ?? 0)) : '-' ?> p_code ?? '') ?> opd_type ?? '') ?> / Amt: opd_fee_amount ?? '') ?> - has_vitals) && (int) $row->has_vitals === 1; ?> - - is_confirmed_for_queue ?? 0) === 1; ?> - has_prescription ?? 0) === 1; ?> - + + Consult - + + + @@ -64,7 +70,7 @@ if ($authUser) { - +