Skip to content

Commit

Permalink
Added a code_type column and support for it to the ar_activity sql ta…
Browse files Browse the repository at this point in the history
…ble, take 4.

 -added a code_types sql column to ar_activity table
 -worked this into Z&H's previous code that migrated copays from billing to ar_session/activity tables
 -display code types in encounter history
 -incorporated storage of code type in ar_activity in arPostPayment/Adjustment functions
 -incorporated interface/billing/sl_eob_invoice.php to store code type in ar_activity
 -incorporated interface/billing/sl_eob_process.php
 -mapping of code_type in ar_activity table is flexible (ie. it will also support
  upgraders from previous versions where it is not mapped)
  • Loading branch information
bradymiller committed Jul 3, 2012
1 parent 72ea436 commit 3d4d206
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 75 deletions.
81 changes: 57 additions & 24 deletions interface/billing/edit_payment.php

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions interface/billing/payment_pat_sel.inc.php
Expand Up @@ -45,7 +45,7 @@
{
$StringForQuery=" and last_level_closed >= 1 ";
}
$ResultSearchNew = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,billing.code,billing.modifier,fee
$ResultSearchNew = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,billing.code_type,billing.code,billing.modifier,fee
FROM billing ,form_encounter
where billing.encounter=form_encounter.encounter and code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
form_encounter.pid ='$hidden_patient_code' and billing.pid ='$hidden_patient_code' $StringForQuery ORDER BY form_encounter.`date`,
Expand Down Expand Up @@ -128,7 +128,7 @@
<td width="55" class="left top" ><?php echo htmlspecialchars( xl('Post For'), ENT_QUOTES) ?></td>
<td width="80" class="left top" ><?php echo htmlspecialchars( xl('Service Date'), ENT_QUOTES) ?></td>
<td width="65" class="left top" ><?php echo htmlspecialchars( xl('Encounter'), ENT_QUOTES) ?></td>
<td width="70" class="left top" ><?php echo htmlspecialchars( xl('CPT Code'), ENT_QUOTES) ?></td>
<td width="70" class="left top" ><?php echo htmlspecialchars( xl('Service Code'), ENT_QUOTES) ?></td>
<td width="55" class="left top" ><?php echo htmlspecialchars( xl('Charge'), ENT_QUOTES) ?></td>
<td width="40" class="left top" ><?php echo htmlspecialchars( xl('Copay'), ENT_QUOTES) ?></td>
<td width="45" class="left top" ><?php echo htmlspecialchars( xl('Remdr'), ENT_QUOTES) ?></td>
Expand Down Expand Up @@ -170,6 +170,7 @@

$ServiceDateArray=split(' ',$RowSearch['date']);
$ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
$Codetype=$RowSearch['code_type'];
$Code=$RowSearch['code'];
$Modifier =$RowSearch['modifier'];
if($Modifier!='')
Expand Down Expand Up @@ -205,15 +206,15 @@

$Copay=$Copay+$PatientPay;
}
//payer_type!=0
//payer_type!=0, supports both mapped and unmapped code_type in ar_activity
$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
pid ='$hidden_patient_code' and (code_type='$Codetype' or code_type='') and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
account_code='PCP')");//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$MoneyGot=$rowMoneyGot['MoneyGot'];

//supports both mapped and unmapped code_type in ar_activity
$resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
pid ='$hidden_patient_code' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
pid ='$hidden_patient_code' and (code_type='$Codetype' or code_type='') and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
$rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
$MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];

Expand Down Expand Up @@ -253,8 +254,8 @@
<td class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($ServiceDate); ?></td>
<td align="right" class="<?php echo $StringClass; ?>" ><input name="HiddenEncounter<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Encounter); ?>"
type="hidden"/><?php echo htmlspecialchars($Encounter); ?></td>
<td class="<?php echo $StringClass; ?>" ><input name="HiddenCode<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Code); ?>"
type="hidden"/><?php echo htmlspecialchars($Code.$ModifierString); ?><input name="HiddenModifier<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Modifier); ?>"
<td class="<?php echo $StringClass; ?>" ><input name="HiddenCodetype<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Codetype); ?>" type="hidden"/><input name="HiddenCode<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Code); ?>"
type="hidden"/><?php echo htmlspecialchars($Codetype."-".$Code.$ModifierString); ?><input name="HiddenModifier<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Modifier); ?>"
type="hidden"/></td>
<td align="right" class="<?php echo $StringClass; ?>" ><input name="HiddenChargeAmount<?php echo $CountIndex; ?>"
id="HiddenChargeAmount<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Fee); ?>" type="hidden"/><?php echo htmlspecialchars($Fee); ?></td>
Expand Down Expand Up @@ -308,4 +309,4 @@
?>
</td>
</tr>
</table>
</table>
6 changes: 4 additions & 2 deletions interface/billing/sl_eob_invoice.php
Expand Up @@ -291,6 +291,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
$thispay = trim($cdata['pay']);
$thisadj = trim($cdata['adj']);
$thisins = trim($cdata['ins']);
$thiscodetype = trim($cdata['code_type']);
$reason = strip_escape_custom($cdata['reason']);

// Get the adjustment reason type. Possible values are:
Expand Down Expand Up @@ -324,7 +325,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
if ($thispay) {
if ($INTEGRATED_AR) {
arPostPayment($patient_id, $encounter_id, $session_id,
$thispay, $code, $payer_type, '', $debug);
$thispay, $code, $payer_type, '', $debug, '', $thiscodetype);
} else {
slPostPayment($trans_id, $thispay, $thisdate, $thissrc, $code, $thisins, $debug);
}
Expand Down Expand Up @@ -361,7 +362,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
}
if ($INTEGRATED_AR) {
arPostAdjustment($patient_id, $encounter_id, $session_id,
$thisadj, $code, $payer_type, $reason, $debug);
$thisadj, $code, $payer_type, $reason, $debug, '', $thiscodetype);
} else {
slPostAdjustment($trans_id, $thisadj, $thisdate, $thissrc, $code, $thisins, $reason, $debug);
}
Expand Down Expand Up @@ -806,6 +807,7 @@ function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
<td class="detail" align="right">
<input type="hidden" name="form_line[<?php echo $code ?>][bal]" value="<?php bucks($cdata['bal']) ?>">
<input type="hidden" name="form_line[<?php echo $code ?>][ins]" value="<?php echo $cdata['ins'] ?>">
<input type="hidden" name="form_line[<?php echo $code ?>][code_type]" value="<?php echo $cdata['code_type'] ?>">
<?php printf("%.2f", $cdata['bal']) ?>&nbsp;
</td>
<td class="detail">
Expand Down
10 changes: 6 additions & 4 deletions interface/billing/sl_eob_process.php
Expand Up @@ -306,9 +306,11 @@ function era_callback(&$out) {
$codekey = $svc['code'];
if ($svc['mod']) $codekey .= ':' . $svc['mod'];
$prev = $codes[$codekey];
$codetype = ''; //will hold code type, if exists

// This reports detail lines already on file for this service item.
if ($prev) {
$codetype = $codes[$codekey]['code_type']; //store code type
writeOldDetail($prev, $patient_name, $invnumber, $service_date, $codekey, $bgcolor);
// Check for sanity in amount charged.
$prevchg = sprintf("%.2f", $prev['chg'] + $prev['adj']);
Expand Down Expand Up @@ -344,7 +346,7 @@ function era_callback(&$out) {
if (!$error && !$debug) {
if ($INTEGRATED_AR) {
arPostCharge($pid, $encounter, 0, $svc['chg'], 1, $service_date,
$codekey, $description, $debug);
$codekey, $description, $debug,'',$codetype);
} else {
slPostCharge($arrow['id'], $svc['chg'], 1, $service_date, $codekey,
$insurance_id, $description, $debug);
Expand Down Expand Up @@ -393,7 +395,7 @@ function era_callback(&$out) {
if (!$error && !$debug) {
if ($INTEGRATED_AR) {
arPostPayment($pid, $encounter,$InsertionId[$out['check_number']], $svc['paid'],//$InsertionId[$out['check_number']] gives the session id
$codekey, substr($inslabel,3), $out['check_number'], $debug);
$codekey, substr($inslabel,3), $out['check_number'], $debug,'',$codetype);
} else {
slPostPayment($arrow['id'], $svc['paid'], $check_date,
"$inslabel/" . $out['check_number'], $codekey, $insurance_id, $debug);
Expand Down Expand Up @@ -440,7 +442,7 @@ function era_callback(&$out) {
if (!$error && !$debug) {
if ($INTEGRATED_AR) {
arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], 0, $codekey,//$InsertionId[$out['check_number']] gives the session id
substr($inslabel,3), $reason, $debug);
substr($inslabel,3), $reason, $debug, '', $codetype);
} else {
slPostAdjustment($arrow['id'], 0, $production_date,
$out['check_number'], $codekey, $insurance_id,
Expand All @@ -456,7 +458,7 @@ function era_callback(&$out) {
if ($INTEGRATED_AR) {
arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], $adj['amount'],//$InsertionId[$out['check_number']] gives the session id
$codekey, substr($inslabel,3),
"Adjust code " . $adj['reason_code'], $debug);
"Adjust code " . $adj['reason_code'], $debug, '', $codetype);
} else {
slPostAdjustment($arrow['id'], $adj['amount'], $production_date,
$out['check_number'], $codekey, $insurance_id,
Expand Down
24 changes: 13 additions & 11 deletions interface/forms/fee_sheet/new.php
Expand Up @@ -413,8 +413,9 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
$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
$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
for ($lino = 1; $bill["$lino"]['code_type']; ++$lino) {
$iter = $bill["$lino"];
$code_type = $iter['code_type'];
Expand All @@ -426,9 +427,10 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {

$id = $iter['id'];
$modifier = trim($iter['mod']);
if(!$mod0 && $modifier != ''){
if( !($cod0) && ($code_types[$code_type]['fee'] == 1) ){
$mod0 = $modifier;
$cod0 = $code;
$ct0 = $code_type;
}
$units = max(1, intval(trim($iter['units'])));
$fee = sprintf('%01.2f',(0 + trim($iter['price'])) * $units);
Expand All @@ -442,9 +444,9 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
$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));
SqlStatement("INSERT INTO ar_activity (pid,encounter,code_type,code,modifier,payer_type,post_time,post_user,session_id,".
"pay_amount,account_code) VALUES (?,?,?,?,?,0,now(),?,?,?,'PCP')",
array($pid,$encounter,$ct0,$cod0,$mod0,$_SESSION['authId'],$session_id,$fee));
}else{
//editing copay saved to ar_session and ar_activity
if($fee < 0){
Expand All @@ -456,12 +458,12 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
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(),".
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($cod0,$mod0,$_SESSION['authId'],$fee,$pid,$encounter,$session_id));
array($ct0,$cod0,$mod0,$_SESSION['authId'],$fee,$pid,$encounter,$session_id));
}
}
if(!$mod0){
if(!$cod0){
$copay_update = TRUE;
$update_session_id = $session_id;
}
Expand Down Expand Up @@ -507,9 +509,9 @@ function genProviderSelect($selname, $toptext, $default=0, $disabled=false) {
//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=?".
sqlStatement("UPDATE ar_activity SET code_type=?, code=?, modifier=?".
" WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?",
array($cod0,$mod0,$pid,$encounter,$update_session_id));
array($ct0,$cod0,$mod0,$pid,$encounter,$update_session_id));
}

// Doing similarly to the above but for products.
Expand Down
23 changes: 14 additions & 9 deletions interface/patient_file/front_payment.php
Expand Up @@ -231,11 +231,13 @@ function calcTaxes($row, $amount) {
array($form_pid,$enc));
if($RowSearch = sqlFetchArray($ResultSearchNew))
{
$Codetype=$RowSearch['code_type'];
$Code=$RowSearch['code'];
$Modifier=$RowSearch['modifier'];
}
else
{
$Codetype='';
$Code='';
$Modifier='';
}
Expand All @@ -247,9 +249,9 @@ function calcTaxes($row, $amount) {
" VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
array($_SESSION['authId'],$form_source,$amount,$form_pid,$form_method));

$insrt_id=idSqlStatement("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($form_pid,$enc,$Code,$Modifier,$_SESSION['authId'],$session_id,$amount));
$insrt_id=idSqlStatement("INSERT INTO ar_activity (pid,encounter,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
" VALUES (?,?,?,?,?,0,now(),?,?,?,'PCP')",
array($form_pid,$enc,$Codetype,$Code,$Modifier,$_SESSION['authId'],$session_id,$amount));

frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0);//insertion to 'payments' table.
}
Expand Down Expand Up @@ -298,20 +300,21 @@ function calcTaxes($row, $amount) {
array($form_pid,$enc));
while($RowSearch = sqlFetchArray($ResultSearchNew))
{
$Codetype=$RowSearch['code_type'];
$Code=$RowSearch['code'];
$Modifier =$RowSearch['modifier'];
$Fee =$RowSearch['fee'];

$resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? ".
"and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
array($form_pid,$Code,$Modifier,$enc));
"and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
array($form_pid,$Codetype,$Code,$Modifier,$enc));
//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$MoneyGot=$rowMoneyGot['MoneyGot'];

$resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where ".
"pid =? and code=? and modifier=? and encounter =?",
array($form_pid,$Code,$Modifier,$enc));
"pid =? and code_type=? and code=? and modifier=? and encounter =?",
array($form_pid,$Codetype,$Code,$Modifier,$enc));
$rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
$MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];

Expand All @@ -332,6 +335,7 @@ function calcTaxes($row, $amount) {
sqlStatement("insert into ar_activity set " .
"pid = ?" .
", encounter = ?" .
", code_type = ?" .
", code = ?" .
", modifier = ?" .
", payer_type = ?" .
Expand All @@ -341,14 +345,15 @@ function calcTaxes($row, $amount) {
", pay_amount = ?" .
", adj_amount = ?" .
", account_code = 'PP'",
array($form_pid,$enc,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$insert_value,0));
array($form_pid,$enc,$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$insert_value,0));
}//if
}//while
if($amount!=0)//if any excess is there.
{
sqlStatement("insert into ar_activity set " .
"pid = ?" .
", encounter = ?" .
", code_type = ?" .
", code = ?" .
", modifier = ?" .
", payer_type = ?" .
Expand All @@ -358,7 +363,7 @@ function calcTaxes($row, $amount) {
", pay_amount = ?" .
", adj_amount = ?" .
", account_code = 'PP'",
array($form_pid,$enc,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$amount,0));
array($form_pid,$enc,$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$amount,0));
}

//--------------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion interface/patient_file/history/encounters.php
Expand Up @@ -609,7 +609,7 @@ function efmouseover(elem, ptid, encid, formname, formid) {
// !$code_types[$iter2['code_type']]['fee']) continue;
$title = htmlspecialchars(($iter2['code_text']), ENT_QUOTES);
$codekey = $iter2['code'];
$codekeydisp = $codekey;
$codekeydisp = $iter2['code_type']." - ".$iter2['code'];
if ($iter2['code_type'] == 'COPAY') {
$codekey = 'CO-PAY';
$codekeydisp = xl('CO-PAY');
Expand Down

0 comments on commit 3d4d206

Please sign in to comment.