Skip to content

Commit

Permalink
Merge pull request openemr#7492 from sjpadgett/weno_updates
Browse files Browse the repository at this point in the history
Weno Search Tuning

(cherry picked from commit 674f8ea)
  • Loading branch information
sjpadgett committed Jun 21, 2024
1 parent 83b352f commit d1cb803
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$weno_zipcode = $_GET['weno_zipcode'] ?? false ?: '';
$weno_only = $_GET['weno_only'] == 'true' ? 'True' : '';
$full_day = $_GET['full_day'] == 'true' ? 'Yes' : '';
$weno_test_pharmacies = $_GET['test_pharmacy'] == 'true' ? 'True' : '';
$weno_test_pharmacies = $_GET['test_pharmacy'] ?? '' == 'true' ? 'True' : '';


// mail order is special case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE TABLE `weno_pharmacy` (
`State_Wide_Mail_Order` varchar(15) NOT NULL,
`Mail_Order_US_State_Serviced` varchar(255) DEFAULT NULL,
`Mail_Order_ US_Territories_Serviced` varchar(255) DEFAULT NULL,
`On_WENO` tinytext DEFAULT NULL,
`On_WENO` varchar(10) DEFAULT NULL,
`24HR` varchar(3) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ncpdp` (`NCPDP_safe`)
Expand All @@ -49,12 +49,12 @@ CREATE TABLE `weno_assigned_pharmacy` (

#IfNotTable weno_download_log
CREATE TABLE `weno_download_log` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`value` VARCHAR(63) NOT NULL,
`status` VARCHAR(255) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `value` (`value`)
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`value` VARCHAR(63) NOT NULL,
`status` VARCHAR(255) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `value` (`value`)
) ENGINE = InnoDB;
#EndIf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public function processWenoPharmacyCsv($filePath, bool $isInsertOnly = true): fa
$sql = "TRUNCATE TABLE weno_pharmacy";
sqlStatement($sql);
}

// Database configuration. Create connection.
$connect = new mysqli($GLOBALS["host"], $GLOBALS["login"], $GLOBALS["pass"], $GLOBALS["dbase"]);
// Use existing connection.
// Compared to creating a new connection, this method is slower by 3 seconds.
// Using the sqlStatement() method is even slower by 10 seconds. That's 13 seconds slower overall.
$connect = $GLOBALS['dbh'];
if ($connect->connect_error) {
$wenoLog->insertWenoLog("pharmacy", "Connection Failed.");
error_log("Connection failed: " . $connect->connect_error);
Expand Down Expand Up @@ -140,7 +141,7 @@ public function processWenoPharmacyCsv($filePath, bool $isInsertOnly = true): fa
}

$connect->commit();
$connect->close();
// $connect->close();
} catch (Exception $e) {
$connect->rollback();
error_log(text($e->getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ public function getWenoProviderId($id = null): mixed
ON DUPLICATE KEY UPDATE `setting_value` = ?";
sqlQuery($sql, [$provider['weno_prov_id'], $id, $provider['weno_prov_id']]);
}

$GLOBALS['weno_provider_uid'] = $GLOBALS['weno_prov_id'] = $provider['weno_prov_id']; // update users
$sql = "INSERT INTO `users` (`weno_prov_id`, `id`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `weno_prov_id` = ?";
sqlQuery($sql, [$GLOBALS['weno_provider_uid'], $id, $GLOBALS['weno_provider_uid']]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public function validateAdminCredentials($resetOnInvalid = false, $where = "pres
if (!empty($newKey)) {
// save new admin production key.
$this->setNewEncryptionKey($newKey);
error_log(errorLogEscape("$where Encryption Verify returned Invalid Key. Attempted to reset key."));
$wenoLog = new WenoLogService();
$wenoLog->insertWenoLog(text("$where"), "reset_encryption_key");
}
Expand Down
2 changes: 1 addition & 1 deletion interface/modules/custom_modules/oe-module-weno/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CREATE TABLE `weno_pharmacy` (
`State_Wide_Mail_Order` varchar(15) NOT NULL,
`Mail_Order_US_State_Serviced` varchar(255) DEFAULT NULL,
`Mail_Order_ US_Territories_Serviced` varchar(255) DEFAULT NULL,
`On_WENO` tinytext DEFAULT NULL,
`On_WENO` varchar(10) DEFAULT NULL,
`24HR` varchar(3) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ncpdp` (`NCPDP_safe`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require_once("$srcdir/patient.inc");

use OpenEMR\Common\Acl\AclMain;
use OpenEMR\Common\Crypto\CryptoGen;
use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Core\Header;
use OpenEMR\Modules\WenoModule\Services\PharmacyService;
Expand Down Expand Up @@ -52,6 +53,8 @@
$isKey = $wenoValidate->validateAdminCredentials(true);
*/

$cryptoGen = new CryptoGen();

// set up the dependencies for the page.
$pharmacyService = new PharmacyService();
$wenoProperties = new TransmitProperties();
Expand All @@ -63,13 +66,15 @@
$provider_name = $wenoProperties->getProviderName();
$patient_name = $wenoProperties->getPatientName();
$facility_name = $wenoProperties->getFacilityInfo();

//set the url for the iframe
$newRxUrl = "https://online.wenoexchange.com/en/NewRx/ComposeRx?useremail=";
if ($urlParam == 'error') { //check to make sure there were no errors
echo TransmitProperties::styleErrors(xlt("Cipher failure check encryption key"));
exit;
}

$urlOut = $newRxUrl . urlencode($provider_info['email']) . "&data=" . urlencode($urlParam);

?>
<!doctype html>
<html lang="en">
Expand Down Expand Up @@ -107,15 +112,15 @@
<script>
$(function () {
$('#form_reset_key').addClass('d-none');
/* Toggle reset button. */
<?php if ((int)$isValidKey > 997) { ?>
/* Toggle reset button. */
<?php if ((int)$isValidKey > 997) { ?>
$(function () {
const warnMsg = "<?php echo xlt('Internet connection problem. Returning to Patient chart when alert closes!'); ?>";
syncAlertMsg(warnMsg, 8000, 'danger', 'lg').then(() => {
window.location.href = "<?php echo $GLOBALS['web_root'] ?>/interface/patient_file/summary/demographics.php?set_pid=<?php echo urlencode(attr($_SESSION['pid'] ?? $pid ?? '')) ?>";
});
});
<?php } else if (!$isValidKey) { ?>
<?php } else if (!$isValidKey) { ?>
$(function () {
$('#form_reset_key').removeClass('d-none');
const warnMsg = "<?php
Expand All @@ -124,19 +129,45 @@
xlt('Afterwards you may continue and no other action is required by you.'); ?>";
syncAlertMsg(warnMsg, 8000, 'danger', 'lg');
});
<?php } else { ?>
$(function () {
$('#form_reset_key').addClass('d-none');
});
<?php } ?>
<?php } else { ?>
$(function () {
$('#form_reset_key').addClass('d-none');
});
<?php } ?>
});
$(function () {
// Function to generate debug info and create a downloadable file
function generateDebugInfo() {
let debugInfo = 'Debug Information:';
debugInfo += '\n- User Agent:' + navigator.userAgent;
debugInfo += '\n- Platform:' + navigator.platform;
debugInfo += '\n- Language:' + navigator.language;
debugInfo += '\n\n- URL:\n <?php echo js_escape($urlOut); ?>';
debugInfo += '\n\n- Data Raw:\n <?php echo js_escape($urlParam); ?>';
debugInfo += '\n\n- Encoded Data:\n <?php echo js_escape(urlencode($urlParam)); ?>';

const blob = new Blob([debugInfo], {type: 'text/plain'});
const url = URL.createObjectURL(blob);
$('#downloadLink').attr('href', url);
}

// Event handler for double-click on the trigger button
$('#trigger-debug').dblclick(function () {
generateDebugInfo();
$('#debugModal').modal('show');
});
$('#triggerButton').click(function () {
generateDebugInfo();
$('#debugModal').modal('show');
});
$('#downloadLink').click(function () {
$('#debugModal').modal('hide');
});
});
</script>
</head>
<body>
<?php
$urlOut = $newRxUrl . urlencode($provider_info['email']) . "&data=" . urlencode($urlParam);
?>
<div class="container-xl">
<div id="trigger-debug" class="container-xl">
<div class="container-xl sticky-container bg-light text-dark">
<form>
<header class="bg-light text-dark text-center">
Expand Down Expand Up @@ -188,16 +219,32 @@
</div>
</div>
<div class="container-xl mt-3">
<iframe id="wenoIfram"
title="Weno IFRAME"
width="100%"
height="900"
src="<?php echo $urlOut; ?>">
</iframe>
<iframe id="wenoIfram" title="Weno IFRAME" width="100%" height="900" src="<?php echo $urlOut; ?>"></iframe>
</div>
<footer>
<a href="<?php echo $GLOBALS['web_root'] ?>/interface/patient_file/summary/demographics.php?set_pid=<?php echo urlencode(attr($_SESSION['pid'] ?? $pid)) ?>" class="btn btn-primary float-right mt-2 mb-4 mr-3"><?php echo xlt("Return to Demographics"); ?></a>
<button id="triggerButton" class="btn btn-primary btn-sm m-2 ml-3" title="<?php echo xla("Download debug information to send to Weno support."); ?>"><i class="fa-solid fa-bug"></i></button>
</footer>
<!-- Modal Structure -->
<div class="modal fade" id="debugModal" tabindex="-1" role="dialog" aria-labelledby="debugModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="debugModalLabel"><?php echo xlt("Weno Debug Information"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p><?php echo xlt("Debug information has been generated. Click below to download."); ?></p>
<a id="downloadLink" class="btn btn-success" download="debug_info_<?php echo md5($provider_info['email']); ?>.txt"><?php echo xlt("Download Debug File"); ?></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo xlt("Close"); ?></button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
$pharmacyService = new PharmacyService();
$prev_prim_pharmacy = $pharmacyService->getWenoPrimaryPharm($_SESSION['pid']) ?? [];
$prev_alt_pharmacy = $pharmacyService->getWenoAlternatePharm($_SESSION['pid']) ?? [];
$prev_prim_pharmacy = json_encode($prev_prim_pharmacy);
$prev_alt_pharmacy = json_encode($prev_alt_pharmacy);
$prev_prim_pharmacy = js_escape($prev_prim_pharmacy);
$prev_alt_pharmacy = js_escape($prev_alt_pharmacy);

$sql = "SELECT list_id, option_id, title FROM list_options WHERE list_id = 'state'";
$res = sqlStatement($sql);
Expand Down Expand Up @@ -170,7 +170,7 @@
<?php
} ?>
</select>
<select class="form-control bg-light text-dark" name="weno_city" id="weno_city" onchange="cityChanged()"><?php echo xlt("Enter City"); ?></select>
<span id="weno_city_select"><select class="form-control bg-light text-dark" name="weno_city" id="weno_city" onchange="cityChanged()"><?php echo xlt("Enter City"); ?></select></span>
</div>
</div>
<div>
Expand All @@ -179,8 +179,8 @@
<?php echo xlt("Search Result Actions."); ?>
</cite>
<span class="ml-1 my-2" role="group">
<button type="button" class="btn btn-success btn-sm my-2" onclick="search()"><?php echo xlt("List Search"); ?></button>
<button type="button" class="btn btn-success btn-sm" onclick="searchOn()"><?php echo xlt("Name Search"); ?></button>
<button id="list-search-button" type="button" class="btn btn-success btn-sm my-2" onclick="search()"><?php echo xlt("List Search"); ?></button>
<button id="name-search-button" type="button" class="btn btn-success btn-sm" onclick="searchOn()"><?php echo xlt("Name Search"); ?></button>
<button type="button" class="btn btn-secondary btn-sm" onclick="clearFilters()"><?php echo xlt("Clear"); ?></button>
<span class="h5 alert-danger mt-3" id="searchResults"></span>
</span>
Expand Down Expand Up @@ -235,9 +235,9 @@
const clone = document.importNode(template.content, true);
wenoForm.appendChild(clone);

const pid = <?php echo json_encode($pid); ?>;
const prevPrimPharmacy = <?php echo json_encode($prev_prim_pharmacy); ?>;
const prevAltPharmacy = <?php echo json_encode($prev_alt_pharmacy); ?>;
const pid = <?php echo js_escape($pid); ?>;
const prevPrimPharmacy = <?php echo js_escape($prev_prim_pharmacy); ?>;
const prevAltPharmacy = <?php echo js_escape($prev_alt_pharmacy); ?>;

if (pid > 0) {
initPharmacyDisplay(prevPrimPharmacy, prevAltPharmacy);
Expand Down Expand Up @@ -277,6 +277,22 @@
wenoOnlyEle.checked = defaultFilters.weno_only === "on";
wenoOnly = document.getElementById('weno_only').checked;
}

const defaultCoverage = defaultFilters.weno_coverage;
if (defaultCoverage == 'State') {
document.getElementById('weno_zipcode').style.display = 'none';
document.getElementById('weno_city_select').style.display = 'none';
}

let triggerSearch = defaultFilters.weno_zipcode || defaultFilters.weno_state || defaultFilters.weno_city;
if (triggerSearch) {
// Initialize the search results
$('#list-search-button').trigger('click');
// Trigger the search after 1 second delay
setTimeout(() => {
$('#name-search-button').trigger('click');
}, 2000);
}
};

function initPharmacyDisplay(prevPrimPharmacy, prevAltPharmacy) {
Expand Down Expand Up @@ -335,7 +351,7 @@ function coverageChanged() {
const coverageElement = document.getElementById('weno_coverage');
const coverage = coverageElement.selectedOptions[0] ? coverageElement.selectedOptions[0].value : '';
const zipcodeElement = document.getElementById('weno_zipcode');
const cityElement = document.getElementById('select2-weno_city-container');
const cityElement = document.getElementById('weno_city_select');

if (coverage === 'State') {
zipcodeElement.style.display = 'none';
Expand Down Expand Up @@ -416,7 +432,7 @@ function createWenoPharmacySelect2() {
},
minimumInputLength: 3,
cache: true,
placeholder: 'Click and Type Filtered Pharmacy Name Search',
placeholder: 'Click here for Selected Filters Pharmacy Search by Name.',
allowClear: true
});
}
Expand Down Expand Up @@ -453,6 +469,12 @@ function createWenoCitySelect2() {
});
}

function destroyWenoCitySelect2() {
if ($('#weno_city').data('select2')) {
$('#weno_city').select2('destroy');
}
}

function searchOn() {
let pharmacySelector = document.getElementById("weno_pharmacy");
if ($('#weno_pharmacy').hasClass('select2-hidden-accessible')) {
Expand All @@ -471,9 +493,6 @@ function search() {
coverage = $('#weno_coverage').val();
$("#searchResults").text('');

const isValidZipcode = wenoZipcode && coverage;
const isValidCityAndState = wenoCity && wenoState && !wenoZipcode;

if (coverage && (wenoState || wenoZipcode)) {
$('#weno_city, #weno_state, #weno_coverage, #weno_zipcode').removeClass("is-invalid");
$('.warn').text('');
Expand All @@ -488,19 +507,21 @@ function search() {
if (!coverage) {
$('#weno_coverage').addClass("is-invalid");
$('.warn').text(jsText('Coverage is required'));
}
if (!wenoState) {
} else if (!wenoState && coverage == 'Local') {
$('#weno_state').addClass("is-invalid");
$('.warn').text(jsText('State or Zipcode is required'));
}
if (!coverage && !wenoZipcode) {
} else if (!wenoState && coverage == 'State') {
$('#weno_state').addClass("is-invalid");
$('.warn').text(jsText('State is required'));
} else if (!coverage && !wenoZipcode) {
$('#weno_zipcode').addClass("is-invalid");
$('.warn').text(jsText('Zipcode is required'));
}
}
}

function makeRequest() {
testPharmacies = document.getElementById('weno_test_pharmacies').checked;
// clear main search fields
if (testPharmacies) {
wenoState = '';
Expand All @@ -510,7 +531,6 @@ function makeRequest() {
}
wenoOnly = document.getElementById('weno_only').checked;
fullDay = document.getElementById('24hr').checked;
testPharmacies = document.getElementById('weno_test_pharmacies').checked;
let data = {
searchFor: 'weno_drop',
weno_state: wenoState,
Expand Down
Loading

0 comments on commit d1cb803

Please sign in to comment.