model = new PatVisitModel(); } public function index() { try { $page = $this->request->getVar('page') ?? 1; $perPage = $this->request->getVar('per_page') ?? 50; $rows = $this->model->paginate($perPage, 'default', $page); $total = $this->model->countAllResults(false); if($rows == []) { $message = "data not found"; } else { $message = "data found"; } return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows, 'total' => $total, 'page' => $page, 'per_page' => $perPage ], 200); } catch (\Exception $e) { return $this->failServerError('Something went wrong '.$e->getMessage()); } } public function show($PVID = null) { try { $row = $this->model->show($PVID); if (empty($row)) { return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200); } catch (\Exception $e) { return $this->failServerError('Something went wrong '.$e->getMessage()); } } public function showByPatient($InternalPID = null) { try { $rows = $this->model->showByPatient($InternalPID); if($rows == []) { $message = "data not found"; } else { $message = "data found"; } return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows ], 200); } catch (\Exception $e) { return $this->failServerError('Something went wrong '.$e->getMessage()); } } public function update() { $input = $this->request->getJSON(true); try { 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); } catch (\Exception $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } public function create() { $input = $this->request->getJSON(true); try { $data = $this->model->createPatVisit($input); 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 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()); } } }