helpers = ['form', 'url']; // Caution: Do not edit this line. parent::initController($request, $response, $logger); $this->db = db_connect(); $this->clinicalAuditTrail = new ClinicalAuditTrail(); $this->fhirR4Builder = new FhirR4Builder(); $this->loadLegacyHospitalConstants(); // Preload any models, libraries, etc, here. // $this->session = service('session'); } /** * @param string|int|null $recordId * @param string|int|null $userId * @param mixed $oldValue * @param mixed $newValue */ protected function auditClinicalUpdate( string $module, string $fieldName, $recordId, $oldValue, $newValue, $userId = null ): void { if ($userId === null && function_exists('auth')) { $user = auth()->user(); $userId = $user->id ?? null; } $this->clinicalAuditTrail->logFieldUpdate($module, $recordId, $fieldName, $oldValue, $newValue, $userId); } protected function loadLegacyHospitalConstants(): void { if (! $this->db || ! method_exists($this->db, 'tableExists') || ! $this->db->tableExists('hospital_setting')) { return; } try { $rows = $this->db->table('hospital_setting') ->select('s_name, s_value') ->get() ->getResultArray(); foreach ($rows as $row) { $key = trim((string) ($row['s_name'] ?? '')); if ($key === '' || ! preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $key)) { continue; } if (! defined($key)) { define($key, (string) ($row['s_value'] ?? '')); } } } catch (\Throwable $e) { } } }