add location.loctype

This commit is contained in:
mahdahar 2025-09-19 15:22:25 +07:00
parent ee5fb52cca
commit f32fe26ba4
9 changed files with 299 additions and 227 deletions

View File

@ -10,12 +10,6 @@ $routes->options('(:any)', function() {
});
$routes->get('/', 'Home::index');
//PUNYA GUS INI TEMP
$routes->get('/api/v1/emr/lab/list-new', 'NUHATEMP::index');
$routes->post('/api/v1/emr/lab/insert', 'NUHATEMP::create');
$routes->post('/api/v1/emr/lab/update-validasi', 'NUHATEMP::update');
$routes->post('/api/v1/emr/lab/detail', 'NUHATEMP::detail');
$routes->group('api', ['filter' => 'auth'], function($routes) {
// $routes->get('coba-auth', 'Auth::coba');
@ -57,6 +51,7 @@ $routes->delete('/api/location', 'Patient::delete');
$routes->get('/api/valueset', 'ValueSet::index');
$routes->get('/api/valueset/(:num)', 'ValueSet::show/$1');
$routes->get('/api/valueset/valuesetdef/(:num)', 'ValueSet::showByValueSetDef/$1');
$routes->post('/api/valueset', 'ValueSet::create');
$routes->patch('/api/valueset', 'ValueSet::update');
$routes->delete('/api/valueset', 'ValueSet::delete');

View File

@ -17,9 +17,10 @@ class Location extends Controller {
}
public function index() {
$rows = $this->db->table('location')
->select("location.LocationID, LocCode, Parent, LocFull, Description, Street1, Street2, City, Province, PostCode, GeoLocationSystem, GeoLocationData")
->join("locationaddress", "location.LocationID=locationaddress.LocationID")
$rows = $this->db->table('location l')
->select("l.LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ")
->join("locationaddress la", "l.LocationID=la.LocationID")
->join("valueset v", "v.VSetID=12 and v.VValue=l.LocType")
->get()->getRowArray();
if (empty($rows)) {
@ -38,16 +39,17 @@ class Location extends Controller {
}
public function show($LocationID = null) {
$rows = $this->db->table('location')
->select("location.LocationID, LocCode, Parent, LocFull, Description, Street1, Street2, City, Province, PostCode, GeoLocationSystem, GeoLocationData")
->join("locationaddress", "location.LocationID=locationaddress.LocationID")
->where('location.LocationID', (int) $LocationID)
$rows = $this->db->table('location l')
->select("l.*, la.*, v.*")
->join("locationaddress la", "l.LocationID=la.LocationID")
->join("valueset v", "v.VSetID=12 and v.VValue=l.loctype")
->where('l.LocationID', (int) $LocationID)
->get()->getResultArray();
if (empty($rows)) {
return $this->respond([
'status' => 'success',
'message' => "Patient with ID $LocationID not found.",
'message' => "Data not found.",
'data' => [],
], 200);
}

View File

@ -1,197 +0,0 @@
<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\Database\RawSql;
class NUHATEMP extends Controller {
use ResponseTrait;
public function __construct() {
$this->db = \Config\Database::connect();
}
// OK - Done
public function index() {
$valid_from = $this->request->getVar('valid_from');
$valid_to = $this->request->getVar('valid_to');
try {
// Data pasien ditemukan dan mengembalikan - success 200
return $this->respond([
"response" => [
"list" => [
[
"tgl" => "2023-07-31T00:12:00Z",
"no_lab" => 153304,
"no_rm" => "001063898",
"nama" => "WAHYUDI",
"tgl_lahir" => "1976-05-15T00:00:00Z",
"jenis_kelamin" => "Laki-laki",
"umur" => "47 tahun, 2 bulan, 15 hari",
"alamat" => "KP GEBANG RT 01/03 SANGIANG JAYA PERIUK",
"ruang" => "",
"kelas" => "",
"status" => "BPJS",
"dokter_pengirim" => "dr. Arie Asnafi, Sp.U",
"jenis_lab" => "pk",
"lis_id" => "2307310001",
"id_ruangan" => "1",
"nama_ruangan" => "Flamboyan",
"id_asuransi" => "2",
"nama_asuransi" => "BPJS KESEHATAN",
"cito" => false,
"list_test" => [
[
"detail_id" => 265833,
"no_lab" => 153304,
"test_id" => 72,
"nama_test" => "Glukosa Sewaktu",
"jenis_lab" => "pk",
"jenis_test" => "t",
"detail_test" => []
]
]
],
[
"tgl" => "2023-07-31T00:53:00Z",
"no_lab" => 153307,
"no_rm" => "001301669",
"nama" => "RAFFASYAH ALKHALIFI PUTRA H",
"tgl_lahir" => "2017-11-28T00:00:00Z",
"jenis_kelamin" => "Laki-laki",
"umur" => "5 tahun, 8 bulan, 2 hari",
"alamat" => "JL TARUMANEGARA I / 4 RT 04 RW 022",
"ruang" => "",
"kelas" => "",
"status" => "BPJS",
"dokter_pengirim" => "dr. Arif Budiman, Sp.A (K)",
"jenis_lab" => "pk",
"lis_id" => "2307310004",
"id_ruangan" => "1",
"nama_ruangan" => "Flamboyan",
"id_asuransi" => "2",
"nama_asuransi" => "BPJS KESEHATAN",
"list_test" => [
[
"detail_id" => 265836,
"no_lab" => 153307,
"test_id" => 31,
"nama_test" => "Darah Lengkap",
"jenis_lab" => "pk",
"jenis_test" => "p",
"detail_test" => [
["paket_id"=>31,"index"=>1,"spasi"=>"0","test_id"=>16,"nama_test"=>"Hemoglobin"],
["paket_id"=>31,"index"=>2,"spasi"=>"0","test_id"=>26,"nama_test"=>"Leukosit"],
["paket_id"=>31,"index"=>3,"spasi"=>"0","test_id"=>28,"nama_test"=>"Eritrosit"],
["paket_id"=>31,"index"=>4,"spasi"=>"0","test_id"=>29,"nama_test"=>"Hematokrit"],
["paket_id"=>31,"index"=>5,"spasi"=>"0","test_id"=>30,"nama_test"=>"Trombosit"],
["paket_id"=>31,"index"=>6,"spasi"=>"0","test_id"=>32,"nama_test"=>"Hitung Jenis"],
["paket_id"=>31,"index"=>7,"spasi"=>"0","test_id"=>33,"nama_test"=>"Eosinofil"],
["paket_id"=>31,"index"=>8,"spasi"=>"0","test_id"=>34,"nama_test"=>"Basofil"],
["paket_id"=>31,"index"=>9,"spasi"=>"0","test_id"=>35,"nama_test"=>"Netrofil Batang"],
["paket_id"=>31,"index"=>10,"spasi"=>"0","test_id"=>36,"nama_test"=>"Netrofil Segmen"],
["paket_id"=>31,"index"=>11,"spasi"=>"0","test_id"=>37,"nama_test"=>"Limfosit"],
["paket_id"=>31,"index"=>12,"spasi"=>"0","test_id"=>38,"nama_test"=>"Monosit"],
["paket_id"=>31,"index"=>13,"spasi"=>"0","test_id"=>39,"nama_test"=>"Laju Endap Darah"]
]
]
]
]
]
],
"metadata" => [
"message" => "Ok",
"code" => 200
]
], 200);
} catch (\Exception $e) {
// Error Server Mengembalikan 500
return $this->failServerError('Something went wrong.'.$e->getMessage());
}
}
// OK - Done
public function create() {
try {
// Data pasien ditemukan dan mengembalikan - success 200
return $this->respond([
"message"=> "Ok",
'status' => 200
], 200);
} catch (\Exception $e) {
// Error Server Mengembalikan 500
return $this->failServerError('Something went wrong.'.$e->getMessage());
}
}
// OK - Done
public function update() {
try {
// Data pasien ditemukan dan mengembalikan - success 200
return $this->respond([
"message"=> "Ok",
'status' => 200
], 200);
} catch (\Exception $e) {
// Error Server Mengembalikan 500
return $this->failServerError('Something went wrong.'.$e->getMessage());
}
}
// OK - Done
public function detail() {
try {
// Data pasien ditemukan dan mengembalikan - success 200
return $this->respond([
"response" => [
"tgl" => "2024-03-08T09:37:00Z",
"no_lab" => 3021,
"no_rm" => "000264395",
"nama" => "CANDY RAMADONA, AN",
"tgl_lahir" => "2007-09-02",
"jenis_kelamin" => "Perempuan",
"umur" => "2023 tahun, 2 bulan, 7 hari",
"alamat" => "PERUM PONDOK JAGUNG BLOK AC.45 001/004",
"ruang" => "",
"kelas" => "",
"status" => "ASURANSI SINAR MAS, PT",
"id_dokter_pengirim" => 2,
"dokter_pengirim" => "dr.Mila Agustia.Sp.A",
"jenis_lab" => "pk",
"lis_id" => "240308208",
"id_ruangan" => "1",
"nama_ruangan" => "DAMAR",
"id_asuransi" => "118",
"nama_asuransi" => "ASURANSI SINAR MAS, PT",
"cito" => false,
"list_test" => [
[
"detail_id" => 4981,
"no_lab" => 3021,
"test_id" => 145,
"nama_test" => "Urin Lengkap (Paket)",
"jenis_lab" => "",
"jenis_test" => "",
"detail_test" => null
]
]
],
"metadata" => [
"message" => "Ok",
"code" => 200
]
], 200);
} catch (\Exception $e) {
// Error Server Mengembalikan 500
return $this->failServerError('Something went wrong.'.$e->getMessage());
}
}
}

View File

@ -0,0 +1,217 @@
<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\Database\RawSql;
class OrderTest extends Controller {
use ResponseTrait;
public function __construct() {
$this->db = \Config\Database::connect();
$this->rulesOrderTest = [
'NameFirst' => 'required'
];
}
public function index() {
$rows = $this->db->table('ordertest')->select("*")->get()->getRowArray();
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($OrderID = null) {
$row=$this->db->table('ordertest')->select("*")->where('OrderID=', $OrderID)->get()->getRowArray();
if (empty($row)) {
return $this->respond([
'status' => 'success',
'message' => "Data not found.",
'data' => [],
], 200);
}
return $this->respond([
'status' => 'success',
'message'=> "Data fetched successfully",
'data' => $row,
], 200);
}
public function create() {
try {
$input = $this->request->getJSON(true);
// Prepare data
$dataOrderTest = $this->prepareOrderTestData($input);
$dataOrderCom = $this->prepareOrderComData($input);
$dataOrderAtt = $this->prepareOrderAttData($input);
if (!$this->validateData($dataLocation, $this->rules)) {
return $this->failValidationErrors($this->validator->getErrors());
}
// Start transaction
$this->db->transStart();
// Insert location
$this->db->table('location')->insert($dataLocation);
$newLocationID = $this->db->insertID();
// Insert address if available
if (!empty($dataLocationAddress)) {
$dataLocationAddress['LocationID'] = $newLocationID;
$this->db->table('locationaddress')->insert($dataLocationAddress);
}
// Complete transaction
$this->db->transComplete();
if ($this->db->transStatus() === false) {
$dbError = $this->db->error();
return $this->failServerError(
'Failed to create location data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
);
}
return $this->respondCreated([
'status' => 'success',
'message' => 'Location created successfully',
'data' => $dataLocation,
], 201);
} catch (\Throwable $e) {
// Ensure rollback if something goes wrong
if ($this->db->transStatus() !== false) {
$this->db->transRollback();
}
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
try {
$input = $this->request->getJSON(true);
// Prepare data
$dataLocation = $this->prepareLocationData($input);
$dataLocationAddress = $this->prepareLocationAddressData($input);
if (!$this->validateData($dataLocation, $this->rules)) {
return $this->failValidationErrors( $this->validator->getErrors());
}
// Start transaction
$this->db->transStart();
// Insert location
$this->db->table('location')->where('LocationID', $dataLocation["LocationID"])->update($dataLocation);
// Insert address if available
if (!empty($dataLocationAddress)) {
$dataLocationAddress['LocationID'] = $input["LocationID"];
$this->db->table('locationaddress')->upsert($dataLocationAddress);
}
// Complete transaction
$this->db->transComplete();
if ($this->db->transStatus() === false) {
$dbError = $this->db->error();
return $this->failServerError(
'Failed to update location data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
);
}
return $this->respondCreated([
'status' => 'success',
'message' => 'Location updated successfully',
'data' => $dataLocation,
], 201);
} catch (\Throwable $e) {
// Ensure rollback if something goes wrong
if ($this->db->transStatus() !== false) {
$this->db->transRollback();
}
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function delete() {
try {
$input = $this->request->getJSON(true);
$LocationID = $input["LocationID"];
if (!$LocationID) {
return $this->failValidationError('LocationID is required.');
}
$location = $this->db->table('location')->where('LocationID', $LocationID)->get()->getRow();
if (!$location) {
return $this->failNotFound("LocationID with {$LocationID} not found.");
}
$this->db->table('location')->where('LocationID', $LocationID)->update(['DelDate' => NOW()]);
return $this->respondDeleted([
'status' => 'success',
'message' => "Location with {$LocationID} deleted successfully."
]);
} catch (\Throwable $e) {
// Ensure rollback if something goes wrong
if ($this->db->transStatus() !== false) {
$this->db->transRollback();
}
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
private function prepareLocationData(array $input): array {
$LinkTo = null;
if (!empty($input['LinkTo'])) {
$ids = array_column($input['LinkTo'], 'InternalPID');
$LinkTo = implode(',', $ids);
}
$data = [
"LocCode" => $input['LocCode'] ?? null,
"Parent" => $input['Parent'] ?? null,
"LocFull" => $input['LocFull'] ?? null,
"Description" => $input['Description'] ?? null,
];
if(!empty($input["LocationID"])) { $data["LocationID"] = $input["LocationID"]; }
return $data;
}
private function prepareLocationAddressData(array $input): array {
$data = [
"LocationID" => $input['LocationID'] ?? null,
"Street1" => $input['Street1'] ?? null,
"Street2" => $input['Street2'] ?? null,
"City" => $input['City'] ?? null,
"Province" => $input['Province'] ?? null,
"PostCode" => $input['PostCode'] ?? null,
"GeoLocationSystem" => $input['GeoLocationSystem'] ?? null,
"GeoLocationData" => $input['GeoLocationData'] ?? null,
];
return $data;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\Database\RawSql;
class PatientAdmission extends Controller {
use ResponseTrait;
public function __construct() {
$this->db = \Config\Database::connect();
}
private function preparePatVisitData(array $input): array {
$data = [
"PVID" => $input['PVID'] ?? null,
"InternalPID" => $input['InternalPID'] ?? null,
"EpisodeID" => $input['EpisodeID'] ?? null
];
if(!empty($input['InternalPVID'])) { $data["InternalPVID"] = $input["InternalPVID"]; }
return $data;
}
private function preparePatDiagData(array $input): array {
$data = [
"InternalPVID" => $input['InternalPVID'] ?? null,
"InternalPID" => $input['InternalPID'] ?? null,
"DiagCode" => $input['DiagCode'] ?? null,
"Diagnosis" => $input['Diagnosis'] ?? null
];
return $data;
}
private function preparePatVisitAdtData(array $input): array {
$data = [
"InternalPVID" => $input['InternalPVID'] ?? null,
"InternalPID" => $input['InternalPID'] ?? null,
"DiagCode" => $input['DiagCode'] ?? null,
"Diagnosis" => $input['Diagnosis'] ?? null
];
return $data;
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\Database\RawSql;
class Patient_Admission extends Controller {
use ResponseTrait;
public function __construct() {
$this->db = \Config\Database::connect();
$this->now = date('Y-m-d H:i:s');
}
}

View File

@ -57,6 +57,27 @@ class ValueSet extends Controller {
], 200);
}
public function showByValueSetDef($VSetID = null) {
$rows = $this->db->table('valueset')
->select("*")
->where('VSetID', (int) $VSetID)
->get()->getResultArray();
if (empty($rows)) {
return $this->respond([
'status' => 'success',
'message' => "ValueSet not found.",
'data' => [],
], 200);
}
return $this->respond([
'status' => 'success',
'message'=> "Data fetched successfully",
'data' => $rows,
], 200);
}
public function create() {
try {
$input = $this->request->getJSON(true);

View File

@ -14,6 +14,7 @@ class CreateLocationTable extends Migration {
'Parent' => ['type' => 'INT', 'null' => true],
'LocFull' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Description' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'LocType' => ['type' => 'varchar', 'constraint' => 11, 'null' => true],
'EndDate' => ['type' => 'DATETIME', 'null' => true]
]);
$this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP');

View File

@ -8,7 +8,7 @@ class DummySeeder extends Seeder {
public function run() {
// location
$data = [
['LocationID'=>1, 'LocCode'=>'QLOC', 'LocFull'=>'Dummy Location', 'Description'=>'Location made for dummy testing' ]
['LocationID'=>1, 'LocCode'=>'QLOC', 'LocFull'=>'Dummy Location', 'LocType'=>'ROOM', 'Description'=>'Location made for dummy testing' ]
];
$this->db->table('location')->insertBatch($data);