diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 0e1ffdf..d217d6d 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -828,6 +828,7 @@ $routes->post('Lab_Admin/report_insert', 'Setting\Template::report_insert');
$routes->post('Lab_Admin/report_delete/(:num)', 'Setting\Template::report_delete/$1');
$routes->post('Lab_Admin/report_ultrasound_insert/(:num)', 'Setting\Template::report_ultrasound_insert/$1');
$routes->post('Lab_Admin/report_ultrasound_update/(:num)', 'Setting\Template::report_ultrasound_update/$1');
+$routes->post('Lab_Admin/report_ultrasound_delete/(:num)/(:num)', 'Setting\Template::report_ultrasound_delete/$1/$2');
$routes->post('Lab_Admin/add_test_repo/(:num)/(:num)', 'Setting\Template::add_test_repo/$1/$2');
$routes->post('Lab_Admin/remove_test_item/(:num)/(:num)', 'Setting\Template::remove_test_item/$1/$2');
$routes->post('Lab_Admin/test_item_search', 'Setting\Template::test_item_search');
diff --git a/app/Controllers/Diagnosis.php b/app/Controllers/Diagnosis.php
index 2802e3a..44c8e4f 100644
--- a/app/Controllers/Diagnosis.php
+++ b/app/Controllers/Diagnosis.php
@@ -1052,7 +1052,7 @@ class Diagnosis extends BaseController
->getRow();
$templateBuilder = $this->db->table('radiology_ultrasound_template')
- ->select('id, template_name')
+ ->select('id, template_name, title, keywords, impression_cat')
->where('Modality', (int) ($reportRow->lab_type ?? 0));
if (! empty($invoiceItem->item_id)) {
@@ -1132,7 +1132,7 @@ class Diagnosis extends BaseController
->getRow();
$templateBuilder = $this->db->table('radiology_ultrasound_template')
- ->select('id, template_name')
+ ->select('id, template_name, title, keywords, impression_cat')
->where('Modality', (int) ($reportRow->lab_type ?? 0));
if (! empty($invoiceItem->item_id)) {
@@ -1165,12 +1165,16 @@ class Diagnosis extends BaseController
}
$row = $this->db->table('radiology_ultrasound_template')
- ->select('Findings, Impression')
+ ->select('template_name, title, keywords, impression_cat, Findings, Impression')
->where('id', $templateId)
->get()
->getRow();
return $this->response->setJSON([
+ 'template_name' => (string) ($row->template_name ?? ''),
+ 'title' => (string) ($row->title ?? ''),
+ 'keywords' => (string) ($row->keywords ?? ''),
+ 'impression_cat' => (string) ($row->impression_cat ?? ''),
'Findings' => (string) ($row->Findings ?? ''),
'Impression' => (string) ($row->Impression ?? ''),
]);
diff --git a/app/Controllers/Setting/Template.php b/app/Controllers/Setting/Template.php
index 7a864eb..e72bc8a 100644
--- a/app/Controllers/Setting/Template.php
+++ b/app/Controllers/Setting/Template.php
@@ -144,6 +144,28 @@ HTML;
return $this->requirePermission($permission);
}
+ private function buildRadiologyTemplatePayload(int $modality): array
+ {
+ $payload = [
+ 'template_name' => trim((string) $this->request->getPost('input_Reportname')),
+ 'title' => trim((string) $this->request->getPost('group_id')),
+ 'charge_id' => (int) $this->request->getPost('charge_id'),
+ 'Findings' => (string) $this->request->getPost('HTMLData'),
+ 'Impression' => (string) $this->request->getPost('Impression'),
+ 'modality' => $modality,
+ ];
+
+ if ($this->db->fieldExists('keywords', 'radiology_ultrasound_template')) {
+ $payload['keywords'] = trim((string) $this->request->getPost('keywords'));
+ }
+
+ if ($this->db->fieldExists('impression_cat', 'radiology_ultrasound_template')) {
+ $payload['impression_cat'] = trim((string) $this->request->getPost('impression_cat'));
+ }
+
+ return $payload;
+ }
+
private function resolveBridgeGatewayConfig(): array
{
$gwUrl = '';
@@ -737,10 +759,6 @@ HTML;
}
$inputReportName = trim((string) $this->request->getPost('input_Reportname'));
- $chargeId = (int) $this->request->getPost('charge_id');
- $groupId = (string) $this->request->getPost('group_id');
- $htmlData = (string) $this->request->getPost('HTMLData');
- $impression = (string) $this->request->getPost('Impression');
if ($inputReportName === '') {
return $this->response->setJSON([
@@ -750,14 +768,7 @@ HTML;
}
$pathLab = new PathLabModel();
- $insertId = $pathLab->insertUltrasoundReport([
- 'template_name' => $inputReportName,
- 'title' => $groupId,
- 'charge_id' => $chargeId,
- 'Findings' => $htmlData,
- 'Impression' => $impression,
- 'modality' => $modality,
- ]);
+ $insertId = $pathLab->insertUltrasoundReport($this->buildRadiologyTemplatePayload($modality));
return $this->response->setJSON([
'insertid' => $insertId,
@@ -780,11 +791,6 @@ HTML;
$repoId = (int) $this->request->getPost('repo_id');
$inputReportName = trim((string) $this->request->getPost('input_Reportname'));
- $chargeId = (int) $this->request->getPost('charge_id');
- $groupId = (string) $this->request->getPost('group_id');
- $htmlData = (string) $this->request->getPost('HTMLData');
- $impression = (string) $this->request->getPost('Impression');
-
if ($repoId <= 0 || $inputReportName === '') {
return $this->response->setJSON([
'update_record' => 0,
@@ -793,14 +799,7 @@ HTML;
}
$pathLab = new PathLabModel();
- $pathLab->updateUltrasoundReport([
- 'template_name' => $inputReportName,
- 'title' => $groupId,
- 'charge_id' => $chargeId,
- 'Findings' => $htmlData,
- 'Impression' => $impression,
- 'modality' => $modality,
- ], $repoId);
+ $pathLab->updateUltrasoundReport($this->buildRadiologyTemplatePayload($modality), $repoId);
return $this->response->setJSON([
'update_record' => 1,
@@ -808,6 +807,52 @@ HTML;
]);
}
+ public function report_ultrasound_delete(int $modality = 2, int $repoId = 0)
+ {
+ if ($resp = $this->requireModalityPermission($modality)) {
+ return $resp;
+ }
+
+ if (! $this->request->isAJAX()) {
+ return $this->response->setStatusCode(400)->setJSON([
+ 'ok' => 0,
+ 'error' => 'Invalid request',
+ ]);
+ }
+
+ if ($repoId <= 0) {
+ return $this->response->setStatusCode(400)->setJSON([
+ 'ok' => 0,
+ 'error' => 'Invalid template ID',
+ ]);
+ }
+
+ $builder = $this->db->table('radiology_ultrasound_template')
+ ->where('id', $repoId)
+ ->where('Modality', $modality);
+
+ $exists = $builder->countAllResults(false);
+ if ($exists <= 0) {
+ return $this->response->setStatusCode(404)->setJSON([
+ 'ok' => 0,
+ 'error' => 'Template not found for selected modality',
+ ]);
+ }
+
+ $deleted = $builder->delete();
+ if (! $deleted) {
+ return $this->response->setStatusCode(500)->setJSON([
+ 'ok' => 0,
+ 'error' => 'Failed to delete template',
+ ]);
+ }
+
+ return $this->response->setJSON([
+ 'ok' => 1,
+ 'message' => 'Template deleted successfully',
+ ]);
+ }
+
public function test_parameter_edit()
{
if ($resp = $this->requirePermission('template.pathology')) {
diff --git a/app/Views/PathLab_Report/ultrasound_report_edit.php b/app/Views/PathLab_Report/ultrasound_report_edit.php
index 115ff53..a98fb2b 100644
--- a/app/Views/PathLab_Report/ultrasound_report_edit.php
+++ b/app/Views/PathLab_Report/ultrasound_report_edit.php
@@ -1,27 +1,66 @@
= form_open() ?>
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
-
+
@@ -92,11 +146,43 @@
= form_close() ?>
diff --git a/app/Views/Setting/Template/index.php b/app/Views/Setting/Template/index.php
index 298f621..e5e925c 100644
--- a/app/Views/Setting/Template/index.php
+++ b/app/Views/Setting/Template/index.php
@@ -161,7 +161,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
-
+
Ultra Sound Template
@@ -169,7 +169,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
-
+
X-Ray Template
@@ -177,7 +177,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
-
+
CT-Scan Template
@@ -185,7 +185,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
-
+
MRI Template
@@ -193,7 +193,7 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c
-
+
ECHO Template
diff --git a/app/Views/diagnosis/lab_final_report_editor.php b/app/Views/diagnosis/lab_final_report_editor.php
index 8ce45ce..bfed3de 100644
--- a/app/Views/diagnosis/lab_final_report_editor.php
+++ b/app/Views/diagnosis/lab_final_report_editor.php
@@ -121,11 +121,56 @@ $editReason = trim((string) ($edit_reason ?? ''));
+
-
-
= esc($tpl->template_name ?? '') ?>
+ template_name ?? '');
+ $tplTitle = trim((string) ($tpl->title ?? ''));
+ $tplKeywords = trim((string) ($tpl->keywords ?? ''));
+ $tplCategory = trim((string) ($tpl->impression_cat ?? ''));
+ $searchBlob = strtolower(trim($tplName . ' ' . $tplTitle . ' ' . $tplKeywords . ' ' . $tplCategory));
+ ?>
+
No templates found
@@ -213,7 +258,8 @@ $editReason = trim((string) ($edit_reason ?? ''));
let count = 0;
items.forEach(function (item) {
- const show = item.textContent.toLowerCase().indexOf(q) !== -1;
+ const source = (item.getAttribute('data-search') || item.textContent || '').toLowerCase();
+ const show = source.indexOf(q) !== -1;
item.style.display = show ? '' : 'none';
if (show) {
count++;
@@ -227,6 +273,42 @@ $editReason = trim((string) ($edit_reason ?? ''));
});
})();
+ function getEditorValue(editorId) {
+ if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[editorId]) {
+ return CKEDITOR.instances[editorId].getData();
+ }
+ const el = document.getElementById(editorId);
+ return el ? el.value : '';
+ }
+
+ function setEditorValue(editorId, value) {
+ if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[editorId]) {
+ CKEDITOR.instances[editorId].setData(value);
+ return;
+ }
+ const el = document.getElementById(editorId);
+ if (el) {
+ el.value = value;
+ }
+ }
+
+ function mergeTemplateContent(currentValue, incomingValue, mode) {
+ if (mode !== 'append') {
+ return incomingValue;
+ }
+
+ const current = (currentValue || '').trim();
+ const incoming = (incomingValue || '').trim();
+ if (!current) {
+ return incoming;
+ }
+ if (!incoming) {
+ return current;
+ }
+
+ return current + '
' + incoming;
+ }
+
// Modal helper function
window._imagingSupportModalInstance = window._imagingSupportModalInstance || null;
function openImagingSupportModal(title, html) {
@@ -315,16 +397,24 @@ $editReason = trim((string) ($edit_reason ?? ''));
const findings = data.Findings || '';
const impression = data.Impression || '';
- if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances.HTMLShow) {
- CKEDITOR.instances.HTMLShow.setData(findings);
- } else {
- document.getElementById('HTMLShow').value = findings;
+ const selectedModeEl = document.querySelector('input[name="tpl_apply_mode"]:checked');
+ const mode = selectedModeEl ? selectedModeEl.value : 'replace';
+ const applyFindings = !!document.getElementById('tpl_apply_findings')?.checked;
+ const applyImpression = !!document.getElementById('tpl_apply_impression')?.checked;
+
+ if (!applyFindings && !applyImpression) {
+ alert('Select Findings and/or Impression to apply template.');
+ return;
}
- if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances.report_data_Impression) {
- CKEDITOR.instances.report_data_Impression.setData(impression);
- } else {
- document.getElementById('report_data_Impression').value = impression;
+ if (applyFindings) {
+ const mergedFindings = mergeTemplateContent(getEditorValue('HTMLShow'), findings, mode);
+ setEditorValue('HTMLShow', mergedFindings);
+ }
+
+ if (applyImpression) {
+ const mergedImpression = mergeTemplateContent(getEditorValue('report_data_Impression'), impression, mode);
+ setEditorValue('report_data_Impression', mergedImpression);
}
})
.catch(e => console.error(e));
diff --git a/app/Views/diagnosis/lab_final_report_show_xray.php b/app/Views/diagnosis/lab_final_report_show_xray.php
index 9dcb8ef..8c3c1ce 100644
--- a/app/Views/diagnosis/lab_final_report_show_xray.php
+++ b/app/Views/diagnosis/lab_final_report_show_xray.php
@@ -60,12 +60,57 @@ $templates = $radiology_ultrasound_template ?? [];
+
-
-
= esc($tpl->template_name ?? '') ?>
+ template_name ?? '');
+ $tplTitle = trim((string) ($tpl->title ?? ''));
+ $tplKeywords = trim((string) ($tpl->keywords ?? ''));
+ $tplCategory = trim((string) ($tpl->impression_cat ?? ''));
+ $searchBlob = strtolower(trim($tplName . ' ' . $tplTitle . ' ' . $tplKeywords . ' ' . $tplCategory));
+ ?>
+
No templates found
@@ -86,7 +131,8 @@ $templates = $radiology_ultrasound_template ?? [];
let count = 0;
items.forEach(function (item) {
- const show = item.textContent.toLowerCase().indexOf(q) !== -1;
+ const source = (item.getAttribute('data-search') || item.textContent || '').toLowerCase();
+ const show = source.indexOf(q) !== -1;
item.style.display = show ? '' : 'none';
if (show) {
count++;
@@ -111,5 +157,72 @@ $templates = $radiology_ultrasound_template ?? [];
}
});
})();
+
+ function getEditorValue(editorId) {
+ if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[editorId]) {
+ return CKEDITOR.instances[editorId].getData();
+ }
+ const el = document.getElementById(editorId);
+ return el ? el.value : '';
+ }
+
+ function setEditorValue(editorId, value) {
+ if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[editorId]) {
+ CKEDITOR.instances[editorId].setData(value);
+ return;
+ }
+ const el = document.getElementById(editorId);
+ if (el) {
+ el.value = value;
+ }
+ }
+
+ function mergeTemplateContent(currentValue, incomingValue, mode) {
+ if (mode !== 'append') {
+ return incomingValue;
+ }
+
+ const current = (currentValue || '').trim();
+ const incoming = (incomingValue || '').trim();
+ if (!current) {
+ return incoming;
+ }
+ if (!incoming) {
+ return current;
+ }
+
+ return current + '
' + incoming;
+ }
+
+ function set_template(templateId) {
+ fetch('= base_url('diagnosis/get-template-xray') ?>/' + templateId, {
+ headers: { 'X-Requested-With': 'XMLHttpRequest' }
+ })
+ .then(r => r.json())
+ .then(data => {
+ const findings = data.Findings || '';
+ const impression = data.Impression || '';
+ const selectedModeEl = document.querySelector('input[name="tpl_apply_mode"]:checked');
+ const mode = selectedModeEl ? selectedModeEl.value : 'replace';
+ const applyFindings = !!document.getElementById('tpl_apply_findings')?.checked;
+ const applyImpression = !!document.getElementById('tpl_apply_impression')?.checked;
+
+ if (!applyFindings && !applyImpression) {
+ alert('Select Findings and/or Impression to apply template.');
+ return;
+ }
+
+ if (applyFindings) {
+ const mergedFindings = mergeTemplateContent(getEditorValue('HTMLShow'), findings, mode);
+ setEditorValue('HTMLShow', mergedFindings);
+ }
+
+ if (applyImpression) {
+ const mergedImpression = mergeTemplateContent(getEditorValue('report_data_Impression'), impression, mode);
+ setEditorValue('report_data_Impression', mergedImpression);
+ }
+ })
+ .catch(e => console.error(e));
+ }