add patvisit endpoint
This commit is contained in:
parent
d28bb3cd4b
commit
7585ce0632
@ -31,6 +31,12 @@ $routes->delete('/api/patient', 'Patient::delete');
|
||||
$routes->patch('/api/patient', 'Patient::update');
|
||||
$routes->get('/api/patient/check', 'Patient::patientCheck');
|
||||
|
||||
//$routes->get('/api/patvisit', 'Patient::index');
|
||||
$routes->post('/api/patvisit', 'PatVisit::create');
|
||||
$routes->get('/api/patvisit/(:num)', 'PatVisit::show/$1');
|
||||
$routes->delete('/api/patvisit', 'PatVisit::delete');
|
||||
$routes->patch('/api/patvisit', 'PatVisit::update');
|
||||
|
||||
$routes->get('/api/race', 'Race::index');
|
||||
$routes->get('/api/race/(:num)', 'Race::show/$1');
|
||||
|
||||
|
||||
154
app/Controllers/PatVisit.php
Normal file
154
app/Controllers/PatVisit.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class PatVisit 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,
|
||||
"Code" => $input['Code'] ?? null,
|
||||
"LocationID" => $input['LocationID'] ?? null,
|
||||
"AttDoc" => $input['AttDoc'] ?? null,
|
||||
"RefDoc" => $input['RefDoc'] ?? null,
|
||||
"AdmDoc" => $input['AdmDoc'] ?? null,
|
||||
"CnsDoc" => $input['CnsDoc'] ?? null
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function show($PVID = null) {
|
||||
try {
|
||||
$row = $this->db->table('patvisit pv')
|
||||
->join('patdiag pd', 'pd.InternalPVID=pv.Internal.PVID', 'left')
|
||||
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
|
||||
->get()->getRowArray();
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "data found",
|
||||
'data' => $row,
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); }
|
||||
|
||||
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
||||
$InternalPVID = $input["InternalPVID"];
|
||||
$dataPatVisit = preparePatVisitData($input);
|
||||
$dataPatDiag = preparePatDiagData($input);
|
||||
$dataPatVisitAdt = preparePatVisitAdtData($input);
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('patvisit')->where('InternalPVID', $InternalPVID)->update($dataPatVisit);
|
||||
$this->db->table('patdiag')->where('InternalPVID', $InternalPVID)->update($dataPatDiag);
|
||||
$this->db->table('patvisitadt')->where('InternalPVID', $InternalPVID)->update($dataPatVisitAdt);
|
||||
|
||||
$dbError = $this->db->error();
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if (!empty($dbError['message'])) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Update failed: ' . $dbError['message']);
|
||||
}
|
||||
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError('Failed to update patient data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown error'));
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data updated successfully',
|
||||
'data' => $dataPatVisit
|
||||
], 201);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); }
|
||||
|
||||
$InternalPVID = $input["InternalPVID"];
|
||||
$dataPatVisit = preparePatVisitData($input);
|
||||
$dataPatDiag = preparePatDiagData($input);
|
||||
$dataPatVisitAdt = preparePatVisitAdtData($input);
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('patvisit')->insert($dataPatVisit);
|
||||
if(!empty($dataPatDiag)) { $this->db->table('patdiag')->insert($dataPatDiag); }
|
||||
if(!empty($dataPatVisitAdt)) {$this->db->table('patvisitadt')->insert($dataPatVisitAdt); }
|
||||
|
||||
$dbError = $this->db->error();
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
if (!empty($dbError['message'])) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Update failed: ' . $dbError['message']);
|
||||
}
|
||||
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError('Failed to update patient data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown error'));
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Data insert success',
|
||||
'data' => $dataPatVisit
|
||||
], 201);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->db->transRollback();
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user