diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9f9943e..d507b9b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -1024,6 +1024,8 @@ $routes->match(['GET', 'POST'], 'setting/template/discharge_templates', 'Setting $routes->post('setting/template/discharge_templates_seed', 'Setting\Template::discharge_templates_seed'); $routes->get('setting/template/discharge_template_get/(:num)', 'Setting\Template::discharge_template_get/$1'); $routes->match(['GET', 'POST'], 'setting/template/discharge_templates/delete/(:num)', 'Setting\Template::discharge_template_delete/$1'); +$routes->get('Ipd_discharge/print_template_builder', 'Ipd_discharge::print_template_builder', ['filter' => 'permission:template.discharge,ipd_discharge.manage']); +$routes->post('Ipd_discharge/discharge_template_rename_ajax', 'Ipd_discharge::discharge_template_rename_ajax', ['filter' => 'permission:template.discharge,ipd_discharge.manage']); $routes->match(['GET', 'POST'], 'setting/template/ipd_document_templates', 'Setting\Template::ipd_document_templates'); $routes->get('setting/template/ipd_document_templates/delete/(:num)', 'Setting\Template::ipd_document_template_delete/$1'); $routes->match(['GET', 'POST'], 'setting/template/diagnosis_print_settings', 'Setting\Template::diagnosis_print_settings'); diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 95db95e..646a965 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -5286,6 +5286,64 @@ class Ipd_discharge extends BaseController ]); } + public function print_template_builder() + { + if ($resp = $this->requireAnyPermission(['template.discharge'])) { + return $resp; + } + + $mode = strtolower(trim((string) $this->request->getGet('mode'))); + if (! in_array($mode, ['list', 'edit'], true)) { + $mode = 'list'; + } + + $this->ensureDischargeTemplateTable(); + $rows = $this->db->table('ipd_discharge_templates') + ->orderBy('is_default', 'DESC') + ->orderBy('id', 'ASC') + ->get() + ->getResultArray(); + + if ($mode === 'list') { + return view('ipd_discharge/discharge_template_list', ['rows' => $rows]); + } + + $editId = (int) ($this->request->getGet('edit') ?? 0); + $editRow = []; + if ($editId > 0) { + foreach ($rows as $row) { + if ((int) ($row['id'] ?? 0) === $editId) { + $editRow = $row; + break; + } + } + } + + return view('ipd_discharge/discharge_template_edit', [ + 'rows' => $rows, + 'edit_row' => $editRow, + ]); + } + + public function discharge_template_rename_ajax() + { + if (! $this->request->isAJAX()) { + return $this->response->setStatusCode(400)->setJSON(['update' => 0]); + } + if ($resp = $this->requireAnyPermission(['template.discharge'])) { + return $this->response->setStatusCode(403)->setJSON(['update' => 0]); + } + $id = (int) ($this->request->getPost('id') ?? 0); + $name = trim((string) ($this->request->getPost('template_name') ?? '')); + if ($id <= 0 || $name === '') { + return $this->response->setJSON(['update' => 0, 'error_text' => 'ID and name required.', + 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash()]); + } + $ok = (bool) $this->db->table('ipd_discharge_templates')->where('id', $id)->update(['template_name' => $name]); + return $this->response->setJSON(['update' => $ok ? 1 : 0, 'error_text' => $ok ? 'Renamed.' : 'Unable to rename.', + 'csrfName' => csrf_token(), 'csrfHash' => csrf_hash()]); + } + public function search_patient_ajax() { $permission = $this->requireAnyPermission([ diff --git a/app/Views/Setting/Template/index.php b/app/Views/Setting/Template/index.php index e5e925c..a76d97f 100644 --- a/app/Views/Setting/Template/index.php +++ b/app/Views/Setting/Template/index.php @@ -211,7 +211,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
- + IPD Discharge Template diff --git a/app/Views/ipd_discharge/discharge_template_edit.php b/app/Views/ipd_discharge/discharge_template_edit.php new file mode 100644 index 0000000..d2948e3 --- /dev/null +++ b/app/Views/ipd_discharge/discharge_template_edit.php @@ -0,0 +1,292 @@ + [ + 'H_Name' => 'Hospital Name', 'hospital_address' => 'Hospital Address', + 'H_phone_No' => 'Hospital Phone', 'H_Email' => 'Hospital Email', + 'H_logo' => 'Hospital Logo (filename)', 'H_logo_abs' => 'Hospital Logo (absolute path for mPDF)', + ], + 'Patient' => [ + 'PATIENT_NAME' => 'Patient Name', 'UHID' => 'UHID', 'AGE_GENDER' => 'Age / Gender', + 'GUARDIAN' => 'Guardian', 'PATIENT_ADDRESS' => 'Address', 'PATIENT_PHONE' => 'Phone', + 'INSURANCE_COMPANY' => 'TPA/Insurance', 'DEPARTMENT' => 'Department', 'DOCTOR_NAMES' => 'Doctors', + ], + 'IPD Info' => [ + 'IPD_CODE' => 'IPD No.', 'ADMIT_DATE' => 'Admission Date', 'ADMISSION_TIME' => 'Admission Time', + 'DISCHARGE_DATE' => 'Discharge Date', 'DISCHARGE_TIME' => 'Discharge Time', + 'DISCHARGE_STATUS' => 'Discharge Status Heading', + ], + 'Clinical Content' => [ + 'CONTENT' => 'Full discharge content (all sections)', + 'FINAL_DIAGNOSIS' => 'Final Diagnosis', 'SURGERY' => 'Surgery', 'PROCEDURE' => 'Procedure', + 'PRESENTING_COMPLAINTS' => 'Presenting Complaints', + 'GENERAL_EXAM_ADMISSION' => 'General Exam on Admission', + 'CLINICAL_INVESTIGATION_REPORTS' => 'Investigation Reports', + 'COURSE_IN_HOSPITAL' => 'Course in Hospital', + 'EXAMINATION_ON_DISCHARGE' => 'Exam on Discharge', + 'DISCHARGE_MEDICATIONS' => 'Discharge Medications', + 'DISCHARGE_SUMMARY' => 'Summary/Advice', 'REVIEW_AFTER' => 'Review After', + 'DIETARY_ADVICE' => 'Dietary Advice', + 'DRUG_ALLERGY_ADR' => 'Drug Allergy/ADR', 'CO_MORBIDITIES' => 'Co-Morbidities', + 'PERSONAL_HISTORY' => 'Personal History', + 'PATIENT_INFO_TABLE' => 'Pre-built Patient Info Table', + ], + 'Print Meta' => [ + 'CURRENT_DATE' => 'Print Date', 'PRINT_TIME' => 'Print Date/Time', + ], +]; +?> +
+
+

IPD Discharge Template Builder

+ + ← Template List + +
+
+ +
+ + +
+ +
+ +
+
+
0 ? 'Edit Template' : 'New Template' ?>
+
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ > + +
+
+ > + +
+
+ +
+ +
+ + + + +
+
+
+
+
+ + +
+
+
Placeholders
+
+ + $items): ?> +
+
+ $desc): ?> + {{}} + +
+ +
+
+
+
+
+ + diff --git a/app/Views/ipd_discharge/discharge_template_list.php b/app/Views/ipd_discharge/discharge_template_list.php new file mode 100644 index 0000000..0f3488b --- /dev/null +++ b/app/Views/ipd_discharge/discharge_template_list.php @@ -0,0 +1,152 @@ + +
+
+

IPD Discharge Template Builder

+ +
+
+ +
+
+
+ +
+
+ + + + + + + + + + + + + + + $row): ?> + + + + + + + + + + +
#Template NameDefaultAuditActions
No templates. Click Add New.
Yes' : '' ?>Audit' : '' ?> + Edit + + +
+
+
+
+
+ +