Removes frames from login gui and condense login gui into a single file.
[openemr.git] / interface / billing / payment_pat_sel.inc.php
blob75c94ebeae3539797057780fba29dc904a3abf68
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
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.
22 //
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')
38 $StringForQuery='';
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);
56 $fname=$row['fname'];
57 $lname=$row['lname'];
58 $mname=$row['mname'];
59 $NameNew=$lname.' '.$fname.' '.$mname;
62 //===============================================================================
64 <table width="1004" border="0" cellspacing="0" cellpadding="0" id="TablePatientPortion">
65 <tr height="5">
66 <td colspan="13" align="left" >
67 <table width="705" border="0" cellspacing="0" cellpadding="0" bgcolor="#DEDEDE">
68 <tr height="5">
69 <td class='title' width="700" ></td>
70 </tr>
71 <tr>
72 <td class='text'><table width="799" border="0" cellspacing="0" cellpadding="0" style="border:1px solid black" >
73 <tr>
74 <td width="45" align="left" class="text">&nbsp;<?php echo htmlspecialchars( xl('Patient'), ENT_QUOTES).':' ?>
75 </td>
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>
81 </td>
82 <td width="84" class="text">&nbsp;<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) ?>
89 </td>
90 </tr>
91 <tr>
92 <td align="left" class="text"></td>
93 <td><div id='ajax_div_patient_section'>
94 <div id='ajax_div_patient_error'>
95 </div>
96 <div id="ajax_div_patient" style="display:none;"></div>
97 </div>
98 </div>
99 </td>
100 <td></td>
101 <td></td>
102 <td></td>
103 <td></td>
104 <td class="text"></td>
105 </tr>
106 </table> </td>
107 </tr>
108 </table>
110 </td>
111 </tr>
112 <tr>
113 <td colspan="13" align="left" >
115 <?php //New distribution section
116 //$CountIndex=0;
117 $CountIndexBelow=0;
118 $PreviousEncounter=0;
119 $PreviousPID=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>
126 </tr>
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>
143 </tr>
144 <?php
148 $CountIndex++;
149 $CountIndexBelow++;
150 $Ins=0;
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)
158 ++$new_payer_type;
159 $new_payer_id = arGetPayerID($hidden_patient_code, $date_of_service, $new_payer_type);
161 if($new_payer_id==0)
163 $Ins=0;
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'];
176 if($Modifier!='')
177 $ModifierString=", $Modifier";
178 else
179 $ModifierString="";
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);
188 $Id=$rowId['id'];
190 if($BillingId!=$Id)//multiple cpt in single encounter
192 $Copay=0.00;
194 else
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 ';
228 else
230 $StringClass=' left top ';
234 if($Ins==1)
236 $bgcolor='#ddddff';
238 elseif($Ins==2)
240 $bgcolor='#ffdddd';
242 elseif($Ins==3)
244 $bgcolor='#F2F1BC';
246 elseif($Ins==0)
248 $bgcolor='#AAFFFF';
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); ?>"
259 type="hidden"/></td>
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>
291 </tr>
292 <?php
294 }while($RowSearch = sqlFetchArray($ResultSearchNew));
296 <tr class="text">
297 <td align="left" colspan="7">&nbsp;</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">&nbsp;</td>
304 <td align="center">&nbsp;</td>
305 </tr>
306 </table>
307 <?php
308 }//if($RowSearch = sqlFetchArray($ResultSearchNew))
310 </td>
311 </tr>
312 </table>