fix: move confirmed opd appointments into waiting
This commit is contained in:
parent
ca4b4195aa
commit
67664ab8ff
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@
|
|||
<label class="form-check-label" for="toggle_missing_vitals_only">Only Missing Vitals</label>
|
||||
</div>
|
||||
</div>
|
||||
<?= 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_1, 'showQueue' => true, 'tabType' => 'waiting', 'tableId' => 'opdWaitingTable', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>
|
||||
<div id="waitingNoRowsHint" class="small text-muted mt-2 d-none">All waiting patients already have vitals.</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="tab_visited">
|
||||
<?= view('billing/opd_appointment_list_table', ['rows' => $opd_list_2, 'showQueue' => true, 'tabType' => 'visited', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>
|
||||
<?= view('billing/opd_appointment_list_table', ['rows' => $opd_list_2, 'showQueue' => true, 'tabType' => 'visited', 'tableId' => 'opdVisitedTable', 'opd_date' => $opd_date, 'doc_id' => $doc_id]) ?>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="tab_cancelled">
|
||||
<?= view('billing/opd_appointment_list_table', ['rows' => $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="<?= csrf_token() ?>"]');
|
||||
|
|
@ -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/<?= esc((int) ($doc_id ?? 0)) ?>/<?= esc($opd_date ?? date('Y-m-d')) ?>', '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();
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ if ($authUser) {
|
|||
}
|
||||
?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-striped align-middle mb-0">
|
||||
<table class="table table-sm table-striped align-middle mb-0"<?= !empty($tableId) ? ' id="' . esc((string) $tableId, 'attr') . '"' : '' ?>>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>OPD No.</th>
|
||||
|
|
@ -22,18 +22,17 @@ if ($authUser) {
|
|||
<tbody>
|
||||
<?php if (!empty($rows)) : ?>
|
||||
<?php foreach ($rows as $row) : ?>
|
||||
<tr data-opd-id="<?= esc((int) ($row->opd_id ?? 0)) ?>" data-has-vitals="<?= esc((int) ($row->has_vitals ?? 0)) ?>">
|
||||
<?php $hasVitals = isset($row->has_vitals) && (int) $row->has_vitals === 1; ?>
|
||||
<?php $isBookedTab = ($tabType ?? '') === 'booking'; ?>
|
||||
<?php $isConfirmedForQueue = (int) ($row->is_confirmed_for_queue ?? 0) === 1; ?>
|
||||
<?php $hasPrescription = (int) ($row->has_prescription ?? 0) === 1; ?>
|
||||
<tr data-opd-id="<?= esc((int) ($row->opd_id ?? 0)) ?>" data-has-vitals="<?= esc((int) ($row->has_vitals ?? 0)) ?>" data-has-prescription="<?= esc((int) ($row->has_prescription ?? 0)) ?>">
|
||||
<td><?= esc($row->opd_code ?? '') ?></td>
|
||||
<td><?= esc(($row->P_name ?? '') . ' { ' . ($row->p_rname ?? '') . ' }') ?></td>
|
||||
<?php if (!empty($showQueue)) : ?><td><?= esc((int) ($row->queue_no ?? 0)) ?></td><?php endif; ?>
|
||||
<?php if (!empty($showQueue)) : ?><td><?= $hasPrescription ? esc((int) ($row->queue_no ?? 0)) : '-' ?></td><?php endif; ?>
|
||||
<td><?= esc($row->p_code ?? '') ?></td>
|
||||
<td><?= esc($row->opd_type ?? '') ?> / Amt: <?= esc($row->opd_fee_amount ?? '') ?></td>
|
||||
<td>
|
||||
<?php $hasVitals = isset($row->has_vitals) && (int) $row->has_vitals === 1; ?>
|
||||
<?php $isBookedTab = ($tabType ?? '') === 'booking'; ?>
|
||||
<?php $isConfirmedForQueue = (int) ($row->is_confirmed_for_queue ?? 0) === 1; ?>
|
||||
<?php $hasPrescription = (int) ($row->has_prescription ?? 0) === 1; ?>
|
||||
|
||||
<?php if ($isBookedTab) : ?>
|
||||
<?php if ($isConfirmedForQueue) : ?>
|
||||
<button type="button" class="btn btn-outline-success btn-sm btn-opd-create-queue" data-opdid="<?= esc((int) ($row->opd_id ?? 0)) ?>" title="Queue">
|
||||
|
|
@ -45,14 +44,21 @@ if ($authUser) {
|
|||
</a>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<?php if ($canOpenPrescription) : ?>
|
||||
<?php if (! $hasPrescription && $isConfirmedForQueue) : ?>
|
||||
<button type="button" class="btn btn-outline-success btn-sm btn-opd-create-queue" data-opdid="<?= esc((int) ($row->opd_id ?? 0)) ?>" title="Queue">
|
||||
Queue
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php if ($canOpenPrescription && $hasPrescription) : ?>
|
||||
<a class="btn btn-outline-primary btn-sm" title="Consult" href="javascript:load_form('/Opd_prescription/Prescription/<?= esc((int) ($row->opd_id ?? 0)) ?>','Consult');">
|
||||
Consult
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn <?= $hasVitals ? 'btn-success' : 'btn-warning text-dark' ?> btn-sm btn-opd-vitals" title="<?= $hasVitals ? 'Vitals Filled' : 'Vitals' ?>" data-opdid="<?= esc((int) ($row->opd_id ?? 0)) ?>" data-patient="<?= esc(($row->P_name ?? '') . ' { ' . ($row->p_rname ?? '') . ' }') ?>">
|
||||
<?= $hasVitals ? 'Vitals ✓' : 'Vitals' ?>
|
||||
</button>
|
||||
<?php if ($hasPrescription) : ?>
|
||||
<button type="button" class="btn <?= $hasVitals ? 'btn-success' : 'btn-warning text-dark' ?> btn-sm btn-opd-vitals" title="<?= $hasVitals ? 'Vitals Filled' : 'Vitals' ?>" data-opdid="<?= esc((int) ($row->opd_id ?? 0)) ?>" data-patient="<?= esc(($row->P_name ?? '') . ' { ' . ($row->p_rname ?? '') . ' }') ?>">
|
||||
<?= $hasVitals ? 'Vitals ✓' : 'Vitals' ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn btn-outline-info btn-sm btn-opd-scan" title="Scan" data-opdid="<?= esc((int) ($row->opd_id ?? 0)) ?>">
|
||||
Scan
|
||||
</button>
|
||||
|
|
@ -64,7 +70,7 @@ if ($authUser) {
|
|||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (($tabType ?? '') === 'waiting') : ?>
|
||||
<?php if (($tabType ?? '') === 'waiting' && $hasPrescription) : ?>
|
||||
<button type="button" class="btn btn-outline-success btn-sm btn-opd-status" data-opd-id="<?= esc((int) ($row->opd_id ?? 0)) ?>" data-opd-status="2" title="Visit Done">
|
||||
Visit Done
|
||||
</button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user