From 0e9ff717ba07ef59e960194d614a35d966daf1c1 Mon Sep 17 00:00:00 2001
From: sunsetsystems
Date: Wed, 27 Feb 2008 06:45:35 +0000
Subject: [PATCH] added acct/disc ACO for price discounting
---
acl_setup.php | 7 +-
acl_upgrade.php | 10 +
interface/forms/fee_sheet/new.php | 1855 ++++++++++++++++++------------------
interface/forms/fee_sheet/view.php | 1855 ++++++++++++++++++------------------
4 files changed, 1880 insertions(+), 1847 deletions(-)
diff --git a/acl_setup.php b/acl_setup.php
index 284dbdec6..f5c1d59bf 100644
--- a/acl_setup.php
+++ b/acl_setup.php
@@ -53,6 +53,7 @@
// Create Accounting ACOs.
//
$gacl->add_object('acct', 'Billing (write optional)' , 'bill' , 10, 0, 'ACO');
+ $gacl->add_object('acct', 'Price Discounting' , 'disc' , 10, 0, 'ACO');
$gacl->add_object('acct', 'EOB Data Entry' , 'eob' , 10, 0, 'ACO');
$gacl->add_object('acct', 'Financial Reporting - my encounters', 'rep' , 10, 0, 'ACO');
$gacl->add_object('acct', 'Financial Reporting - anything' , 'rep_a', 10, 0, 'ACO');
@@ -119,7 +120,7 @@
//
$gacl->add_acl(
array(
- 'acct'=>array('bill', 'eob', 'rep', 'rep_a'),
+ 'acct'=>array('bill', 'disc', 'eob', 'rep', 'rep_a'),
'admin'=>array('calendar', 'database', 'forms', 'practice', 'superbill', 'users', 'batchcom', 'language', 'super', 'drugs', 'acl'),
'encounters'=>array('auth_a', 'coding_a', 'notes_a', 'date_a'),
'patients'=>array('appt', 'demo', 'med', 'trans', 'docs', 'notes'),
@@ -133,7 +134,7 @@
//
$gacl->add_acl(
array(
- 'acct'=>array('rep'),
+ 'acct'=>array('disc', 'rep'),
'admin'=>array('drugs'),
'encounters'=>array('auth_a', 'coding_a', 'notes_a', 'date_a'),
'patients'=>array('appt', 'demo', 'med', 'trans', 'docs', 'notes'),
@@ -178,7 +179,7 @@
//
$gacl->add_acl(
array(
- 'acct'=>array('bill', 'eob', 'rep', 'rep_a'),
+ 'acct'=>array('bill', 'disc', 'eob', 'rep', 'rep_a'),
'admin'=>array('practice', 'superbill'),
'encounters'=>array('auth_a', 'coding_a', 'date_a'),
'patients'=>array('appt', 'demo')
diff --git a/acl_upgrade.php b/acl_upgrade.php
index 3d958b573..93e0eeb1a 100644
--- a/acl_upgrade.php
+++ b/acl_upgrade.php
@@ -25,6 +25,8 @@
// ADD acl ACL Administration (Administrators)
// Section "sensitivities" (Sensitivities):
// EDIT high High (ensure the order variable is '20')
+// Section "acct" (Accounting):
+// ADD disc Price Discounting (Administrators, Physicians, Accounting(write))
//Ensure that phpGACL has been installed
@@ -70,6 +72,8 @@ addObjectAclWithOrder('sensitivities', 'Sensitivities', 'high', 'High', 20);
addObjectAcl('admin', 'Administration', 'drugs', 'Pharmacy Dispensary');
//Add 'ACL Administration' object (added in 2.8.4)
addObjectAcl('admin', 'Administration', 'acl', 'ACL Administration');
+//Add 'Price Discounting' object (added in 2.8.4)
+addObjectAcl('acct', 'Accounting', 'disc', 'Price Discounting');
//Update already existing Objects
@@ -104,6 +108,12 @@ updateAcl($doc_write, 'Physicians', 'admin', 'Administration', 'drugs', 'Pharmac
updateAcl($clin_write, 'Clinicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
//Insert the 'acl' object from the 'admin' section into the Administrators group write ACL (added in 2.8.4)
updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'acl', 'ACL Administration', 'write');
+//Insert the 'disc' object from the 'acct' section into the Administrators group write ACL (added in 2.8.4)
+updateAcl($admin_write, 'Administrators', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
+//Insert the 'disc' object from the 'acct' section into the Accounting group write ACL (added in 2.8.4)
+updateAcl($back_write, 'Accounting', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
+//Insert the 'disc' object from the 'acct' section into the Physicians group write ACL (added in 2.8.4)
+updateAcl($doc_write, 'Physicians', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
//Function will return an array that contains the ACL ID number.
diff --git a/interface/forms/fee_sheet/new.php b/interface/forms/fee_sheet/new.php
index 5e3a8b85e..de1618592 100644
--- a/interface/forms/fee_sheet/new.php
+++ b/interface/forms/fee_sheet/new.php
@@ -1,922 +1,933 @@
-
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-
-require_once("../../globals.php");
-require_once("$srcdir/api.inc");
-require_once("codes.php");
-require_once("../../../custom/code_types.inc.php");
-require_once("../../drugs/drugs.inc.php");
-
-// Possible units of measure for NDC drug quantities.
-//
-$ndc_uom_choices = array(
- 'ML' => 'ML',
- 'GR' => 'Grams',
- 'F2' => 'I.U.',
- 'UN' => 'Units'
-);
-
-// $FEE_SHEET_COLUMNS should be defined in codes.php.
-if (empty($FEE_SHEET_COLUMNS)) $FEE_SHEET_COLUMNS = 2;
-
-$returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
-
-// If Save was clicked, save the new and modified billing lines;
-// then if no error, redirect to $returnurl.
-//
-if ($_POST['bn_save']) {
- $provid = $_POST['ProviderID'];
- if (! $provid) $provid = $_SESSION["authUserID"];
-
- $bill = $_POST['bill'];
- for ($lino = 1; $bill["$lino"]['code_type']; ++$lino) {
- $iter = $bill["$lino"];
-
- // Skip disabled (billed) line items.
- if ($iter['billed']) continue;
-
- $id = $iter['id'];
- $code_type = $iter['code_type'];
- $code = $iter['code'];
- $modifier = trim($iter['mod']);
- $units = max(1, intval(trim($iter['units'])));
- $fee = 0 + trim($iter['fee']);
- if ($code_type == 'COPAY') {
- if ($fee > 0) $fee = 0 - $fee;
- $code = sprintf('%01.2f', 0 - $fee);
- }
- $justify = trim($iter['justify']);
- if ($justify) $justify = str_replace(',', ':', $justify) . ':';
- // $auth = $iter['auth'] ? "1" : "0";
- $auth = "1";
- $del = $iter['del'];
-
- $ndc_info = '';
- if ($iter['ndcnum']) {
- $ndc_info = 'N4' . trim($iter['ndcnum']) . ' ' . $iter['ndcuom'] .
- trim($iter['ndcqty']);
- }
-
- // If the item is already in the database...
- if ($id) {
- if ($del) {
- deleteBilling($id);
- }
- else {
- // authorizeBilling($id, $auth);
- sqlQuery("UPDATE billing SET code = '$code', " .
- "units = '$units', fee = '$fee', modifier = '$modifier', " .
- "authorized = $auth, provider_id = '$provid', " .
- "ndc_info = '$ndc_info', justify = '$justify' WHERE " .
- "id = '$id' AND billed = 0 AND activity = 1");
- }
- }
-
- // Otherwise it's a new item...
- else if (! $del) {
- $query = "select code_text from codes where code_type = '" .
- $code_types[$code_type]['id'] . "' and " .
- "code = '$code' and ";
- if ($modifier) {
- $query .= "modifier = '$modifier'";
- } else {
- $query .= "(modifier is null or modifier = '')";
- }
- $result = sqlQuery($query);
- $code_text = addslashes($result['code_text']);
- addBilling($encounter, $code_type, $code, $code_text, $pid, $auth,
- $provid, $modifier, $units, $fee, $ndc_info, $justify);
- }
- } // end for
-
- // Doing similarly to the above but for products.
- $prod = $_POST['prod'];
- for ($lino = 1; $prod["$lino"]['drug_id']; ++$lino) {
- $iter = $prod["$lino"];
-
- if (!empty($iter['billed'])) continue;
-
- $drug_id = $iter['drug_id'];
- $sale_id = $iter['sale_id']; // present only if already saved
- $units = max(1, intval(trim($iter['units'])));
- $fee = 0 + trim($iter['fee']);
- $del = $iter['del'];
-
- // If the item is already in the database...
- if ($sale_id) {
- if ($del) {
- // Zero out this sale and reverse its inventory update. We bring in
- // drug_sales twice so that the original quantity can be referenced
- // unambiguously.
- sqlStatement("UPDATE drug_sales AS dsr, drug_sales AS ds, " .
- "drug_inventory AS di " .
- "SET di.on_hand = di.on_hand + dsr.quantity, " .
- "ds.quantity = 0, ds.fee = 0 WHERE " .
- "dsr.sale_id = '$sale_id' AND ds.sale_id = dsr.sale_id AND " .
- "di.inventory_id = ds.inventory_id");
- // And delete the sale for good measure.
- sqlStatement("DELETE FROM drug_sales WHERE sale_id = '$sale_id'");
- }
- else {
- // Modify the sale and adjust inventory accordingly.
- $query = "UPDATE drug_sales AS dsr, drug_sales AS ds, " .
- "drug_inventory AS di " .
- "SET di.on_hand = di.on_hand + dsr.quantity - $units, " .
- "ds.quantity = '$units', ds.fee = '$fee' WHERE " .
- "dsr.sale_id = '$sale_id' AND ds.sale_id = dsr.sale_id AND " .
- "di.inventory_id = ds.inventory_id";
- sqlStatement($query);
- }
- }
-
- // Otherwise it's a new item...
- else if (! $del) {
- $sale_id = sellDrug($drug_id, $units, $fee, $pid, $encounter);
- if (!$sale_id) die("Insufficient inventory for product ID \"$drug_id\".");
- }
- } // end for
-
- // Note: I was going to compute taxes here, but now I think better to
- // do that at checkout time (in pos_checkout.php which also posts to SL).
- // Currently taxes with insurance claims make no sense, so for now we'll
- // ignore tax computation in the insurance billing logic.
-
- formHeader("Redirecting....");
- formJump();
- formFooter();
- exit;
-}
-
-$billresult = getBillingByEncounter($pid, $encounter, "*");
-?>
-
-
- html_header_show();?>
-
-
-
-
-
- topmargin="0" rightmargin="0" leftmargin="2"
- bottommargin="0" marginwidth="2" marginheight="0">
-
-
-
-
-
- |
- |
- if (modifiers_are_used()) { ?>
- |
- } ?>
- if (fees_are_used()) { ?>
- |
- |
- |
- } ?>
- |
- |
- |
-
-
- 0) $fee = 0 - $fee;
- }
- if (! $code_text) {
- // $query = "select units, fee, code_text from codes where code_type = '" .
- $query = "select id, units, code_text from codes where code_type = '" .
- $code_types[$codetype]['id'] . "' and " .
- "code = '$code' and ";
- if ($modifier) {
- $query .= "modifier = '$modifier'";
- } else {
- $query .= "(modifier is null or modifier = '')";
- }
- $result = sqlQuery($query);
- $code_text = $result['code_text'];
- if (empty($units)) $units = max(1, intval($result['units']));
- if (!isset($fee)) {
- // $fee = $result['fee'];
- // The above is obsolete now, fees come from the prices table:
- $query = "SELECT prices.pr_price " .
- "FROM patient_data, prices WHERE " .
- "patient_data.pid = '$pid' AND " .
- "prices.pr_id = '" . $result['id'] . "' AND " .
- "prices.pr_selector = '' AND " .
- "prices.pr_level = patient_data.pricelevel " .
- "LIMIT 1";
- echo "\n\n"; // debugging
- $prrow = sqlQuery($query);
- $fee = empty($prrow) ? 0 : $prrow['pr_price'];
- }
- }
- $fee = sprintf('%01.2f', $fee);
- $strike1 = ($id && $del) ? "" : "";
- $strike2 = ($id && $del) ? "" : "";
- echo " \n";
- echo " $strike1$codetype$strike2";
- if ($id) {
- echo "";
- }
- echo "";
- echo "";
- echo "";
- echo " | \n";
- if ($codetype != 'COPAY') {
- echo " $strike1$code$strike2 | \n";
- } else {
- echo " | \n";
- }
- if ($billed) {
- if (modifiers_are_used()) {
- echo " $strike1$modifier$strike2" .
- " | \n";
- }
- if (fees_are_used()) {
- if ($codetype != 'COPAY') {
- echo " $units | \n";
- } else {
- echo " | \n";
- }
- echo " $fee | \n";
- echo " $justify | \n";
- }
- echo " | \n";
- echo " | \n";
- } else {
- if (modifiers_are_used()) {
- if ($codetype != 'COPAY' && ($code_types[$codetype]['mod'] || $modifier)) {
- echo " | \n";
- } else {
- echo " | \n";
- }
- }
- if (fees_are_used()) {
- if ($codetype == 'COPAY' || $code_types[$codetype]['fee'] || $fee != 0) {
- echo " ";
- if ($codetype != 'COPAY') {
- echo "";
- } else {
- echo "";
- }
- echo " | \n";
- echo " " .
- " | \n";
- if ($code_types[$codetype]['just'] || $justify) {
- echo " ";
- echo "";
- echo " | \n";
- $justinit .= "setJustify(f['bill[$lino][justify]']);\n";
- } else {
- echo " | \n";
- }
- } else {
- echo " | \n";
- echo " | \n";
- echo " | \n";
- }
- }
- echo " | \n";
- echo " | \n";
- }
-
- echo " $strike1" . ucfirst(strtolower($code_text)) . "$strike2 | \n";
- echo "
\n";
-
- // If NDC info exists or may be required, add a line for it.
- if ($codetype == 'HCPCS' && $ndc_applies && !$billed) {
- $ndcnum = ''; $ndcuom = ''; $ndcqty = '';
- if (preg_match('/^N4(\S+)\s+(\S\S)(.*)/', $ndc_info, $tmp)) {
- $ndcnum = $tmp[1]; $ndcuom = $tmp[2]; $ndcqty = $tmp[3];
- }
- echo " \n";
- echo " | \n";
- echo " NDC: ";
- echo "";
- echo " Qty: ";
- echo "";
- echo " ";
- echo "";
- echo " | \n";
- echo "
\n";
- }
- else if ($ndc_info) {
- echo " \n";
- echo " | \n";
- echo " NDC Data: $ndc_info | \n";
- echo "
\n";
- }
-}
-
-// This writes a product (drug_sales) line item to the output page.
-//
-function echoProdLine($lino, $drug_id, $del = FALSE, $units = NULL,
- $fee = NULL, $sale_id = 0, $billed = FALSE)
-{
- global $code_types, $ndc_applies, $pid;
-
- /*******************************************************************
- list ($drug_id, $selector) = explode(':', $drugsel);
- if (! $units) { // if this is a new selection then apply defaults for it
- $query = "SELECT dt.*, d.name FROM drug_templates, drugs WHERE " .
- "dt.drug_id = '$drug_id' AND dt.selector = '$selector' AND " .
- "d.drug_id = dt.drug_id";
- $result = sqlQuery($query);
- $code_text = $result['name'] . " ($selector)";
- if (empty($units)) $units = max(1, intval($result['quantity']));
- if (!isset($fee)) {
- // Fees come from the prices table:
- $query = "SELECT prices.pr_price " .
- "FROM patient_data, prices WHERE " .
- "patient_data.pid = '$pid' AND " .
- "prices.pr_id = '$drug_id' AND " .
- "prices.pr_selector = '$selector' AND " .
- "prices.pr_level = patient_data.pricelevel " .
- "LIMIT 1";
- // echo "\n\n"; // debugging
- $prrow = sqlQuery($query);
- $fee = empty($prrow) ? 0 : $prrow['pr_price'];
- }
- }
- *******************************************************************/
- $drow = sqlQuery("SELECT name FROM drugs WHERE drug_id = '$drug_id'");
- $code_text = $drow['name'];
- /******************************************************************/
-
- $fee = sprintf('%01.2f', $fee);
- $strike1 = ($sale_id && $del) ? "" : "";
- $strike2 = ($sale_id && $del) ? "" : "";
- echo " \n";
- echo " {$strike1}Product$strike2";
- echo "";
- echo "";
- echo "";
- echo " | \n";
- echo " $strike1$drug_id$strike2 | \n";
- if (modifiers_are_used()) {
- echo " | \n";
- }
- if ($billed) {
- if (fees_are_used()) {
- echo " $units | \n";
- echo " $fee | \n";
- echo " | \n"; // justify
- }
- echo " | \n"; // auth
- echo " | \n";
- } else {
- if (fees_are_used()) {
- echo " ";
- echo "";
- echo " | \n";
- echo " " .
- " | \n";
- echo " | \n";
- }
- echo " | \n"; // auth
- echo " | \n";
- }
-
- echo " $strike1" . ucfirst(strtolower($code_text)) . "$strike2 | \n";
- echo "
\n";
-}
-
-$encounter_provid = -1;
-
-// Generate lines for items already in the billing table for this encounter,
-// and also set the rendering provider if we come across one.
-//
-$bill_lino = 0;
-if ($billresult) {
- foreach ($billresult as $iter) {
- ++$bill_lino;
- $bline = $_POST['bill']["$bill_lino"];
- $del = $bline['del']; // preserve Delete if checked
-
- $modifier = trim($iter["modifier"]);
- $units = $iter["units"];
- $fee = $iter["fee"];
- $authorized = $iter["authorized"];
- $ndc_info = $iter["ndc_info"];
- $justify = trim($iter['justify']);
- if ($justify) $justify = substr(str_replace(':', ',', $justify), 0, strlen($justify) - 1);
-
- // Also preserve other items from the form, if present.
- if ($bline['id'] && !$iter["billed"]) {
- $modifier = trim($bline['mod']);
- $units = trim($bline['units']);
- $fee = trim($bline['fee']);
- $authorized = $bline['auth'];
- $ndc_info = '';
- if ($bline['ndcnum']) {
- $ndc_info = 'N4' . trim($bline['ndcnum']) . ' ' . $bline['ndcuom'] .
- trim($bline['ndcqty']);
- }
- $justify = $bline['justify'];
- }
-
- // list($code, $modifier) = explode("-", $iter["code"]);
- echoLine($bill_lino, $iter["code_type"], trim($iter["code"]),
- $modifier, $ndc_info, $authorized,
- $del, $units, $fee, $iter["id"], $iter["billed"],
- $iter["code_text"], $justify);
- // If no default provider yet then try this one.
- if ($encounter_provid < 0 && ! $del) $encounter_provid = $iter["provider_id"];
- }
-}
-
-// Echo new billing items from this form here, but omit any line
-// whose Delete checkbox is checked.
-//
-if ($_POST['bill']) {
- foreach ($_POST['bill'] as $key => $iter) {
- if ($iter["id"]) continue; // skip if it came from the database
- if ($iter["del"]) continue; // skip if Delete was checked
- $ndc_info = '';
- if ($iter['ndcnum']) {
- $ndc_info = 'N4' . trim($iter['ndcnum']) . ' ' . $iter['ndcuom'] .
- trim($iter['ndcqty']);
- }
- $fee = 0 + trim($iter['fee']);
- if ($iter['code_type'] == 'COPAY' && $fee > 0) $fee = 0 - $fee;
- echoLine(++$bill_lino, $iter["code_type"], $iter["code"], trim($iter["mod"]),
- $ndc_info, $iter["auth"], $iter["del"], trim($iter["units"]),
- $fee, NULL, FALSE, NULL, $iter["justify"]);
- }
-}
-
-// Generate lines for items already in the drug_sales table for this encounter.
-//
-$query = "SELECT * FROM drug_sales WHERE " .
- "pid = '$pid' AND encounter = '$encounter' " .
- "ORDER BY sale_id";
-$sres = sqlStatement($query);
-$prod_lino = 0;
-while ($srow = sqlFetchArray($sres)) {
- ++$prod_lino;
- $pline = $_POST['prod']["$prod_lino"];
- $del = $pline['del']; // preserve Delete if checked
- $sale_id = $srow['sale_id'];
- $drug_id = $srow['drug_id'];
- $units = $srow['quantity'];
- $fee = $srow['fee'];
- $billed = $srow['billed'];
- // Also preserve other items from the form, if present and unbilled.
- if ($pline['sale_id'] && !$srow['billed']) {
- $units = trim($pline['units']);
- $fee = trim($pline['fee']);
- }
- echoProdLine($prod_lino, $drug_id, $del, $units, $fee, $sale_id, $billed);
-}
-
-// Echo new product items from this form here, but omit any line
-// whose Delete checkbox is checked.
-//
-if ($_POST['prod']) {
- foreach ($_POST['prod'] as $key => $iter) {
- if ($iter["sale_id"]) continue; // skip if it came from the database
- if ($iter["del"]) continue; // skip if Delete was checked
- $fee = 0 + trim($iter['fee']);
- echoProdLine(++$prod_lino, $iter['drug_id'], FALSE, trim($iter["units"]), $fee);
- }
-}
-
-// If new billing code(s) were
-
-
-
-
-
-
-
-\n";
-echo "