diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index b858d94..fc43d8c 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -3,9 +3,10 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use CodeIgniter\Database\RawSql; + use App\Models\CounterModel; +use App\Models\PatVisitModel; class PatVisit extends Controller { use ResponseTrait; @@ -20,10 +21,7 @@ class PatVisit extends Controller { public function show($PVID = null) { try { - $row = $this->db->table('patvisit pv') - ->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') - ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') - ->get()->getResultArray(); + $row = new PatVisitModel()->show($PVID); return $this->respond([ 'status' => 'success', diff --git a/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php b/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php index 51df1d9..ca1320d 100644 --- a/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php +++ b/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php @@ -13,11 +13,12 @@ class CreatePVTables extends Migration { 'PVID' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true], 'InternalPID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'EpisodeID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate'=> ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); - $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); + $this->forge->addKey('InternalPVID', true); $this->forge->addUniqueKey('PVID'); $this->forge->createTable('patvisit'); @@ -28,11 +29,11 @@ class CreatePVTables extends Migration { 'InternalPID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'DiagCode' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Diagnosis' => ['type' => 'TEXT', 'null' => true], + 'CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); - $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('InternalPVID', true); $this->forge->createTable('patdiag'); @@ -46,11 +47,11 @@ class CreatePVTables extends Migration { 'RefDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'AdmDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'CnsDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], + 'CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate'=> ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); - $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PVADTID', true); $this->forge->createTable('patvisitadt'); @@ -74,8 +75,8 @@ class CreatePVTables extends Migration { 'EventID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'ActivityID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Reason' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'LogDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP' ]); - $this->forge->addField('LogDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatVisLogID', true); $this->forge->createTable('patvisitlog'); } diff --git a/app/Database/Migrations/2025-09-12-011643_Contact.php b/app/Database/Migrations/2025-09-12-011643_Contact.php index 89746ff..503cc69 100644 --- a/app/Database/Migrations/2025-09-12-011643_Contact.php +++ b/app/Database/Migrations/2025-09-12-011643_Contact.php @@ -37,8 +37,8 @@ class CreateContactTable extends Migration { 'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], 'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], - 'ContactStartDate' => [ 'type' => 'DATE', 'null' => true ], - 'ContactEndDate' => [ 'type' => 'DATE', 'null' => true ], + 'ContactStartDate' => [ 'type' => 'DATETIME', 'null' => true ], + 'ContactEndDate' => [ 'type' => 'DATETIME', 'null' => true ], ]); $this->forge->addKey('ContactDetID', true); $this->forge->addUniqueKey(['SiteID','ContactID']); @@ -50,8 +50,8 @@ class CreateContactTable extends Migration { 'AbbTex' => [ 'type' => 'VARCHAR', 'constraint' => 5, 'null' => true ], 'FullText' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ], 'Description' => [ 'type' => 'TEXT', 'null' => true ], + 'CreateDate' => [ 'type' => 'DATETIME', 'null' => true ], ]); - $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('OccupationID', true); $this->forge->createTable('occupation'); } diff --git a/app/Models/ContactModel.php b/app/Models/ContactModel.php index 1364e87..d0661ca 100644 --- a/app/Models/ContactModel.php +++ b/app/Models/ContactModel.php @@ -51,7 +51,7 @@ class ContactModel extends Model { 'SiteID' => $row['SiteID'] ?? null, 'ContactDetID' => $row['ContactDetID'], 'ContactCode' => $row['ContactCode'] ?? null, - 'ContactEmail' => $row['DetailPhone'] ?? null, + 'ContactEmail' => $row['ContactEmail'] ?? null, 'OccupationID' => $row['OccupationID'] ?? null, 'JobTitle' => $row['JobTitle'] ?? null, 'Department' => $row['Department'] ?? null, diff --git a/app/Models/PatVisitModel.php b/app/Models/PatVisitModel.php new file mode 100644 index 0000000..e1caf3d --- /dev/null +++ b/app/Models/PatVisitModel.php @@ -0,0 +1,39 @@ +join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') + ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') + ->where('PVID',$PVID)->get()->getResultArray(); + return $rows; + } + + public function use($CounterID) { + $row = $this->where('CounterID',$CounterID)->get()->getResultArray(); + $cValue = $row[0]['CounterValue']; + $cStart = $row[0]['CounterStart']; + $cEnd = $row[0]['CounterEnd']; + $cReset = $row[0]['CounterReset']; + $cPad = strlen((string)$cEnd); + // next value > end, back to start + if($cValue > $cEnd) { $cValue = $cStart; } + $cnum = str_pad($cValue, $cPad, "0", STR_PAD_LEFT); + $cValue_next = $cValue+1; + $this->set('CounterValue', $cValue_next)->where('CounterID',$CounterID)->update(); + return $cnum; + } + +}