add pva cr

This commit is contained in:
mahdahar 2025-10-23 12:16:52 +07:00
parent 95e44415cb
commit a71a587573
3 changed files with 28 additions and 8 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->get('/api/patvisit/(:any)', 'PatVisit::show/$1');
$routes->delete('/api/patvisit', 'PatVisit::delete'); $routes->delete('/api/patvisit', 'PatVisit::delete');
$routes->patch('/api/patvisit', 'PatVisit::update'); $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', 'Race::index');
$routes->get('/api/race/(:num)', 'Race::show/$1'); $routes->get('/api/race/(:num)', 'Race::show/$1');

View File

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

@ -89,7 +89,6 @@ class PatVisitModel extends BaseModel {
// patdiag // patdiag
$exist = $modelPD->where('InternalPVID',$InternalPVID)->find(); $exist = $modelPD->where('InternalPVID',$InternalPVID)->find();
$tmp = '';
if($exist) { if($exist) {
if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) { if( !empty($input['PatDiag']) && ( !empty($input['PatDiag']['DiagCode']) || !empty($input['PatDiag']['Diagnosis']) ) ) {
$tmp = $modelPD->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update(); $tmp = $modelPD->where('InternalPVID',$InternalPVID)->set($input['PatDiag'])->update();