Add OPD appointment time capture and storage with date+time display

This commit is contained in:
DevSoftTech Server 2026-04-28 07:59:47 +05:30
parent cef10f70e1
commit bd274a3fc3
6 changed files with 101 additions and 4 deletions

View File

@ -1474,6 +1474,7 @@ class Opd extends BaseController
$feeId = (int) $this->request->getPost('fee_id');
$pid = (int) $this->request->getPost('pid');
$appointmentDate = (string) $this->request->getPost('datepicker_appointment');
$appointmentTime = (string) $this->request->getPost('appointment_time');
$abhaAddress = trim((string) $this->request->getPost('abha_address'));
if ($docId <= 0 || $feeId <= 0 || $pid <= 0 || $appointmentDate === '') {
@ -1528,6 +1529,9 @@ class Opd extends BaseController
$userId = $user->id ?? '';
$userNameInfo = $userLabel . ' [' . date('d-m-Y H:i:s') . '] ' . $userId;
// Combine appointment date and time into datetime
$appointmentDateTime = str_to_MysqlDateTime($appointmentDate, $appointmentTime);
$insert = [
'p_id' => $pid,
'P_name' => strtoupper((string) $personInfo[0]->p_fname),
@ -1539,7 +1543,7 @@ class Opd extends BaseController
'opd_fee_desc' => $docFee[0]->doc_fee_desc,
'doc_name' => $docInfo[0]->p_fname,
'opd_fee_type' => $docFee[0]->doc_fee_type,
'apointment_date' => str_to_MysqlDate($appointmentDate),
'apointment_date' => $appointmentDateTime,
'doc_spec' => $docInfo[0]->SpecName,
'prepared_by' => $userNameInfo,
];
@ -2382,7 +2386,21 @@ class Opd extends BaseController
$lastVisitText = 'Last Visit : ' . $lastVisitDate;
}
$bookTime = (string) ($opd->apointment_date ?? '');
$bookTime = '';
if (!empty($opd->apointment_date)) {
$dateTime = $opd->apointment_date;
// Format datetime to "dd/mm/yyyy HH:MM" format
if (preg_match('/^\d{4}-\d{2}-\d{2}/', $dateTime)) {
try {
$dt = new \DateTime($dateTime);
$bookTime = $dt->format('d/m/Y H:i');
} catch (\Exception $e) {
$bookTime = (string) $dateTime;
}
} else {
$bookTime = (string) $dateTime;
}
}
$rxMeds = is_array($data['rx_medicines'] ?? null) ? $data['rx_medicines'] : [];

View File

@ -111,6 +111,7 @@ class Opdcase extends BaseController
$pid = (int) $this->request->getPost('pid');
$insuranceId = (int) $this->request->getPost('insurance_id');
$appointmentDate = (string) $this->request->getPost('datepicker_appointment');
$appointmentTime = (string) $this->request->getPost('appointment_time');
if ($docId <= 0 || $feeId <= 0 || $pid <= 0 || $insuranceId <= 0 || $appointmentDate === '') {
return $this->response->setJSON([
@ -158,6 +159,9 @@ class Opdcase extends BaseController
$opdFeeAmount = $insurance[0]->opd_fee ?? 0;
$opdFeeDesc = $insurance[0]->opd_desc ?? '';
// Combine appointment date and time into datetime
$appointmentDateTime = str_to_MysqlDateTime($appointmentDate, $appointmentTime);
$insert = [
'p_id' => $pid,
'P_name' => strtoupper((string) $personInfo[0]->p_fname),
@ -169,7 +173,7 @@ class Opdcase extends BaseController
'opd_fee_desc' => $opdFeeDesc,
'doc_name' => $docInfo[0]->p_fname,
'doc_spec' => $docInfo[0]->SpecName,
'apointment_date' => str_to_MysqlDate($appointmentDate),
'apointment_date' => $appointmentDateTime,
'opd_fee_type' => '1',
'prepared_by' => $userNameInfo,
];

View File

@ -0,0 +1,42 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class ChangeOpdAppointmentDateToDATETIME extends Migration
{
public function up()
{
// Change the apointment_date column from DATE to DATETIME to store both date and time
$this->db->disableForeignKeyChecks();
$this->forge->modifyColumn('opd_master', [
'apointment_date' => [
'type' => 'DATETIME',
'null' => true,
'default' => null,
'comment' => 'Appointment date and time'
]
]);
$this->db->enableForeignKeyChecks();
}
public function down()
{
// Revert the column back to DATE type
$this->db->disableForeignKeyChecks();
$this->forge->modifyColumn('opd_master', [
'apointment_date' => [
'type' => 'DATE',
'null' => true,
'default' => null,
'comment' => 'Appointment date'
]
]);
$this->db->enableForeignKeyChecks();
}
}

View File

@ -18,6 +18,27 @@ function str_to_MysqlDate(string $strDate): string
return '1900-01-01';
}
function str_to_MysqlDateTime(string $strDate, string $strTime = ''): string
{
$mysqlDate = str_to_MysqlDate($strDate);
// Validate and format time (HH:MM)
$strTime = trim($strTime);
if ($strTime === '') {
$strTime = '00:00:00';
} elseif (preg_match('/^\d{2}:\d{2}$/', $strTime) === 1) {
$strTime = $strTime . ':00';
} elseif (!preg_match('/^\d{2}:\d{2}:\d{2}$/', $strTime)) {
$strTime = '00:00:00';
}
if ($mysqlDate === '1900-01-01') {
return '1900-01-01 00:00:00';
}
return $mysqlDate . ' ' . $strTime;
}
function MysqlDate_to_str(?string $strDate): string
{
if ($strDate === null || $strDate === '') {

View File

@ -29,6 +29,11 @@
<input class="form-control datepicker" id="datepicker_appointment" name="datepicker_appointment"
type="text" value="<?= date('d/m/Y') ?>" readonly>
</div>
<div class="col-md-2">
<label class="form-label">Time</label>
<input class="form-control" id="appointment_time" name="appointment_time"
type="time" value="<?= date('H:i') ?>">
</div>
</div>
<div class="row g-3 mt-2" id="ShowDoctor">
@ -136,6 +141,7 @@
"input_clam_id": $('#input_clam_id').val(),
"pid": $('#pid').val(),
"datepicker_appointment": $('#datepicker_appointment').val(),
"appointment_time": $('#appointment_time').val(),
[csrf.name]: csrf.value
}, function(data) {
updateCsrf(data);

View File

@ -25,7 +25,12 @@
<input class="form-control datepicker" id="datepicker_appointment" name="datepicker_appointment"
type="text" value="<?= date('d/m/Y') ?>" readonly>
</div>
<div class="col-md-4">
<div class="col-md-2">
<label class="form-label">Time</label>
<input class="form-control" id="appointment_time" name="appointment_time"
type="time" value="<?= date('H:i') ?>">
</div>
<div class="col-md-3">
<label class="form-label">ABHA Address</label>
<input class="form-control" id="abha_address" name="abha_address" type="text"
maxlength="18" value="<?= esc($person_info[0]->abha_address ?? $person_info[0]->abha ?? '') ?>"
@ -132,6 +137,7 @@
"input_clam_id": $('#input_clam_id').val(),
"pid": $('#pid').val(),
"datepicker_appointment": $('#datepicker_appointment').val(),
"appointment_time": $('#appointment_time').val(),
"abha_address": $('#abha_address').val(),
[csrf.name]: csrf.value
}, function(data) {