Skip to content

Commit

Permalink
Weno fixes and updates (openemr#7204)
Browse files Browse the repository at this point in the history
* Weno fixes and updates
- Improve pharmacy import by using transactional queries. From 4 minutes to 40 seconds.
- improve validation and error reporting.
- some code cleanup for warnings and in general
- fix frame screen output to use the current theme so user always see content.

* - fix block style how nitpicking is this!

* - fix all header blocks.

* - no clue

* php warning

* styles

* - I was running ci on wrong directory! tsktsk

* - don't log thounsands of inserts

---------

Co-authored-by: stephen waite <[email protected]>
  • Loading branch information
sjpadgett and stephenwaite authored Feb 3, 2024
1 parent 8d6dc1c commit e77ac66
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use OpenEMR\Modules\WenoModule\Services\PharmacyService;

$cryptoGen = new CryptoGen();
$weno_username = $GLOBALS['weno_admin_username'];
$weno_password = $cryptoGen->decryptStandard($GLOBALS['weno_admin_password']);
$encryption_key = $cryptoGen->decryptStandard($GLOBALS['weno_encryption_key']);
$weno_username = $GLOBALS['weno_admin_username'] ?? '';
$weno_password = $cryptoGen->decryptStandard($GLOBALS['weno_admin_password'] ?? '');
$encryption_key = $cryptoGen->decryptStandard($GLOBALS['weno_encryption_key'] ?? '');
$baseurl = "https://online.wenoexchange.com/en/EPCS/DownloadPharmacyDirectory";

$data = array(
Expand Down Expand Up @@ -105,87 +105,98 @@ function download_zipfile($fileUrl, $zipped_file)

$l = 0;
if (file_exists($csvFile)) {
// let's do transaction as this is long import
$records = fopen($csvFile, "r");

while (!feof($records)) {
$line = fgetcsv($records);

if ($l <= 1) {
$l++;
continue;
}
if (!isset($line[1])) {
continue;
try {
if ($records ?? null) {
sqlStatementNoLog('SET autocommit=0');
sqlStatementNoLog('START TRANSACTION');
}
if (!isset($line[1])) {
continue;
}
if (!empty($line)) {
if ($data['Daily'] == 'N') {
$ncpdp = str_replace(['[', ']'], '', $line[3]);
$npi = str_replace(['[', ']'], '', $line[5]);
$business_name = $line[6];
$address_line_1 = $line[7];
$address_line_2 = $line[8];
$city = $line[9];
$state = $line[10];
$zipcode = str_replace(['[', ']'], '', $line[11]);
$country = $line[12];
$international = $line[13];
$pharmacy_phone = str_replace(['[', ']'], '', $line[16]);
$on_weno = $line[21];
$test_pharmacy = $line[17];
$state_wide_mail = $line[18];
$fullDay = $line[22];
} else {
$ncpdp = str_replace(['[', ']'], '', $line[3]);
$npi = str_replace(['[', ']'], '', $line[7]);
$business_name = $line[8];
$city = $line[11];
$state = $line[12];
$zipcode = str_replace(['[', ']'], '', $line[14]);
$country = $line[15];
$address_line_1 = $line[9];
$address_line_2 = $line[10];
$international = $line[16];
$pharmacy_phone = str_replace(['[', ']'], '', $line[20]);
$county = $line[33];
$on_weno = $line[37];
$compounding = $line[41];
$medicaid_id = $line[45];
$dea = $line[44];
$test_pharmacy = $line[29];
$fullDay = $line[40];
$state_wide_mail = $line[47];
}
while (!feof($records)) {
$line = fgetcsv($records);

$insertdata['ncpdp'] = $ncpdp;
$insertdata['npi'] = $npi;
$insertdata['business_name'] = $business_name;
$insertdata['address_line_1'] = $address_line_1;
$insertdata['address_line_2'] = $address_line_2;
$insertdata['city'] = $city;
$insertdata['state'] = $state;
$insertdata['zipcode'] = $zipcode;
$insertdata['country'] = $country;
$insertdata['international'] = $international;
$insertdata['pharmacy_phone'] = $pharmacy_phone;
$insertdata['on_weno'] = $on_weno;
$insertdata['test_pharmacy'] = $test_pharmacy;
$insertdata['state_wide_mail'] = $state_wide_mail;
$insertdata['fullDay'] = $fullDay;

if ($data['Daily'] == 'Y') {
$insertPharmacy->updatePharmacies($insertdata);
} else {
$insertPharmacy->insertPharmacies($insertdata);
if ($l <= 1) {
$l++;
continue;
}
if (!isset($line[1])) {
continue;
}
if (!isset($line[1])) {
continue;
}
if (!empty($line)) {
if ($data['Daily'] == 'N') {
$ncpdp = str_replace(['[', ']'], '', $line[3]);
$npi = str_replace(['[', ']'], '', $line[5]);
$business_name = $line[6];
$address_line_1 = $line[7];
$address_line_2 = $line[8];
$city = $line[9];
$state = $line[10];
$zipcode = str_replace(['[', ']'], '', $line[11]);
$country = $line[12];
$international = $line[13];
$pharmacy_phone = str_replace(['[', ']'], '', $line[16]);
$on_weno = $line[21];
$test_pharmacy = $line[17];
$state_wide_mail = $line[18];
$fullDay = $line[22];
} else {
$ncpdp = str_replace(['[', ']'], '', $line[3]);
$npi = str_replace(['[', ']'], '', $line[7]);
$business_name = $line[8];
$city = $line[11];
$state = $line[12];
$zipcode = str_replace(['[', ']'], '', $line[14]);
$country = $line[15];
$address_line_1 = $line[9];
$address_line_2 = $line[10];
$international = $line[16];
$pharmacy_phone = str_replace(['[', ']'], '', $line[20]);
$county = $line[33];
$on_weno = $line[37];
$compounding = $line[41];
$medicaid_id = $line[45];
$dea = $line[44];
$test_pharmacy = $line[29];
$fullDay = $line[40];
$state_wide_mail = $line[47];
}

$insertdata['ncpdp'] = $ncpdp;
$insertdata['npi'] = $npi;
$insertdata['business_name'] = $business_name;
$insertdata['address_line_1'] = $address_line_1;
$insertdata['address_line_2'] = $address_line_2;
$insertdata['city'] = $city;
$insertdata['state'] = $state;
$insertdata['zipcode'] = $zipcode;
$insertdata['country'] = $country;
$insertdata['international'] = $international;
$insertdata['pharmacy_phone'] = $pharmacy_phone;
$insertdata['on_weno'] = $on_weno;
$insertdata['test_pharmacy'] = $test_pharmacy;
$insertdata['state_wide_mail'] = $state_wide_mail;
$insertdata['fullDay'] = $fullDay;

if ($data['Daily'] == 'Y') {
$insertPharmacy->updatePharmacies($insertdata);
} else {
$insertPharmacy->insertPharmacies($insertdata);
}

++$l;
}

++$l;
}
} catch (Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
$wenolog->insertWenoLog("pharmacy", "Success");
fclose($records);
sqlStatementNoLog('COMMIT');
sqlStatementNoLog('SET autocommit=1');

foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
* @copyright Copyright (c) 2021 Sherwin Gaddis <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

use OpenEMR\Common\Crypto\CryptoGen;
use OpenEMR\Modules\WenoModule\Services\LogProperties;
use OpenEMR\Modules\WenoModule\Services\WenoPharmaciesJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down Expand Up @@ -38,9 +38,9 @@ public function retrieveDataFile($url, $storelocation)

$result = $this->extractFile($path_to_extract, $storelocation);
if ($result == "Imported") {
return "complete";
return "Imported";
} else {
return "failed";
return $result;
}
}

Expand Down Expand Up @@ -74,6 +74,9 @@ public function extractFile($path_to_extract, $storelocation)
$result = $import->importPharmacy($csvFile, $files);
if ($result == "Imported") {
$wenolog->insertWenoLog("pharmacy", "Success");
return $result;
} else {
return $result;
}

return "Imported";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* @package OpenEMR
* @link http://www.open-emr.org
* @author Sherwin Gaddis <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function insertPharmacies($insertdata)
$sql .= "24hr = ? ";

try {
sqlInsert($sql, [
sqlStatementNoLog($sql, [
$insertdata['ncpdp'],
$insertdata['npi'],
$insertdata['business_name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@ private function getPatientInfo()
++$missing;
}
if ($missing > 0) {
echo "<div style='font-size: 1.25rem; background-color: white; color: red;'>" . $log . "</div>";
die('Please add the missing data and try again');
$this->errorWithDie($log);
}
return $patient;
}

public function errorWithDie($error)
{
$log = "<div><p style='font-size: 1.25rem; background-color: white; color: red;'>" .
$error . "<br />" . xlt('Please address errors and try again') .
"</p></div>";
die($log);
}

/**
* @return string
* New Rx
Expand Down Expand Up @@ -230,19 +237,22 @@ public function getPharmacy()
{
$data = sqlQuery("SELECT * FROM `weno_assigned_pharmacy` WHERE `pid` = ? ", [$_SESSION["pid"]]);
if (empty($data)) {
die("Weno Pharmacies not set. head over to Patient's Demographics select Choices select Weno Pharmacy Selector to Assign Pharmacies");
$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);
}
$response = array(
"primary" => $data['primary_ncpdp'],
"alternate" => $data['alternate_ncpdp']
);

if (empty($response['primary'])) {
die("Weno Primary Pharmacy not set. Head over to Patient's Demographics select Choices select Weno Pharmacy Selector to Assign Primary Pharmacy");
$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);
}

if (empty($response['alternate'])) {
die("Weno Alternate Pharmacy not set. Head over to Patient's Demographics select Choices select Weno Pharmacy Selector to Assign Primary Pharmacy");
$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);
}
return $response;
}
Expand Down
Loading

0 comments on commit e77ac66

Please sign in to comment.