Skip to content

Commit

Permalink
Backport etherfax openemr#7429 openemr#7447
Browse files Browse the repository at this point in the history
- etherfax changes
  • Loading branch information
sjpadgett committed May 22, 2024
1 parent a60e591 commit 316035f
Show file tree
Hide file tree
Showing 7 changed files with 865 additions and 590 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function getLayoutRes()
$form_city = '';
$form_postcode = '';
$form_countrycode = '';
$form_regdate = DateToYYYYMMDD(trim($_POST['regdate']));
$form_regdate = DateToYYYYMMDD(trim($_POST['regdate'] ?? ''));
newPatientData(
$_POST["db_id"],
$_POST["db_id"] ?? '',
$_POST["title"] ?? '',
$form_fname,
$form_lname,
Expand Down Expand Up @@ -160,16 +160,16 @@ function getLayoutUOR($form_id, $field_id)
$_POST = $data;
unset($data);
}
$form_pubpid = $_POST['pubpid'] ? trim($_POST['pubpid']) : '';
$form_title = $_POST['title'] ? trim($_POST['title']) : '';
$form_fname = $_POST['fname'] ? trim($_POST['fname']) : '';
$form_mname = $_POST['mname'] ? trim($_POST['mname']) : '';
$form_lname = $_POST['lname'] ? trim($_POST['lname']) : '';
$form_refsource = $_POST['refsource'] ? trim($_POST['refsource']) : '';
$form_sex = $_POST['sex'] ? trim($_POST['sex']) : '';
$form_refsource = $_POST['refsource'] ? trim($_POST['refsource']) : '';
$form_dob = $_POST['DOB'] ? trim($_POST['DOB']) : '';
$form_regdate = $_POST['regdate'] ? trim($_POST['regdate']) : date('Y-m-d');
$form_pubpid = $_POST['pubpid'] ?? '' ? trim($_POST['pubpid']) : '';
$form_title = $_POST['title'] ?? '' ? trim($_POST['title']) : '';
$form_fname = $_POST['fname'] ?? '' ? trim($_POST['fname']) : '';
$form_mname = $_POST['mname'] ?? '' ? trim($_POST['mname']) : '';
$form_lname = $_POST['lname'] ?? '' ? trim($_POST['lname']) : '';
$form_refsource = $_POST['refsource'] ?? '' ? trim($_POST['refsource']) : '';
$form_sex = $_POST['sex'] ?? '' ? trim($_POST['sex']) : '';
$form_refsource = $_POST['refsource'] ?? '' ? trim($_POST['refsource']) : '';
$form_dob = $_POST['DOB'] ?? '' ? trim($_POST['DOB']) : '';
$form_regdate = $_POST['regdate'] ?? '' ? trim($_POST['regdate']) : date('Y-m-d');

?>
<!DOCTYPE html>
Expand Down
Loading

0 comments on commit 316035f

Please sign in to comment.