function default_action_process()
 {
     if ($_POST['process'] != "true") {
         return;
     }
     $this->well_child = new FormWellChild($_POST['id']);
     parent::populate_object($this->well_child);
     $new_form = false;
     if (empty($_POST['id'])) {
         $new_form = true;
     }
     $this->well_child->persist();
     if ($GLOBALS['encounter'] == "") {
         $GLOBALS['encounter'] = date("Ymd");
     }
     if ($new_form) {
         addForm($GLOBALS['encounter'], "Well Child Visit", $this->well_child->id, "well_child", $GLOBALS['pid'], $_SESSION['userauthorized']);
     }
     if (!empty($_POST['cpt_code'])) {
         $sql = "select * from codes where code ='" . mysql_real_escape_string($_POST['cpt_code']) . "' order by id";
         $results = sqlQ($sql);
         $row = mysql_fetch_array($results);
         if (!empty($row)) {
             addBilling(date("Ymd"), 'CPT4', $row['code'], $row['code_text'], $_SESSION['pid'], $_SESSION['userauthorized'], $_SESSION['authUserID'], $row['modifier'], $row['units'], $row['fee']);
         }
     }
     $_POST['process'] = "";
     return;
 }
 function default_action_process()
 {
     if ($_POST['process'] != "true") {
         return;
     }
     $this->evaluation = new FormEvaluation($_POST['id']);
     parent::populate_object($this->evaluation);
     $this->evaluation->persist();
     if ($GLOBALS['encounter'] == "") {
         $GLOBALS['encounter'] = date("Ymd");
     }
     addForm($GLOBALS['encounter'], "Evaluation Form", $this->evaluation->id, "evaluation", $GLOBALS['pid'], $_SESSION['userauthorized']);
     if (!empty($_POST['cpt_code'])) {
         $sql = "select * from codes where code ='" . add_escape_custom($_POST['cpt_code']) . "' order by id";
         $results = sqlQ($sql);
         $row = sqlFetchArray($results);
         if (!empty($row)) {
             addBilling(date("Ymd"), 'CPT4', $row['code'], $row['code_text'], $_SESSION['pid'], $_SESSION['userauthorized'], $_SESSION['authUserID'], $row['modifier'], $row['units'], $row['fee']);
         }
     }
     $_POST['process'] = "";
     return;
 }
 function default_action_process()
 {
     if ($_POST['process'] != "true") {
         return;
     }
     $this->prosthesis = new FormProsthesis($_POST['id']);
     parent::populate_object($this->prosthesis);
     $this->prosthesis->persist();
     if ($GLOBALS['encounter'] == "") {
         $GLOBALS['encounter'] = date("Ymd");
     }
     addForm($GLOBALS['encounter'], "Prosthesis & Orthotics Form", $this->prosthesis->id, "prosthesis", $GLOBALS['pid'], $_SESSION['userauthorized']);
     if (!empty($_POST['cpt_code'])) {
         $sql = "select * from codes where code ='" . mysql_real_escape_string($_POST['cpt_code']) . "' order by id";
         $results = sqlQ($sql);
         $row = mysql_fetch_array($results);
         if (!empty($row)) {
             addBilling(date("Ymd"), 'CPT4', $row['code'], $row['code_text'], $_SESSION['pid'], $_SESSION['userauthorized'], $_SESSION['authUserID'], $row['modifier'], $row['units'], $row['fee']);
         }
     }
     $_POST['process'] = "";
     return;
 }
Ejemplo n.º 4
0
             die($msg);
         }
     }
 }
 // Post payment.
 if ($_POST['form_amount']) {
     $amount = sprintf('%01.2f', trim($_POST['form_amount']));
     $form_source = trim($_POST['form_source']);
     $paydesc = trim($_POST['form_method']);
     if ($INTEGRATED_AR) {
         // Post the payment as a billed copay into the billing table.
         // Maybe this should even be done for the SL case.
         if (!empty($form_source)) {
             $paydesc .= " {$form_source}";
         }
         addBilling($form_encounter, 'COPAY', $amount, $paydesc, $form_pid, 0, 0, '', '', 0 - $amount, '', '', 1);
     } else {
         $msg = invoice_add_line_item($invoice_info, 'COPAY', $paydesc, $form_source, 0 - $amount);
         if ($msg) {
             die($msg);
         }
     }
 }
 if (!$INTEGRATED_AR) {
     $msg = invoice_post($invoice_info);
     if ($msg) {
         die($msg);
     }
 }
 // If applicable, set the invoice reference number.
 $invoice_refno = '';
Ejemplo n.º 5
0
function arPostCharge($patient_id, $encounter_id, $session_id, $amount, $units, $thisdate, $code, $description, $debug)
{
    /*****************************************************************
       // Select an existing billing item as a template.
       $row= sqlQuery("SELECT * FROM billing WHERE " .
         "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
         "code_type = 'CPT4' AND activity = 1 " .
         "ORDER BY id DESC LIMIT 1");
       $this_authorized = 0;
       $this_provider = 0;
       if (!empty($row)) {
         $this_authorized = $row['authorized'];
         $this_provider = $row['provider_id'];
       }
       *****************************************************************/
    $codeonly = $code;
    $modifier = '';
    $tmp = strpos($code, ':');
    if ($tmp) {
        $codeonly = substr($code, 0, $tmp);
        $modifier = substr($code, $tmp + 1);
    }
    addBilling($encounter_id, 'CPT4', $codeonly, addslashes($description), $patient_id, 0, 0, $modifier, $units, $amount, '', '');
}
Ejemplo n.º 6
0
$N = 10;
$mode = $_GET['mode'];
$type = $_GET['type'];
$modifier = $_GET['modifier'];
$units = $_GET['units'];
$fee = $_GET['fee'];
$code = $_GET['code'];
$text = $_GET['text'];
if (isset($mode)) {
    if ($mode == "add") {
        if (strtolower($type) == "copay") {
            addBilling($encounter, $type, sprintf("%01.2f", $code), strip_escape_custom($text), $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, sprintf("%01.2f", 0 - $code));
        } elseif (strtolower($type) == "other") {
            addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, sprintf("%01.2f", $fee));
        } else {
            addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, $fee);
        }
    }
}
?>
<html>
<head>
<?php 
html_header_show();
?>
<link rel="stylesheet" href="<?php 
echo $css_header;
?>
" type="text/css">
</head>
<body class="body_bottom">
Ejemplo n.º 7
0
function arPostCharge($patient_id, $encounter_id, $session_id, $amount, $units, $thisdate, $code, $description, $debug, $codetype = '')
{
    /*****************************************************************
       // Select an existing billing item as a template.
       $row= sqlQuery("SELECT * FROM billing WHERE " .
         "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
         "code_type = 'CPT4' AND activity = 1 " .
         "ORDER BY id DESC LIMIT 1");
       $this_authorized = 0;
       $this_provider = 0;
       if (!empty($row)) {
         $this_authorized = $row['authorized'];
         $this_provider = $row['provider_id'];
       }
       *****************************************************************/
    if (empty($codetype)) {
        // default to CPT4 if empty, which is consistent with previous functionality.
        $codetype = "CPT4";
    }
    $codeonly = $code;
    $modifier = '';
    $tmp = strpos($code, ':');
    if ($tmp) {
        $codeonly = substr($code, 0, $tmp);
        $modifier = substr($code, $tmp + 1);
    }
    addBilling($encounter_id, $codetype, $codeonly, $description, $patient_id, 0, 0, $modifier, $units, $amount, '', '');
}
Ejemplo n.º 8
0
$fee = -$amount_paid;
$amount_paid = $feeSum - $discountAmount;
//Post by getfeesheet web serivece for view Only
$itemFee = $_POST['itemFee'];
$date = $_POST['date'];
$units = add_escape_custom($_POST['units']);
$code_type = 'COPAY';
$auth = "1";
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('acct', 'bill', $user);
    $_SESSION['authUser'] = $user;
    $_SESSION['authGroup'] = $site;
    $_SESSION['pid'] = $patientId;
    if ($acl_allow) {
        addBilling($visit_id, $code_type, $code, $code_text, $patientId, $auth, $provider = "0", $modifier = "0", $units, $fee, $ndc_info = '', $justify = '', $billed = "1", $notecodes = '');
        $strQuery1 = "UPDATE `billing` SET";
        $strQuery1 .= " activity  = 0";
        $strQuery1 .= " WHERE encounter = " . add_escape_custom($visit_id) . " AND pid = " . add_escape_custom($patientId);
        $result1 = sqlStatement($strQuery1);
        $strQuery2 = 'UPDATE `billing` SET';
        $strQuery2 .= ' fee  = "' . add_escape_custom($feeSum) . '",';
        $strQuery2 .= ' bill_date  = "' . date('Y-m-d H:i:s') . '",';
        $strQuery2 .= ' billed  = 1';
        $strQuery2 .= ' WHERE id = ' . add_escape_custom($billing_id);
        $result2 = sqlStatement($strQuery2);
        $strQuery3 = "INSERT INTO ar_activity ( pid, encounter, code, modifier, payer_type, post_user, post_time, session_id, memo, adj_amount ) \n                                            VALUES ( '" . add_escape_custom($patientId) . "',\n                                                    '" . add_escape_custom($visit_id) . "',\n                                                    '',\n                                                    '',\n                                                    '0',\n                                                    '" . $userId . "',\n                                                    '" . date('Y-m-d H:i:s') . "',\\\n                                                    '0',\n                                                    'Discount',\n                                                    '" . add_escape_custom($discountAmount) . "'\n                                                        )";
        $result3 = sqlStatement($strQuery3);
        if ($result1 && $result2 && $result3) {
            $xml_string .= "<status>0</status>";
            $xml_string .= "<reason>The Checkout has been added.</reason>";
Ejemplo n.º 9
0
         if ($msg) {
             die($msg);
         }
     }
     if ($code_type == 'PROD') {
         // Product sales. The fee and encounter ID may have changed.
         $query = "update drug_sales SET fee = ?, " . "encounter = ?, billed = 1 WHERE " . "sale_id = ?";
         sqlQuery($query, array($amount, $form_encounter, $id));
     } else {
         if ($code_type == 'TAX') {
             // In the SL case taxes show up on the invoice as line items.
             // Otherwise we gotta save them somewhere, and in the billing
             // table with a code type of TAX seems easiest.
             // They will have to be stripped back out when building this
             // script's input form.
             addBilling($form_encounter, 'TAX', 'TAX', 'Taxes', $form_pid, 0, 0, '', '', $amount, '', '', 1);
         } else {
             // Because there is no insurance here, there is no need for a claims
             // table entry and so we do not call updateClaim().  Note we should not
             // eliminate billed and bill_date from the billing table!
             $query = "UPDATE billing SET fee = ?, billed = 1, " . "bill_date = NOW() WHERE id = ?";
             sqlQuery($query, array($amount, $id));
         }
     }
 }
 // Post discount.
 if ($_POST['form_discount']) {
     if ($GLOBALS['discount_by_money']) {
         $amount = sprintf('%01.2f', trim($_POST['form_discount']));
     } else {
         $amount = sprintf('%01.2f', trim($_POST['form_discount']) * $form_amount / 100);
Ejemplo n.º 10
0
<?php

include_once "../../globals.php";
include_once "{$srcdir}/billing.inc";
$targparm = $GLOBALS['concurrent_layout'] ? "" : "target='Main'";
if (isset($mode)) {
    if ($mode == "add") {
        addBilling($encounter, $type, $code, $text, $pid, $userauthorized, $_SESSION['authUserID']);
    } elseif ($mode == "delete") {
        deleteBilling($id);
    } elseif ($mode == "clear") {
        clearBilling($id);
    }
}
?>
<html>
<head>
<?php 
html_header_show();
?>
<link rel="stylesheet" href="<?php 
echo $css_header;
?>
" type="text/css">
</head>

<body class="body_top">

<?php 
if ($GLOBALS['concurrent_layout']) {
    ?>
Ejemplo n.º 11
0
                deleteBilling($id);
            } else {
                // authorizeBilling($id, $auth);
                sqlQuery("update billing set fee = '{$fee}', modifier = '{$modifier}', " . "authorized = {$auth}, provider_id = '{$provid}' where " . "id = '{$id}' and billed = 0 and activity = 1");
            }
        } 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, "", $fee);
            }
        }
    }
    terminate_coding();
    exit;
}
?>

<style>
.billcell { font-family: sans-serif; font-size: 10pt }
</style>
<script language="JavaScript">

// This is invoked by <select onchange> for the various dropdowns,
// including search results.
Ejemplo n.º 12
0
$discountAmount = !empty($_POST['discountAmount']) ? $_POST['discountAmount'] : 0;
$billing_id = $_POST['billing_id'];
$charges = $fee - $discountAmount;
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('acct', 'bill', $user);
    // Session variable used in addBilling() function
    $_SESSION['authUser'] = $user;
    if ($acl_allow) {
        if ($code_type == 'TAX') {
            // In the SL case taxes show up on the invoice as line items.
            // Otherwise we gotta save them somewhere, and in the billing
            // table with a code type of TAX seems easiest.
            // They will have to be stripped back out when building this
            // script's input form.
            addBilling($visit_id, 'TAX', 'TAX', 'Taxes', $patientId, 0, 0, '', '', $charges, '', '', 1);
        } else {
            // Because there is no insurance here, there is no need for a claims
            // table entry and so we do not call updateClaim().  Note we should not
            // eliminate billed and bill_date from the billing table!
            $query = "UPDATE billing SET fee = ?, billed = 1, " . "bill_date = NOW() WHERE id = ?";
            sqlQuery($query, array($charges, $billing_id));
        }
        if (!empty($discountAmount)) {
            $time = date('Y-m-d H:i:s');
            $memo = 'Discount';
            $query = "INSERT INTO ar_activity ( " . "pid, encounter, code, modifier, payer_type, post_user, post_time, " . "session_id, memo, adj_amount " . ") VALUES ( " . "?, " . "?, " . "'', " . "'', " . "'0', " . "?, " . "?, " . "'0', " . "?, " . "? " . ")";
            sqlStatement($query, array($patientId, $visit_id, $userId, $time, $memo, $amount));
        }
        if (!empty($charges)) {
            $amount = sprintf('%01.2f', trim($charges));
Ejemplo n.º 13
0
     $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " . "forms.pid = '{$pid}' AND forms.encounter = '{$encounter}' AND " . "forms.formdir='newpatient' AND users.username = forms.user AND " . "users.authorized = 1");
     $provid = $tmp['id'] ? $tmp['id'] : $_SESSION["authUserID"];
     if (strtolower($type) == "copay") {
         addBilling($encounter, $type, sprintf("%01.2f", $code), strip_escape_custom($payment_method), $pid, $userauthorized, $provid, $modifier, $units, sprintf("%01.2f", 0 - $code));
     } elseif (strtolower($type) == "other") {
         addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized, $provid, $modifier, $units, sprintf("%01.2f", $fee));
     } else {
         $ndc_info = '';
         // If HCPCS, get and save default NDC data.
         if (strtolower($type) == "hcpcs") {
             $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " . "code_type = 'HCPCS' AND code = '{$code}' AND ndc_info LIKE 'N4%' " . "ORDER BY date DESC LIMIT 1");
             if (!empty($tmp)) {
                 $ndc_info = $tmp['ndc_info'];
             }
         }
         addBilling($encounter, $type, $code, strip_escape_custom($text), $pid, $userauthorized, $provid, $modifier, $units, $fee, $ndc_info);
     }
 } elseif ($mode == "justify") {
     $diags = $_POST['code']['diag'];
     $procs = $_POST['code']['proc'];
     $sql = array();
     if (!empty($procs) && !empty($diags)) {
         $sql = array();
         foreach ($procs as $proc) {
             $justify_string = "";
             foreach ($diags as $diag) {
                 $justify_string .= $diag . ":";
             }
             $sql[] = "UPDATE billing set justify = concat(justify,'" . add_escape_custom($justify_string) . "') where encounter = '" . add_escape_custom($_POST['encounter_id']) . "' and pid = '" . add_escape_custom($_POST['patient_id']) . "' and code = '" . add_escape_custom($proc) . "'";
         }
     }
Ejemplo n.º 14
0
$modifier = $_POST['modifier'];
$units = max(1, intval(trim($_POST['units'])));
$price = $_POST['price'];
$priceLevel = $_POST['priceLevel'];
$justify = $_POST['justify'];
$ndc_info = !empty($_POST['ndc_info']) ? $_POST['ndc_info'] : '';
$noteCodes = !empty($_POST['noteCodes']) ? $_POST['noteCodes'] : '';
$fee = sprintf('%01.2f', (0 + trim($price)) * $units);
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('acct', 'bill', $user);
    $_SESSION['authUser'] = $user;
    $_SESSION['authGroup'] = $site;
    $_SESSION['pid'] = $patientId;
    if ($acl_allow) {
        addBilling($visit_id, $code_type, $code, $code_text, $patientId, $auth, $provider_id, $modifier, $units, $fee, $ndc_info, $justify, 0, $noteCodes);
        $strQuery1 = 'UPDATE `patient_data` SET';
        $strQuery1 .= ' pricelevel  = "' . add_escape_custom($priceLevel) . '"';
        $strQuery1 .= ' WHERE pid = ?';
        $result1 = sqlStatement($strQuery1, array($patientId));
        $strQuery2 = 'UPDATE `form_encounter` SET';
        $strQuery2 .= ' provider_id  = "' . add_escape_custom($provider_id) . '",';
        $strQuery2 .= ' supervisor_id  = "' . add_escape_custom($supervisor_id) . '"';
        $strQuery2 .= ' WHERE pid = ?' . ' AND encounter = ?';
        $result2 = sqlStatement($strQuery2, array($patientId, $visit_id));
        if ($result1 && $result2) {
            $xml_string .= "<status>0</status>";
            $xml_string .= "<reason>Fee Sheet added successfully</reason>";
        }
    } else {
        $xml_string .= "<status>-2</status>\n";
Ejemplo n.º 15
0
$patdata = sqlQuery("SELECT " . "p.fname, p.mname, p.lname, p.pubpid, i.copay " . "FROM patient_data AS p " . "LEFT OUTER JOIN insurance_data AS i ON " . "i.pid = p.pid AND i.type = 'primary' " . "WHERE p.pid = '{$pid}' ORDER BY i.date DESC LIMIT 1");
$alertmsg = '';
// anything here pops up in an alert box
// If the Save button was clicked...
if ($_POST['form_save']) {
    $form_pid = $_POST['form_pid'];
    $form_method = trim($_POST['form_method']);
    $form_source = trim($_POST['form_source']);
    // Post payments for unbilled encounters.  These go into the billing table.
    if ($_POST['form_upay']) {
        foreach ($_POST['form_upay'] as $enc => $payment) {
            if ($amount = 0 + $payment) {
                if (!$enc) {
                    $enc = todaysEncounter($form_pid);
                }
                addBilling($enc, 'COPAY', sprintf('%.2f', $amount), $form_method, $form_pid, 1, $_SESSION["authUserID"], '', 1, 0 - $amount, '', '');
                frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0);
            }
        }
    }
    // Post payments for previously billed encounters.  These go to A/R.
    if ($_POST['form_bpay']) {
        foreach ($_POST['form_bpay'] as $enc => $payment) {
            if ($amount = 0 + $payment) {
                if ($INTEGRATED_AR) {
                    $thissrc = '';
                    if ($form_method) {
                        $thissrc .= $form_method;
                        if ($form_source) {
                            $thissrc .= " {$form_source}";
                        }
Ejemplo n.º 16
0
     $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 = ?, " . "units = ?, fee = ?, modifier = ?, " . "authorized = ?, provider_id = ?, " . "ndc_info = ?, justify = ?, notecodes = ? " . "WHERE " . "id = ? AND billed = 0 AND activity = 1", array($code, $units, $fee, $modifier, $auth, $provid, $ndc_info, $justify, $notecodes, $id));
         }
     } else {
         if (!$del) {
             $code_text = lookup_code_descriptions($code_type . ":" . $code);
             addBilling($encounter, $code_type, $code, $code_text, $pid, $auth, $provid, $modifier, $units, $fee, $ndc_info, $justify, 0, $notecodes);
         }
     }
 }
 // end for
 //if modifier is not inserted during loop update the record using the first
 //non-empty modifier and code
 if ($copay_update == TRUE && $update_session_id != '' && $mod0 != '') {
     sqlStatement("UPDATE ar_activity SET code_type=?, code=?, modifier=?" . " WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?", array($ct0, $cod0, $mod0, $pid, $encounter, $update_session_id));
 }
 // 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;
Ejemplo n.º 17
0
$modifier = $_GET['modifier'];
$units = $_GET['units'];
$fee = $_GET['fee'];
$code = $_GET['code'];
$text = $_GET['text'];
if (!get_magic_quotes_gpc()) {
    $text = addslashes($text);
}
if (isset($mode)) {
    if ($mode == "add") {
        if (strtolower($type) == "copay") {
            addBilling($encounter, $type, sprintf("%01.2f", $code), $text, $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, sprintf("%01.2f", 0 - $code));
        } elseif (strtolower($type) == "other") {
            addBilling($encounter, $type, $code, $text, $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, sprintf("%01.2f", $fee));
        } else {
            addBilling($encounter, $type, $code, $text, $pid, $userauthorized, $_SESSION['authUserID'], $modifier, $units, $fee);
        }
    }
}
?>
<html>
<head>
<?php 
html_header_show();
?>
<link rel="stylesheet" href="<?php 
echo $css_header;
?>
" type="text/css">
</head>
<body class="body_bottom">
Ejemplo n.º 18
0
         if ($dups[$item["code"]] == '1') {
             continue;
         }
         $dups[$item["code"]] = "1";
         $sql = "SELECT codes.*, prices.pr_price FROM codes " . "LEFT OUTER JOIN patient_data ON patient_data.pid = '{$pid}' " . "LEFT OUTER JOIN prices ON prices.pr_id = codes.id AND " . "prices.pr_selector = '' AND " . "prices.pr_level = patient_data.pricelevel " . "WHERE code =?" . " LIMIT 1";
         $result = sqlStatement($sql, array($item['code']));
         while ($res = sqlFetchArray($result)) {
             $item["codedesc"] = $res["code_text"];
             // = "NP EYE intermediate exam"
             if (!$item["modifier"]) {
                 $item["modifier"] = $res["modifier"];
             }
             $item["units"] = $res["units"];
             $item["fee"] = $res["pr_price"];
         }
         addBilling($encounter, $item["codetype"], $item["code"], $item["codedesc"], $pid, '1', $providerID, $item["modifier"], $item["units"], $item["fee"], $ndc_info, $justify, $billed, '');
     }
     echo 'ok';
     exit;
 }
 /*** END CODE to DEAL WITH PMSFH/ISUUE_TYPES  ****/
 /* Let's save the encounter specific values.
     // Any field that exists in the database could be updated
     // so we need to exclude the important ones...
     // id  date  pid   user  groupname   authorized  activity.  Any other just add them below.
     // Doing it this way means you can add new fields on a web page and in the DB without touching this function.
     // The update feature still works because it only updates columns that are in the table you are working on.
    */
 $query = "SHOW COLUMNS from " . $table_name . "";
 $result = sqlStatement($query);
 if (!$result) {
Ejemplo n.º 19
0
 public function save(&$bill, &$prod, $main_provid = NULL, $main_supid = NULL, $default_warehouse = NULL, $mark_as_closed = false)
 {
     global $code_types;
     if (isset($main_provid) && $main_supid == $main_provid) {
         $main_supid = 0;
     }
     $copay_update = FALSE;
     $update_session_id = '';
     $ct0 = '';
     // takes the code type of the first fee type code type entry from the fee sheet, against which the copay is posted
     $cod0 = '';
     // takes the code of the first fee type code type entry from the fee sheet, against which the copay is posted
     $mod0 = '';
     // takes the modifier of the first fee type code type entry from the fee sheet, against which the copay is posted
     if (is_array($bill)) {
         foreach ($bill as $iter) {
             // Skip disabled (billed) line items.
             if (!empty($iter['billed'])) {
                 continue;
             }
             $id = $iter['id'];
             $code_type = $iter['code_type'];
             $code = $iter['code'];
             $del = !empty($iter['del']);
             $units = empty($iter['units']) ? 1 : intval($iter['units']);
             $price = empty($iter['price']) ? 0 : 0 + trim($iter['price']);
             $pricelevel = empty($iter['pricelevel']) ? '' : $iter['pricelevel'];
             $modifier = empty($iter['mod']) ? '' : trim($iter['mod']);
             $justify = empty($iter['justify']) ? '' : trim($iter['justify']);
             $notecodes = empty($iter['notecodes']) ? '' : trim($iter['notecodes']);
             $provid = empty($iter['provid']) ? 0 : intval($iter['provid']);
             $fee = sprintf('%01.2f', $price * $units);
             if (!$cod0 && $code_types[$code_type]['fee'] == 1) {
                 $mod0 = $modifier;
                 $cod0 = $code;
                 $ct0 = $code_type;
             }
             if ($code_type == 'COPAY') {
                 if ($fee < 0) {
                     $fee = $fee * -1;
                 }
                 if (!$id) {
                     // adding new copay from fee sheet into ar_session and ar_activity tables
                     $session_id = idSqlStatement("INSERT INTO ar_session " . "(payer_id, user_id, pay_total, payment_type, description, patient_id, payment_method, " . "adjustment_code, post_to_date) " . "VALUES ('0',?,?,'patient','COPAY',?,'','patient_payment',now())", array($_SESSION['authId'], $fee, $this->pid));
                     sqlBeginTrans();
                     $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE " . "pid = ? AND encounter = ?", array($this->pid, $this->encounter));
                     SqlStatement("INSERT INTO ar_activity (pid, encounter, sequence_no, code_type, code, modifier, " . "payer_type, post_time, post_user, session_id, " . "pay_amount, account_code) VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')", array($this->pid, $this->encounter, $sequence_no['increment'], $ct0, $cod0, $mod0, $_SESSION['authId'], $session_id, $fee));
                     sqlCommitTrans();
                 } else {
                     // editing copay saved to ar_session and ar_activity
                     $session_id = $id;
                     $res_amount = sqlQuery("SELECT pay_amount FROM ar_activity WHERE pid=? AND encounter=? AND session_id=?", array($this->pid, $this->encounter, $session_id));
                     if ($fee != $res_amount['pay_amount']) {
                         sqlStatement("UPDATE ar_session SET user_id=?,pay_total=?,modified_time=now(),post_to_date=now() WHERE session_id=?", array($_SESSION['authId'], $fee, $session_id));
                         sqlStatement("UPDATE ar_activity SET code_type=?, code=?, modifier=?, post_user=?, post_time=now()," . "pay_amount=?, modified_time=now() WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?", array($ct0, $cod0, $mod0, $_SESSION['authId'], $fee, $this->pid, $this->encounter, $session_id));
                     }
                 }
                 if (!$cod0) {
                     $copay_update = TRUE;
                     $update_session_id = $session_id;
                 }
                 continue;
             }
             # Code to create justification for all codes based on first justification
             if ($GLOBALS['replicate_justification'] == '1') {
                 if ($justify != '') {
                     $autojustify = $justify;
                 }
             }
             if ($GLOBALS['replicate_justification'] == '1' && $justify == '' && check_is_code_type_justify($code_type)) {
                 $justify = $autojustify;
             }
             if ($justify) {
                 $justify = str_replace(',', ':', $justify) . ':';
             }
             $auth = "1";
             $ndc_info = '';
             if (!empty($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) {
                     $this->logFSMessage(xl('Service deleted'));
                     deleteBilling($id);
                 } else {
                     $tmp = sqlQuery("SELECT * FROM billing WHERE id = ? AND (billed = 0 or billed is NULL) AND activity = 1", array($id));
                     if (!empty($tmp)) {
                         $tmparr = array('code' => $code, 'authorized' => $auth);
                         if (isset($iter['units'])) {
                             $tmparr['units'] = $units;
                         }
                         if (isset($iter['price'])) {
                             $tmparr['fee'] = $fee;
                         }
                         if (isset($iter['pricelevel'])) {
                             $tmparr['pricelevel'] = $pricelevel;
                         }
                         if (isset($iter['mod'])) {
                             $tmparr['modifier'] = $modifier;
                         }
                         if (isset($iter['provid'])) {
                             $tmparr['provider_id'] = $provid;
                         }
                         if (isset($iter['ndcnum'])) {
                             $tmparr['ndc_info'] = $ndc_info;
                         }
                         if (isset($iter['justify'])) {
                             $tmparr['justify'] = $justify;
                         }
                         if (isset($iter['notecodes'])) {
                             $tmparr['notecodes'] = $notecodes;
                         }
                         foreach ($tmparr as $key => $value) {
                             if ($tmp[$key] != $value) {
                                 if ('fee' == $key) {
                                     $this->logFSMessage(xl('Price changed'));
                                 }
                                 if ('units' == $key) {
                                     $this->logFSMessage(xl('Quantity changed'));
                                 }
                                 if ('provider_id' == $key) {
                                     $this->logFSMessage(xl('Service provider changed'));
                                 }
                                 sqlStatement("UPDATE billing SET `{$key}` = ? WHERE id = ?", array($value, $id));
                             }
                         }
                     }
                 }
             } else {
                 if (!$del) {
                     $this->logFSMessage(xl('Service added'));
                     $code_text = lookup_code_descriptions($code_type . ":" . $code);
                     addBilling($this->encounter, $code_type, $code, $code_text, $this->pid, $auth, $provid, $modifier, $units, $fee, $ndc_info, $justify, 0, $notecodes, $pricelevel);
                 }
             }
         }
     }
     // end for
     // if modifier is not inserted during loop update the record using the first
     // non-empty modifier and code
     if ($copay_update == TRUE && $update_session_id != '' && $mod0 != '') {
         sqlStatement("UPDATE ar_activity SET code_type = ?, code = ?, modifier = ?" . " WHERE pid = ? AND encounter = ? AND account_code = 'PCP' AND session_id = ?", array($ct0, $cod0, $mod0, $this->pid, $this->encounter, $update_session_id));
     }
     // Doing similarly to the above but for products.
     if (is_array($prod)) {
         foreach ($prod as $iter) {
             // Skip disabled (billed) line items.
             if (!empty($iter['billed'])) {
                 continue;
             }
             $drug_id = $iter['drug_id'];
             $selector = empty($iter['selector']) ? '' : $iter['selector'];
             $sale_id = $iter['sale_id'];
             // present only if already saved
             $units = max(1, intval(trim($iter['units'])));
             $price = empty($iter['price']) ? 0 : 0 + trim($iter['price']);
             $pricelevel = empty($iter['pricelevel']) ? '' : $iter['pricelevel'];
             $fee = sprintf('%01.2f', $price * $units);
             $del = !empty($iter['del']);
             $rxid = 0;
             $warehouse_id = empty($iter['warehouse']) ? '' : $iter['warehouse'];
             $somechange = false;
             // If the item is already in the database...
             if ($sale_id) {
                 $tmprow = sqlQuery("SELECT ds.prescription_id, ds.quantity, ds.inventory_id, ds.fee, " . "ds.sale_date, di.warehouse_id " . "FROM drug_sales AS ds " . "LEFT JOIN drug_inventory AS di ON di.inventory_id = ds.inventory_id " . "WHERE ds.sale_id = ?", array($sale_id));
                 $rxid = 0 + $tmprow['prescription_id'];
                 if ($del) {
                     if (!empty($tmprow)) {
                         // Delete this sale and reverse its inventory update.
                         $this->logFSMessage(xl('Product deleted'));
                         sqlStatement("DELETE FROM drug_sales WHERE sale_id = ?", array($sale_id));
                         if (!empty($tmprow['inventory_id'])) {
                             sqlStatement("UPDATE drug_inventory SET on_hand = on_hand + ? WHERE inventory_id = ?", array($tmprow['quantity'], $tmprow['inventory_id']));
                         }
                     }
                     if ($rxid) {
                         sqlStatement("DELETE FROM prescriptions WHERE id = ?", array($rxid));
                     }
                 } else {
                     // Modify the sale and adjust inventory accordingly.
                     if (!empty($tmprow)) {
                         foreach (array('quantity' => $units, 'fee' => $fee, 'pricelevel' => $pricelevel, 'selector' => $selector, 'sale_date' => $this->visit_date) as $key => $value) {
                             if ($tmprow[$key] != $value) {
                                 $somechange = true;
                                 if ('fee' == $key) {
                                     $this->logFSMessage(xl('Price changed'));
                                 }
                                 if ('pricelevel' == $key) {
                                     $this->logFSMessage(xl('Price level changed'));
                                 }
                                 if ('selector' == $key) {
                                     $this->logFSMessage(xl('Template selector changed'));
                                 }
                                 if ('quantity' == $key) {
                                     $this->logFSMessage(xl('Quantity changed'));
                                 }
                                 sqlStatement("UPDATE drug_sales SET `{$key}` = ? WHERE sale_id = ?", array($value, $sale_id));
                                 if ($key == 'quantity' && $tmprow['inventory_id']) {
                                     sqlStatement("UPDATE drug_inventory SET on_hand = on_hand - ? WHERE inventory_id = ?", array($units - $tmprow['quantity'], $tmprow['inventory_id']));
                                 }
                             }
                         }
                         if ($tmprow['inventory_id'] && $warehouse_id && $warehouse_id != $tmprow['warehouse_id']) {
                             // Changing warehouse.  Requires deleting and re-adding the sale.
                             // Not setting $somechange because this alone does not affect a prescription.
                             $this->logFSMessage(xl('Warehouse changed'));
                             sqlStatement("DELETE FROM drug_sales WHERE sale_id = ?", array($sale_id));
                             sqlStatement("UPDATE drug_inventory SET on_hand = on_hand + ? WHERE inventory_id = ?", array($units, $tmprow['inventory_id']));
                             $tmpnull = null;
                             $sale_id = sellDrug($drug_id, $units, $fee, $this->pid, $this->encounter, empty($iter['rx']) ? 0 : $rxid, $this->visit_date, '', $warehouse_id, false, $tmpnull, $pricelevel, $selector);
                         }
                     }
                     // Delete Rx if $rxid and flag not set.
                     if ($GLOBALS['gbl_auto_create_rx'] && $rxid && empty($iter['rx'])) {
                         sqlStatement("UPDATE drug_sales SET prescription_id = 0 WHERE sale_id = ?", array($sale_id));
                         sqlStatement("DELETE FROM prescriptions WHERE id = ?", array($rxid));
                     }
                 }
             } else {
                 if (!$del) {
                     $somechange = true;
                     $this->logFSMessage(xl('Product added'));
                     $tmpnull = null;
                     $sale_id = sellDrug($drug_id, $units, $fee, $this->pid, $this->encounter, 0, $this->visit_date, '', $warehouse_id, false, $tmpnull, $pricelevel, $selector);
                     if (!$sale_id) {
                         die(xlt("Insufficient inventory for product ID") . " \"" . text($drug_id) . "\".");
                     }
                 }
             }
             // If a prescription applies, create or update it.
             if (!empty($iter['rx']) && !$del && ($somechange || empty($rxid))) {
                 // If an active rx already exists for this drug and date we will
                 // replace it, otherwise we'll make a new one.
                 if (empty($rxid)) {
                     $rxid = '';
                 }
                 // Get default drug attributes; prefer the template with the matching selector.
                 $drow = sqlQuery("SELECT dt.*, " . "d.name, d.form, d.size, d.unit, d.route, d.substitute " . "FROM drugs AS d, drug_templates AS dt WHERE " . "d.drug_id = ? AND dt.drug_id = d.drug_id " . "ORDER BY (dt.selector = ?) DESC, dt.quantity, dt.dosage, dt.selector LIMIT 1", array($drug_id, $selector));
                 if (!empty($drow)) {
                     $rxobj = new Prescription($rxid);
                     $rxobj->set_patient_id($this->pid);
                     $rxobj->set_provider_id(isset($main_provid) ? $main_provid : $this->provider_id);
                     $rxobj->set_drug_id($drug_id);
                     $rxobj->set_quantity($units);
                     $rxobj->set_per_refill($units);
                     $rxobj->set_start_date_y(substr($this->visit_date, 0, 4));
                     $rxobj->set_start_date_m(substr($this->visit_date, 5, 2));
                     $rxobj->set_start_date_d(substr($this->visit_date, 8, 2));
                     $rxobj->set_date_added($this->visit_date);
                     // Remaining attributes are the drug and template defaults.
                     $rxobj->set_drug($drow['name']);
                     $rxobj->set_unit($drow['unit']);
                     $rxobj->set_dosage($drow['dosage']);
                     $rxobj->set_form($drow['form']);
                     $rxobj->set_refills($drow['refills']);
                     $rxobj->set_size($drow['size']);
                     $rxobj->set_route($drow['route']);
                     $rxobj->set_interval($drow['period']);
                     $rxobj->set_substitute($drow['substitute']);
                     //
                     $rxobj->persist();
                     // Set drug_sales.prescription_id to $rxobj->get_id().
                     $oldrxid = $rxid;
                     $rxid = 0 + $rxobj->get_id();
                     if ($rxid != $oldrxid) {
                         sqlStatement("UPDATE drug_sales SET prescription_id = ? WHERE sale_id = ?", array($rxid, $sale_id));
                     }
                 }
             }
         }
     }
     // end for
     // Set default and/or supervising provider for the encounter.
     if (isset($main_provid) && $main_provid != $this->provider_id) {
         $this->logFSMessage(xl('Default provider changed'));
         sqlStatement("UPDATE form_encounter SET provider_id = ? WHERE pid = ? AND encounter = ?", array($main_provid, $this->pid, $this->encounter));
         $this->provider_id = $main_provid;
     }
     if (isset($main_supid) && $main_supid != $this->supervisor_id) {
         sqlStatement("UPDATE form_encounter SET supervisor_id = ? WHERE pid = ? AND encounter = ?", array($main_supid, $this->pid, $this->encounter));
         $this->supervisor_id = $main_supid;
     }
     // Save-and-Close is currently specific to Family Planning but might be more
     // generally useful.  It provides the ability to mark an encounter as billed
     // directly from the Fee Sheet, if there are no charges.
     if ($mark_as_closed) {
         $tmp1 = sqlQuery("SELECT SUM(ABS(fee)) AS sum FROM drug_sales WHERE " . "pid = ? AND encounter = ? AND billed = 0", array($this->pid, $this->encounter));
         $tmp2 = sqlQuery("SELECT SUM(ABS(fee)) AS sum FROM billing WHERE " . "pid = ? AND encounter = ? AND billed = 0 AND activity = 1", array($this->pid, $this->encounter));
         if ($tmp1['sum'] + $tmp2['sum'] == 0) {
             sqlStatement("update drug_sales SET billed = 1 WHERE " . "pid = ? AND encounter = ? AND billed = 0", array($this->pid, $this->encounter));
             sqlStatement("UPDATE billing SET billed = 1, bill_date = NOW() WHERE " . "pid = ? AND encounter = ? AND billed = 0 AND activity = 1", array($this->pid, $this->encounter));
         } else {
             // Would be good to display an error message here... they clicked
             // Save and Close but the close could not be done.  However the
             // framework does not provide an easy way to do that.
         }
     }
 }
Ejemplo n.º 20
0
     $tmp = sqlQuery("SELECT users.id FROM forms, users WHERE " . "forms.pid = '{$pid}' AND forms.encounter = '{$encounter}' AND " . "forms.formdir='newpatient' AND users.username = forms.user AND " . "users.authorized = 1");
     $provid = $tmp['id'] ? $tmp['id'] : $_SESSION["authUserID"];
     if (strtolower($type) == "copay") {
         addBilling($encounter, $type, sprintf("%01.2f", $code), $payment_method, $pid, $userauthorized, $provid, $modifier, $units, sprintf("%01.2f", 0 - $code));
     } elseif (strtolower($type) == "other") {
         addBilling($encounter, $type, $code, $text, $pid, $userauthorized, $provid, $modifier, $units, sprintf("%01.2f", $fee));
     } else {
         $ndc_info = '';
         // If HCPCS, get and save default NDC data.
         if (strtolower($type) == "hcpcs") {
             $tmp = sqlQuery("SELECT ndc_info FROM billing WHERE " . "code_type = 'HCPCS' AND code = '{$code}' AND ndc_info LIKE 'N4%' " . "ORDER BY date DESC LIMIT 1");
             if (!empty($tmp)) {
                 $ndc_info = $tmp['ndc_info'];
             }
         }
         addBilling($encounter, $type, $code, $text, $pid, $userauthorized, $provid, $modifier, $units, $fee, $ndc_info);
     }
 } elseif ($mode == "justify") {
     $diags = $_POST['code']['diag'];
     $procs = $_POST['code']['proc'];
     $sql = array();
     if (!empty($procs) && !empty($diags)) {
         $sql = array();
         foreach ($procs as $proc) {
             $justify_string = "";
             foreach ($diags as $diag) {
                 $justify_string .= $diag . ":";
             }
             $sql[] = "UPDATE billing set justify = concat(justify,'" . mysql_real_escape_string($justify_string) . "') where encounter = '" . mysql_real_escape_string($_POST['encounter_id']) . "' and pid = '" . mysql_real_escape_string($_POST['patient_id']) . "' and code = '" . mysql_real_escape_string($proc) . "'";
         }
     }