add specimen

This commit is contained in:
mahdahar 2025-10-14 10:48:20 +07:00
parent b5939e1cc9
commit 677504e225
5 changed files with 129 additions and 2 deletions

View File

@ -85,3 +85,9 @@ $routes->get('/api/counter/(:num)', 'Counter::show/$1');
$routes->post('/api/counter', 'Counter::create');
$routes->patch('/api/counter', 'Counter::update');
$routes->delete('/api/counter', 'Counter::delete');
$routes->get('/api/containerdef/', 'Specimen\ContainerDef::index');
$routes->get('/api/containerdef/(:num)', 'Specimen\ContainerDef::show/$1');
$routes->post('/api/containerdef', 'Specimen\ContainerDef::create');
$routes->patch('/api/containerdef', 'Specimen\ContainerDef::update');
$routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete');

View File

@ -0,0 +1,65 @@
<?php
namespace App\Controllers\Specimen;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Specimen\ContainerDefModel;
class ContainerDef extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
protected $rules;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new ContainerDefModel();
$this->rules = [
'ConCode' => 'required|max_length[50]',
'ConName' => 'required|max_length[50]'
];
}
public function index() {
try {
$rows = $this->model->findAll();
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
return $this->failServerError('Exception : '.$e->getMessage());
}
}
public function show($ConDefID) {
try {
$rows = $this->model->find($ConDefID);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
return $this->failServerError('Exception : '.$e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$ConDefID = $this->model->insert($input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID created successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$ConDefID = $this->model->update($input['ConDefID'], $input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID updated successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
class SpecimenSeeder extends Seeder {
public function run() {
// containerdef
$data = [
['ConCode' => '1','ConName' => 'SST', 'ConDesc' =>'Evacuated blood collection tube, gel separator', 'Additive' => "Gel", 'ConClass' => '1'],
['ConCode' => '11','ConName' => 'Plain', 'ConDesc' =>'Evacuated blood collection tube, no additive/metal-free', 'Additive' => "None", 'ConClass' => '1'],
['ConCode' => '12','ConName' => '2Hr PP', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa 2 Jam PP', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
['ConCode' => '13','ConName' => 'Glukosa Sewaktu', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa Sewaktu', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
['ConCode' => '14','ConName' => 'GTT 30 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 30 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
['ConCode' => '15','ConName' => 'GTT 60 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 60 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
['ConCode' => '16','ConName' => 'GTT 120 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 90 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
['ConCode' => '20','ConName' => 'RST', 'ConDesc' =>'Evacuated blood collection tube, thrombin/clot activator/gel separator', 'Additive' => "Clot activator", 'ConClass' => '1'],
['ConCode' => '101','ConName' => 'EDTA - Hematologi', 'ConDesc' =>'Evacuated blood collection tube, K2EDTA/aprotinin', 'Additive' => "K2EDTA", 'ConClass' => '1'],
['ConCode' => '150','ConName' => 'Citrate - Koagulasi', 'ConDesc' =>'Evacuated blood collection tube, untuk koagulasi', 'Additive' => "Sodium citrate (substance)", 'ConClass' => '1'],
['ConCode' => '200','ConName' => 'Aliquot', 'ConDesc' =>'General specimen container, no additive, non-sterile. Untuk aliquot', 'Additive' => "", 'ConClass' => '1'],
['ConCode' => '290','ConName' => 'Pot Urin', 'ConDesc' =>'Non-sterile urine specimen container IVD', 'Additive' => "<null>", 'ConClass' => '1'],
['ConCode' => '295','ConName' => 'Urine Container', 'ConDesc' =>'Urine specimen container', 'Additive' => "<null>", 'ConClass' => '1'],
['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => "<null>", 'ConClass' => '2']
];
$this->db->table('containerdef')->insertBatch($data);
}
}

View File

@ -13,7 +13,8 @@ class PatientModel extends BaseUtcModel {
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'DelDate';
public function getPatients($filters = []) {
$qname = "LOWER(CONCAT_WS(' ', IFNULL(Prefix,''), IFNULL(NameFirst,''), IFNULL(NameMiddle,''), IFNULL(NameLast,''), IFNULL(NameMaiden,''), IFNULL(Suffix,'')))";

View File

@ -0,0 +1,23 @@
<?php
namespace App\Models\Specimen;
use App\Models\BaseUtcModel;
class ContainerDefModel extends BaseUtcModel {
protected $table = 'containerdef';
protected $primaryKey = 'ConDefID';
protected $allowedFields = ['SiteID', 'ConCode', 'ConName', 'ConDesc', 'Additive', 'ConClass', 'Color', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
protected $beforeInsert = ['normalizeDatesToUTC'];
protected $beforeUpdate = ['normalizeDatesToUTC'];
protected $afterFind = ['convertDatesToUTCISO'];
protected $afterInsert = ['convertDatesToUTCISO'];
protected $afterUpdate = ['convertDatesToUTCISO'];
}