From 874d5ffba6b7b5026794eb8bda65eabced90adf6 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 31 Mar 2026 06:35:36 +0530 Subject: [PATCH] feat: add granular template permissions for role-based template access - add new permissions: template.opd_print, template.pathology_print, template.diagnosis_print, template.document_print, template.ipd_document - Template controller now accepts new permission keys (with backward-compatible fallbacks) - IPD Document Master now has independent permission key (template.ipd_document) - Template index tile visibility updated to use new granular keys - OPD print template builder now honors template.opd_print permission - preserve existing behavior via legacy permission fallbacks to avoid role breakage --- app/Config/AuthGroups.php | 5 +++++ app/Controllers/Opd.php | 2 +- app/Controllers/Setting/Template.php | 20 ++++++++++++++++---- app/Views/Setting/Template/index.php | 25 +++++++++++++++++++------ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/Config/AuthGroups.php b/app/Config/AuthGroups.php index 7222cc0..e12c8b3 100644 --- a/app/Config/AuthGroups.php +++ b/app/Config/AuthGroups.php @@ -124,6 +124,11 @@ class AuthGroups extends ShieldAuthGroups 'template.mri' => 'Can access MRI templates', 'template.echo' => 'Can access ECHO templates', 'template.discharge' => 'Can access IPD discharge templates', + 'template.opd_print' => 'Can access OPD print templates', + 'template.pathology_print' => 'Can access pathology print templates', + 'template.diagnosis_print' => 'Can access diagnosis print templates', + 'template.document_print' => 'Can access document print templates', + 'template.ipd_document' => 'Can access IPD document master templates', ]; /** diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index e78f75b..cafb1c8 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -41,7 +41,7 @@ class Opd extends BaseController return false; } - if (method_exists($user, 'can') && $user->can('billing.opd.edit')) { + if (method_exists($user, 'can') && ($user->can('template.opd_print') || $user->can('billing.opd.edit'))) { return true; } diff --git a/app/Controllers/Setting/Template.php b/app/Controllers/Setting/Template.php index cd25deb..70a45f6 100644 --- a/app/Controllers/Setting/Template.php +++ b/app/Controllers/Setting/Template.php @@ -16,6 +16,11 @@ class Template extends BaseController 'template.mri', 'template.echo', 'template.discharge', + 'template.opd_print', + 'template.pathology_print', + 'template.diagnosis_print', + 'template.document_print', + 'template.ipd_document', ]; public function __construct() @@ -715,7 +720,11 @@ HTML; public function diagnosis_print_settings(int $modality = 3) { - if ($resp = $this->requireAnyPermission(['template.pathology', 'template.ultrasound', 'template.xray', 'template.ct', 'template.mri', 'template.echo'])) { + if ($resp = $this->requireAnyPermission([ + 'template.diagnosis_print', + 'template.pathology_print', + 'template.pathology', 'template.ultrasound', 'template.xray', 'template.ct', 'template.mri', 'template.echo', + ])) { return $resp; } @@ -978,7 +987,10 @@ HTML; public function document_print_settings() { - if ($resp = $this->requireAnyPermission(['doctor_work.template_workspace.access', 'doctor_work.access', 'template.pathology'])) { + if ($resp = $this->requireAnyPermission([ + 'template.document_print', + 'doctor_work.template_workspace.access', 'doctor_work.access', 'template.pathology', + ])) { return $resp; } @@ -1608,7 +1620,7 @@ HTML, public function ipd_document_templates() { - if ($resp = $this->requireAnyPermission(['template.discharge'])) { + if ($resp = $this->requireAnyPermission(['template.ipd_document', 'template.discharge'])) { return $resp; } @@ -1674,7 +1686,7 @@ HTML, public function ipd_document_template_delete(int $id) { - if ($resp = $this->requireAnyPermission(['template.discharge'])) { + if ($resp = $this->requireAnyPermission(['template.ipd_document', 'template.discharge'])) { return $resp; } diff --git a/app/Views/Setting/Template/index.php b/app/Views/Setting/Template/index.php index af1c831..db2a176 100644 --- a/app/Views/Setting/Template/index.php +++ b/app/Views/Setting/Template/index.php @@ -7,17 +7,27 @@ $canCt = $user && method_exists($user, 'can') ? $user->can('template.ct') : fals $canMri = $user && method_exists($user, 'can') ? $user->can('template.mri') : false; $canEcho = $user && method_exists($user, 'can') ? $user->can('template.echo') : false; $canDischarge = $user && method_exists($user, 'can') ? $user->can('template.discharge') : false; -$canOpdPrintTemplate = $user && method_exists($user, 'can') ? $user->can('billing.opd.edit') : false; -$canDiagnosisPrintTemplate = $canPathology || $canUltrasound || $canXray || $canCt || $canMri || $canEcho; -$canDoctorDocumentPrintTemplate = $user && method_exists($user, 'can') - ? ($user->can('doctor_work.template_workspace.access') || $user->can('doctor_work.access') || $user->can('template.pathology')) +$canOpdPrintTemplate = $user && method_exists($user, 'can') + ? ($user->can('template.opd_print') || $user->can('billing.opd.edit')) : false; +$canPathologyPrintTemplate = $user && method_exists($user, 'can') + ? ($user->can('template.pathology_print') || $user->can('template.pathology')) + : false; +$canDiagnosisPrintTemplate = $user && method_exists($user, 'can') + ? ($user->can('template.diagnosis_print') || $canPathology || $canUltrasound || $canXray || $canCt || $canMri || $canEcho) + : ($canPathology || $canUltrasound || $canXray || $canCt || $canMri || $canEcho); +$canDoctorDocumentPrintTemplate = $user && method_exists($user, 'can') + ? ($user->can('template.document_print') || $user->can('doctor_work.template_workspace.access') || $user->can('doctor_work.access') || $user->can('template.pathology')) + : false; +$canIpdDocumentMaster = $user && method_exists($user, 'can') + ? ($user->can('template.ipd_document') || $user->can('template.discharge')) + : $canDischarge; if (! $canOpdPrintTemplate && $user && method_exists($user, 'inGroup')) { $canOpdPrintTemplate = $user->inGroup('OPDEdit', 'admin', 'superadmin', 'developer'); } -$hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $canMri || $canEcho || $canDischarge || $canDoctorDocumentPrintTemplate; +$hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $canMri || $canEcho || $canDischarge || $canOpdPrintTemplate || $canPathologyPrintTemplate || $canDiagnosisPrintTemplate || $canDoctorDocumentPrintTemplate || $canIpdDocumentMaster; ?>
@@ -206,6 +216,9 @@ $hasTemplateAccess = $canPathology || $canUltrasound || $canXray || $canCt || $c IPD Discharge Template
+ + +