Skip to content

Commit

Permalink
faxsms fixes (openemr#7818)
Browse files Browse the repository at this point in the history
* faxsms fixes
RC setup from services menu wasn't refreshing after save.
ensure phone numbers are formatted
fix RC sendSMS for rest api endpoint

* resize some dialogs
  • Loading branch information
sjpadgett authored Nov 21, 2024
1 parent 96230d2 commit 0eeae03
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @package OpenEMR
* @link http://www.open-emr.org
* @author Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2018-2021 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2018-2024 Jerry Padgett <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
let url = top.webroot_url + '/interface/modules/custom_modules/oe-module-faxsms/contact.php?type=fax&isDocuments=0&isQueue=' +
encodeURIComponent(from) + '&file=' + encodeURIComponent(filePath);
// leave dialog name param empty so send dialogs can cascade.
dlgopen(url, '', 'modal-sm', 700, '', title, { // dialog restores session
dlgopen(url, '', 'modal-sm', 800, '', title, { // dialog restores session
buttons: [
{text: btnClose, close: true, style: 'secondary btn-sm'}
],
Expand Down Expand Up @@ -521,7 +521,7 @@ function messageReply(phone) {
let url = top.webroot_url + '/interface/modules/custom_modules/oe-module-faxsms/contact.php?type=sms&isSMS=1&recipient=' +
encodeURIComponent(phone);
// leave dialog name param empty so send dialogs can cascade.
dlgopen(url, '', 'modal-sm', 600, '', title, {
dlgopen(url, '', 'modal-sm', 700, '', title, {
buttons: [
{text: btnClose, close: true, style: 'secondary btn-sm'}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function getFaxContent() {
let btnClose = <?php echo xlj("Cancel"); ?>;
let title = <?php echo xlj("Send To Contact"); ?>;
let url = top.webroot_url + '/interface/modules/custom_modules/oe-module-faxsms/contact.php?isContent=0&type=fax&file=' + encodeURIComponent(content);
dlgopen(url, '', 'modal-sm', 700, '', title, {buttons: [{text: btnClose, close: true, style: 'secondary'}]});
dlgopen(url, '', 'modal-sm', 775, '', title, {buttons: [{text: btnClose, close: true, style: 'secondary'}]});
return false;
}
}).always(function () {
Expand Down Expand Up @@ -253,7 +253,7 @@ function sendSMS(pid, phone) {
let url = top.webroot_url +
'/interface/modules/custom_modules/oe-module-faxsms/contact.php?type=sms&isSMS=1&pid=' + encodeURIComponent(pid) +
'&recipient=' + encodeURIComponent(phone);
dlgopen(url, '', 'modal-md', 700, '', title, {
dlgopen(url, '', 'modal-md', 775, '', title, {
buttons: [{text: btnClose, close: true, style: 'secondary'}]
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
die("<h3>" . xlt("Not Authorised!") . "</h3>");
}
$c = $clientApp->getCredentials();
$module_config = $_REQUEST['module_config'] ?? 1;
echo "<script>var pid=" . js_escape($pid) . "</script>";
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -66,6 +67,7 @@
$('#setup-form').find('.messages').remove();
<?php if (!$module_config) { ?>
dlgclose();
location.reload();
<?php } else { ?>
location.reload();
<?php } ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ protected function saveSetup(array $setup = []): string
$username = $this->getRequest('username');
$ext = $this->getRequest('extension');
$account = $this->getRequest('account');
$phone = $this->getRequest('phone');
$phone = $this->formatPhoneForSave($this->getRequest('phone'));
$password = $this->getRequest('password');
$appkey = $this->getRequest('key');
$appsecret = $this->getRequest('secret');
$production = $this->getRequest('production');
$smsNumber = $this->getRequest('smsnumber');
$smsNumber = $this->formatPhoneForSave($this->getRequest('smsnumber'));
$smsMessage = $this->getRequest('smsmessage');
$smsHours = $this->getRequest('smshours');
$jwt = $this->getRequest('jwt');
Expand Down Expand Up @@ -619,4 +619,16 @@ public function verifyAcl($sect = 'patients', $v = 'docs', $u = ''): bool
{
return AclMain::aclCheckCore($sect, $v, $u);
}

public function formatPhoneForSave($number): string
{
// this is u.s only. need E-164
$n = preg_replace('/[^0-9]/', '', $number);
if (stripos($n, '1') === 0) {
$n = '+' . $n;
} else {
$n = '+1' . $n;
}
return $n;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,28 @@ public function faxProcessUploads(): string
* @param string $from
* @return string|bool
*/
public function sendSMS(string $toPhone = '', string $subject = '', string $message = '', string $from = ''): string|bool
public function sendSMS($toPhone = '', $subject = '', $message = '', $from = ''): string|bool
{
$authErrorMsg = $this->authenticate();
if ($authErrorMsg !== 1) {
return text(js_escape($authErrorMsg));
// goes to alert
}
$toPhone = $toPhone ?: $this->getRequest('phone');
$from = $from ?: $this->getRequest('from');
$message = $message ?: $this->getRequest('comments');

$smsNumber = $this->credentials['smsNumber'];
$smsNumber = $this->formatPhone($this->credentials['smsNumber']);
$from = $this->formatPhone($from);
$toPhone = $this->formatPhone($toPhone);
if ($smsNumber) {
try {
$this->platform->post('/account/~/extension/~/sms', [
'from' => ['phoneNumber' => $smsNumber],
'to' => [['phoneNumber' => $toPhone]],
'text' => $message,
]);
sleep(1);
sleep(1.25);
// RC may only allow 1/second.
return true;
} catch (ApiException $e) {
Expand Down Expand Up @@ -408,6 +413,7 @@ private function sendFaxRequest($phone, $content, $fileName = '', $comments = 'N
$content = file_get_contents($content);
}
try {
$phone = $this->formatPhone($phone);
$mime = FileUtils::fileGetMimeType($fileName, $content);
$type = $mime['type'];
$fileName = $mime['filePath'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ public function onNotifyDocumentRenderOneTime(SendNotificationEvent $event)

if ($patient['hipaa_allowsms'] == 'YES' && $includeSMS) {
$clientApp = AppDispatch::getApiService('sms');
$clientApp->sendSMS(
$status_api = $clientApp->sendSMS(
$recipientPhone,
"",
$text_message,
$recipientPhone
);
if ($status_api !== true) {
$status .= text($status_api);
}
$status .= xlt("Message sent.");
}

Expand Down Expand Up @@ -148,12 +151,15 @@ public function onNotifySendEvent(SendNotificationEvent $event): string

if ($patient['hipaa_allowsms'] == 'YES') {
$clientApp = AppDispatch::getApiService('sms');
$clientApp->sendSMS(
$status_api = $clientApp->sendSMS(
$recipientPhone,
"",
$message,
null // will get the "from" phone # from credentials
);
if ($status_api !== true) {
$status .= text($status_api);
}
$status .= xlt("Message sent.");
}

Expand Down Expand Up @@ -245,7 +251,7 @@ function sendNotification(pid, docName, docId, details) {
let btnClose = <?php echo xlj("Cancel"); ?>;
let title = <?php echo xlj("Send Message"); ?>;
let url = top.webroot_url + '<?php echo $url_part ?>' + encodeURIComponent(pid) + '&title=' + encodeURIComponent(docName) + '&template_id=' + encodeURIComponent(docId) + '&details=' + encodeURIComponent(details);
dlgopen(url, '', 'modal-sm', 700, '', title, {
dlgopen(url, '', 'modal-sm', 775, '', title, {
buttons: [{text: btnClose, close: true, style: 'secondary'}]
});
}
Expand Down

0 comments on commit 0eeae03

Please sign in to comment.