2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Patient ajax section and listing of charges..Used in New Payment and Edit Payment screen.
29 //===============================================================================
30 if (isset($_POST["mode"]))
32 if (($_POST["mode"] == "search" ||
$_POST["default_search_patient"] == "default_search_patient") && $_REQUEST['hidden_patient_code']*1>0)
34 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
35 $RadioPaid=$_REQUEST['RadioPaid'];
36 if($RadioPaid=='Show_Paid')
40 elseif($RadioPaid=='Non_Paid')
42 $StringForQuery=" and last_level_closed = 0 ";
44 elseif($RadioPaid=='Show_Primary_Complete')
46 $StringForQuery=" and last_level_closed >= 1 ";
48 $ResultSearchNew = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,billing.code_type,billing.code,billing.modifier,fee
49 FROM billing ,form_encounter
50 where billing.encounter=form_encounter.encounter and code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
51 form_encounter.pid ='$hidden_patient_code' and billing.pid ='$hidden_patient_code' $StringForQuery ORDER BY form_encounter.`date`,
52 form_encounter.encounter,billing.code,billing.modifier");
53 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
54 where pid ='".$_REQUEST['hidden_patient_code']."'");
55 $row = sqlFetchArray($res);
59 $NameNew=$lname.' '.$fname.' '.$mname;
62 //===============================================================================
64 <table width
="1004" border
="0" cellspacing
="0" cellpadding
="0" id
="TablePatientPortion">
66 <td colspan
="13" align
="left" >
67 <table width
="705" border
="0" cellspacing
="0" cellpadding
="0" bgcolor
="#DEDEDE">
69 <td
class='title' width
="700" ></td
>
72 <td
class='text'><table width
="799" border
="0" cellspacing
="0" cellpadding
="0" style
="border:1px solid black" >
74 <td width
="45" align
="left" class="text"> 
;<?php
echo htmlspecialchars( xl('Patient'), ENT_QUOTES
).':' ?
>
76 <td width
="265"><input type
="hidden" id
="hidden_ajax_patient_close_value" value
="<?php echo $Message=='' ? htmlspecialchars($NameNew) : '' ;?>" />
77 <input name
='patient_code' style
="width:265px" id
='patient_code' class="text" onKeyDown
="PreventIt(event)"
78 value
="<?php echo $Message=='' ? htmlspecialchars($NameNew) : '' ;?>" autocomplete
="off" /></td
> <!--onKeyUp
="ajaxFunction(event,'patient','edit_payment.php');" -->
79 <td width
="55" colspan
="2" style
="padding-left:5px;" ><div
class="text" name
="patient_name" id
="patient_name"
80 style
="border:1px solid black; ; padding-left:5px; width:55px; height:17px;"><?php
echo $Message=='' ?
htmlspecialchars(formData('hidden_patient_code')) : '' ;?
></div
>
82 <td width
="84" class="text"> 
;<input type
="radio" name
="RadioPaid" onClick
="SearchOnceMore()" <?php
echo $_REQUEST['RadioPaid']=='Non_Paid'
83 ||
$_REQUEST['RadioPaid']=='' ?
'checked' : '' ; ?
> value
="Non_Paid" id
="Non_Paid" /><?php
echo htmlspecialchars( xl('Non Paid'), ENT_QUOTES
) ?
></td
>
84 <td width
="168" class="text"><input type
="radio" name
="RadioPaid" onClick
="SearchOnceMore()"
85 <?php
echo $_REQUEST['RadioPaid']=='Show_Primary_Complete' ?
'checked' : '' ; ?
> value
="Show_Primary_Complete"
86 id
="Show_Primary_Complete" /><?php
echo htmlspecialchars( xl('Show Primary Complete'), ENT_QUOTES
) ?
></td
>
87 <td width
="157" class="text"><input type
="radio" name
="RadioPaid" onClick
="SearchOnceMore()"
88 <?php
echo $_REQUEST['RadioPaid']=='Show_Paid' ?
'checked' : '' ; ?
> value
="Show_Paid" id
="Show_Paid" /><?php
echo htmlspecialchars( xl('Show All Transactions'), ENT_QUOTES
) ?
>
92 <td align
="left" class="text"></td
>
93 <td
><div id
='ajax_div_patient_section'>
94 <div id
='ajax_div_patient_error'>
96 <div id
="ajax_div_patient" style
="display:none;"></div
>
104 <td
class="text"></td
>
113 <td colspan
="13" align
="left" >
115 <?php
//New distribution section
118 $PreviousEncounter=0;
120 if($RowSearch = sqlFetchArray($ResultSearchNew))
123 <table width
="1004" border
="0" cellpadding
="0" cellspacing
="0" align
="center" id
="TableDistributePortion">
124 <tr
class="text" height
="10">
125 <td colspan
="14"></td
>
127 <tr
class="text" bgcolor
="#dddddd">
128 <td width
="55" class="left top" ><?php
echo htmlspecialchars( xl('Post For'), ENT_QUOTES
) ?
></td
>
129 <td width
="80" class="left top" ><?php
echo htmlspecialchars( xl('Service Date'), ENT_QUOTES
) ?
></td
>
130 <td width
="65" class="left top" ><?php
echo htmlspecialchars( xl('Encounter'), ENT_QUOTES
) ?
></td
>
131 <td width
="70" class="left top" ><?php
echo htmlspecialchars( xl('Service Code'), ENT_QUOTES
) ?
></td
>
132 <td width
="55" class="left top" ><?php
echo htmlspecialchars( xl('Charge'), ENT_QUOTES
) ?
></td
>
133 <td width
="40" class="left top" ><?php
echo htmlspecialchars( xl('Copay'), ENT_QUOTES
) ?
></td
>
134 <td width
="45" class="left top" ><?php
echo htmlspecialchars( xl('Remdr'), ENT_QUOTES
) ?
></td
>
135 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('Allowed'), ENT_QUOTES
) ?
></td
>
136 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('Payment'), ENT_QUOTES
) ?
></td
>
137 <td width
="70" class="left top" ><?php
echo htmlspecialchars( xl('Adj Amount'), ENT_QUOTES
) ?
></td
>
138 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('Deductible'), ENT_QUOTES
) ?
></td
>
139 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('Takeback'), ENT_QUOTES
) ?
></td
>
140 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('MSP Code'), ENT_QUOTES
) ?
></td
>
141 <td width
="60" class="left top" ><?php
echo htmlspecialchars( xl('Follow Up'), ENT_QUOTES
) ?
></td
>
142 <td width
="209" class="left top right" ><?php
echo htmlspecialchars( xl('Follow Up Reason'), ENT_QUOTES
) ?
></td
>
151 // Determine the next insurance level to be billed.
152 $ferow = sqlQuery("SELECT date, last_level_closed " .
153 "FROM form_encounter WHERE " .
154 "pid = '$hidden_patient_code' AND encounter = '".$RowSearch['encounter']."'");
155 $date_of_service = substr($ferow['date'], 0, 10);
156 $new_payer_type = 0 +
$ferow['last_level_closed'];
157 if ($new_payer_type <= 3 && !empty($ferow['last_level_closed']) ||
$new_payer_type == 0)
159 $new_payer_id = arGetPayerID($hidden_patient_code, $date_of_service, $new_payer_type);
165 elseif($new_payer_id>0)
167 $Ins=$new_payer_type;
171 $ServiceDateArray=explode(' ',$RowSearch['date']);
172 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
173 $Codetype=$RowSearch['code_type'];
174 $Code=$RowSearch['code'];
175 $Modifier =$RowSearch['modifier'];
177 $ModifierString=", $Modifier";
180 $Fee=$RowSearch['fee'];
181 $Encounter=$RowSearch['encounter'];
183 //Always associating the copay to a particular charge.
184 $BillingId=$RowSearch['id'];
185 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
186 pid ='$hidden_patient_code' and encounter ='$Encounter' and billing.activity!=0 order by id");
187 $rowId = sqlFetchArray($resId);
190 if($BillingId!=$Id)//multiple cpt in single encounter
196 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where code_type='COPAY' and
197 pid ='$hidden_patient_code' and encounter ='$Encounter' and billing.activity!=0");
198 $rowCopay = sqlFetchArray($resCopay);
199 $Copay=$rowCopay['copay']*-1;
201 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
202 pid ='$hidden_patient_code' and encounter ='$Encounter' and payer_type=0 and
203 account_code='PCP'");//new fees screen copay gives account_code='PCP'
204 $rowMoneyGot = sqlFetchArray($resMoneyGot);
205 $PatientPay=$rowMoneyGot['PatientPay'];
207 $Copay=$Copay+
$PatientPay;
209 //payer_type!=0, supports both mapped and unmapped code_type in ar_activity
210 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
211 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
212 account_code='PCP')");//new fees screen copay gives account_code='PCP'
213 $rowMoneyGot = sqlFetchArray($resMoneyGot);
214 $MoneyGot=$rowMoneyGot['MoneyGot'];
215 //supports both mapped and unmapped code_type in ar_activity
216 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
217 pid ='$hidden_patient_code' and (code_type='$Codetype' or code_type='') and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
218 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
219 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
221 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
223 $TotalRows=sqlNumRows($ResultSearchNew);
224 if($CountIndexBelow==sqlNumRows($ResultSearchNew))
226 $StringClass=' bottom left top ';
230 $StringClass=' left top ';
251 <tr
class="text" bgcolor
='<?php echo $bgcolor; ?>' id
="trCharges<?php echo $CountIndex; ?>">
252 <td align
="left" class="<?php echo $StringClass; ?>" ><input name
="HiddenIns<?php echo $CountIndex; ?>" id
="HiddenIns<?php echo $CountIndex; ?>"
253 value
="<?php echo htmlspecialchars($Ins); ?>" type
="hidden"/><?php
echo generate_select_list("payment_ins$CountIndex", "payment_ins", "$Ins", "Insurance/Patient",'','','ActionOnInsPat("'.$CountIndex.'")');?
></td
>
254 <td
class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars($ServiceDate); ?
></td
>
255 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenEncounter<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Encounter); ?>"
256 type
="hidden"/><?php
echo htmlspecialchars($Encounter); ?
></td
>
257 <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); ?>"
258 type
="hidden"/><?php
echo htmlspecialchars($Codetype."-".$Code.$ModifierString); ?
><input name
="HiddenModifier<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Modifier); ?>"
260 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenChargeAmount<?php echo $CountIndex; ?>"
261 id
="HiddenChargeAmount<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Fee); ?>" type
="hidden"/><?php
echo htmlspecialchars($Fee); ?
></td
>
262 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenCopayAmount<?php echo $CountIndex; ?>"
263 id
="HiddenCopayAmount<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Copay); ?>" type
="hidden"/><?php
echo htmlspecialchars(number_format($Copay,2)); ?
></td
>
264 <td align
="right" id
="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars(round($Remainder,2)); ?
></td
>
265 <input name
="HiddenRemainderTd<?php echo $CountIndex; ?>" id
="HiddenRemainderTd<?php echo $CountIndex; ?>"
266 value
="<?php echo htmlspecialchars(round($Remainder,2)); ?>" type
="hidden"/>
267 <td
class="<?php echo $StringClass; ?>" ><input name
="Allowed<?php echo $CountIndex; ?>" id
="Allowed<?php echo $CountIndex; ?>"
268 onKeyDown
="PreventIt(event)" autocomplete
="off"
269 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Allowed','initialallowtotal');UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Payment','initialpaymenttotal');UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'AdjAmount','initialAdjAmounttotal');RestoreValues(<?php echo $CountIndex; ?>)"
270 type
="text" style
="width:60px;text-align:right; font-size:12px" /></td
>
271 <td
class="<?php echo $StringClass; ?>" ><input type
="text" name
="Payment<?php echo $CountIndex; ?>"
272 onKeyDown
="PreventIt(event)" autocomplete
="off" id
="Payment<?php echo $CountIndex; ?>"
273 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Payment','initialpaymenttotal');RestoreValues(<?php echo $CountIndex; ?>)"
274 style
="width:60px;text-align:right; font-size:12px" /></td
>
275 <td
class="<?php echo $StringClass; ?>" ><input name
="AdjAmount<?php echo $CountIndex; ?>" onKeyDown
="PreventIt(event)"
276 autocomplete
="off" id
="AdjAmount<?php echo $CountIndex; ?>"
277 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'AdjAmount','initialAdjAmounttotal');RestoreValues(<?php echo $CountIndex; ?>)"
278 type
="text" style
="width:70px;text-align:right; font-size:12px" /></td
>
279 <td
class="<?php echo $StringClass; ?>" ><input name
="Deductible<?php echo $CountIndex; ?>" id
="Deductible<?php echo $CountIndex; ?>"
280 onKeyDown
="PreventIt(event)" onChange
="ValidateNumeric(this);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Deductible','initialdeductibletotal');" autocomplete
="off" type
="text"
281 style
="width:60px;text-align:right; font-size:12px" /></td
>
282 <td
class="<?php echo $StringClass; ?>" ><input name
="Takeback<?php echo $CountIndex; ?>" onKeyDown
="PreventIt(event)" autocomplete
="off"
283 id
="Takeback<?php echo $CountIndex; ?>"
284 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Takeback','initialtakebacktotal');RestoreValues(<?php echo $CountIndex; ?>)"
285 type
="text" style
="width:60px;text-align:right; font-size:12px" /></td
>
286 <td align
="left" class="<?php echo $StringClass; ?>" ><input name
="HiddenReasonCode<?php echo $CountIndex; ?>" id
="HiddenReasonCode<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($ReasonCodeDB); ?>" type
="hidden"/><?php
echo generate_select_list( "ReasonCode$CountIndex", "msp_remit_codes", "", "MSP Code", "--" ); ?
></td
>
287 <td align
="center" class="<?php echo $StringClass; ?>" ><input type
="checkbox" id
="FollowUp<?php echo $CountIndex; ?>"
288 name
="FollowUp<?php echo $CountIndex; ?>" value
="y" onClick
="ActionFollowUp(<?php echo $CountIndex; ?>)" /></td
>
289 <td
class="<?php echo $StringClass; ?> right" ><input onKeyDown
="PreventIt(event)" id
="FollowUpReason<?php echo $CountIndex; ?>"
290 name
="FollowUpReason<?php echo $CountIndex; ?>" readonly
="" type
="text" style
="width:209px;font-size:12px" /></td
>
294 }while($RowSearch = sqlFetchArray($ResultSearchNew));
297 <td align
="left" colspan
="7"> 
;</td
>
298 <td
class="left bottom" bgcolor
="#6699FF" id
="initialallowtotal" align
="right" >0</td
>
299 <td
class="left bottom" bgcolor
="#6699FF" id
="initialpaymenttotal" align
="right" >0</td
>
300 <td
class="left bottom" bgcolor
="#6699FF" id
="initialAdjAmounttotal" align
="right" >0</td
>
301 <td
class="left bottom" bgcolor
="#6699FF" id
="initialdeductibletotal" align
="right">0</td
>
302 <td
class="left bottom right" bgcolor
="#6699FF" id
="initialtakebacktotal" align
="right">0</td
>
303 <td align
="center"> 
;</td
>
304 <td align
="center"> 
;</td
>
308 }//if($RowSearch = sqlFetchArray($ResultSearchNew))