fixes for prior commit - moved Documents menu item to Procedures->Lab documents
[openemr.git] / interface / patient_file / encounter / cash_receipt.php
blob04fedce4d0dc0446efcd5f993efad8327afcb3c9
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("../../globals.php");
8 require_once("$srcdir/forms.inc");
9 require_once("$srcdir/billing.inc");
10 require_once("$srcdir/pnotes.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/report.inc");
13 require_once(dirname(__file__) . "/../../../library/classes/Document.class.php");
14 require_once(dirname(__file__) . "/../../../library/classes/Note.class.php");
15 require_once("$srcdir/options.inc.php");
16 require_once("$srcdir/formatting.inc.php");
18 $N = 6;
19 $first_issue = 1;
21 function postToGet($arin) {
22 $getstring="";
23 foreach ($arin as $key => $val) {
24 $getstring.=urlencode($key)."=".urlencode($val)."&";
26 return $getstring;
29 <html>
30 <head>
31 <?php html_header_show();?>
32 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
33 </head>
35 <body bgcolor="#ffffff" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
36 <p>
37 <?php
38 if (sizeof($_GET) > 0) {
39 $ar = $_GET;
40 } else {
41 $ar = $_POST;
44 $titleres = getPatientData($pid, "fname,lname,providerID");
45 // $sql = "select * from facility where billing_location = 1";
46 $sql = "select f.* from facility f ".
47 "LEFT JOIN form_encounter fe on fe.facility_id = f.id ".
48 "where fe.encounter = " . $encounter;
49 $db = $GLOBALS['adodb']['db'];
50 $results = $db->Execute($sql);
51 $facility = array();
52 if (!$results->EOF) {
53 $facility = $results->fields;
56 $practice_logo = "../../../custom/practice_logo.gif";
57 if (file_exists($practice_logo)) {
58 echo "<img src='$practice_logo' align='left'>\n";
61 <h2><?php echo $facility['name']?></h2>
62 <?php echo $facility['street']?><br>
63 <?php echo $facility['city']?>, <?php echo $facility['state']?> <?php echo $facility['postal_code']?><br clear='all'>
64 <?php echo $facility['phone']?><br>
66 </p>
68 <a href="javascript:window.close();"><font class=title><?php print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br><br>
70 <table>
71 <tr><td><?php xl('Generated on','e'); ?>:</td><td> <?php print oeFormatShortDate(date("Y-m-d"));?></td></tr>
72 <?php
73 if ($date_result = sqlQuery("select date from form_encounter where encounter='" .
74 $encounter . "' and pid='$pid'"))
76 $encounter_date = date("D F jS", strtotime($date_result{"date"}));
77 $raw_encounter_date = date("Y-m-d", strtotime($date_result{"date"}));
81 <tr><td><?php xl('Date Of Service','e'); ?>: </td><td> <?php print oeFormatShortDate($raw_encounter_date);?></td></tr>
82 </table>
83 <br><br>
84 <?php
85 //$provider = getProviderName($titleres['providerID']);
87 //print "Provider: " . $provider . "</br>";
89 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
90 while($result = sqlFetchArray($inclookupres)) {
91 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
94 $printed = false;
96 foreach ($ar as $key => $val) {
97 if (!$printed && strpos($key, "newpatient_") === 0) {
98 $billing = getPatientBillingEncounter($pid, $val);
99 foreach ($billing as $b) {
100 if(!empty($b['provider_name'])) {
101 echo "Provider: " . $b['provider_name'] . "<br>";
102 $printed = true;
103 break;
109 foreach ($ar as $key => $val) {
111 /****
112 // WTF?? Redo this.
113 if (!empty($ar['newpatient'])){
114 foreach ($ar['newpatient'] as $be) {
115 $ta = split(":", $be);
116 $billing = getPatientBillingEncounter($pid, $ta[1]);
117 if(!$printed) {
118 foreach ($billing as $b) {
119 if(!empty($b['provider_name'])) {
120 echo "Provider: " . $b['provider_name'] . "<br>";
121 $printed = true;
122 break;
128 ****/
130 if (stristr($key,"include_")) {
131 //print "include: $val<br>\n";
133 if ($val == "demographics") {
135 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
136 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
138 } elseif ($val == "history") {
140 print "<br><font class=bold>".xl('History Data').":</font><br>";
141 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
143 } elseif ($val == "employer") {
145 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
146 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
148 } elseif ($val == "insurance") {
150 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
151 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
152 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
153 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
154 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
155 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
157 } elseif ($val == "billing") {
159 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
160 if (count($ar['newpatient']) > 0) {
161 $billings = array();
162 echo "<table>";
163 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
164 $total = 0.00;
165 $copays = 0.00;
166 foreach ($ar['newpatient'] as $be) {
167 $ta = split(":",$be);
168 $billing = getPatientBillingEncounter($pid,$ta[1]);
169 $billings[] = $billing;
170 foreach ($billing as $b) {
171 echo "<tr>\n";
172 echo "<td class=text>";
173 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
174 echo "</td>\n";
175 echo "<td class=text>";
176 echo oeFormatMoney($b['fee']);
177 echo "</td>\n";
178 echo "</tr>\n";
179 $total += $b['fee'];
180 if ($b['code_type'] == "COPAY") {
181 $copays += $b['fee'];
185 echo "<tr><td>&nbsp;</td></tr>";
186 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
187 echo "<tr><td class=bold>Paid</td><td class=text>" . oeFormatMoney($copays) . "</td></tr>";
188 echo "<tr><td class=bold>Total</td><td class=text>" . oeFormatMoney($total - $copays) . "</td></tr>";
189 echo "</table>";
190 echo "<pre>";
191 //print_r($billings);
192 echo "</pre>";
194 else {
195 printPatientBilling($pid);
199 /****
200 } elseif ($val == "allergies") {
201 print "<font class=bold>Patient Allergies:</font><br>";
202 printListData($pid, "allergy", "1");
203 } elseif ($val == "medications") {
204 print "<font class=bold>Patient Medications:</font><br>";
205 printListData($pid, "medication", "1");
206 } elseif ($val == "medical_problems") {
207 print "<font class=bold>Patient Medical Problems:</font><br>";
208 printListData($pid, "medical_problem", "1");
209 ****/
211 } elseif ($val == "immunizations") {
212 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
213 $sql = "select i1.immunization_id as immunization_id, if(i1.administered_date,concat(i1.administered_date,' - ') ,substring(i1.note,1,20) ) as immunization_data from immunizations i1 where i1.patient_id = $pid order by administered_date desc";
214 $result = sqlStatement($sql);
215 while ($row=sqlFetchArray($result)) {
216 echo "<span class=text> " . $row{'immunization_data'} .
217 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
218 "</span><br>\n";
221 } elseif ($val == "notes") {
223 print "<font class=bold>".xl('Patient Notes').":</font><br>";
224 printPatientNotes($pid);
226 } elseif ($val == "transactions") {
228 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
229 printPatientTransactions($pid);
233 } else {
235 if ($key == "documents") {
236 echo "<br><br>";
237 foreach($val as $valkey => $valvalue) {
238 $document_id = $valvalue;
239 if (!is_numeric($document_id)) continue;
240 $d = new Document($document_id);
241 $fname = basename($d->get_url());
242 $extension = substr($fname, strrpos($fname,"."));
243 echo "Document '" . $fname ."'<br>";
244 $notes = Note::notes_factory($d->get_id());
245 echo "<table>";
246 foreach ($notes as $note) {
247 echo '<tr>';
248 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
249 echo '</tr>';
250 echo '<tr>';
251 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
252 echo '</tr>';
253 echo '<tr>';
254 echo '<td>'.$note->get_note().'<br><br></td>';
255 echo '</tr>';
257 echo "</table>";
258 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
259 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
261 else {
262 echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."' ".xl('cannot be displayed inline becuase its type is not supported by the browser').".<br><br>";
267 else if (strpos($key, "issue_") === 0) {
269 if ($first_issue) {
270 $first_issue = 0;
271 echo "<br>\n";
273 preg_match('/^(.*)_(\d+)$/', $key, $res);
274 $rowid = $res[2];
275 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
276 "FROM lists WHERE id = '$rowid'");
277 $diagnosis = $irow['diagnosis'];
278 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
279 $irow['comments'] . "</span><br>\n";
280 // Show issue's chief diagnosis and its description:
281 if ($diagnosis) {
282 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
283 "code = '$diagnosis' AND " .
284 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
285 "LIMIT 1");
286 echo "<span class='bold'>&nbsp;Diagnosis: </span><span class='text'>" .
287 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
292 // Otherwise we have an "encounter form" form field whose name is like
293 // dirname_formid, with a value which is the encounter ID.
295 else {
297 $form_encounter = $val;
298 preg_match('/^(.*)_(\d+)$/', $key, $res);
299 $form_id = $res[2];
300 $formres = getFormNameByFormdir($res[1]);
301 $dateres = getEncounterDateByEncounter($form_encounter);
302 if ($res[1] == 'newpatient') print "<br>\n";
303 print "<span class='bold'>" . $formres{"form_name"} .
304 "</span><span class=text>(" . oeFormatShortDate(strtotime($dateres{"date"})) .
305 ")" . "</span><br>\n";
306 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
307 if ($res[1] == 'newpatient') {
308 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
309 "encounter = '$form_encounter' AND activity = 1 AND " .
310 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
311 "ORDER BY date");
312 while ($brow=sqlFetchArray($bres)) {
313 echo "<span class='bold'>&nbsp;Procedure: </span><span class='text'>" .
314 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
322 //borrowed from diagnosis.php
325 <table border="1" cellpadding=5>
326 <?php
327 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
328 $billing_html = array();
329 $total = 0.0;
330 $copay = 0.0;
332 //test
333 // foreach ($result as $key => $val) {
334 // print "<h2>$key</h2>";
335 // foreach($val as $key2 => $val2) {
336 // print "<p> $key2 = $val2 </p>\n";
337 // }
338 // }
339 //end test
341 foreach ($result as $iter) {
342 $html = '';
343 if ($iter["code_type"] == "ICD9") {
344 $html .= "<tr><td>".$iter[code_type].
345 "</td><td>".$iter[code]."</td><td>"
346 .$iter["code_text"]."</td></tr>\n";
347 $billing_html[$iter["code_type"]] .= $html;
348 $counter++;
350 elseif ($iter["code_type"] == "COPAY") {
351 $html .= "<tr><td>".xl('Payment').":</td><td>".xl('Thank You')."!</td><td>"
352 .$iter["code_text"]."</td><td>"
353 . oeFormatMoney($iter["code"]) . "</td></tr>\n";
354 if ($iter["code"] > 0.00) {
355 $copay += $iter["code"];
356 $billing_html[$iter["code_type"]] .= $html;
359 else {
360 $html .= "<tr><td>".$iter[code_type].
361 "</td><td>".$iter[code]."</td><td>"
362 .$iter["code_text"].' '.$iter['modifier']
363 ."</td><td>" . oeFormatMoney($iter['fee']) . "</td></tr>\n";
364 $billing_html[$iter["code_type"]] .= $html;
365 $total += $iter['fee'];
366 $js = split(":",$iter['justify']);
367 $counter = 0;
368 foreach ($js as $j) {
369 if(!empty($j)) {
370 if ($counter == 0) {
371 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
373 else {
374 $billing_html[$iter["code_type"]] .= " ($j)";
376 $counter++;
381 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
386 $billing_html["CPT4"] .= "<tr><td>".xl('total')."</td><td></td><td></td><td>" . oeFormatMoney($total) . "</td></tr>\n";
388 <tr><td><?php xl('code type','e'); ?></td><td><?php xl('code','e'); ?></td><td><?php xl('description','e'); ?></td><td><?php xl('fee','e'); ?></td></tr>
389 <?php
390 $key = "ICD9"; $val = $billing_html[$key];
391 print $val;
392 $key = "CPT4"; $val = $billing_html[$key];
393 print $val;
394 $key = "COPAY"; $val = $billing_html[$key];
395 print $val;
396 $balance = $total-$copay;
397 if ($balance != 0.00) {
398 print "<tr><td>".xl('balance')."</td><td></td><td>".xl('Please pay this amount').":</td><td>" . oeFormatMoney($balance) . "</td></tr>\n";
403 </tr></table>
404 <?php
405 //if ($balance != 0.00) {
406 // print "<p>Note: The balance recorded above only reflects the encounter described by this statement. It does not reflect the balance of the entire account. A negative number in the balance field indicates a credit due to overpayment</p>";
410 </body>
411 </html>