diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index 7c066f3..5536824 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -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()); diff --git a/app/Helpers/utc_helper.php b/app/Helpers/utc_helper.php index a05c64e..04012ef 100644 --- a/app/Helpers/utc_helper.php +++ b/app/Helpers/utc_helper.php @@ -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 } diff --git a/app/Models/BaseUtcModel.php b/app/Models/BaseUtcModel.php new file mode 100644 index 0000000..c276b5b --- /dev/null +++ b/app/Models/BaseUtcModel.php @@ -0,0 +1,29 @@ + end, back to start if($cValue > $cEnd) { $cValue = $cStart; } diff --git a/app/Models/OccupationModel.php b/app/Models/OccupationModel.php index 7e10747..dccb6a7 100644 --- a/app/Models/OccupationModel.php +++ b/app/Models/OccupationModel.php @@ -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']; diff --git a/app/Models/PatVisitModel.php b/app/Models/PatVisitModel.php index befa875..46a6fa4 100644 --- a/app/Models/PatVisitModel.php +++ b/app/Models/PatVisitModel.php @@ -2,19 +2,19 @@ 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 $createdField = 'CreateDate'; - + protected $useTimestamps = false; + protected $createdField = 'CreateDate'; + protected $updatedField = ''; + protected $beforeInsert = ['normalizeDatesToUTC']; protected $beforeUpdate = ['normalizeDatesToUTC']; protected $afterFind = ['convertDatesToUTCISO']; @@ -43,18 +43,15 @@ 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); + $input['PVID'] = $this->visnum_prefix .$counter->use(2); } $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']; diff --git a/app/Models/PatientModel.php b/app/Models/PatientModel.php index 4b70c56..6346497 100644 --- a/app/Models/PatientModel.php +++ b/app/Models/PatientModel.php @@ -1,11 +1,9 @@