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,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('CPT 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=split(' ',$RowSearch['date']);
172 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
173 $Code=$RowSearch['code'];
174 $Modifier =$RowSearch['modifier'];
176 $ModifierString=", $Modifier";
179 $Fee=$RowSearch['fee'];
180 $Encounter=$RowSearch['encounter'];
182 //Always associating the copay to a particular charge.
183 $BillingId=$RowSearch['id'];
184 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
185 pid ='$hidden_patient_code' and encounter ='$Encounter' and billing.activity!=0 order by id");
186 $rowId = sqlFetchArray($resId);
189 if($BillingId!=$Id)//multiple cpt in single encounter
195 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where code_type='COPAY' and
196 pid ='$hidden_patient_code' and encounter ='$Encounter' and billing.activity!=0");
197 $rowCopay = sqlFetchArray($resCopay);
198 $Copay=$rowCopay['copay']*-1;
200 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
201 pid ='$hidden_patient_code' and encounter ='$Encounter' and payer_type=0 and
202 account_code='PCP'");//new fees screen copay gives account_code='PCP'
203 $rowMoneyGot = sqlFetchArray($resMoneyGot);
204 $PatientPay=$rowMoneyGot['PatientPay'];
206 $Copay=$Copay+
$PatientPay;
209 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
210 pid ='$hidden_patient_code' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
211 account_code='PCP')");//new fees screen copay gives account_code='PCP'
212 $rowMoneyGot = sqlFetchArray($resMoneyGot);
213 $MoneyGot=$rowMoneyGot['MoneyGot'];
215 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
216 pid ='$hidden_patient_code' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
217 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
218 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
220 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
222 $TotalRows=sqlNumRows($ResultSearchNew);
223 if($CountIndexBelow==sqlNumRows($ResultSearchNew))
225 $StringClass=' bottom left top ';
229 $StringClass=' left top ';
250 <tr
class="text" bgcolor
='<?php echo $bgcolor; ?>' id
="trCharges<?php echo $CountIndex; ?>">
251 <td align
="left" class="<?php echo $StringClass; ?>" ><input name
="HiddenIns<?php echo $CountIndex; ?>" id
="HiddenIns<?php echo $CountIndex; ?>"
252 value
="<?php echo htmlspecialchars($Ins); ?>" type
="hidden"/><?php
echo generate_select_list("payment_ins$CountIndex", "payment_ins", "$Ins", "Insurance/Patient",'','','ActionOnInsPat("'.$CountIndex.'")');?
></td
>
253 <td
class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars($ServiceDate); ?
></td
>
254 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenEncounter<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Encounter); ?>"
255 type
="hidden"/><?php
echo htmlspecialchars($Encounter); ?
></td
>
256 <td
class="<?php echo $StringClass; ?>" ><input name
="HiddenCode<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Code); ?>"
257 type
="hidden"/><?php
echo htmlspecialchars($Code.$ModifierString); ?
><input name
="HiddenModifier<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Modifier); ?>"
259 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenChargeAmount<?php echo $CountIndex; ?>"
260 id
="HiddenChargeAmount<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Fee); ?>" type
="hidden"/><?php
echo htmlspecialchars($Fee); ?
></td
>
261 <td align
="right" class="<?php echo $StringClass; ?>" ><input name
="HiddenCopayAmount<?php echo $CountIndex; ?>"
262 id
="HiddenCopayAmount<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars($Copay); ?>" type
="hidden"/><?php
echo htmlspecialchars(number_format($Copay,2)); ?
></td
>
263 <td align
="right" id
="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars(round($Remainder,2)); ?
></td
>
264 <input name
="HiddenRemainderTd<?php echo $CountIndex; ?>" id
="HiddenRemainderTd<?php echo $CountIndex; ?>"
265 value
="<?php echo htmlspecialchars(round($Remainder,2)); ?>" type
="hidden"/>
266 <td
class="<?php echo $StringClass; ?>" ><input name
="Allowed<?php echo $CountIndex; ?>" id
="Allowed<?php echo $CountIndex; ?>"
267 onKeyDown
="PreventIt(event)" autocomplete
="off"
268 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; ?>)"
269 type
="text" style
="width:60px;text-align:right; font-size:12px" /></td
>
270 <td
class="<?php echo $StringClass; ?>" ><input type
="text" name
="Payment<?php echo $CountIndex; ?>"
271 onKeyDown
="PreventIt(event)" autocomplete
="off" id
="Payment<?php echo $CountIndex; ?>"
272 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Payment','initialpaymenttotal');RestoreValues(<?php echo $CountIndex; ?>)"
273 style
="width:60px;text-align:right; font-size:12px" /></td
>
274 <td
class="<?php echo $StringClass; ?>" ><input name
="AdjAmount<?php echo $CountIndex; ?>" onKeyDown
="PreventIt(event)"
275 autocomplete
="off" id
="AdjAmount<?php echo $CountIndex; ?>"
276 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'AdjAmount','initialAdjAmounttotal');RestoreValues(<?php echo $CountIndex; ?>)"
277 type
="text" style
="width:70px;text-align:right; font-size:12px" /></td
>
278 <td
class="<?php echo $StringClass; ?>" ><input name
="Deductible<?php echo $CountIndex; ?>" id
="Deductible<?php echo $CountIndex; ?>"
279 onKeyDown
="PreventIt(event)" onChange
="ValidateNumeric(this);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Deductible','initialdeductibletotal');" autocomplete
="off" type
="text"
280 style
="width:60px;text-align:right; font-size:12px" /></td
>
281 <td
class="<?php echo $StringClass; ?>" ><input name
="Takeback<?php echo $CountIndex; ?>" onKeyDown
="PreventIt(event)" autocomplete
="off"
282 id
="Takeback<?php echo $CountIndex; ?>"
283 onChange
="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(<?php echo $CountIndexAbove*1+1; ?>,<?php echo $TotalRows; ?>,'Takeback','initialtakebacktotal');RestoreValues(<?php echo $CountIndex; ?>)"
284 type
="text" style
="width:60px;text-align:right; font-size:12px" /></td
>
285 <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
>
286 <td align
="center" class="<?php echo $StringClass; ?>" ><input type
="checkbox" id
="FollowUp<?php echo $CountIndex; ?>"
287 name
="FollowUp<?php echo $CountIndex; ?>" value
="y" onClick
="ActionFollowUp(<?php echo $CountIndex; ?>)" /></td
>
288 <td
class="<?php echo $StringClass; ?> right" ><input onKeyDown
="PreventIt(event)" id
="FollowUpReason<?php echo $CountIndex; ?>"
289 name
="FollowUpReason<?php echo $CountIndex; ?>" readonly
="" type
="text" style
="width:209px;font-size:12px" /></td
>
293 }while($RowSearch = sqlFetchArray($ResultSearchNew));
296 <td align
="left" colspan
="7"> 
;</td
>
297 <td
class="left bottom" bgcolor
="#6699FF" id
="initialallowtotal" align
="right" >0</td
>
298 <td
class="left bottom" bgcolor
="#6699FF" id
="initialpaymenttotal" align
="right" >0</td
>
299 <td
class="left bottom" bgcolor
="#6699FF" id
="initialAdjAmounttotal" align
="right" >0</td
>
300 <td
class="left bottom" bgcolor
="#6699FF" id
="initialdeductibletotal" align
="right">0</td
>
301 <td
class="left bottom right" bgcolor
="#6699FF" id
="initialtakebacktotal" align
="right">0</td
>
302 <td align
="center"> 
;</td
>
303 <td align
="center"> 
;</td
>
307 }//if($RowSearch = sqlFetchArray($ResultSearchNew))