Skip to content

Commit

Permalink
Migrate sql billing copay items to ar_session/ar_activity sql tables.
Browse files Browse the repository at this point in the history
Modified all scripts within OpenEMR place and use copay tries in ar_session
and ar_activity tables. During upgrade, all copay entries will also be migrated
from the billing table to the ar_session and ar_activity tables.

Signed-off-by: Ajil <[email protected]>
  • Loading branch information
Ajil authored and bradymiller committed Apr 28, 2012
1 parent ca65552 commit 9e98195
Show file tree
Hide file tree
Showing 16 changed files with 1,429 additions and 445 deletions.
46 changes: 46 additions & 0 deletions interface/billing/billing_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,52 @@ class='link_submit' ><?php echo htmlspecialchars(xl('[View Printable Report]'),
else {
$rhtml .= "<td></td>\n";
}
if($last_encounter_id != $this_encounter_id){
$rhtml2 = "";
$rowcnt = 0;
$resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,date(post_time) as date FROM ar_activity where ".
"pid = ? and encounter = ? and payer_type=0 and account_code='PCP'",
array($iter['enc_pid'],$iter['enc_encounter']));
//new fees screen copay gives account_code='PCP'
if(sqlNumRows($resMoneyGot) > 0){
$lcount += 2;
$rcount++;
}
//checks whether a copay exists for the encounter and if exists displays it.
while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
$rowcnt++;
$PatientPay=$rowMoneyGot['PatientPay'];
$date=$rowMoneyGot['date'];
if($PatientPay > 0){
if($rhtml){
$rhtml2 .= "<tr bgcolor='$bgcolor'>\n";
}
$rhtml2 .= "<td width='50'>";
$rhtml2 .= "<span class='text'>".xla('COPAY').": </span>";
$rhtml2 .= "</td>\n";
$rhtml2 .= "<td><span class='text'>".attr(oeFormatMoney($PatientPay))."</span><span style='font-size:8pt;'>&nbsp;</span></td>\n";
$rhtml2 .= '<td align="right"><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
$rhtml2 .= "</span></td>\n";
$rhtml2 .= '<td><span style="font-size:8pt;">&nbsp;&nbsp;&nbsp;';
$rhtml2 .= "</span></td>\n";
$rhtml2 .= '<td width=100>&nbsp;&nbsp;&nbsp;<span style="font-size:8pt;">';
$rhtml2 .= attr(oeFormatSDFT(strtotime($date)));
$rhtml2 .= "</span></td>\n";
if ($iter['id'] && $iter['authorized'] != 1) {
$rhtml2 .= "<td><span class=alert>".xla("Note: This code was not entered by an authorized user. Only authorized codes may be uploaded to the Open Medical Billing Network for processing. If you wish to upload these codes, please select an authorized user here.")."</span></td>\n";
}else{
$rhtml2 .= "<td></td>\n";
}
if(!$iter['id'] && $rowcnt == 1){
$rhtml2 .= "<td><input type='checkbox' value='0' name='claims[" . attr($this_encounter_id) . "][bill]' onclick='set_button_states()' id='CheckBoxBilling" . $CheckBoxBilling*1 . "'>&nbsp;</td>\n";
$CheckBoxBilling++;
}else{
$rhtml2 .= "<td></td>\n";
}
}
}
$rhtml .= $rhtml2;
}
$rhtml .= "</tr>\n";
$last_encounter_id = $this_encounter_id;

Expand Down
7 changes: 2 additions & 5 deletions interface/billing/edit_payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,7 @@ function DeletePaymentDistribution(DeleteId)
$Copay=$rowCopay['copay']*-1;

$resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
pid ='$PId' and encounter ='$Encounter' and payer_type=0 and
(code='CO-PAY' or account_code='PCP')");//new fees screen copay gives account_code='PCP'
//openemr payment screen copay gives code='CO-PAY'
pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$PatientPay=$rowMoneyGot['PatientPay'];

Expand All @@ -884,9 +882,8 @@ function DeletePaymentDistribution(DeleteId)
{//Fetch all values
$resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
pid ='$PId' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
(code='CO-PAY' or account_code='PCP'))");
account_code='PCP')");
//new fees screen copay gives account_code='PCP'
//openemr payment screen copay gives code='CO-PAY'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$MoneyGot=$rowMoneyGot['MoneyGot'];

Expand Down
6 changes: 2 additions & 4 deletions interface/billing/payment_pat_sel.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@

$resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
pid ='$hidden_patient_code' and encounter ='$Encounter' and payer_type=0 and
(code='CO-PAY' or account_code='PCP')");//new fees screen copay gives account_code='PCP'
//openemr payment screen copay gives code='CO-PAY'
account_code='PCP'");//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$PatientPay=$rowMoneyGot['PatientPay'];

Expand All @@ -209,8 +208,7 @@
//payer_type!=0
$resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
pid ='$hidden_patient_code' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
(code='CO-PAY' or account_code='PCP'))");//new fees screen copay gives account_code='PCP'
//openemr payment screen copay gives code='CO-PAY'
account_code='PCP')");//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$MoneyGot=$rowMoneyGot['MoneyGot'];

Expand Down
2 changes: 1 addition & 1 deletion interface/billing/print_billing_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
$N = 1;

$itero = array();
if ($ret = getBillsBetween($code_type)) {
if ($ret = getBillsBetweenReport($code_type)) {
$old_pid = -1;
$first_time = 1;
$encid = 0;
Expand Down
85 changes: 79 additions & 6 deletions interface/forms/fee_sheet/new.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ function echoLine($lino, $codetype, $code, $modifier, $ndc_info='',
echo " <tr>\n";
echo " <td class='billcell'>$strike1" .
($codetype == 'COPAY' ? xl($codetype) : $codetype) . $strike2;
//if the line to ouput is copay, show the date here passed as $ndc_info,
//since this variable is not applicable in the case of copay.
if($codetype == 'COPAY'){
echo "(".htmlspecialchars($ndc_info).")";
$ndc_info = '';
}
if ($id) {
echo "<input type='hidden' name='bill[$lino][id]' value='$id'>";
}
Expand Down Expand Up @@ -400,6 +406,10 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
$default_warehouse = $_POST['default_warehouse'];

$bill = $_POST['bill'];
$copay_update = FALSE;
$update_session_id = '';
$cod0 = '';//takes the code of the first non-empty modifier from the fee sheet, against which the copay is posted
$mod0 = '';//takes the first non-empty modifier from the fee sheet, against which the copay is posted
for ($lino = 1; $bill["$lino"]['code_type']; ++$lino) {
$iter = $bill["$lino"];
$code_type = $iter['code_type'];
Expand All @@ -411,11 +421,46 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {

$id = $iter['id'];
$modifier = trim($iter['mod']);
if(!$mod0 && $modifier != ''){
$mod0 = $modifier;
$cod0 = $code;
}
$units = max(1, intval(trim($iter['units'])));
$fee = sprintf('%01.2f',(0 + trim($iter['price'])) * $units);
if ($code_type == 'COPAY') {
if ($fee > 0) $fee = 0 - $fee;
$code = sprintf('%01.2f', 0 - $fee);

if($code_type == 'COPAY'){
if($id == ''){
//adding new copay from fee sheet into ar_session and ar_activity tables
if($fee < 0){
$fee = $fee * -1;
}
$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,$pid));
SqlStatement("INSERT INTO ar_activity (pid,encounter,code,modifier,payer_type,post_time,post_user,session_id,".
"pay_amount,account_code) VALUES (?,?,?,?,0,now(),?,?,?,'PCP')",
array($pid,$encounter,$cod0,$mod0,$_SESSION['authId'],$session_id,$fee));
}else{
//editing copay saved to ar_session and ar_activity
if($fee < 0){
$fee = $fee * -1;
}
$session_id = $id;
$res_amount = sqlQuery("SELECT pay_amount FROM ar_activity WHERE pid=? AND encounter=? AND session_id=?",
array($pid,$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=?, modifier=?, post_user=?, post_time=now(),".
"pay_amount=?, modified_time=now() WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?",
array($cod0,$mod0,$_SESSION['authId'],$fee,$pid,$encounter,$session_id));
}
}
if(!$mod0){
$copay_update = TRUE;
$update_session_id = $session_id;
}
continue;
}
$justify = trim($iter['justify']);
$notecodes = trim(strip_escape_custom($iter['notecodes']));
Expand Down Expand Up @@ -453,6 +498,14 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
$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=?, modifier=?".
" WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?",
array($cod0,$mod0,$pid,$encounter,$update_session_id));
}

// Doing similarly to the above but for products.
$prod = $_POST['prod'];
Expand Down Expand Up @@ -915,7 +968,12 @@ function setJustify(seljust) {
$notecodes = strip_escape_custom(trim($bline['notecodes']));
$provider_id = 0 + $bline['provid'];
}


if($iter['code_type'] == 'COPAY'){//moved copay display to below
--$bill_lino;
continue;
}

// list($code, $modifier) = explode("-", $iter["code"]);
echoLine($bill_lino, $iter["code_type"], trim($iter["code"]),
$modifier, $ndc_info, $authorized,
Expand All @@ -924,6 +982,15 @@ function setJustify(seljust) {
}
}

$resMoneyGot = sqlStatement("SELECT pay_amount as PatientPay,session_id as id,date(post_time) as date ".
"FROM ar_activity where pid =? and encounter =? and payer_type=0 and account_code='PCP'",
array($pid,$encounter));//new fees screen copay gives account_code='PCP'
while($rowMoneyGot = sqlFetchArray($resMoneyGot)){
$PatientPay=$rowMoneyGot['PatientPay']*-1;
$id=$rowMoneyGot['id'];
echoLine(++$bill_lino,'COPAY','','',$rowMoneyGot['date'],'1','','',$PatientPay,$id);
}

// Echo new billing items from this form here, but omit any line
// whose Delete checkbox is checked.
//
Expand All @@ -939,7 +1006,13 @@ function setJustify(seljust) {
// $fee = 0 + trim($iter['fee']);
$units = max(1, intval(trim($iter['units'])));
$fee = sprintf('%01.2f',(0 + trim($iter['price'])) * $units);
if ($iter['code_type'] == 'COPAY' && $fee > 0) $fee = 0 - $fee;
//the date is passed as $ndc_info, since this variable is not applicable in the case of copay.
$ndc_info = '';
if ($iter['code_type'] == 'COPAY'){
$ndc_info = date("Y-m-d");
if($fee > 0)
$fee = 0 - $fee;
}
echoLine(++$bill_lino, $iter["code_type"], $iter["code"], trim($iter["mod"]),
$ndc_info, $iter["auth"], $iter["del"], $units,
$fee, NULL, FALSE, NULL, $iter["justify"], 0 + $iter['provid'],
Expand Down Expand Up @@ -1001,7 +1074,7 @@ function setJustify(seljust) {
$tmp = sqlQuery("SELECT copay FROM insurance_data WHERE pid = '$pid' " .
"AND type = 'primary' ORDER BY date DESC LIMIT 1");
$code = sprintf('%01.2f', 0 + $tmp['copay']);
echoLine(++$bill_lino, $newtype, $code, '', '', '1', '0', '1',
echoLine(++$bill_lino, $newtype, $code, '', date("Y-m-d"), '1', '0', '1',
sprintf('%01.2f', 0 - $code));
}
else if ($newtype == 'PROD') {
Expand Down
94 changes: 18 additions & 76 deletions interface/main/calendar/add_edit_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
include_once("$srcdir/calendar.inc");
include_once("$srcdir/formdata.inc.php");
include_once("$srcdir/options.inc.php");
include_once("$srcdir/encounter_events.inc.php");

// Things that might be passed by our opener.
//
Expand Down Expand Up @@ -62,39 +63,6 @@

<?php

// insert an event
// $args is mainly filled with content from the POST http var
function InsertEvent($args) {
return sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
"pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
"pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
"pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
"pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility,pc_billing_location " .
") VALUES ( " .
"'" . $args['form_category'] . "', " .
"'" . $args['new_multiple_value'] . "', " .
"'" . $args['form_provider'] . "', " .
"'" . $args['form_pid'] . "', " .
"'" . formDataCore($args['form_title']) . "', " .
"NOW(), " .
"'" . formDataCore($args['form_comments']) . "', " .
"'" . $_SESSION['authUserID'] . "', " .
"'" . $args['event_date'] . "', " .
"'" . fixDate($args['form_enddate']) . "', " .
"'" . $args['duration'] . "', " .
"'" . ($args['form_repeat'] ? '1' : '0') . "', " .
"'" . serialize($args['recurrspec']) . "', " .
"'" . $args['starttime'] ."', " .
"'" . $args['endtime'] ."', " .
"'" . $args['form_allday'] . "', " .
"'" . $args['form_apptstatus'] . "', " .
"'" . $args['form_prefcat'] . "', " .
"'" . $args['locationspec'] ."', " .
"1, " .
"1, " .(int)$args['facility']. ",".(int)$args['billing_facility']." )"
);
}
//================================================================================================================
function InsertEventFull()
{
global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
Expand Down Expand Up @@ -141,49 +109,23 @@ function InsertEventFull()
function DOBandEncounter()
{
global $event_date,$info_msg;
// Save new DOB if it's there.
$patient_dob = trim($_POST['form_dob']);
if ($patient_dob && $_POST['form_pid']) {
sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
"pid = '" . $_POST['form_pid'] . "'");
}

// Auto-create a new encounter if appropriate.
//
if ($GLOBALS['auto_create_new_encounters'] &&
$_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
{
$tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
"pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
if ($tmprow['count'] == 0) {
$tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
$_POST['form_provider'] . "'");
$username = $tmprow['username'];
$facility = $tmprow['facility'];
// $facility_id = $tmprow['facility_id'];
$facility_id = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $tmprow['facility_id'];
$conn = $GLOBALS['adodb']['db'];
$encounter = $conn->GenID("sequences");

addForm($encounter, "New Patient Encounter",
sqlInsert("INSERT INTO form_encounter SET " .
"date = '$event_date', " .
"reason = '" . formData("form_comments") . "', " .
"facility = '$facility', " .
"facility_id = '" . (int)$_POST['facility'] . "', " .
"billing_facility = '" . (int)$_POST['billing_facility'] . "', " .
"provider_id = '" . (int)$_POST['form_provider'] . "', " .
"pid = '" . $_POST['form_pid'] . "', " .
"encounter = '$encounter', " .
"pc_catid = '" . $_POST['form_category'] . "'"
),
"newpatient", $_POST['form_pid'], "1", "NOW()", $username
);
$info_msg .= xl("New encounter created with id");
$info_msg .= " $encounter";
}

}
// Save new DOB if it's there.
$patient_dob = trim($_POST['form_dob']);
if ($patient_dob && $_POST['form_pid']) {
sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
"pid = '" . $_POST['form_pid'] . "'");
}

// Auto-create a new encounter if appropriate.
//
if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
{
$encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, formData("form_comments"), $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
if($encounter){
$info_msg .= xl("New encounter created with id");
$info_msg .= " $encounter";
}
}
}
//================================================================================================================

Expand Down
Loading

0 comments on commit 9e98195

Please sign in to comment.