* @author Brady Miller * @copyright Copyright (c) 2015-2017 Rod Roark * @copyright Copyright (c) 2018 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once("../../interface/globals.php"); require_once("$fileroot/custom/code_types.inc.php"); require_once("$fileroot/interface/drugs/drugs.inc.php"); use OpenEMR\Common\Csrf\CsrfUtils; //verify csrf if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } function write_code_info($codetype, $code, $selector, $pricelevel) { global $code_types; $wh = ''; // options for warehouse selection if ($codetype == 'PROD') { $wrow = sqlQuery( "SELECT default_warehouse FROM users WHERE username = ?", array($_SESSION['authUser']) ); $defaultwh = empty($wrow['default_warehouse']) ? '' : $wrow['default_warehouse']; // $crow = sqlQuery( "SELECT d.name, p.pr_price " . "FROM drugs AS d " . "LEFT JOIN prices AS p ON p.pr_id = d.drug_id AND p.pr_selector = ? AND p.pr_level = ? " . "WHERE d.drug_id = ?", array($selector, $pricelevel, $code) ); $desc = $crow['name']; $price = empty($crow['pr_price']) ? 0 : (0 + $crow['pr_price']); // $lres = sqlStatement("SELECT * FROM list_options " . "WHERE list_id = 'warehouse' AND activity = 1 ORDER BY seq, title"); $wh .= ""; while ($lrow = sqlFetchArray($lres)) { $wh .= ""; } } else { // not PROD $cres = return_code_information($codetype, $code, false); $desc = ''; $price = 0; if ($crow = sqlFetchArray($cres)) { $desc = trim($crow['code_text']); if ($code_types[$codetype]['fee']) { if ($code_types[$codetype]['external'] == 0) { $prow = sqlQuery( "SELECT pr_price " . "FROM prices WHERE pr_id = ? AND pr_selector = '' AND pr_level = ? " . "LIMIT 1", array($crow['id'], $pricelevel) ); if (!empty($prow['pr_price'])) { $price = 0 + $prow['pr_price']; } } else { // external code set with fees, prices table not supported $price = 0 + $crow['fee']; } } } } // error_log("Warehouse string is: " . $wh); // debugging echo "code_attributes_handler(" . js_escape($codetype) . "," . js_escape($code) . "," . js_escape($desc) . "," . js_escape($price) . "," . js_escape($wh) . ");"; } $pricelevel = isset($_GET['pricelevel']) ? $_GET['pricelevel'] : ''; if (!empty($_GET['list'])) { // This case supports packages of codes. $arrcodes = explode('~', $_GET['list']); foreach ($arrcodes as $codestring) { if ($codestring === '') { continue; } $arrcode = explode('|', $codestring); $codetype = $arrcode[0]; list($code, $modifier) = explode(":", $arrcode[1]); $selector = isset($arrcode[2]) ? $arrcode[2] : ''; write_code_info($codetype, $code, $selector, $pricelevel); } } else { // This is the normal case of adding a single code. $codetype = isset($_GET['codetype' ]) ? $_GET['codetype' ] : ''; $code = isset($_GET['code' ]) ? $_GET['code' ] : ''; $selector = isset($_GET['selector' ]) ? $_GET['selector' ] : ''; write_code_info($codetype, $code, $selector, $pricelevel); }