forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
217 lines (184 loc) · 6.79 KB
/
Bootstrap.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
<?php
/**
* Bootstrap file for the exporter
*
* @package OpenEMR
* @link http:https://www.open-emr.org
*
* @author Stephen Nielson <[email protected]
* @copyright Copyright (c) 2023 OpenEMR Foundation, Inc
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\Modules\EhiExporter;
/**
* Note the below use statements are importing classes from the OpenEMR core codebase
*/
use OpenEMR\Common\Logging\SystemLogger;
use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Core\Kernel;
use OpenEMR\Events\Core\TwigEnvironmentEvent;
use OpenEMR\Events\Globals\GlobalsInitializedEvent;
use OpenEMR\Events\Main\Tabs\RenderEvent;
use OpenEMR\Events\RestApiExtend\RestApiResourceServiceEvent;
use OpenEMR\Events\RestApiExtend\RestApiScopeEvent;
use OpenEMR\Modules\EhiExporter\Services\EhiExporter;
use OpenEMR\Services\Globals\GlobalSetting;
use OpenEMR\Menu\MenuEvent;
use OpenEMR\Events\RestApiExtend\RestApiCreateEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Twig\Error\LoaderError;
use Twig\Loader\FilesystemLoader;
// we import our own classes here.. although this use statement is unnecessary it forces the autoloader to be tested.
use OpenEMR\Modules\CustomModuleSkeleton\TaskRestController;
class Bootstrap
{
const MODULE_INSTALLATION_PATH = "/interface/modules/custom_modules/";
const MODULE_NAME = "oe-module-ehi-exporter";
const CERTIFIED_RELEASE_VERSION = "7.0.2";
/**
* @var EventDispatcherInterface The object responsible for sending and subscribing to events through the OpenEMR system
*/
private $eventDispatcher;
/**
* @var GlobalConfig Holds our module global configuration values that can be used throughout the module.
*/
private $globalsConfig;
/**
* @var string The folder name of the module. Set dynamically from searching the filesystem.
*/
private $moduleDirectoryName;
/**
* @var \Twig\Environment The twig rendering environment
*/
private $twig;
/**
* @var SystemLogger
*/
private $logger;
private static self $instance;
public function __construct(EventDispatcherInterface $eventDispatcher, ?Kernel $kernel = null)
{
if (empty($kernel)) {
$kernel = new Kernel();
}
// NOTE: eventually you will be able to pull the twig container directly from the kernel instead of instantiating
// it here.
$twig = new TwigContainer($this->getTemplatePath(), $kernel);
$twigEnv = $twig->getTwig();
$this->twig = $twigEnv;
$this->moduleDirectoryName = basename(dirname(__DIR__));
$this->eventDispatcher = $eventDispatcher;
// we inject our globals value.
$this->globalsConfig = new GlobalConfig($GLOBALS);
$this->logger = new SystemLogger();
}
public static function instantiate(EventDispatcher $eventDispatcher, Kernel $kernel): self
{
if (!isset(self::$instance)) {
self::$instance = new Bootstrap($eventDispatcher, $kernel);
self::$instance->subscribeToEvents();
}
return self::$instance;
}
public function getAssetPath()
{
return $GLOBALS['webroot'] . self::MODULE_INSTALLATION_PATH . $this->moduleDirectoryName . "/public/assets/";
}
public function getLogger()
{
return new SystemLogger();
}
public function getExporter()
{
$xmlConfigPath = $GLOBALS['webserver_root'] . DIRECTORY_SEPARATOR . 'Documentation' . DIRECTORY_SEPARATOR . 'EHI_Export';
// . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'openemr.openemr.xml';
return new EhiExporter(
$GLOBALS['webserver_root'] . $this->getPublicPath(),
$this->getPublicPath(),
$xmlConfigPath,
$this->getTwig()
);
}
public function getTwig()
{
$container = new TwigContainer($this->getTemplatePath(), $GLOBALS['kernel']);
return $container->getTwig();
}
public function subscribeToEvents()
{
// $this->addGlobalSettings();
$this->eventDispatcher->addListener(MenuEvent::MENU_UPDATE, [$this, 'addCustomModuleMenuItem']);
}
public function addCustomModuleMenuItem(MenuEvent $event)
{
$menu = $event->getMenu();
$menuItem = new \stdClass();
$menuItem->requirement = 0;
$menuItem->target = 'msc';
$menuItem->menu_id = 'ehiExporter0';
$menuItem->label = xlt("Electronic Health Information Export");
$menuItem->url = "/interface/modules/custom_modules/" . self::MODULE_NAME . "/public/";
$menuItem->children = [];
/**
* This defines the Access Control List properties that are required to use this module.
* Only Administrators are allowed to use this feature.
*/
$menuItem->acl_req = ["admin", "super"];
/**
* If you want your menu item to allows be shown then leave this property blank.
*/
$menuItem->global_req = [];
foreach ($menu as $item) {
if ($item->menu_id == 'misimg') {
$item->children[] = $menuItem;
break;
}
}
$event->setMenu($menu);
return $event;
}
/**
* @return GlobalConfig
*/
public function getGlobalConfig()
{
return $this->globalsConfig;
}
public function addGlobalSettings()
{
$this->eventDispatcher->addListener(GlobalsInitializedEvent::EVENT_HANDLE, [$this, 'addGlobalSettingsSection']);
}
public function addGlobalSettingsSection(GlobalsInitializedEvent $event)
{
// when we add more configuration we can add this here...
// $service = $event->getGlobalsService();
// $section = xlt("Ehi Exporter Module");
// $service->createSection($section, 'Portal');
//
// $settings = $this->globalsConfig->getGlobalSettingSectionConfiguration();
//
// foreach ($settings as $key => $config) {
// $value = $GLOBALS[$key] ?? $config['default'];
// $service->appendToSection(
// $section,
// $key,
// new GlobalSetting(
// xlt($config['title']),
// $config['type'],
// $value,
// xlt($config['description']),
// true
// )
// );
// }
}
private function getPublicPath()
{
return self::MODULE_INSTALLATION_PATH . ($this->moduleDirectoryName ?? '') . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR;
}
public function getTemplatePath()
{
return \dirname(__DIR__) . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR;
}
}