Skip to content

Commit

Permalink
This is a rewrite of the log sync feature. It is broken up into small… (
Browse files Browse the repository at this point in the history
openemr#4463)

* This is a rewrite of the log sync feature. It is broken up into smaller classes that handle one specific task.

* PSR stuff again and again

* Caught an error in the cryptography
  • Loading branch information
juggernautsei committed Jun 14, 2021
1 parent 4e4ecd1 commit a2832de
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 174 deletions.
2 changes: 1 addition & 1 deletion interface/super/edit_globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function checkBackgroundServices()
* this is to sync the prescription logs
*/
$wenoservices = $GLOBALS['weno_rx_enable'] == 1 ? '1' : '0';
updateBackgroundService('WenoExchange', $wenoservices, 240);
updateBackgroundService('WenoExchange', $wenoservices, 1);
}
?>
<!DOCTYPE html>
Expand Down
2 changes: 2 additions & 0 deletions library/weno_log_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

require_once "../interface/globals.php";

use OpenEMR\Rx\Weno\Container;

function start_weno()
Expand Down
59 changes: 59 additions & 0 deletions src/Rx/Weno/LogDataInsert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

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

namespace OpenEMR\Rx\Weno;

class LogDataInsert
{

public function __construct()
{
}
public function insertPrescriptions($insertdata)
{
$sql = "INSERT INTO prescriptions SET "
. "id = ?, "
. "active = ?, "
. "date_added = ?, "
. "patient_id = ?, "
. "drug = ?, "
. "form = ?, "
. "quantity = ?, "
. "refills = ?, "
. "substitute = ?,"
. "note = ?, "
. "rxnorm_drugcode = ?, "
. "external_id = ?, "
. "indication = ?, "
. "txDate = ? ";

try {
sqlInsert($sql, [
$insertdata['id'],
$insertdata['active'],
$insertdata['date_added'],
$insertdata['patient_id'],
$insertdata['drug'],
$insertdata['form'],
$insertdata['quantity'],
$insertdata['refills'],
$insertdata['substitute'],
$insertdata['note'],
$insertdata['rxnorm_drugcode'],
$insertdata['provider_id'],
$insertdata['prescriptionguid'],
$insertdata['txDate']
]);
echo "inserted data! <br>";
} catch (Exception $e) {
return $e->getMessage();
}
}
}
116 changes: 116 additions & 0 deletions src/Rx/Weno/LogImportBuild.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

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

namespace OpenEMR\Rx\Weno;

class LogImportBuild
{
public $rxsynclog;

public function __construct()
{
$this->insertdata = new LogDataInsert();
$this->rxsynclog = $GLOBALS['OE_SITE_DIR'] . "/documents/logs_and_misc/logsync.csv";
}

public function prescriptionId()
{
$sql = "SELECT MAX(id) as id FROM prescriptions";
$record = sqlQuery($sql);
$rec = 1 + $record['id'];
return $rec;
}

public function drugForm($title)
{
$sql = "SELECT option_id FROM list_options WHERE list_id = 'drug_form' AND title = ?";
$drugformid = sqlQuery($sql, [$title]);
return $drugformid['option_id'];
}

public function checkMessageId()
{
$sql = "select count(*) as count from prescriptions where indication = ?";
$entry = sqlQuery($sql, [$this->messageid]);
return $entry['count'];
}

public function buildInsertArray()
{
$l = 0;
if (file_exists($this->rxsynclog)) {
$records = fopen($this->rxsynclog, "r");

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

if ($l <= 2) {
$l++;
continue;
}
if (!isset($line[1])) {
continue;
}
if (isset($line[4])) {
$this->messageid = isset($line[4]) ? $line[4] : null;
$is_saved = $this->checkMessageId();
if ($is_saved > 0) {
continue;
}
}
if (!empty($line)) {
$pr = $line[2] ?? null;
$provider = explode(":", $pr);
$windate = $line[16] ?? null;
$idate = substr(trim($windate), 0, -5);
$idate = explode(" ", $idate);
$idate = explode("/", $idate[0]);
$year = $idate[2] ?? null;
$month = $idate[0] ?? null;
$day = $idate[1] ?? null;
$idate = $year . '-' . $month . '-' . $day;
$ida = filter_var($idate, FILTER_SANITIZE_NUMBER_INT);
$p = $line[1] ?? null;
$pid = filter_var($p, FILTER_SANITIZE_NUMBER_INT);
$r = $line[22] ?? null;
$refills = filter_var($r, FILTER_SANITIZE_NUMBER_INT);

$insertdata = [];
$rec = $this->prescriptionId();
$insertdata['id'] = $rec;
$active = 1;
$insertdata['active'] = $active;
$insertdata['date_added'] = $ida;
$insertdata['patient_id'] = $pid;
$drug = isset($line[11]) ? str_replace('"', '', $line[11]) : null;
$insertdata['drug'] = $drug;
$type = $this->drugForm($line[19]);
$insertdata['form'] = $type ?? null;
$insertdata['quantity'] = $line[18] ?? null;
$insertdata['refills'] = $refills;
$sub = ($line[14] = 'Allowed' ? 1 : 0);
$insertdata['substitute'] = $sub ?? null;
$insertdata['note'] = $line[21] ?? null;
$insertdata['rxnorm_drugcode'] = $line[12] ?? null;
$insertdata['provider_id'] = $provider[0];
$insertdata['prescriptionguid'] = $line[4] ?? null;
$insertdata['txDate'] = $ida;
$loginsert = new LogDataInsert();
$loginsert->insertPrescriptions($insertdata);

++$l;
}
}
fclose($records);
} else {
echo "File is missing!";
}
}
}
Loading

0 comments on commit a2832de

Please sign in to comment.