From 520263d6921e2a8c79b5cc35fb3c61ff741cdc57 Mon Sep 17 00:00:00 2001 From: Jerry Padgett Date: Sun, 4 Feb 2024 21:13:26 -0500 Subject: [PATCH] - fix transaction for pharmacy download (#7208) - refactor user defualt fac to include select from user facility when user is not logged into facility. - convert error to interface style helper to static - create static styler for echo to interface. - refactor all show errors to include a style compatable with themes. --- .../src/Services/LogProperties.php | 9 +-- .../src/Services/TransmitProperties.php | 67 ++++++++++++------- .../src/Services/WenoPharmaciesImport.php | 4 ++ .../oe-module-weno/templates/indexrx.php | 3 +- .../oe-module-weno/templates/rxlogmanager.php | 5 +- .../oe-module-weno/templates/synch.php | 3 +- 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/interface/modules/custom_modules/oe-module-weno/src/Services/LogProperties.php b/interface/modules/custom_modules/oe-module-weno/src/Services/LogProperties.php index bc145872d0a..8fcd64de1e9 100644 --- a/interface/modules/custom_modules/oe-module-weno/src/Services/LogProperties.php +++ b/interface/modules/custom_modules/oe-module-weno/src/Services/LogProperties.php @@ -143,7 +143,7 @@ public function logSync() $logurlparam = $this->logEpcs(); $syncLogs = "https://online.wenoexchange.com/en/EPCS/DownloadNewRxSyncDataVal?useremail="; if ($logurlparam == 'error') { - echo xlt("Cipher failure check encryption key"); + echo TransmitProperties::styleErrors(xlt("Cipher failure check encryption key")); error_log("Cipher failure check encryption key", time()); exit; } @@ -187,16 +187,17 @@ public function getProviderEmail() if (!empty($provider_info)) { return $provider_info; } else { - $error = "Provider email address is missing. Go to [User settings > Email] to add provider's weno registered email address"; + $error = xlt("Provider email address is missing. Go to [User settings > Email] to add provider's weno registered email address"); error_log($error); - exit; + TransmitProperties::errorWithDie($error); } } else if ($GLOBALS['weno_admin_username']) { $provider_info["email"] = $GLOBALS['weno_admin_username']; return $provider_info; } else { - $error = "Provider email address is missing. Go to [User settings > Email] to add provider's weno registered email address"; + $error = xlt("Provider email address is missing. Go to User settings Weno tab to add provider's weno registered email address"); error_log($error); + echo TransmitProperties::styleErrors($error); exit; } } diff --git a/interface/modules/custom_modules/oe-module-weno/src/Services/TransmitProperties.php b/interface/modules/custom_modules/oe-module-weno/src/Services/TransmitProperties.php index 263d8ddc40d..320ba60befb 100644 --- a/interface/modules/custom_modules/oe-module-weno/src/Services/TransmitProperties.php +++ b/interface/modules/custom_modules/oe-module-weno/src/Services/TransmitProperties.php @@ -15,6 +15,7 @@ namespace OpenEMR\Modules\WenoModule\Services; use OpenEMR\Common\Crypto\CryptoGen; +use OpenEMR\Services\FacilityService; class TransmitProperties { @@ -98,13 +99,13 @@ public function createJsonObject() } /** - * @return mixed + * @return array|void */ public function getProviderEmail() { $provider_info = ['email' => $GLOBALS['weno_provider_email']]; if (empty($provider_info['email'])) { - echo xlt('Provider email address is missing. Go to [User Settings select Weno Tab] and enter your Weno Provider Password'); + echo self::styleErrors(xlt('Provider email address is missing and required. Go to User Settings select Weno Tab and enter your Weno Provider Password')); exit; } else { return $provider_info; @@ -112,24 +113,31 @@ public function getProviderEmail() } /** - * @return mixed + * @return array|false|null */ - public function getFacilityInfo() + public function getFacilityInfo(): array|null|false { - $locid = sqlQuery("select name, street, city, state, postal_code, phone, fax, weno_id from facility where id = ?", [$_SESSION['facilityId'] ?? null]); + // is user logged into facility + if (!empty($_SESSION['facilityId'])) { + $locId = sqlQuery("select name, street, city, state, postal_code, phone, fax, weno_id from facility where id = ?", [$_SESSION['facilityId'] ?? null]); + } else { + // from users facility + $facilityService = new FacilityService(); + $locId = $facilityService->getFacilityForUser($_SESSION['authUserID']); + } - if (empty($locid['weno_id'])) { + if (empty($locId['weno_id'])) { //if not in an encounter then get the first facility location id as default - $default_facility = sqlQuery("SELECT name, street, city, state, postal_code, phone, fax, weno_id from facility order by id asc limit 1"); + $default_facility = sqlQuery("SELECT name, street, city, state, postal_code, phone, fax, weno_id from facility order by id limit 1"); - if (empty($default_facility)) { - echo xlt('Facility ID is missing. head over to Admin -> Other -> Weno Management. Enter the Weno ID of your facility'); + if (empty($default_facility['weno_id'])) { + echo self::styleErrors(xlt('Facility ID is missing. From Admin select Other then Weno Management. Enter the Weno ID of your facility')); exit; } else { return $default_facility; } } - return $locid; + return $locId; } /** @@ -147,40 +155,47 @@ private function getPatientInfo() } $patient = sqlQuery("select title, fname, lname, mname, street, state, city, email, phone_cell, postal_code, dob, sex, pid from patient_data where pid=?", [$_SESSION['pid']]); if (empty($patient['fname'])) { - $log .= xlt("First Name Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . ""; + $log .= xlt("Last Name Missing, From the Patient Chart select Demographics select Who. Save and retry") . "
"; ++$missing; } if (empty($patient['dob'])) { - $log .= xlt("Date of Birth Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . "
"; + $log .= xlt("Date of Birth Missing, From the Patient Chart select Demographics select Who. Save and retry") . "
"; ++$missing; } if (empty($patient['sex'])) { - $log .= xlt("Gender Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . "
"; + $log .= xlt("Gender Missing, From the Patient Chart select Demographics select Who. Save and retry") . "
"; ++$missing; } if (empty($patient['postal_code'])) { - $log .= xlt("Zip Code Missing, head over to the Patient Chart select Demographics select Contact select Postal Code. Save and retry") . "
"; + $log .= xlt("Zip Code Missing, From the Patient Chart select Demographics select Contact select Postal Code. Save and retry") . "
"; ++$missing; } if (empty($patient['street'])) { - $log .= xlt("Street Address incomplete Missing, head over to the Patient Chart select Demographics select Contact. Save and retry") . "
"; + $log .= xlt("Street Address incomplete Missing, From the Patient Chart select Demographics select Contact. Save and retry") . "
"; ++$missing; } if ($missing > 0) { - $this->errorWithDie($log); + self::errorWithDie($log); } return $patient; } - public function errorWithDie($error) + public static function styleErrors($error): string { - $log = "

" . - $error . "
" . xlt('Please address errors and try again') . + $log = "

" . + $error . "
" . xlt('Please address errors and try again!') . + "
" . xlt("Use browser Back button or Click Patient Name from top Patient bar.") . "

"; + return $log; + } + + public static function errorWithDie($error): void + { + $log = self::styleErrors($error); die($log); } @@ -237,8 +252,8 @@ public function getPharmacy() { $data = sqlQuery("SELECT * FROM `weno_assigned_pharmacy` WHERE `pid` = ? ", [$_SESSION["pid"]]); if (empty($data)) { - $log = xlt("Weno Pharmacies not set. Head over to Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Pharmacies"); - $this->errorWithDie($log); + $log = xlt("Weno Pharmacies not set. From Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Pharmacies"); + self::errorWithDie($log); } $response = array( "primary" => $data['primary_ncpdp'], @@ -246,13 +261,13 @@ public function getPharmacy() ); if (empty($response['primary'])) { - $log = xlt("Weno Primary Pharmacy not set. Head over to Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Primary Pharmacy"); - $this->errorWithDie($log); + $log = xlt("Weno Primary Pharmacy not set. From Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Primary Pharmacy"); + self::errorWithDie($log); } if (empty($response['alternate'])) { - $log = xlt("Weno Alternate Pharmacy not set. Head over to Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Primary Pharmacy"); - $this->errorWithDie($log); + $log = xlt("Weno Alternate Pharmacy not set. From Patient's Demographics select Choices then select Weno Pharmacy Selector to Assign Primary Pharmacy"); + self::errorWithDie($log); } return $response; } diff --git a/interface/modules/custom_modules/oe-module-weno/src/Services/WenoPharmaciesImport.php b/interface/modules/custom_modules/oe-module-weno/src/Services/WenoPharmaciesImport.php index 845c855e045..91cd93c0d76 100644 --- a/interface/modules/custom_modules/oe-module-weno/src/Services/WenoPharmaciesImport.php +++ b/interface/modules/custom_modules/oe-module-weno/src/Services/WenoPharmaciesImport.php @@ -34,6 +34,10 @@ public function importPharmacy($csvFile, $files) $records = fopen($csvFile, "r"); try { + if ($records ?? null) { + sqlStatementNoLog('SET autocommit=0'); + sqlStatementNoLog('START TRANSACTION'); + } while (!feof($records)) { $line = fgetcsv($records); diff --git a/interface/modules/custom_modules/oe-module-weno/templates/indexrx.php b/interface/modules/custom_modules/oe-module-weno/templates/indexrx.php index 76bca3f7caa..1e4fb953a6a 100644 --- a/interface/modules/custom_modules/oe-module-weno/templates/indexrx.php +++ b/interface/modules/custom_modules/oe-module-weno/templates/indexrx.php @@ -18,6 +18,7 @@ use OpenEMR\Core\Header; use OpenEMR\Modules\WenoModule\Services\PharmacyService; use OpenEMR\Modules\WenoModule\Services\Container; +use OpenEMR\Modules\WenoModule\Services\TransmitProperties; //ensure user has proper access @@ -46,7 +47,7 @@ $newRxUrl = "https://online.wenoexchange.com/en/NewRx/ComposeRx?useremail="; if ($urlParam == 'error') { //check to make sure there were no errors - echo xlt("Cipher failure check encryption key"); + echo TransmitProperties::styleErrors(xlt("Cipher failure check encryption key")); exit; } ?> diff --git a/interface/modules/custom_modules/oe-module-weno/templates/rxlogmanager.php b/interface/modules/custom_modules/oe-module-weno/templates/rxlogmanager.php index 34f2c7cf5b0..2ad2eba07f5 100644 --- a/interface/modules/custom_modules/oe-module-weno/templates/rxlogmanager.php +++ b/interface/modules/custom_modules/oe-module-weno/templates/rxlogmanager.php @@ -12,12 +12,13 @@ use OpenEMR\Common\Acl\AclMain; use OpenEMR\Modules\WenoModule\Services\LogProperties; +use OpenEMR\Modules\WenoModule\Services\TransmitProperties; /* * access control is on Weno side based on the user login */ if (!AclMain::aclCheckCore('patient', 'med')) { - echo xlt('Prescriptions Review Not Authorized'); + echo TransmitProperties::styleErrors(xlt('Prescriptions Review Not Authorized')); exit; } @@ -26,7 +27,7 @@ $provider_info = $log_properties->getProviderEmail(); if ($logurlparam == 'error') { - echo xlt("Cipher failure check encryption key"); + echo TransmitProperties::styleErrors(xlt("Cipher failure check encryption key")); exit; } diff --git a/interface/modules/custom_modules/oe-module-weno/templates/synch.php b/interface/modules/custom_modules/oe-module-weno/templates/synch.php index 17d53c17c60..e5a1017f291 100644 --- a/interface/modules/custom_modules/oe-module-weno/templates/synch.php +++ b/interface/modules/custom_modules/oe-module-weno/templates/synch.php @@ -12,12 +12,13 @@ use OpenEMR\Modules\WenoModule\Services\LogProperties; use OpenEMR\Common\Acl\AclMain; +use OpenEMR\Modules\WenoModule\Services\TransmitProperties; /* * access control is on Weno side based on the user login */ if (!AclMain::aclCheckCore('patient', 'med')) { - echo xlt('Prescriptions Review Not Authorized'); + echo TransmitProperties::styleErrors(xlt('Prescriptions Review Not Authorized')); exit; }