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 { class PatVisit extends Controller {
use ResponseTrait; use ResponseTrait;
protected $modelPatVisit; protected $model;
public function __construct() { public function __construct() {
$this->modelPatVisit = new PatVisitModel(); $this->model = new PatVisitModel();
} }
public function show($PVID = null) { public function show($PVID = null) {
try { try {
$row = $this->modelPatVisit->show($PVID); $row = $this->model->show($PVID);
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200); return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage()); return $this->failServerError('Something went wrong '.$e->getMessage());
@ -25,7 +25,7 @@ class PatVisit extends Controller {
public function showByPatient($InternalPID = null) { public function showByPatient($InternalPID = null) {
try { try {
$row = $this->modelPatVisit->showByPatient($InternalPID); $row = $this->model->showByPatient($InternalPID);
return $this->respond(['status' => 'success', 'message'=> "data found", 'data' => $row ], 200); return $this->respond(['status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage()); return $this->failServerError('Something went wrong '.$e->getMessage());
@ -36,7 +36,7 @@ class PatVisit extends Controller {
$input = $this->request->getJSON(true); $input = $this->request->getJSON(true);
try { try {
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); } 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); return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage()); return $this->failServerError('Something went wrong: ' . $e->getMessage());
@ -46,7 +46,7 @@ class PatVisit extends Controller {
public function create() { public function create() {
$input = $this->request->getJSON(true); $input = $this->request->getJSON(true);
try { try {
$data = $this->modelPatVisit->createPatVisit($input); $data = $this->model->createPatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201); return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage()); 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); $data[$key] = convert_array_to_utc_iso($value);
} elseif (is_string($value) && is_datetime_string($value)) { } elseif (is_string($value) && is_datetime_string($value)) {
try { 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) { } catch (\Exception $e) {
// skip // 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; use CodeIgniter\Model;
class ContactDetailModel extends Model { class ContactDetailModel extends BaseUtcModel {
protected $table = 'contactdetail'; protected $table = 'contactdetail';
protected $primaryKey = 'ContactDetID'; protected $primaryKey = 'ContactDetID';
protected $allowedFields = ['ContactID', 'SiteID', 'ContactCode', 'ContactEmail', 'OccupationID', 'JobTitle', 'Department', 'ContactStartDate', 'ContactEndDate']; protected $allowedFields = ['ContactID', 'SiteID', 'ContactCode', 'ContactEmail', 'OccupationID', 'JobTitle', 'Department', 'ContactStartDate', 'ContactEndDate'];
protected $useTimestamps = true; protected $useTimestamps = true;
protected $createdField = 'ContactStartDate'; protected $createdField = 'ContactStartDate';
protected $updatedField = '';
protected $beforeInsert = ['normalizeDatesToUTC']; protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC']; protected $beforeUpdate = ['normalizeDatesToUTC'];

View File

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

View File

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

View File

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

View File

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

View File

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