diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a9e8df8..bc30f0b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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'); diff --git a/app/Controllers/Organization/Department.php b/app/Controllers/Organization/Department.php new file mode 100644 index 0000000..178da36 --- /dev/null +++ b/app/Controllers/Organization/Department.php @@ -0,0 +1,72 @@ +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()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Discipline.php b/app/Controllers/Organization/Discipline.php new file mode 100644 index 0000000..56a429a --- /dev/null +++ b/app/Controllers/Organization/Discipline.php @@ -0,0 +1,78 @@ +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() ); + } + */ + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Workbench.php b/app/Controllers/Organization/Workbench.php new file mode 100644 index 0000000..60b05d4 --- /dev/null +++ b/app/Controllers/Organization/Workbench.php @@ -0,0 +1,72 @@ +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()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Workstation.php b/app/Controllers/Organization/Workstation.php new file mode 100644 index 0000000..2b5aaaf --- /dev/null +++ b/app/Controllers/Organization/Workstation.php @@ -0,0 +1,72 @@ +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()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index ccb813f..f0916da 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -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()); + } + } } \ No newline at end of file diff --git a/app/Controllers/Test/ValueSetDef.php b/app/Controllers/Test/ValueSetDef.php new file mode 100644 index 0000000..bea445c --- /dev/null +++ b/app/Controllers/Test/ValueSetDef.php @@ -0,0 +1,69 @@ +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()); + } + } + +} \ No newline at end of file diff --git a/app/Database/Migrations/2025-10-11-100001_Test_Management copy.php b/app/Database/Migrations/2025-10-11-100001_Test.php similarity index 100% rename from app/Database/Migrations/2025-10-11-100001_Test_Management copy.php rename to app/Database/Migrations/2025-10-11-100001_Test.php diff --git a/app/Database/Migrations/2025-10-12-100001_Ref_Range.php b/app/Database/Migrations/2025-10-12-100001_Ref_Range.php index 6818568..9c98e6d 100644 --- a/app/Database/Migrations/2025-10-12-100001_Ref_Range.php +++ b/app/Database/Migrations/2025-10-12-100001_Ref_Range.php @@ -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([ diff --git a/app/Database/Migrations/2025-10-22-100001_Zones_CRM.php b/app/Database/Migrations/2025-10-22-100001_CRM_Zones.php similarity index 94% rename from app/Database/Migrations/2025-10-22-100001_Zones_CRM.php rename to app/Database/Migrations/2025-10-22-100001_CRM_Zones.php index 051d1f3..7029497 100644 --- a/app/Database/Migrations/2025-10-22-100001_Zones_CRM.php +++ b/app/Database/Migrations/2025-10-22-100001_CRM_Zones.php @@ -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([ diff --git a/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php new file mode 100644 index 0000000..a0d167e --- /dev/null +++ b/app/Database/Migrations/2025-10-23-100001_CRM_Organizations.php @@ -0,0 +1,37 @@ +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'); + } +} \ No newline at end of file diff --git a/app/Database/Migrations/2025-10-23-110105_Organization.php b/app/Database/Migrations/2025-10-23-110105_Organization.php new file mode 100644 index 0000000..34fe3ba --- /dev/null +++ b/app/Database/Migrations/2025-10-23-110105_Organization.php @@ -0,0 +1,64 @@ +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); + } +} diff --git a/app/Database/Migrations/2025-10-29-100201_Equipment.php b/app/Database/Migrations/2025-10-29-100201_Equipment.php new file mode 100644 index 0000000..1ff7bd1 --- /dev/null +++ b/app/Database/Migrations/2025-10-29-100201_Equipment.php @@ -0,0 +1,65 @@ +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); + } +} diff --git a/app/Models/Organization/DepartmentModel.php b/app/Models/Organization/DepartmentModel.php new file mode 100644 index 0000000..30cb2fb --- /dev/null +++ b/app/Models/Organization/DepartmentModel.php @@ -0,0 +1,16 @@ +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; diff --git a/app/Models/RefRange/RefNumModel.php b/app/Models/RefRange/RefNumModel.php new file mode 100644 index 0000000..6bc1e82 --- /dev/null +++ b/app/Models/RefRange/RefNumModel.php @@ -0,0 +1,20 @@ +