$doctorModel->getDoctors(), ]); } public function create(): string { $templateContext = $this->getDoctorTemplateContext(); return view('Setting/Doctor/Doctor_V', [ 'errors' => session('errors'), 'template_options' => $templateContext['options'], 'template_fields' => $templateContext['fields'], ]); } public function store() { $rules = [ 'input_name' => 'required', 'input_email' => 'permit_empty|valid_email', 'input_mphone1' => 'permit_empty|numeric', ]; if (! $this->validate($rules)) { if ($this->request->isAJAX()) { $templateContext = $this->getDoctorTemplateContext(); return view('Setting/Doctor/Doctor_V', [ 'errors' => $this->validator->getErrors(), 'formData' => $this->request->getPost(), 'template_options' => $templateContext['options'], 'template_fields' => $templateContext['fields'], ]); } return redirect()->back()->withInput()->with('errors', $this->validator->getErrors()); } $doctorModel = new DoctorModel(); $regField = $this->resolveDoctorRegField(); $shortDescription = trim((string) $this->request->getPost('txt_doc_sign')); $regInput = trim((string) $this->request->getPost('input_doc_reg_no')); if ($regInput === '' && $shortDescription !== '') { $regInput = $this->extractRegNoFromText($shortDescription); } $data = [ 'p_title' => $this->request->getPost('select_title'), 'mphone1' => $this->request->getPost('input_mphone1'), 'p_fname' => $this->request->getPost('input_name'), 'gender' => $this->request->getPost('optionsRadios_gender'), 'dob' => str_to_MysqlDate((string) $this->request->getPost('datepicker_dob')), 'zip' => $this->request->getPost('input_zip'), 'email1' => $this->request->getPost('input_email'), 'doc_sign' => $shortDescription, ]; $templateContext = $this->getDoctorTemplateContext(); $templateFieldMap = [ 'opd_print_format' => 'tmpl_opd_print_format', 'opd_blank_print' => 'tmpl_opd_blank_print', 'rx_pre_print_letter_head_format' => 'tmpl_rx_pre_print_letter_head_format', 'rx_blank_letter_head' => 'tmpl_rx_blank_letter_head', 'rx_plain_paper' => 'tmpl_rx_plain_paper', ]; foreach ($templateFieldMap as $dbField => $inputField) { if (! in_array($dbField, $templateContext['fields'], true)) { continue; } $templateName = strtolower(trim((string) $this->request->getPost($inputField))); $templateName = preg_replace('/[^a-z0-9_\-]/', '', $templateName) ?? ''; $data[$dbField] = $templateName; } if ($regField !== null) { $data[$regField] = $regInput; } $insertId = $doctorModel->insert($data); if ($insertId <= 0) { $errors = ['Unable to create doctor.']; if ($this->request->isAJAX()) { $templateContext = $this->getDoctorTemplateContext(); return view('Setting/Doctor/Doctor_V', [ 'errors' => $errors, 'formData' => $this->request->getPost(), 'template_options' => $templateContext['options'], 'template_fields' => $templateContext['fields'], ]); } return redirect()->back()->withInput()->with('errors', $errors); } return $this->doctorRecord($insertId); } public function doctorRecord(int $id): string { $doctorModel = new DoctorModel(); $templateContext = $this->getDoctorTemplateContext(); return view('Setting/Doctor/Doctor_profile_V', [ 'data' => $doctorModel->getDoctorById($id), 'doc_spec_a' => $doctorModel->getDoctorSpecs($id), 'doc_spec_l' => $doctorModel->getSpecsList(), 'doc_fee_type' => $doctorModel->getFeeTypes(), 'doc_fee_list' => $doctorModel->getDoctorFees($id), 'doc_ipd_fee_list' => $doctorModel->getDoctorIpdFees($id), 'doc_ipd_fee_type' => $doctorModel->getIpdFeeTypes(), 'template_options' => $templateContext['options'], 'template_fields' => $templateContext['fields'], ]); } public function updateRecord() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['update' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $regField = $this->resolveDoctorRegField(); $shortDescription = trim((string) $this->request->getPost('txt_doc_sign')); $regInput = trim((string) $this->request->getPost('input_doc_reg_no')); if ($regInput === '' && $shortDescription !== '') { $regInput = $this->extractRegNoFromText($shortDescription); } $data = [ 'p_title' => $this->request->getPost('select_title'), 'mphone1' => $this->request->getPost('input_mphone1'), 'p_fname' => $this->request->getPost('input_name'), 'gender' => $this->request->getPost('optionsRadios_gender'), 'dob' => str_to_MysqlDate((string) $this->request->getPost('datepicker_dob')), 'zip' => $this->request->getPost('input_zip'), 'doc_sign' => $shortDescription, 'email1' => $this->request->getPost('input_email'), ]; $templateContext = $this->getDoctorTemplateContext(); $templateFieldMap = [ 'opd_print_format' => 'tmpl_opd_print_format', 'opd_blank_print' => 'tmpl_opd_blank_print', 'rx_pre_print_letter_head_format' => 'tmpl_rx_pre_print_letter_head_format', 'rx_blank_letter_head' => 'tmpl_rx_blank_letter_head', 'rx_plain_paper' => 'tmpl_rx_plain_paper', ]; foreach ($templateFieldMap as $dbField => $inputField) { if (! in_array($dbField, $templateContext['fields'], true)) { continue; } $templateName = strtolower(trim((string) $this->request->getPost($inputField))); $templateName = preg_replace('/[^a-z0-9_\-]/', '', $templateName) ?? ''; $data[$dbField] = $templateName; } if ($regField !== null) { $data[$regField] = $regInput; } $updated = $doctorModel->updateDoctor($data, $docId); return $this->response->setJSON([ 'update' => $updated ? 1 : 0, 'showcontent' => $updated ? 'Data Saved successfully' : '', 'error_text' => $updated ? '' : 'Please Check', ]); } public function doctorRecordSpec() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['update' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $isAdd = (int) $this->request->getPost('isadd') === 1; if ($isAdd) { $specId = (int) $this->request->getPost('doc_spec'); if ($specId > 0 && ! $doctorModel->specExists($docId, $specId)) { $doctorModel->insertSpec([ 'doc_id' => $docId, 'med_spec_id' => $specId, ]); } } else { $specId = (int) $this->request->getPost('doc_spec_id'); if ($specId > 0) { $doctorModel->removeSpec($specId); } } $specListHtml = $this->renderSpecList($doctorModel->getDoctorSpecs($docId)); return $this->response->setJSON([ 'update' => 1, 'show_Specility_list' => $specListHtml, 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), ]); } public function addFee() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['inser_id' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $feeType = (int) $this->request->getPost('fee_type'); $existing = $doctorModel->getDoctorFeeByType($docId, $feeType); if ($existing !== null) { $doctorModel->removeFee((int) $existing->id, $this->getFeeAuditData()); } $insertId = $doctorModel->insertFee([ 'doc_id' => $docId, 'doc_fee_desc' => $this->request->getPost('input_fee_desc'), 'doc_fee_type' => $feeType, 'amount' => $this->request->getPost('input_fee_amount'), ]); $feeList = $doctorModel->getDoctorFees($docId); return $this->response->setJSON([ 'inser_id' => $insertId > 0 ? 1 : 0, 'showcontent' => $insertId > 0 ? 'Fee added successfully' : '', 'error_text' => $insertId > 0 ? '' : 'Please Check', 'show_fee_list' => $this->renderFeeList($feeList), 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), ]); } public function addIpdFee() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['inser_id' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $feeType = (int) $this->request->getPost('fee_type'); $existing = $doctorModel->getDoctorIpdFeeByType($docId, $feeType); if ($existing !== null) { $doctorModel->removeIpdFee((int) $existing->id); } $insertId = $doctorModel->insertIpdFee([ 'doc_id' => $docId, 'doc_fee_desc' => $this->request->getPost('input_fee_desc'), 'doc_fee_type' => $feeType, 'amount' => $this->request->getPost('input_fee_amount'), ]); $feeList = $doctorModel->getDoctorIpdFees($docId); return $this->response->setJSON([ 'inser_id' => $insertId > 0 ? 1 : 0, 'showcontent' => $insertId > 0 ? 'IPD Fee added successfully' : '', 'error_text' => $insertId > 0 ? '' : 'Please Check', 'show_fee_list' => $this->renderFeeList($feeList), 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), ]); } public function removeFee() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['update' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $removeId = (int) $this->request->getPost('rid'); $deleted = $doctorModel->removeFee($removeId, $this->getFeeAuditData()); $feeList = $doctorModel->getDoctorFees($docId); return $this->response->setJSON([ 'update' => $deleted ? 1 : 0, 'showcontent' => $deleted ? 'Fee Removed successfully' : '', 'error_text' => $deleted ? '' : 'Please Check', 'show_fee_list' => $this->renderFeeList($feeList), 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), ]); } public function removeIpdFee() { if (! $this->request->isAJAX()) { return $this->response->setJSON(['update' => 0, 'error_text' => 'Invalid request']); } $doctorModel = new DoctorModel(); $docId = (int) $this->request->getPost('doc_id'); $removeId = (int) $this->request->getPost('rid'); $deleted = $doctorModel->removeIpdFee($removeId); $feeList = $doctorModel->getDoctorIpdFees($docId); return $this->response->setJSON([ 'update' => $deleted ? 1 : 0, 'showcontent' => $deleted ? 'IPD Fee Removed successfully' : '', 'error_text' => $deleted ? '' : 'Please Check', 'show_fee_list' => $this->renderFeeList($feeList), 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash(), ]); } public function specs(): string { $doctorModel = new DoctorModel(); return view('Setting/Doctor/Spec_List', [ 'specs' => $doctorModel->getMedSpecs(), ]); } public function ipdFeeTypes(): string { $doctorModel = new DoctorModel(); return view('Setting/Doctor/Ipd_FeeType_List', [ 'feeTypes' => $doctorModel->getIpdFeeTypes(), ]); } public function storeIpdFeeType() { $name = trim((string) $this->request->getPost('fee_type')); if ($name === '') { return $this->renderIpdFeeTypeListWithErrors(['fee_type' => 'Fee type is required.']); } $doctorModel = new DoctorModel(); $doctorModel->insertIpdFeeType($name); return $this->renderIpdFeeTypeListWithMessage('IPD fee type added successfully.'); } public function updateIpdFeeType() { $id = (int) $this->request->getPost('id'); $name = trim((string) $this->request->getPost('fee_type')); if ($id <= 0 || $name === '') { return $this->renderIpdFeeTypeListWithErrors(['fee_type' => 'Fee type is required.']); } $doctorModel = new DoctorModel(); $doctorModel->updateIpdFeeType($id, $name); return $this->renderIpdFeeTypeListWithMessage('IPD fee type updated successfully.'); } public function deleteIpdFeeType() { $id = (int) $this->request->getPost('id'); if ($id <= 0) { return $this->renderIpdFeeTypeListWithErrors(['fee_type' => 'Invalid fee type.']); } $doctorModel = new DoctorModel(); $doctorModel->deleteIpdFeeType($id); return $this->renderIpdFeeTypeListWithMessage('IPD fee type deleted successfully.'); } public function storeSpec() { $name = trim((string) $this->request->getPost('SpecName')); if ($name === '') { return $this->renderSpecListWithErrors(['SpecName' => 'Spec name is required.']); } $doctorModel = new DoctorModel(); $doctorModel->insertMedSpec($name); return $this->renderSpecListWithMessage('Speciality added successfully.'); } public function updateSpec() { $id = (int) $this->request->getPost('id'); $name = trim((string) $this->request->getPost('SpecName')); if ($id <= 0 || $name === '') { return $this->renderSpecListWithErrors(['SpecName' => 'Spec name is required.']); } $doctorModel = new DoctorModel(); $doctorModel->updateMedSpec($id, $name); return $this->renderSpecListWithMessage('Speciality updated successfully.'); } public function deleteSpec() { $id = (int) $this->request->getPost('id'); if ($id <= 0) { return $this->renderSpecListWithErrors(['SpecName' => 'Invalid speciality.']); } $doctorModel = new DoctorModel(); $doctorModel->deleteMedSpec($id); return $this->renderSpecListWithMessage('Speciality deleted successfully.'); } private function renderSpecList(array $specs): string { $html = ''; foreach ($specs as $row) { $name = esc($row->SpecName ?? ''); $docSpecId = (int) ($row->doc_spec_id ?? 0); $html .= '
| Fee Type | Description | Amount | |
|---|---|---|---|
| ' . $feeType . ' | ' . $desc . ' | ' . $amount . ' | ' . $button . ' |