Skip to content

Commit

Permalink
Module fixes and updates (openemr#7429)
Browse files Browse the repository at this point in the history
* Module fixes and updates
- PHP warnings

* faxsms etherfax module Improvements
- several PHP warnins and error fixed
- introduct two new classes to support image to pdf including tiff images

* - remove unneeded controller

* - add resize image method for GD
- pull image control to using just service
- add JS funtions to convert tiff to jpeg/png for backup to imagick
- add imagick support for tiff to image to pdf

* - add tiff and downgrade jsPDF for compatability
- update hpm packages

* Some refactor for readability

* major refactor to consoldate shared rescources and readabilty.

* - fix reversed signature args for callerid and caller name on fax send causing server to reject the request.

* =- add caller id in fax lisy

* change function call
  • Loading branch information
sjpadgett authored May 20, 2024
1 parent e153ce2 commit 4cafd7d
Show file tree
Hide file tree
Showing 9 changed files with 1,481 additions and 732 deletions.
8 changes: 7 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ assets:
script: jszip.min.js
jspdf:
basePath: '%assets_static_relative%/jspdf/dist/'
script: jspdf.umd.min.js
script: jspdf.min.js
jspdfdebug:
basePath: '%assets_static_relative%/jspdf/dist/'
script: jspdf.debug.js
jstiff:
basePath: '%assets_static_relative%/tiff/'
script: tiff.min.js
dwv:
basePath: '%assets_static_relative%/dwv/'
script:
Expand Down
119 changes: 64 additions & 55 deletions interface/modules/custom_modules/oe-module-faxsms/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,68 +96,77 @@
}
}
// when the form is submitted
$('#contact-form').on('submit', function (e) {
if (!e.isDefaultPrevented()) {
let wait = '<div class="text-center wait"><i class="fa fa-cog fa-spin fa-2x"></i></div>';
let url = 'sendFax?type=fax';
if (isSms) {
url = 'sendSMS?type=sms';
}
if (isForward) {
url = 'forwardFax?type=fax';
}
if (isEmail) {
url = 'sendEmail?type=email';
}
if (isOnetime) {
url = "./library/api_onetime.php?";
if (isSms) {
url += 'sendOneTime&type=sms'
} else {
url += 'sendOneTime&type=email';
}
}
$(document).ready(function() {
// Ensuring event handlers are set after the DOM is fully loaded
$('#contact-form').on('submit', function(e) {
e.preventDefault(); // Prevent the default form submit

const wait = '<div class="text-center wait"><i class="fa fa-cog fa-spin fa-2x"></i></div>';
$('#contact-form').find('.messages').html(wait);
// POST values in the background the script URL

const url = buildUrl();
const formData = $(this).serialize();

$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
success: function (data) {
try {
let t_data = JSON.parse(data);
data = t_data;
} catch (e) {
}
let err = (data.search(/Exception/) !== -1 ? 1 : 0);
if (!err) {
err = (data.search(/Error:/) !== -1) ? 1 : 0;
}
// Type of the message: success or danger. Apply it to the alert.
let messageAlert = 'alert-' + (err !== 0 ? 'danger' : 'success');
let messageText = data;

// let's compose alert box HTML
let alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable">' +
'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';

// If we have messageAlert and messageText
if (messageAlert && messageText) {
// inject the alert to messages div in our form
$('#contact-form').find('.messages').html(alertBox);
setTimeout(function () {
if (!err) {
// close dialog as we have success.
dlgclose();
}
// if error let user close dialog for time to read error message.
}, 4000);
}
data: formData,
success: handleResponse,
error: function() {
showErrorMessage('An unexpected error occurred and your request could not be completed.');
}
});
return false;
});

function buildUrl() {
// Simplify logic by directly mapping conditions to URLs
if (isOnetime) {
const type = isSms ? 'sms' : 'email';
return `./library/api_onetime.php?sendOneTime&type=${encodeURIComponent(type)}`;
}

if (isSms) {
return 'sendSMS?type=sms';
} else if (isForward) {
return 'forwardFax?type=fax';
} else if (isEmail) {
return 'sendEmail?type=email';
} else {
return 'sendFax?type=fax';
}
}

function handleResponse(data) {
let jsonData;
try {
jsonData = JSON.parse(data);
} catch (e) {
jsonData = data; // Use data as is if it can't be parsed as JSON
}

const isError = /Exception|Error:/.test(jsonData);
const messageType = isError ? 'danger' : 'success';
const messageText = jsonData;
const alertBox = `<div class="alert alert-${messageType} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
${messageText}
</div>`;

$('#contact-form').find('.messages').html(alertBox);
if (!isError) {
setTimeout(() => { dlgclose(); }, 4000); // Auto-close dialog on success
}
}
})

function showErrorMessage(message) {
const alertBox = `<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
${message}
</div>`;
$('#contact-form').find('.messages').html(alertBox);
}
});

});

function sel_patient() {
Expand Down
Loading

0 comments on commit 4cafd7d

Please sign in to comment.