Skip to content

Commit

Permalink
Merge pull request openemr#7488 from sjpadgett/module_702
Browse files Browse the repository at this point in the history
picks for patch2
  • Loading branch information
sjpadgett authored Jun 17, 2024
2 parents f104cf7 + 7183f3d commit 12b35e2
Show file tree
Hide file tree
Showing 31 changed files with 1,178 additions and 825 deletions.
79 changes: 42 additions & 37 deletions interface/modules/custom_modules/oe-module-faxsms/messageUI.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Fax SMS Module Member
* Fax and SMS Module UI Member
*
* @package OpenEMR
* @link http://www.open-emr.org
Expand Down Expand Up @@ -34,8 +34,8 @@
die("<h3>" . xlt("Not Authorised!") . "</h3>");
}
Header::setupHeader(['opener', 'datetime-picker', 'jspdf', 'jstiff']);
echo "<script>const pid=" . js_escape($pid) . ";const portalUrl=" . js_escape($clientApp->portalUrl ?? '') .
";const currentService=" . js_escape($service) . ";const serviceType=" . js_escape($serviceType) . "</script>";
echo "<script>let pid=" . js_escape($pid ?? 0) . ";let portalUrl=" . js_escape($clientApp->portalUrl ?? '') .
";let currentService=" . js_escape($service) . ";let serviceType=" . js_escape($serviceType) . "</script>";
?>
<script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/dropzone/dist/dropzone.js"></script>
<script>
Expand Down Expand Up @@ -313,10 +313,6 @@ function showPrint(base64, _contentType = 'image/tiff') {

function showDocument(_base64, _contentType = 'image/tiff') {
try {
// Log the type and value of _base64 to debug
console.log('Type of _base64:', typeof _base64);
console.log('Content of _base64:', _base64);

// Ensure _base64 is a string
if (typeof _base64 !== 'string') {
throw new TypeError('Expected a base64 string');
Expand Down Expand Up @@ -356,54 +352,63 @@ function displayInNewWindow(dataUrl) {
}
}

// SMS status
// SMS Fax status
function retrieveMsgs(e = '', req = '') {
try {
top.restoreSession();
} catch (error) {
console.log('Session restore failed!');
console.log('Session restore failed!', error);
}

if (e !== '') {
e.preventDefault();
e.stopPropagation();
}
let actionUrl = 'fetchSMSList?type=sms';
if (serviceType === 'fax') {
actionUrl = 'fax/getPending?type=fax';
}
let id = pid;
let datefrom = $('#fromdate').val();
let dateto = $('#todate').val();
let data = [];
$(".brand").addClass('fa fa-spinner fa-spin');
$("#rcvdetails tbody").empty();
$("#sent-details tbody").empty();
$("#msgdetails tbody").empty();
return $.post(actionUrl,
{
'type': serviceType,
'pid': pid,
'datefrom': datefrom,
'dateto': dateto
}, function () {
}, 'json').done(function (data) {

const actionUrl = (serviceType === 'fax') ? 'fax/getPending?type=fax' : 'fetchSMSList?type=sms';
const datefrom = $('#fromdate').val();
const dateto = $('#todate').val();

// Cache DOM elements
const brandElement = $(".brand");
const rcvDetailsBody = $("#rcvdetails tbody");
const sentDetailsBody = $("#sent-details tbody");
const msgDetailsBody = $("#msgdetails tbody");

// Start loading animation
brandElement.addClass('fa fa-spinner fa-spin');
rcvDetailsBody.empty();
sentDetailsBody.empty();
msgDetailsBody.empty();

return $.post(actionUrl, {
'type': serviceType,
'pid': pid,
'datefrom': datefrom,
'dateto': dateto
}, null, 'json').done(function (data) {
brandElement.removeClass('fa fa-spinner fa-spin');

if (data.error) {
$(".brand").removeClass('fa fa-spinner fa-spin');
alertMsg(data.error);
return false;
}
// populate our cards
$("#rcvdetails tbody").empty().append(data[0]);
$("#sent-details tbody").empty().append(data[1]);
$("#msgdetails tbody").empty().append(data[2]);
// get call logs

// Populate our cards
rcvDetailsBody.append(data[0]);
sentDetailsBody.append(data[1]);
msgDetailsBody.append(data[2]);

// Get call logs if the service type is SMS
if (serviceType === 'sms') {
getLogs();
}
}).fail(function (xhr, status, error) {
alertMsg(<?php echo xlj('Not Authenticated or not authorised. Ensure valid credentials are setup from Activity menu.'); ?>, 7000);
const message = `Error: ${error || 'Request to fetch pending new faxes failed with Unknown error!'}<br />Perhaps invalid or missing credentials. Verify, fix and try again if so.`;
alertMsg(message, 10000);
console.error('Request failed: ', status, error);
}).always(function () {
$(".brand").removeClass('fa fa-spinner fa-spin');
brandElement.removeClass('fa fa-spinner fa-spin');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,34 @@ public static function emailDocument($email, $body, $file, array $user = []): st
*/
public function fetchReminderCount(): string
{
// removed polling API to download pending faxes.
// this is better served in a background task.
return json_encode($this->fetchQueueCount());
}

/**
* @return int
*/
public function pollAndInsertAllPendingFax(): int
{
// authenticate and return if not successful. security measure
if (!$this->authenticate()) {
error_log('Error: Authentication failed polling fax server.');
return 0;
}
$c = 0;
while ($fax = $this->client->getNextUnreadFax(true)) {
$c++;
if ($c > 20) {
break;
}
if (!empty($fax->JobId)) {
$this->insertFaxQueue($fax);
$this->client->setFaxReceived($fax->JobId);
}
}

return json_encode($this->fetchQueueCount());
// return the count of faxes processed
return $c;
}

/**
Expand Down Expand Up @@ -328,11 +346,12 @@ public function getPending()
if (!$this->authenticate()) {
return $this->authErrorDefault;
}

// Let us fetch any new pending faxes to queue.
$newFaxCount = $this->pollAndInsertAllPendingFax();
$pull = $this->fetchReminderCount();
$dateFrom = date("Y-m-d H:i:s", strtotime(($this->getRequest('datefrom') . 'T00:00:01')));
$dateTo = date("Y-m-d H:i:s", strtotime(($this->getRequest('dateto') . 'T23:59:59')));
$faxStore = $this->fetchFaxQueue($dateFrom, $dateTo);
$faxStore = $this->fetchFaxQueue($dateFrom, $dateTo, false);
$responseMsgs = [0 => '', 2 => xlt('Not Implemented')];

foreach ($faxStore as $faxDetails) {
Expand Down Expand Up @@ -581,8 +600,12 @@ public function insertFaxQueue($faxDetails): int
* @param $end
* @return array
*/
public function fetchFaxQueue($start, $end): array
public function fetchFaxQueue($start, $end, $pollForNew = false): array
{
if ($pollForNew) {
$this->pollAndInsertAllPendingFax();
}

$rows = [];
$result = sqlStatement("SELECT `id`, `details_json`, `receive_date` FROM `oe_faxsms_queue` WHERE `deleted` = '0' AND (`receive_date` > ? AND `receive_date` < ?)", [$start, $end]);

Expand Down
2 changes: 1 addition & 1 deletion interface/modules/custom_modules/oe-module-weno/info.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Weno EZ Integration eRx Module v1.0.0
Weno EZ Integration eRx Module v2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function wenoAlertManager(option, element, spinElement) {
element.classList.add("d-none");
element.classList.remove("alert", "alert-success");
element.innerHTML = "";
window.location.replace(window.location.href)
window.location.replace(window.location.href);
}, 3000
);

Expand All @@ -47,6 +47,7 @@ function wenoAlertManager(option, element, spinElement) {
element.classList.add("d-none");
element.classList.remove("alert", "alert-danger");
element.innerHTML = "";
window.location.replace(window.location.href);
}, 5000);
element.classList.remove("d-none");
element.classList.add("alert", "alert-danger");
Expand Down
Loading

0 comments on commit 12b35e2

Please sign in to comment.