fix: OPD running validity period no longer extends per running visit
OpdModel.php: - running_opd_id lookup now uses doctor's configured opd_valid_no_days instead of hardcoded 4 days (resolveRunningLookupDate helper) - Doctors with validity > 5 days now correctly link running OPD back to the original paid OPD even on days 5..N of the window Opd.php (buildOpdLetterPrintData): - For running OPD entries (running_opd=1 or opd_fee_type=3), expiry display now shows "OPD Start Date: [paid visit] | Valid Upto: [paid visit + validity]" using old_opd record — mirrors Opd_print_1 legacy behavior and prevents validity window from advancing with each visit
This commit is contained in:
parent
21ddeefe40
commit
eec0642466
|
|
@ -2197,7 +2197,16 @@ class Opd extends BaseController
|
||||||
$opdNo = (string) ($opd->opd_code ?? '');
|
$opdNo = (string) ($opd->opd_code ?? '');
|
||||||
$opdDate = (string) ($opd->str_apointment_date ?? '');
|
$opdDate = (string) ($opd->str_apointment_date ?? '');
|
||||||
$expDate = trim((string) ($opd->opd_Exp_Date ?? ''));
|
$expDate = trim((string) ($opd->opd_Exp_Date ?? ''));
|
||||||
$expDateText = $expDate !== '' ? ('<b>Valid Upto : </b>' . esc($expDate)) : '';
|
$isRunningOpdEntry = ((int) ($opd->running_opd ?? 0) === 1)
|
||||||
|
|| ((int) ($opd->opd_fee_type ?? 0) === 3);
|
||||||
|
if ($isRunningOpdEntry && !empty($data['old_opd'][0] ?? null)) {
|
||||||
|
$oldExpDate = trim((string) ($data['old_opd'][0]->opd_Exp_Date ?? ''));
|
||||||
|
$oldStartDate = trim((string) ($data['old_opd'][0]->str_apointment_date ?? ''));
|
||||||
|
$expDateText = ($oldStartDate !== '' ? 'OPD Start Date : ' . esc($oldStartDate) . '<br>' : '')
|
||||||
|
. ($oldExpDate !== '' ? '<b>Valid Upto : </b>' . esc($oldExpDate) : '');
|
||||||
|
} else {
|
||||||
|
$expDateText = $expDate !== '' ? ('<b>Valid Upto : </b>' . esc($expDate)) : '';
|
||||||
|
}
|
||||||
|
|
||||||
$specName = trim((string) ($doctor->SpecName ?? $opd->doc_spec ?? ''));
|
$specName = trim((string) ($doctor->SpecName ?? $opd->doc_spec ?? ''));
|
||||||
$doctorShortDescription = trim((string) ($doctor->doc_sign ?? $opd->doc_sign ?? ''));
|
$doctorShortDescription = trim((string) ($doctor->doc_sign ?? $opd->doc_sign ?? ''));
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class OpdModel
|
||||||
|
|
||||||
$lastOpdRow = $this->db->table('opd_master')
|
$lastOpdRow = $this->db->table('opd_master')
|
||||||
->select('max(opd_id) as last_opd_id')
|
->select('max(opd_id) as last_opd_id')
|
||||||
->where('apointment_date >=', date('Y-m-d', strtotime('-4 days')))
|
->where('apointment_date >=', $this->resolveRunningLookupDate($docId))
|
||||||
->where('apointment_date <=', date('Y-m-d'))
|
->where('apointment_date <=', date('Y-m-d'))
|
||||||
->where('running_opd', 0)
|
->where('running_opd', 0)
|
||||||
->where('opd_fee_type <>', 3)
|
->where('opd_fee_type <>', 3)
|
||||||
|
|
@ -108,4 +108,15 @@ class OpdModel
|
||||||
|
|
||||||
return $insertId;
|
return $insertId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function resolveRunningLookupDate(int $docId): string
|
||||||
|
{
|
||||||
|
$docRow = $this->db->table('doctor_master')
|
||||||
|
->select('opd_valid_no_days')
|
||||||
|
->where('id', $docId)
|
||||||
|
->get()
|
||||||
|
->getRow();
|
||||||
|
$validDays = max(4, (int) ($docRow->opd_valid_no_days ?? 5) - 1);
|
||||||
|
return date('Y-m-d', strtotime('-' . $validDays . ' days'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user