diff --git a/app/Controllers/Contact.php b/app/Controllers/Contact.php index 65bd62a..6a23034 100644 --- a/app/Controllers/Contact.php +++ b/app/Controllers/Contact.php @@ -20,7 +20,7 @@ class Contact extends Controller { public function index() { $model = new ContactModel(); - $rows = $model->getContactsWithDetail(); + $rows = $model->getContacts(); if (empty($rows)) { return $this->respond([ diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index c4f3573..fc43d8c 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -3,13 +3,17 @@ 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; + protected $db; + protected $visnum_prefix; + public function __construct() { $this->db = \Config\Database::connect(); $this->visnum_prefix = "DV"; @@ -17,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 1dd712d..d0661ca 100644 --- a/app/Models/ContactModel.php +++ b/app/Models/ContactModel.php @@ -18,32 +18,40 @@ class ContactModel extends Model { return $rows; } + public function getContacts() { + $rows = $this->select("ContactID, NameFirst, NameLast, Title, Initial, Specialty")->get()->getResultArray(); + return $rows; + } + public function getContactWithDetail($ContactID) { $rows = $this->where('contact.ContactID', $ContactID)->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->get()->getResultArray(); - $contact = [ - 'ContactID' => $rows[0]['ContactID'], - 'NameFirst' => $rows[0]['NameFirst'] ?? null, - 'NameLast' => $rows[0]['NameLast'] ?? null, - 'Title' => $rows[0]['Title'] ?? null, - 'Initial' => $rows[0]['Initial'] ?? null, - 'Birthdate' => $rows[0]['Birthdate'] ?? null, - 'EmailAddress1' => $rows[0]['EmailAddress1'] ?? null, - 'EmailAddress2' => $rows[0]['EmailAddress2'] ?? null, - 'Phone' => $rows[0]['Phone'] ?? null, - 'MobilePhone1' => $rows[0]['MobilePhone1'] ?? null, - 'MobilePhone2' => $rows[0]['MobilePhone2'] ?? null, - 'Specialty' => $rows[0]['Specialty'] ?? null, - 'SubSpecialty' => $rows[0]['SubSpecialty'] ?? null, - 'Details' => [] - ]; - + $contact = []; + foreach ($rows as $row) { + if(empty($contact['NameFirst'])) { + $contact = [ + 'ContactID' => $ContactID, + 'NameFirst' => $row['NameFirst'] ?? null, + 'NameLast' => $row['NameLast'] ?? null, + 'Title' => $row['Title'] ?? null, + 'Initial' => $row['Initial'] ?? null, + 'Birthdate' => $row['Birthdate'] ?? null, + 'EmailAddress1' => $row['EmailAddress1'] ?? null, + 'EmailAddress2' => $row['EmailAddress2'] ?? null, + 'Phone' => $row['Phone'] ?? null, + 'MobilePhone1' => $row['MobilePhone1'] ?? null, + 'MobilePhone2' => $row['MobilePhone2'] ?? null, + 'Specialty' => $row['Specialty'] ?? null, + 'SubSpecialty' => $row['SubSpecialty'] ?? null, + 'Details' => [] + ]; + } if (!empty($row['ContactDetID'])) { $contact['Details'][] = [ '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, @@ -52,7 +60,7 @@ class ContactModel extends Model { ]; } } - + return $contact; } 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; + } + +}