Skip to content

Commit

Permalink
- fix transaction for pharmacy download (openemr#7208)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sjpadgett authored Feb 5, 2024
1 parent e77ac66 commit 520263d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace OpenEMR\Modules\WenoModule\Services;

use OpenEMR\Common\Crypto\CryptoGen;
use OpenEMR\Services\FacilityService;

class TransmitProperties
{
Expand Down Expand Up @@ -98,38 +99,45 @@ 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;
}
}

/**
* @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;
}

/**
Expand All @@ -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") . "<brselect";
$log .= xlt("First Name Missing, From the Patient Chart select Demographics select Who. Save and retry") . "<brselect";
++$missing;
}
if (empty($patient['lname'])) {
$log .= xlt("Last Name Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . "<br>";
$log .= xlt("Last Name Missing, From the Patient Chart select Demographics select Who. Save and retry") . "<br>";
++$missing;
}
if (empty($patient['dob'])) {
$log .= xlt("Date of Birth Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . "<br>";
$log .= xlt("Date of Birth Missing, From the Patient Chart select Demographics select Who. Save and retry") . "<br>";
++$missing;
}
if (empty($patient['sex'])) {
$log .= xlt("Gender Missing, head over to the Patient Chart select Demographics select Who. Save and retry") . "<br>";
$log .= xlt("Gender Missing, From the Patient Chart select Demographics select Who. Save and retry") . "<br>";
++$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") . "<br>";
$log .= xlt("Zip Code Missing, From the Patient Chart select Demographics select Contact select Postal Code. Save and retry") . "<br>";
++$missing;
}
if (empty($patient['street'])) {
$log .= xlt("Street Address incomplete Missing, head over to the Patient Chart select Demographics select Contact. Save and retry") . "<br>";
$log .= xlt("Street Address incomplete Missing, From the Patient Chart select Demographics select Contact. Save and retry") . "<br>";
++$missing;
}
if ($missing > 0) {
$this->errorWithDie($log);
self::errorWithDie($log);
}
return $patient;
}

public function errorWithDie($error)
public static function styleErrors($error): string
{
$log = "<div><p style='font-size: 1.25rem; background-color: white; color: red;'>" .
$error . "<br />" . xlt('Please address errors and try again') .
$log = "<div><p style='font-size: 1.25rem; color: red;'>" .
$error . "<br />" . xlt('Please address errors and try again!') .
"<br />" . xlt("Use browser Back button or Click Patient Name from top Patient bar.") .
"</p></div>";
return $log;
}

public static function errorWithDie($error): void
{
$log = self::styleErrors($error);
die($log);
}

Expand Down Expand Up @@ -237,22 +252,22 @@ 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'],
"alternate" => $data['alternate_ncpdp']
);

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 520263d

Please sign in to comment.