This commit is contained in:
mikael-zakaria 2025-11-04 09:42:15 +07:00
commit ff1b3e0e9b
27 changed files with 874 additions and 51 deletions

View File

@ -36,6 +36,8 @@ $routes->get('/api/patvisit/patient/(:num)', 'PatVisit::showByPatient/$1');
$routes->get('/api/patvisit/(:any)', 'PatVisit::show/$1');
$routes->delete('/api/patvisit', 'PatVisit::delete');
$routes->patch('/api/patvisit', 'PatVisit::update');
$routes->post('/api/patvisitadt', 'PatVisit::createADT');
$routes->patch('/api/patvisitadt', 'PatVisit::updateADT');
$routes->get('/api/race', 'Race::index');
$routes->get('/api/race/(:num)', 'Race::show/$1');
@ -92,6 +94,32 @@ $routes->post('/api/containerdef', 'Specimen\ContainerDef::create');
$routes->patch('/api/containerdef', 'Specimen\ContainerDef::update');
$routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete');
//organization
// discipline
$routes->get('/api/organization/discipline/', 'Organization\Discipline::index');
$routes->get('/api/organization/discipline/(:num)', 'Organization\Discipline::show/$1');
$routes->post('/api/organization/discipline', 'Organization\Discipline::create');
$routes->patch('/api/organization/discipline', 'Organization\Discipline::update');
$routes->delete('/api/organization/discipline', 'Organization\Discipline::delete');
// department
$routes->get('/api/organization/department/', 'Organization\Department::index');
$routes->get('/api/organization/department/(:num)', 'Organization\Department::show/$1');
$routes->post('/api/organization/department', 'Organization\Department::create');
$routes->patch('/api/organization/department', 'Organization\Department::update');
$routes->delete('/api/organization/department', 'Organization\Department::delete');
// workstation
$routes->get('/api/organization/workstation/', 'Organization\Workstation::index');
$routes->get('/api/organization/workstation/(:num)', 'Organization\Workstation::show/$1');
$routes->post('/api/organization/workstation', 'Organization\Workstation::create');
$routes->patch('/api/organization/workstation', 'Organization\Workstation::update');
$routes->delete('/api/organization/workstation', 'Organization\Workstation::delete');
// workbench
$routes->get('/api/organization/workbench/', 'Organization\Workbench::index');
$routes->get('/api/organization/workbench/(:num)', 'Organization\Workbench::show/$1');
$routes->post('/api/organization/workbench', 'Organization\Workbench::create');
$routes->patch('/api/organization/workbench', 'Organization\Workbench::update');
$routes->delete('/api/organization/workbench', 'Organization\Workbench::delete');
// Khusus
$routes->get('/api/zones', 'Zones::index');
$routes->get('/api/zones/synchronize', 'Zones::synchronize');

View File

@ -0,0 +1,72 @@
<?php
namespace App\Controllers\Organization;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Organization\DepartmentModel;
class Department extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new DepartmentModel();
}
public function index() {
$rows = $this->model->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($DepartmentID = null) {
$rows = $this->model->where('DepartmentID', $DepartmentID)->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$id = $input["DepartmentID"];
if (!$id) { return $this->failValidationErrors('ID is required.'); }
$this->model->delete($id);
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$id = $this->model->insert($input,true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
$id = $input['DepartmentID'];
$this->model->update($id, $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace App\Controllers\Organization;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Organization\DisciplineModel;
class Discipline extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new DisciplineModel();
}
public function index() {
$rows = $this->model->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($DisciplineID = null) {
$rows = $this->model->where('DisciplineID', $DisciplineID)->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$id = $input["DisciplineID"];
if (!$id) { return $this->failValidationErrors('ID is required.'); }
$this->model->delete($id);
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$id = $this->model->insert($input,true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
$id = $input['DisciplineID'];
$this->model->update($id, $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
/*
try {
$id = $input['DisciplineID'];
$this->model->where('DisciplineID', $id)->update();
echo $this->model->getLastQuery();
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage() );
}
*/
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace App\Controllers\Organization;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Organization\WorkbenchModel;
class Workbench extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new WorkbenchModel();
}
public function index() {
$rows = $this->model->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($WorkbenchID = null) {
$rows = $this->model->where('WorkbenchID', $WorkbenchID)->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$id = $input["WorkbenchID"];
if (!$id) { return $this->failValidationErrors('ID is required.'); }
$this->model->delete($id);
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$id = $this->model->insert($input,true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
$id = $input['WorkbenchID'];
$this->model->update($id, $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace App\Controllers\Organization;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Organization\WorkstationModel;
class Workstation extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new WorkstationModel();
}
public function index() {
$rows = $this->model->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($WorkstationID = null) {
$rows = $this->model->where('WorkstationID', $WorkstationID)->findAll();
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$id = $input["WorkstationID"];
if (!$id) { return $this->failValidationErrors('ID is required.'); }
$this->model->delete($id);
return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$id = $this->model->insert($input,true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
$id = $input['WorkstationID'];
$this->model->update($id, $input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -4,6 +4,7 @@ namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\PatVisit\PatVisitModel;
use App\Models\PatVisit\PatVisitADTModel;
class PatVisit extends BaseController {
use ResponseTrait;
@ -17,11 +18,8 @@ class PatVisit extends BaseController {
public function show($PVID = null) {
try {
$row = $this->model->show($PVID);
if($row == []) {
$message = "data not found";
} else {
$message = "data found";
}
if($row == []) { $message = "data not found"; }
else { $message = "data found"; }
return $this->respond([ 'status' => 'success', 'message'=> $message, 'data' => $row ], 200);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage());
@ -42,7 +40,6 @@ class PatVisit extends BaseController {
public function update() {
$input = $this->request->getJSON(true);
try {
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
$data = $this->model->updatePatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
@ -54,7 +51,6 @@ class PatVisit extends BaseController {
public function create() {
$input = $this->request->getJSON(true);
try {
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
$data = $this->model->createPatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
} catch (\Exception $e) {
@ -62,4 +58,27 @@ class PatVisit extends BaseController {
}
}
public function createADT() {
$input = $this->request->getJSON(true);
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
$modelPVA = new PatVisitADTModel();
try {
$data = $modelPVA->insert($input, true);
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function updateADT() {
$input = $this->request->getJSON(true);
if (!$input["PVADTID"] || !is_numeric($input["PVADTID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
$modelPVA = new PatVisitADTModel();
try {
$data = $modelPVA->update($input['PVADTID'], $input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace App\Controllers\ValueSet;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Test\TestDefModel;
class TestDef extends BaseController {
use ResponseTrait;
protected $db;
protected $rules;
protected $model;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new TestDefModel;
}
public function index() {
$param = $this->request->getVar('param');
$rows = $this->model->getValueSetDefs($param);
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
public function show($VSetID = null) {
$rows = $this->model->find($VSetID);
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
public function create() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$VSetID = $this->model->insert($input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID created successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
$VSetID = $input["VID"];
if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); }
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); }
try {
$this->model->update($VSetID,$input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID updated successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function delete() {
$input = $this->request->getJSON(true);
$VSetID = $input['VSetID'];
if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); }
try {
$this->model->delete($VSetID);
return $this->respondDeleted(['status' => 'success', 'message' => "Data $VSetID deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -4,7 +4,7 @@ namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateTestsTable extends Migration {
class CreateRefRangesTable extends Migration {
public function up() {
$this->forge->addField([

View File

@ -4,7 +4,7 @@ namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateZonessTable extends Migration {
class CreateZonesTable extends Migration {
public function up() {
$this->forge->addField([

View File

@ -0,0 +1,37 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateCRMOrgTable extends Migration {
public function up() {
$this->forge->addField([
'accountid' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'parrentaccount' => ['type' => 'INT', 'null' => true],
'accountname' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false],
'accountnpwp' => ['type' => 'VARCHAR', 'constraint' => 5, 'null' => false],
'inital' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'zoneid' => ['type' => 'int', 'null' => true],
'zip' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'country' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'email_1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'email_2' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'phone' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'fax' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'createdate' => ['type' => 'datetime', 'null'=> true],
'enddate' => ['type' => 'datetime', 'null'=> true]
]);
$this->forge->addKey('accountid', true);
$this->forge->createTable('accounts');
}
public function down() {
$this->forge->dropTable('accounts');
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class Organization extends Migration {
public function up() {
$this->forge->addField([
'DisciplineID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DisciplineCode' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> false],
'DisciplineName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DisciplineID', true);
$this->forge->createTable('discipline');
$this->forge->addField([
'DepartmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DisciplineID' => ['type' => 'int', 'null'=> false],
'SiteID' => ['type' => 'int', 'null'=> false],
'DepartmentCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'DepartmentName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DepartmentID', true);
$this->forge->createTable('department');
$this->forge->addField([
'WorkstationID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DepartmentID' => ['type' => 'int', 'null'=> false],
'WorkstationCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'WorkstationName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Type' => ['type' => 'tinyint', 'null'=> true],
'LinkTo' => ['type' => 'int', 'null'=> true],
'Enable' => ['type' => 'bit', 'null'=> true],
'EquipmentID' => ['type' => 'varchar', 'constraint'=>'10', 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('WorkstationID', true);
$this->forge->createTable('workstation');
$this->forge->addField([
'WorkbenchID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DepartmentID' => ['type' => 'int', 'null'=> false],
'WorkbenchCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'WorkbenchName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('WorkbenchID', true);
$this->forge->createTable('workbench');
}
public function down() {
$this->forge->dropTable('discipline', true);
$this->forge->dropTable('department', true);
$this->forge->dropTable('workstation', true);
$this->forge->dropTable('workbench', true);
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class Equipment extends Migration {
public function up() {
$this->forge->addField([
'EquipmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DepartmentID' => ['type' => 'int', 'constraint'=> 10, 'null'=> false],
'InstrumentID' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'InstrumentName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Enable' => ['type' => 'bit', 'null'=> false],
'EquipmentRole' => ['type' => 'varchar', 'constraint' => 1, 'null'=> false],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('EquipmentID', true);
$this->forge->createTable('equipmentlist');
$this->forge->addField([
'InterfaceID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'InstrumentID' => ['type' => 'int', 'null'=> false],
'SiteID' => ['type' => 'int', 'null'=> true],
'InterfaceName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'InterfaceDesc' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Protocol' => ['type' => 'varchar', 'constraint'=> 50, 'null'=> true],
'IPAddress' => ['type' => 'varchar', 'constraint'=> 50, 'null'=> true],
'Port' => ['type' => 'varchar', 'constraint'=> 25, 'null'=> true],
'COM' => ['type' => 'varchar', 'constraint'=> 5, 'null'=> true],
'Baud' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true],
'Data' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true],
'Parity' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true],
'Stop' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('InterfaceID', true);
$this->forge->createTable('comparameters');
$this->forge->addField([
'EquipmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DeviceName' => ['type' => 'varchar', 'constraint' => 50,'null'=> false],
'Description' => ['type' => 'varchar', 'constraint' => 50,'null'=> false],
'SiteID' => ['type' => 'int', 'null'=> true],
'LocationID' => ['type' => 'int', 'null'=> true],
'DIDType' => ['type' => 'varchar', 'constraint'=>10, 'null'=> true],
'DID' => ['type' => 'varchar', 'constraint'=>100, 'null'=> true],
'MachineID' => ['type' => 'varchar', 'constraint'=>100, 'null'=> true],
'IPAddress' => ['type' => 'varchar', 'constraint'=>25, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('EquipmentID', true);
$this->forge->createTable('devicelist');
}
public function down() {
$this->forge->dropTable('equipmentlist', true);
$this->forge->dropTable('comparameters', true);
$this->forge->dropTable('devicelist', true);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Models\Organization;
use App\Models\BaseModel;
class DepartmentModel extends BaseModel {
protected $table = 'department';
protected $primaryKey = 'DepartmentID';
protected $allowedFields = ['DisciplineID', 'SiteID', 'DepartmentCode', 'DepartmentName', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Models\Organization;
use App\Models\BaseModel;
class DisciplineModel extends BaseModel {
protected $table = 'discipline';
protected $primaryKey = 'DisciplineID';
protected $allowedFields = ['DisciplineCode', 'DisciplineName', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Models\Organization;
use App\Models\BaseModel;
class WorkbenchModel extends BaseModel {
protected $table = 'workbench';
protected $primaryKey = 'WorkbenchID';
protected $allowedFields = ['DepartmentID', 'WorkbenchCode', 'WorkbenchName', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Models\Organization;
use App\Models\BaseModel;
class WorkstationModel extends BaseModel {
protected $table = 'workstation';
protected $primaryKey = 'WorkstationID';
protected $allowedFields = ['DepartmentID', 'WorkstationCode', 'WorkstationName', 'Type', 'LinkTo', 'Enable',
'EquipmentID', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
}

View File

@ -6,7 +6,7 @@ use App\Models\BaseModel;
class PatDiagModel extends BaseModel {
protected $table = 'patdiag';
protected $primaryKey = 'InternalPVID';
protected $allowedFields = ['InternalPID', 'DiagCode', 'Diagnosis', 'CreateDate', 'EndDate', 'ArchivedDate', 'DelDate'];
protected $allowedFields = ['InternalPVID','InternalPID', 'DiagCode', 'Diagnosis', 'CreateDate', 'EndDate', 'ArchivedDate', 'DelDate'];
protected $visnum_prefix;
protected $useTimestamps = true;

View File

@ -21,7 +21,7 @@ class PatVisitModel extends BaseModel {
public function show($PVID) {
$rows = $this->select("*, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate")
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID', 'left')
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID and patdiag.DelDate is null', 'left')
->join('patvisitadt', 'patvisitadt.InternalPVID=patvisit.InternalPVID', 'left')
->where('patvisit.PVID',$PVID)->findAll();
return $rows;
@ -29,84 +29,112 @@ class PatVisitModel extends BaseModel {
public function showByPatient($InternalPID) {
$rows = $this->select("*, patvisit.CreateDate as PVCreateDate, patdiag.CreateDate as PDCreateDate, patvisitadt.CreateDate as PVACreateDate")
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID', 'left')
->join('patvisitadt', 'patvisitadt.InternalPVID=patvisit.InternalPVID', 'left')
->join('patdiag', 'patdiag.InternalPVID=patvisit.InternalPVID and patdiag.DelDate is null', 'left')
->join('(SELECT a1.*
FROM patvisitadt a1
INNER JOIN (
SELECT InternalPVID, MAX(PVADTID) AS MaxID
FROM patvisitadt
GROUP BY InternalPVID
) a2 ON a1.InternalPVID = a2.InternalPVID AND a1.PVADTID = a2.MaxID
) AS patvisitadt',
'patvisitadt.InternalPVID = patvisit.InternalPVID',
'left')
->join('location', 'location.LocationID=patvisitadt.LocationID', 'left')
->where('patvisit.InternalPID',$InternalPID)->findAll();
return $rows;
}
public function createPatVisit($input) {
$db = \Config\Database::connect();
$db = $this->db;
$modelPD = new PatDiagModel();
$modelPVA = new PatVisitADTModel();
$db->transBegin();
try{
$db->transStart();
if (!isset($input['PVID']) || $input['PVID']=='') {
$modelCounter = new CounterModel();
$input['PVID'] = $this->visnum_prefix .$modelCounter->use(2);
}
$InternalPVID = $this->insert($input, true);
if(!empty($input['PatDiag'])) {
if($InternalPVID === false) { throw new \Exception("Failed to insert main PatVisit record."); }
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
$input['PatDiag']['InternalPVID'] = $InternalPVID;
//$db->table('patdiag')->insert($input['PatDiag']);
$modelPD->insert($input['PatDiag']);
$tmp = $modelPD->insert($input['PatDiag']);
if ($tmp === false) { throw new \Exception("Failed to insert PatDiag record."); }
}
if(!empty($input['PatVisitADT'])) {
if( !empty($input['PatVisitADT']) ) {
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
//$db->table('patvisitadt')->insert($input['PatVisitADT']);
$modelPVA->insert($input['PatVisitADT']);
$tmp = $modelPVA->insert($input['PatVisitADT']);
if ($tmp === false) {
throw new \Exception("Failed to insert PatVisitADT record.");
}
}
$db->transComplete();
$data = [ "PVID"=>$input['PVID'], "InternalPVID"=>$InternalPVID ];
return $data;
} catch (\Exception $e) {
$db->transRollback();
if ($db->transStatus() === FALSE) {
$db->transRollback();
return false;
} else {
$db->transCommit();
$data = [ "PVID" => $input['PVID'], "InternalPVID" => $InternalPVID ];
return $data;
}
} catch (\Exception $e) {
$db->transRollback();
throw $e;
}
}
}
public function updatePatVisit($input) {
$InternalPVID = $input['InternalPVID'];
$modelPD = new PatDiagModel();
$modelPVA = new PatVisitADTModel();
$db = $this->db;
$db->transBegin();
try{
$this->db->transStart();
$this->where('InternalPVID',$InternalPVID)->set($input)->update();
// patdiag
$exist = $this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->get()->getRow();
$exist = $modelPD->where('InternalPVID',$InternalPVID)->find();
if($exist) {
if(!empty($input['PatDiag'])) {
$input['PatDiag']['InternalPVID'] = $InternalPVID;
$this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update();
} else { $this->db->table('patdiag')->where('InternalPVID',$InternalPVID)->delete(); }
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
$tmp = $modelPD->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update();
} else { $tmp = $modelPD->delete($InternalPVID); }
} else {
if(!empty($input['PatDiag'])) {
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
$input['PatDiag']['InternalPVID'] = $InternalPVID;
$this->db->table('patdiag')->insert($input['PatDiag']);
$tmp = $modelPD->insert($input['PatDiag']);
}
}
if ($tmp === false) {
$error = $db->error();
throw new \Exception("Failed to update PatDiag record. ". $error['message']);
}
if(!empty($input['PatVisitADT'])) {
$adtList = $input['PatVisitADT'];
usort($adtList, fn($a, $b) => $a['sequence'] <=> $b['sequence']);
foreach ($adtList as $adt) {
$adt['InternalPVID'] = $InternalPVID;
$tmp = $modelPVA->insert($adt);
if ($tmp === false) {
$error = $db->error();
throw new \Exception("Failed to update PatVisitADT record. ". $error['message']);
}
}
}
// patvisitadt
$exist = $this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->get()->getRow();
if($exist) {
if(!empty($input['PatVisitADT'])) {
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
$this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->set($input['PatVisitADT'])->update();
} else { $this->db->table('patvisitadt')->where('InternalPVID',$InternalPVID)->delete(); }
if ($db->transStatus() === FALSE) {
$db->transRollback();
return false;
} else {
if(!empty($input['PatVisitADT'])) {
$input['PatVisitADT']['InternalPVID'] = $InternalPVID;
$this->db->table('patvisitadt')->insert($input['PatVisitADT']);
}
$db->transCommit();
$data = [ "PVID" => $input['PVID'], "InternalPVID" => $InternalPVID ];
return $data;
}
$this->db->transComplete();
return $input['PVID'];
} catch (\Exception $e) {
$this->db->transRollback();
throw $e;

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models\RefRange;
use App\Models\BaseModel;
class RefNumModel extends BaseModel {
protected $table = 'refnum';
protected $primaryKey = 'RefNumID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'SpcType', 'Sex', 'AgeStart', 'AgeEnd',
'CriticalLow', 'Low', 'High', 'CriticalHigh',
'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models\RefRange;
use App\Models\BaseModel;
class RefTHoldModel extends BaseModel {
protected $table = 'refthold';
protected $primaryKey = 'RefTHoldID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'SpcType', 'Sex', 'AgeStart', 'AgeEnd',
'Threshold', 'BelowTxt', 'AboveTxt', 'GrayzoneLow', 'GrayzoneHigh', 'GrayzoneTxt',
'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Models\RefRange;
use App\Models\BaseModel;
class RefVSetModel extends BaseModel {
protected $table = 'refvset';
protected $primaryKey = 'RefVSetID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'SpcType', 'Sex', 'AgeStart', 'AgeEnd',
'RefTxt', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Models\Test;
use App\Models\BaseModel;
class TestDefCalModel extends BaseModel {
protected $table = 'testdefcal';
protected $primaryKey = 'TestCalID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'FormulaCode', 'FormulaLang', 'FormulaInput',
'Unit1', 'Factor', 'Unit2', 'Decimal' ,'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Models\Test;
use App\Models\BaseModel;
class TestDefModel extends BaseModel {
protected $table = 'testdef';
protected $primaryKey = 'TestID';
protected $allowedFields = ['ParentTest', 'TestCode', 'TestName', 'Description', 'DisciplineID',
'Method', 'Seq', 'CountStat', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Models\Test;
use App\Models\BaseModel;
class TestDefSiteModel extends BaseModel {
protected $table = 'testdefsite';
protected $primaryKey = 'TestSiteID';
protected $allowedFields = ['SiteID', 'TestSiteCode', 'TestSiteName', 'Type', 'Description', 'SeqScr', 'SeqRpt', 'IndentLeft',
'VisibleScr', 'VisibleRpt', 'CountStat', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models\Test;
use App\Models\BaseModel;
class TestDefTechModel extends BaseModel {
protected $table = 'testdeftech';
protected $primaryKey = 'TestTechID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'DisciplineID', 'DepartmentID', 'WorkstationID', 'EquipmentID', 'VSet', 'SpcType',
'ReqQty', 'ReqQtyUnit', 'Unit1', 'Factor', 'Unit2', 'Decimal', 'CollReq', 'ConDefID', 'TestTechCode', 'TestTechAbb', 'TestTechName',
'Method', 'ExpectedTAT', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Models\Test;
use App\Models\BaseModel;
class TestGrpModel extends BaseModel {
protected $table = 'testgrp';
protected $primaryKey = 'TestGrpID';
protected $allowedFields = ['SiteID', 'TestSiteID', 'Member', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = "EndDate";
}