From 4750f2947b1bd68ba5aba36e46d2b6fdb3fba533 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Wed, 15 Oct 2025 19:14:13 +0700 Subject: [PATCH] change datetime to utc using CI4 find findall --- app/Models/BaseModel.php | 2 +- app/Models/Contact/ContactDetailModel.php | 6 ------ app/Models/Contact/ContactModel.php | 15 ++++++--------- app/Models/CounterModel.php | 3 ++- app/Models/Location/LocationModel.php | 13 +++---------- app/Models/PatVisitModel.php | 13 ++++--------- app/Models/Specimen/ContainerDefModel.php | 2 +- app/Models/ValueSet/ValueSetDefModel.php | 15 ++++----------- app/Models/ValueSet/ValueSetModel.php | 13 ++----------- 9 files changed, 23 insertions(+), 59 deletions(-) diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 9e3ba00..35b68d8 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -7,7 +7,7 @@ use CodeIgniter\Model; class BaseModel extends Model { protected $beforeInsert = ['normalizeDatesToUTC']; protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; + protected $afterFind = ['convertDatesToUTCISO']; protected $afterInsert = ['convertDatesToUTCISO']; protected $afterUpdate = ['convertDatesToUTCISO']; diff --git a/app/Models/Contact/ContactDetailModel.php b/app/Models/Contact/ContactDetailModel.php index 5a94f5f..215d7b7 100644 --- a/app/Models/Contact/ContactDetailModel.php +++ b/app/Models/Contact/ContactDetailModel.php @@ -12,12 +12,6 @@ class ContactDetailModel extends BaseModel { protected $useTimestamps = true; protected $createdField = 'ContactStartDate'; protected $updatedField = ''; - - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; public function syncDetails(int $ContactID, array $contactDetails) { try { diff --git a/app/Models/Contact/ContactModel.php b/app/Models/Contact/ContactModel.php index 41acb30..d2b2646 100644 --- a/app/Models/Contact/ContactModel.php +++ b/app/Models/Contact/ContactModel.php @@ -7,17 +7,14 @@ use App\Models\BaseModel; class ContactModel extends BaseModel { protected $table = 'contact'; 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 $updatedField = ''; - - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; + protected $useSoftDeletes = true; + protected $deletedField = "EndDate"; public function getContactsWithDetail() { $rows = $this->select("contact.ContactID, cd.SiteID, cd.ContactCode, NameFirst, NameLast, Specialty") @@ -37,7 +34,7 @@ class ContactModel extends BaseModel { } public function getContactWithDetail($ContactID) { - $rows = $this->where('contact.ContactID', $ContactID)->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->get()->getResultArray(); + $rows = $this->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->where('contact.ContactID', $ContactID)->findAll(); $contact = []; foreach ($rows as $row) { diff --git a/app/Models/CounterModel.php b/app/Models/CounterModel.php index cd838da..c9de4d8 100644 --- a/app/Models/CounterModel.php +++ b/app/Models/CounterModel.php @@ -10,7 +10,8 @@ class CounterModel extends BaseModel { protected $useTimestamps = true; protected $createdField = "CreateDate"; protected $updatedField = ""; - protected $useSoftDeletes = "EndDate"; + protected $useSoftDeletes = true; + protected $deletedField = "EndDate"; public function use($CounterID) { $row = $this->where('CounterID',$CounterID)->get()->getResultArray(); diff --git a/app/Models/Location/LocationModel.php b/app/Models/Location/LocationModel.php index 1759c70..8455713 100644 --- a/app/Models/Location/LocationModel.php +++ b/app/Models/Location/LocationModel.php @@ -12,20 +12,13 @@ class LocationModel extends BaseModel { protected $updatedField = ''; protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; public function getLocations($LocCode, $LocName) { $sql = $this->select("LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ") ->join("valueset v", "v.VSetID=12 and v.VValue=location.loctype", 'left'); if($LocName != '') { $sql->like('LocFull', $LocName, 'both'); } if($LocCode != '') { $sql->like('LocCode', $LocCode, 'both'); } - $rows = $sql->get()->getResultArray(); - + $rows = $sql->findAll(); return $rows; } @@ -33,8 +26,8 @@ class LocationModel extends BaseModel { $rows = $this->select("location.*, la.*, v.*") ->join("locationaddress la", "location.LocationID=la.LocationID", "left") ->join("valueset v", "v.VSetID=12 and v.VValue=location.loctype", "left") - ->where('location.LocationID', (int) $LocationID) - ->get()->getResultArray(); + ->where('location.LocationID', (int) $LocationID)->findAll(); + //->get()->getResultArray(); return $rows; } diff --git a/app/Models/PatVisitModel.php b/app/Models/PatVisitModel.php index 4de7380..5e2401d 100644 --- a/app/Models/PatVisitModel.php +++ b/app/Models/PatVisitModel.php @@ -14,22 +14,17 @@ class PatVisitModel extends BaseModel { protected $useTimestamps = true; protected $createdField = 'CreateDate'; protected $updatedField = ''; - - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; + protected $useSoftDeletes = true; + protected $deletedField = 'EndDate'; public function __construct() { - $this->db = \Config\Database::connect(); $this->visnum_prefix = "DV"; } public function show($PVID) { $rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left') ->join('patvisitadt pva', 'pva.InternalPVID=patvisit.InternalPVID', 'left') - ->where('patvisit.PVID',$PVID)->get()->getResultArray(); + ->where('patvisit.PVID',$PVID)->findAll(); return $rows; } @@ -37,7 +32,7 @@ class PatVisitModel extends BaseModel { $rows = $this->join('patdiag pd', 'pd.InternalPVID=patvisit.InternalPVID', 'left') ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') ->join('location l', 'l.LocationID=pva.LocationID', 'left') - ->where('patvisit.InternalPID',$InternalPID)->get()->getResultArray(); + ->where('patvisit.InternalPID',$InternalPID)->findAll(); return $rows; } diff --git a/app/Models/Specimen/ContainerDefModel.php b/app/Models/Specimen/ContainerDefModel.php index 6415096..df83524 100644 --- a/app/Models/Specimen/ContainerDefModel.php +++ b/app/Models/Specimen/ContainerDefModel.php @@ -25,7 +25,7 @@ class ContainerDefModel extends BaseModel { ->join('valueset vscol', 'vscol.VID=containerdef.Color', 'left') ->join('valueset vscla', 'vscla.VID=containerdef.ConClass', 'left') ->join('valueset vsadd', 'vsadd.VID=containerdef.Additive', 'left') - ->where('ConDefID', $ConDefID)->get()->getResultArray(); + ->where('ConDefID', $ConDefID)->findAll(); return $rows; } } \ No newline at end of file diff --git a/app/Models/ValueSet/ValueSetDefModel.php b/app/Models/ValueSet/ValueSetDefModel.php index 65c84bd..e740c6f 100644 --- a/app/Models/ValueSet/ValueSetDefModel.php +++ b/app/Models/ValueSet/ValueSetDefModel.php @@ -14,19 +14,12 @@ class ValueSetDefModel extends BaseModel { protected $updatedField = ''; protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; -/* - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; -*/ + public function getValueSetDefs($param = null) { if ($param !== null) { - $builder = $this->builder(); - $builder->like('VSName', $param, 'both'); - $builder->orlike('VSDesc', $param, 'both'); - $rows = $builder->get()->getResultArray(); + $rows = $this->like('VSName', $param, 'both') + ->orlike('VSDesc', $param, 'both') + ->findAll(); } else { $rows = $this->findAll(); } diff --git a/app/Models/ValueSet/ValueSetModel.php b/app/Models/ValueSet/ValueSetModel.php index edb0a94..a4bd376 100644 --- a/app/Models/ValueSet/ValueSetModel.php +++ b/app/Models/ValueSet/ValueSetModel.php @@ -15,21 +15,12 @@ class ValueSetModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; - public function getValueSets($param = null) { if ($param !== null) { - $builder = $this->builder(); - $builder->groupStart() + $rows = $this->groupStart() ->like('VValue', $param, 'both') ->orlike('VDesc', $param, 'both') - ->groupEnd(); - $rows = $builder->get()->getResultArray(); - + ->groupEnd()->findAll(); return $rows; } else { return $this->findAll();