forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleManagerListener.php
233 lines (208 loc) · 7.11 KB
/
ModuleManagerListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
* Class to be called from Laminas Module Manager for reporting management actions.
* Example is if the module is enabled, disabled or unregistered ect.
*
* The class is in the Laminas "Installer\Controller" namespace.
* Currently, register isn't supported of which support should be a part of install.
* If an error needs to be reported to user, return description of error.
* However, whatever action trapped here has already occurred in Manager.
* Catch any exceptions because chances are they will be overlooked in Laminas module.
* Report them in the return value.
*
* @package OpenEMR Modules
* @link https://www.open-emr.org
* @author Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2024 Jerry Padgett <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
/*
* Do not declare a namespace
* If you want Laminas manager to set namespace set it in getModuleNamespace
* otherwise uncomment below and set path.
*
* */
/*
$classLoader = new \OpenEMR\Core\ModulesClassLoader($GLOBALS['fileroot']);
$classLoader->registerNamespaceIfNotExists("OpenEMR\\Modules\\ClaimRevConnector\\", __DIR__ . DIRECTORY_SEPARATOR . 'src');
*/
use OpenEMR\Core\AbstractModuleActionListener;
use OpenEMR\Modules\ClaimRevConnector\Services\ModuleServices;
/* Allows maintenance of background tasks depending on Module Manager action. */
class ModuleManagerListener extends AbstractModuleActionListener
{
public function __construct()
{
parent::__construct();
}
/**
* @param $methodName
* @param $modId
* @param string $currentActionStatus
* @return string On method success a $currentAction status should be returned or error string.
*/
public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string
{
if (method_exists(self::class, $methodName)) {
return self::$methodName($modId, $currentActionStatus);
} else {
// no reason to report action method is missing.
return $currentActionStatus;
}
}
/**
* Required method to return namespace
* If namespace isn't provided return empty string
* and register namespace at top of this script..
*
* @return string
*/
public static function getModuleNamespace(): string
{
// Module Manager will register this namespace.
return 'OpenEMR\\Modules\\ClaimRevConnector\\';
}
/**
* Required method to return this class object
* so it will be instantiated in Laminas Manager.
*
* @return ModuleManagerListener
*/
public static function initListenerSelf(): ModuleManagerListener
{
return new self();
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function install($modId, $currentActionStatus): mixed
{
$modService = new ModuleServices();
/* setting the active ui flag here will allow the config button to show
* before enable. This is a good thing because it allows the user to
* configure the module before enabling it. However, if the module is disabled
* this flag is reset by MM.
*/
$modService::setModuleState($modId, '0', '1');
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function help_requested($modId, $currentActionStatus): mixed
{
// must call a script that implements a dialog to show help.
// I can't find a way to override the Lamina's UI except using a dialog.
if (file_exists(__DIR__ . '/show_help.php')) {
include __DIR__ . '/show_help.php';
}
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function preenable($modId, $currentActionStatus): mixed
{
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function enable($modId, $currentActionStatus): mixed
{
$modService = new ModuleServices();
if ($modService->isClaimRevConfigured()) {
$modService::setModuleState($modId, '1', '0');
return $currentActionStatus;
}
$modService::setModuleState($modId, '1', '1');
return xlt("Claim Rev Service is not configured. Please configure Claim Rev Service in the Admin Config.");
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function disable($modId, $currentActionStatus): mixed
{
// allow config button to show before enable.
ModuleServices::setModuleState($modId, '0', '1');
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function unregister($modId, $currentActionStatus): mixed
{
$sql = "DELETE FROM `background_services` WHERE `name` = ? OR `name` = ? OR `name` = ?";
sqlQuery($sql, array('ClaimRev_Send', 'ClaimRev_Receive', 'ClaimRev_Elig_Send_Receive'));
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function reset_module($modId, $currentActionStatus): mixed
{
$rtn = true;
$modService = new ModuleServices();
$logMessage = ''; // Initialize an empty string to store log messages
if (!$modService::getModuleState($modId)) {
$sql = "DELETE FROM `globals` WHERE `gl_name` LIKE 'oe_claimrev%'";
$rtn = sqlQuery($sql);
$logMessage .= "DELETE FROM `globals`: " . (empty($rtn) ? "Success" : "Failed") . "\n";
$sql = "DROP TABLE IF EXISTS `mod_claimrev_eligibility`";
$rtn = sqlQuery($sql);
$logMessage .= "DROP TABLE `mod_claimrev_eligibility`: " . (empty($rtn) ? "Success" : "Failed") . "\n";
error_log(text($logMessage));
}
// return log messages to the MM to show user.
return text($logMessage);
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function install_sql($modId, $currentActionStatus): mixed
{
return $currentActionStatus;
}
/**
* @param $modId
* @param $currentActionStatus
* @return mixed
*/
private function upgrade_sql($modId, $currentActionStatus): mixed
{
return $currentActionStatus;
}
/**
* Grab all Module setup or columns values.
*
* @param $modId
* @param string $col
* @return array
*/
function getModuleRegistry($modId, $col = '*'): array
{
$registry = [];
$sql = "SELECT $col FROM modules WHERE mod_id = ?";
$results = sqlQuery($sql, array($modId));
foreach ($results as $k => $v) {
$registry[$k] = trim((preg_replace('/\R/', '', $v)));
}
return $registry;
}
}