fix all to utc

This commit is contained in:
mahdahar 2025-10-13 12:28:09 +07:00
parent fb5a65103a
commit 28d0d8cddd
9 changed files with 55 additions and 32 deletions

View File

@ -8,15 +8,15 @@ use App\Models\PatVisitModel;
class PatVisit extends Controller {
use ResponseTrait;
protected $modelPatVisit;
protected $model;
public function __construct() {
$this->modelPatVisit = new PatVisitModel();
$this->model = new PatVisitModel();
}
public function show($PVID = null) {
try {
$row = $this->modelPatVisit->show($PVID);
$row = $this->model->show($PVID);
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage());
@ -25,7 +25,7 @@ class PatVisit extends Controller {
public function showByPatient($InternalPID = null) {
try {
$row = $this->modelPatVisit->showByPatient($InternalPID);
$row = $this->model->showByPatient($InternalPID);
return $this->respond(['status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage());
@ -36,7 +36,7 @@ class PatVisit extends Controller {
$input = $this->request->getJSON(true);
try {
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
$data = $this->modelPatVisit->updatePatVisit($input);
$data = $this->model->updatePatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
@ -46,7 +46,7 @@ class PatVisit extends Controller {
public function create() {
$input = $this->request->getJSON(true);
try {
$data = $this->modelPatVisit->createPatVisit($input);
$data = $this->model->createPatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());

View File

@ -36,7 +36,7 @@ if (!function_exists('convert_array_to_utc_iso')) {
$data[$key] = convert_array_to_utc_iso($value);
} elseif (is_string($value) && is_datetime_string($value)) {
try {
$data[$key] = Time::parse($value, 'UTC')->toISOString();
$data[$key] = Time::parse($value, 'UTC')->format('Y-m-d\TH:i:s.v\Z');
} catch (\Exception $e) {
// skip
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class BaseUtcModel extends Model {
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];
protected $afterFind = ['convertDatesToUTCISO'];
protected $afterInsert = ['convertDatesToUTCISO'];
protected $afterUpdate = ['convertDatesToUTCISO'];
protected function normalizeDatesToUTC(array $data) {
helper('utc');
if (isset($data['data'])) {
$data['data'] = convert_array_to_utc($data['data']);
}
return $data;
}
protected function convertDatesToUTCISO(array $data) {
helper('utc');
if (isset($data['data'])) {
$data['data'] = convert_array_to_utc_iso($data['data']);
}
return $data;
}
}

View File

@ -4,13 +4,14 @@ namespace App\Models;
use CodeIgniter\Model;
class ContactDetailModel extends Model {
class ContactDetailModel extends BaseUtcModel {
protected $table = 'contactdetail';
protected $primaryKey = 'ContactDetID';
protected $allowedFields = ['ContactID', 'SiteID', 'ContactCode', 'ContactEmail', 'OccupationID', 'JobTitle', 'Department', 'ContactStartDate', 'ContactEndDate'];
protected $useTimestamps = true;
protected $createdField = 'ContactStartDate';
protected $updatedField = '';
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];

View File

@ -4,13 +4,14 @@ namespace App\Models;
use CodeIgniter\Model;
class ContactModel extends Model {
class ContactModel extends BaseUtcModel {
protected $table = 'contact';
protected $primaryKey = 'ContactID';
protected $allowedFields = ['NameFirst', 'NameLast', 'Title', 'Initial', 'Birthdate', 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone1', 'MobilePhone2', 'Specialty', 'SubSpecialty', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];

View File

@ -2,9 +2,7 @@
namespace App\Models;
use CodeIgniter\Model;
class CounterModel extends Model {
class CounterModel extends BaseUtcModel {
protected $table = 'counter';
protected $primaryKey = 'CounterID';
protected $allowedFields = ['CounterValue', 'CounterStart', 'CounterEnd', 'CounterReset'];
@ -14,7 +12,7 @@ class CounterModel extends Model {
$cValue = $row[0]['CounterValue'];
$cStart = $row[0]['CounterStart'];
$cEnd = $row[0]['CounterEnd'];
$cReset = $row[0]['CounterReset'];
//$cReset = $row[0]['CounterReset'];
$cPad = strlen((string)$cEnd);
// next value > end, back to start
if($cValue > $cEnd) { $cValue = $cStart; }

View File

@ -2,9 +2,7 @@
namespace App\Models;
use CodeIgniter\Model;
class OccupationModel extends Model {
class OccupationModel extends BaseUtcModel {
protected $table = 'occupation';
protected $primaryKey = 'OccupationID';
protected $allowedFields = ['OccCode', 'OccText', 'Description'];

View File

@ -2,18 +2,18 @@
namespace App\Models;
use CodeIgniter\Model;
use App\Models\CounterModel;
class PatVisitModel extends Model {
class PatVisitModel extends BaseUtcModel {
protected $table = 'patvisit';
protected $primaryKey = 'InternalPVID';
protected $allowedFields = ['PVID', 'InternalPID', 'EpisodeID', 'CreateDate', 'EndDate'];
protected $db;
protected $visnum_prefix;
protected $useTimestamps = true;
protected $useTimestamps = false;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];
@ -43,9 +43,7 @@ class PatVisitModel extends Model {
public function createPatVisit($input) {
try{
$input = $this->transformPatVisit($input);
//$input = $this->transformPatVisit($input);
if (!isset($input['PVID']) || $input['PVID']=='') {
$counter = new CounterModel();
$input['PVID'] = $this->visnum_prefix .$counter->use(2);
@ -53,8 +51,7 @@ class PatVisitModel extends Model {
$this->db->transStart();
$this->insert($input);
$InternalPVID = $this->getInsertID();
/*
if(!empty($input['PatDiag'])) {
$input['PatDiag']['InternalPVID'] = $InternalPVID;
$this->db->table('patdiag')->insert($input['PatDiag']);
@ -63,7 +60,7 @@ class PatVisitModel extends Model {
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
$this->db->table('patvisitadt')->insert($input['PatVisitADT']);
}
*/
$this->db->transComplete();
return $input['PVID'];

View File

@ -1,11 +1,9 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
use CodeIgniter\Database\RawSql;
class PatientModel extends Model {
class PatientModel extends BaseUtcModel {
protected $table = 'patient';
protected $primaryKey = 'InternalPID';
protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'Birthdate', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3',
@ -13,6 +11,7 @@ class PatientModel extends Model {
'DeathIndicator', 'DeathDateTime', 'LinkTo', 'CreateDate', 'DelDate' ];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];