4 * Bootstrap for custom Fax SMS module.
5 * Since this was our original example module,
6 * I've left it basically intact from original.
9 * @link http://www.open-emr.org
11 * @author Stephen Nielson <stephen@nielson.org>
12 * @copyright Copyright (c) 2019 Stephen Nielson <stephen@nielson.org>
13 * @author Jerry Padgett <sjpadgett@gmail.com>
14 * @copyright Copyright (c) 2019-2023 Jerry Padgett <sjpadgett@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 This module uses an abstract class to arbitrate and dispatch
20 API calls to different vendor services for both the fax and sms type on a per-call basis.
21 To add new vendors, just follow and use the existing dispatching flow
22 for an existing service type and vendor service.
25 use OpenEMR\Events\Messaging\SendNotificationEvent
;
26 use OpenEMR\Events\Messaging\SendSmsEvent
;
27 use OpenEMR\Events\PatientDocuments\PatientDocumentEvent
;
28 use OpenEMR\Events\PatientReport\PatientReportEvent
;
29 use OpenEMR\Menu\MenuEvent
;
30 use OpenEMR\Modules\FaxSMS\Controller\AppDispatch
;
31 use OpenEMR\Modules\FaxSMS\Events\NotificationEventListener
;
32 use Symfony\Component\EventDispatcher\EventDispatcher
;
33 use Symfony\Component\EventDispatcher\EventDispatcherInterface
;
34 use Symfony\Contracts\EventDispatcher\Event
;
37 $allowFax = ($GLOBALS['oefax_enable_fax'] ??
null);
38 $allowSMS = ($GLOBALS['oefax_enable_sms'] ??
null);
39 $allowSMSButtons = ($GLOBALS['oesms_send'] ??
null);
42 * @global OpenEMR\Core\ModulesClassLoader $classLoader
44 $classLoader->registerNamespaceIfNotExists('OpenEMR\\Modules\\FaxSMS\\', __DIR__
. DIRECTORY_SEPARATOR
. 'src');
47 * @var EventDispatcherInterface $eventDispatcher
49 * @global $eventDispatcher @see ModulesApplication::loadCustomModule
50 * @global $module @see ModulesApplication::loadCustomModule
54 * @global EventDispatcher $dispatcher Injected by the OpenEMR module loader;
56 $dispatcher = $GLOBALS['kernel']->getEventDispatcher();
59 function oe_module_faxsms_add_menu_item(MenuEvent
$event): MenuEvent
61 $allowFax = ($GLOBALS['oefax_enable_fax'] ??
null);
62 $allowSMS = ($GLOBALS['oefax_enable_sms'] ??
null);
63 $menu = $event->getMenu();
65 $menuItem = new stdClass();
66 $menuItem->requirement
= 0;
67 $menuItem->target
= 'sms';
68 $menuItem->menu_id
= 'mod0';
69 $menuItem->label
= $allowSMS == '2' ?
xlt("Manage Twilio Messaging") : xlt("Manage Messaging");
70 $menuItem->url
= "/interface/modules/custom_modules/oe-module-faxsms/messageUI.php?type=sms";
71 $menuItem->children
= [];
72 $menuItem->acl_req
= ["patients", "docs"];
73 $menuItem->global_req
= ["oefax_enable_sms"];
75 $menuItem2 = new stdClass();
76 $menuItem2->requirement
= 0;
77 $menuItem2->target
= 'fax';
78 $menuItem2->menu_id
= 'mod1';
79 $menuItem2->label
= $allowFax == '3' ?
xlt("Manage etherFAX") : xlt("Manage FAX");
80 $menuItem2->url
= "/interface/modules/custom_modules/oe-module-faxsms/messageUI.php?type=fax";
81 $menuItem2->children
= [];
82 $menuItem2->acl_req
= ["patients", "docs"];
83 $menuItem2->global_req
= ["oefax_enable_fax"];
84 // Child of Manage Modules top menu.
85 foreach ($menu as $item) {
86 if ($item->menu_id
== 'modimg') {
87 // ensure service is on in globals.
88 if (!empty($allowFax)) {
89 $item->children
[] = $menuItem2;
91 if (!empty($allowSMS)) {
92 $item->children
[] = $menuItem;
97 $event->setMenu($menu);
101 $eventDispatcher->addListener(MenuEvent
::MENU_UPDATE
, 'oe_module_faxsms_add_menu_item');
103 /* Moved globals Module setup section to module config panel. That's why it's there. */
105 // patient report send fax button
106 function oe_module_faxsms_patient_report_render_action_buttons(Event
$event): void
109 <button type
="button" class="genfax btn btn-success btn-sm btn-send-msg" value
="<?php echo xla('Send Fax'); ?>"><?php
echo xlt('Send Fax'); ?
></button
><span id
="waitplace"></span
>
110 <input type
='hidden' name
='fax' value
='0'>
114 function oe_module_faxsms_patient_report_render_javascript_post_load(Event
$event): void
117 function getFaxContent() {
118 top
.restoreSession();
119 document
.report_form
.fax
.value
= 1;
120 let url
= 'custom_report.php';
121 let wait
= '<span id="wait"><?php echo ' ' . xlt("Building Document") . ' ... '; ?><i class="fa fa-cog fa-spin fa-2x"></i></span>';
122 $
("#waitplace").append(wait
);
126 data
: $
("#report_form").serialize(),
127 success
: function (content
) {
128 document
.report_form
.fax
.value
= 0;
129 let btnClose
= <?php
echo xlj("Cancel"); ?
>;
130 let title
= <?php
echo xlj("Send To Contact"); ?
>;
131 let url
= top
.webroot_url +
'/interface/modules/custom_modules/oe-module-faxsms/contact.php?isContent=0&type=fax&file=' +
encodeURIComponent(content
);
132 dlgopen(url
, '', 'modal-sm', 700, '', title
, {buttons
: [{text
: btnClose
, close
: true, style
: 'secondary'}]});
135 }).always(function () {
140 $
(".genfax").click(function() {getFaxContent();});
143 // patient documents fax anchor
144 function oe_module_faxsms_document_render_action_anchors(Event
$event): void
147 <a
class="btn btn-success btn-sm btn-send-msg" href
="" onclick
="return doFax(event,file,mime)">
148 <span
><?php
echo xlt('Send Fax'); ?
></span
>
153 function oe_module_faxsms_document_render_javascript_fax_dialog(Event
$event): void
156 function doFax(e
, filePath
, mime
='') {
158 let btnClose
= <?php
echo xlj("Cancel"); ?
>;
159 let title
= <?php
echo xlj("Send To Contact"); ?
>;
160 let url
= top
.webroot_url +
161 '/interface/modules/custom_modules/oe-module-faxsms/contact.php?isDocuments=1&type=fax&file=' +
162 encodeURIComponent(filePath
) +
'&mime=' +
encodeURIComponent(mime
) +
'&docid=' +
encodeURIComponent(docid
);
163 dlgopen(url
, 'faxto', 'modal-md', 700, '', title
, {buttons
: [{text
: btnClose
, close
: true, style
: 'primary'}]});
168 function oe_module_faxsms_sms_render_action_buttons(Event
$event): void
171 <button type
="button" class="sendsms btn btn-success btn-send-msg"
173 <?php echo attr_js($event->getPid()); ?>,
174 <?php echo attr_js($event->getRecipientPhone()); ?>
176 value
="true"><?php
echo xlt('Send SMS'); ?
></button
>
179 function oe_module_faxsms_sms_render_javascript_post_load(Event
$event): void
182 function sendSMS(pid
, phone
) {
183 let btnClose
= <?php
echo xlj("Cancel"); ?
>;
184 let title
= <?php
echo xlj("Send SMS Message"); ?
>;
185 let url
= top
.webroot_url +
186 '/interface/modules/custom_modules/oe-module-faxsms/contact.php?type=sms&isSMS=1&pid=' +
encodeURIComponent(pid
) +
187 '&recipient=' +
encodeURIComponent(phone
);
188 dlgopen(url
, '', 'modal-sm', 700, '', title
, {
189 buttons
: [{text
: btnClose
, close
: true, style
: 'secondary'}]
194 // SMS and/or Email send notification
196 function notificationButton(Event
$notificationEvent): void
199 <button type
="button" class="sendsms btn btn-success btn-sm btn-send-msg"
200 onclick
="sendNotification(
201 <?php echo attr_js($notificationEvent->getPid()); ?>,
202 <?php echo attr_js($notificationEvent->getDocumentName()); ?>,
203 <?php echo attr_js($notificationEvent->getPatientDetails()); ?>
205 value
="true"><?php
echo xlt('Notify'); ?
></button
>
209 function notificationDialogFunction(Event
$event): void
212 function sendNotification(pid
, docName
, details
) {
213 let btnClose
= <?php
echo xlj("Cancel"); ?
>;
214 let title
= <?php
echo xlj("Send Message"); ?
>;
215 let url
= top
.webroot_url +
216 '/interface/modules/custom_modules/oe-module-faxsms/contact.php?type=sms&isSMS=1&isNotification=1&pid=' +
217 encodeURIComponent(pid
) +
218 '&title=' +
encodeURIComponent(docName
) +
219 '&details=' +
encodeURIComponent(details
);
220 dlgopen(url
, '', 'modal-sm', 700, '', title
, {
221 buttons
: [{text
: btnClose
, close
: true, style
: 'secondary'}]
226 // We also have a drop box in the user interface. Could be an event for elsewhere.
229 $eventDispatcher->addListener(PatientReportEvent
::ACTIONS_RENDER_POST
, 'oe_module_faxsms_patient_report_render_action_buttons');
230 $eventDispatcher->addListener(PatientReportEvent
::JAVASCRIPT_READY_POST
, 'oe_module_faxsms_patient_report_render_javascript_post_load');
232 $eventDispatcher->addListener(PatientDocumentEvent
::ACTIONS_RENDER_FAX_ANCHOR
, 'oe_module_faxsms_document_render_action_anchors');
233 $eventDispatcher->addListener(PatientDocumentEvent
::JAVASCRIPT_READY_FAX_DIALOG
, 'oe_module_faxsms_document_render_javascript_fax_dialog');
236 if ($allowSMSButtons) {
237 $eventDispatcher->addListener(SendSmsEvent
::ACTIONS_RENDER_SMS_POST
, 'oe_module_faxsms_sms_render_action_buttons');
238 $eventDispatcher->addListener(SendSmsEvent
::JAVASCRIPT_READY_SMS_POST
, 'oe_module_faxsms_sms_render_javascript_post_load');
241 if (!empty($_SESSION['session_database_uuid'] ??
null) && $allowSMS) {
242 $eventDispatcher->addListener(SendNotificationEvent
::SEND_NOTIFICATION_BY_SERVICE
, [new NotificationEventListener(), 'onNotifyEvent']);
244 $eventDispatcher->addListener(SendNotificationEvent
::ACTIONS_RENDER_NOTIFICATION_POST
, 'notificationButton');
245 $eventDispatcher->addListener(SendNotificationEvent
::JAVASCRIPT_READY_NOTIFICATION_POST
, 'notificationDialogFunction');