This commit is contained in:
mikael-zakaria 2025-09-26 14:11:32 +07:00
commit c73d09fe52
6 changed files with 81 additions and 32 deletions

View File

@ -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([

View File

@ -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',

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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;
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class PatVisitModel extends Model {
protected $table = 'patvisit';
protected $primaryKey = 'InternalPVID';
protected $allowedFields = ['PVID', 'InternalPID', 'EpisodeID', 'EndDate'];
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'CreateDate';
protected $deletedField = 'EndDate';
public function show($PVID) {
$rows = $this->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;
}
}