Highway to PSR2
[openemr.git] / interface / patient_file / encounter / cash_receipt.php
blob5f3c055cd2680c5c7150e9ee569bcbb5568e75d1
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("$srcdir/options.inc.php");
15 $N = 6;
16 $first_issue = 1;
18 function postToGet($arin)
20 $getstring="";
21 foreach ($arin as $key => $val) {
22 $getstring.=urlencode($key)."=".urlencode($val)."&";
25 return $getstring;
28 <html>
29 <head>
30 <?php html_header_show();?>
31 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
32 </head>
34 <body bgcolor="#ffffff" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
35 <p>
36 <?php
37 if (sizeof($_GET) > 0) {
38 $ar = $_GET;
39 } else {
40 $ar = $_POST;
43 $titleres = getPatientData($pid, "fname,lname,providerID");
44 // $sql = "select * from facility where billing_location = 1";
45 $sql = "select f.* from facility f ".
46 "LEFT JOIN form_encounter fe on fe.facility_id = f.id ".
47 "where fe.encounter = " . $encounter;
48 $db = $GLOBALS['adodb']['db'];
49 $results = $db->Execute($sql);
50 $facility = array();
51 if (!$results->EOF) {
52 $facility = $results->fields;
55 $practice_logo = "../../../custom/practice_logo.gif";
56 if (file_exists($practice_logo)) {
57 echo "<img src='$practice_logo' align='left'>\n";
60 <h2><?php echo $facility['name']?></h2>
61 <?php echo $facility['street']?><br>
62 <?php echo $facility['city']?>, <?php echo $facility['state']?> <?php echo $facility['postal_code']?><br clear='all'>
63 <?php echo $facility['phone']?><br>
65 </p>
67 <a href="javascript:window.close();"><font class=title><?php print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br><br>
69 <table>
70 <tr><td><?php xl('Generated on', 'e'); ?>:</td><td> <?php print oeFormatShortDate(date("Y-m-d"));?></td></tr>
71 <?php
72 if ($date_result = sqlQuery("select date from form_encounter where encounter='" .
73 $encounter . "' and pid='$pid'")) {
74 $encounter_date = date("D F jS", strtotime($date_result{"date"}));
75 $raw_encounter_date = date("Y-m-d", strtotime($date_result{"date"}));
78 <tr><td><?php xl('Date Of Service', 'e'); ?>: </td><td> <?php print oeFormatShortDate($raw_encounter_date);?></td></tr>
79 </table>
80 <br><br>
81 <?php
82 //$provider = getProviderName($titleres['providerID']);
84 //print "Provider: " . $provider . "</br>";
86 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
87 while ($result = sqlFetchArray($inclookupres)) {
88 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
91 $printed = false;
93 foreach ($ar as $key => $val) {
94 if (!$printed && strpos($key, "newpatient_") === 0) {
95 $billing = getPatientBillingEncounter($pid, $val);
96 foreach ($billing as $b) {
97 if (!empty($b['provider_name'])) {
98 echo "Provider: " . $b['provider_name'] . "<br>";
99 $printed = true;
100 break;
106 foreach ($ar as $key => $val) {
107 /****
108 // WTF?? Redo this.
109 if (!empty($ar['newpatient'])){
110 foreach ($ar['newpatient'] as $be) {
111 $ta = split(":", $be);
112 $billing = getPatientBillingEncounter($pid, $ta[1]);
113 if(!$printed) {
114 foreach ($billing as $b) {
115 if(!empty($b['provider_name'])) {
116 echo "Provider: " . $b['provider_name'] . "<br>";
117 $printed = true;
118 break;
124 ****/
126 if (stristr($key, "include_")) {
127 //print "include: $val<br>\n";
129 if ($val == "demographics") {
130 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
131 printRecDataOne($patient_data_array, getRecPatientData($pid), $N);
132 } elseif ($val == "history") {
133 print "<br><font class=bold>".xl('History Data').":</font><br>";
134 printRecDataOne($history_data_array, getRecHistoryData($pid), $N);
135 } elseif ($val == "employer") {
136 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
137 printRecDataOne($employer_data_array, getRecEmployerData($pid), $N);
138 } elseif ($val == "insurance") {
139 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
140 printRecDataOne($insurance_data_array, getRecInsuranceData($pid, "primary"), $N);
141 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
142 printRecDataOne($insurance_data_array, getRecInsuranceData($pid, "secondary"), $N);
143 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
144 printRecDataOne($insurance_data_array, getRecInsuranceData($pid, "tertiary"), $N);
145 } elseif ($val == "billing") {
146 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
147 if (count($ar['newpatient']) > 0) {
148 $billings = array();
149 echo "<table>";
150 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
151 $total = 0.00;
152 $copays = 0.00;
153 foreach ($ar['newpatient'] as $be) {
154 $ta = explode(":", $be);
155 $billing = getPatientBillingEncounter($pid, $ta[1]);
156 $billings[] = $billing;
157 foreach ($billing as $b) {
158 echo "<tr>\n";
159 echo "<td class=text>";
160 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
161 echo "</td>\n";
162 echo "<td class=text>";
163 echo oeFormatMoney($b['fee']);
164 echo "</td>\n";
165 echo "</tr>\n";
166 $total += $b['fee'];
167 if ($b['code_type'] == "COPAY") {
168 $copays += $b['fee'];
173 echo "<tr><td>&nbsp;</td></tr>";
174 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
175 echo "<tr><td class=bold>Paid</td><td class=text>" . oeFormatMoney($copays) . "</td></tr>";
176 echo "<tr><td class=bold>Total</td><td class=text>" . oeFormatMoney($total - $copays) . "</td></tr>";
177 echo "</table>";
178 echo "<pre>";
179 //print_r($billings);
180 echo "</pre>";
181 } else {
182 printPatientBilling($pid);
186 /****
187 } elseif ($val == "allergies") {
188 print "<font class=bold>Patient Allergies:</font><br>";
189 printListData($pid, "allergy", "1");
190 } elseif ($val == "medications") {
191 print "<font class=bold>Patient Medications:</font><br>";
192 printListData($pid, "medication", "1");
193 } elseif ($val == "medical_problems") {
194 print "<font class=bold>Patient Medical Problems:</font><br>";
195 printListData($pid, "medical_problem", "1");
196 ****/
197 } elseif ($val == "immunizations") {
198 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
199 $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";
200 $result = sqlStatement($sql);
201 while ($row=sqlFetchArray($result)) {
202 echo "<span class=text> " . $row{'immunization_data'} .
203 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
204 "</span><br>\n";
206 } elseif ($val == "notes") {
207 print "<font class=bold>".xl('Patient Notes').":</font><br>";
208 printPatientNotes($pid);
209 } elseif ($val == "transactions") {
210 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
211 printPatientTransactions($pid);
213 } else {
214 if ($key == "documents") {
215 echo "<br><br>";
216 foreach ($val as $valkey => $valvalue) {
217 $document_id = $valvalue;
218 if (!is_numeric($document_id)) {
219 continue;
222 $d = new Document($document_id);
223 $fname = basename($d->get_url());
224 $extension = substr($fname, strrpos($fname, "."));
225 echo "Document '" . $fname ."'<br>";
226 $n = new Note();
227 $notes = $n->notes_factory($d->get_id());
228 echo "<table>";
229 foreach ($notes as $note) {
230 echo '<tr>';
231 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
232 echo '</tr>';
233 echo '<tr>';
234 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
235 echo '</tr>';
236 echo '<tr>';
237 echo '<td>'.$note->get_note().'<br><br></td>';
238 echo '</tr>';
241 echo "</table>";
242 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
243 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
244 } else {
245 echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."' ".xl('cannot be displayed inline becuase its type is not supported by the browser').".<br><br>";
248 } else if (strpos($key, "issue_") === 0) {
249 if ($first_issue) {
250 $first_issue = 0;
251 echo "<br>\n";
254 preg_match('/^(.*)_(\d+)$/', $key, $res);
255 $rowid = $res[2];
256 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
257 "FROM lists WHERE id = '$rowid'");
258 $diagnosis = $irow['diagnosis'];
259 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
260 $irow['comments'] . "</span><br>\n";
261 // Show issue's chief diagnosis and its description:
262 if ($diagnosis) {
263 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
264 "code = '$diagnosis' AND " .
265 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
266 "LIMIT 1");
267 echo "<span class='bold'>&nbsp;Diagnosis: </span><span class='text'>" .
268 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
270 } // Otherwise we have an "encounter form" form field whose name is like
271 // dirname_formid, with a value which is the encounter ID.
273 else {
274 $form_encounter = $val;
275 preg_match('/^(.*)_(\d+)$/', $key, $res);
276 $form_id = $res[2];
277 $formres = getFormNameByFormdir($res[1]);
278 $dateres = getEncounterDateByEncounter($form_encounter);
279 if ($res[1] == 'newpatient') {
280 print "<br>\n";
283 print "<span class='bold'>" . $formres{"form_name"} .
284 "</span><span class=text>(" . oeFormatShortDate(strtotime($dateres{"date"})) .
285 ")" . "</span><br>\n";
286 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
287 if ($res[1] == 'newpatient') {
288 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
289 "encounter = '$form_encounter' AND activity = 1 AND " .
290 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
291 "ORDER BY date");
292 while ($brow=sqlFetchArray($bres)) {
293 echo "<span class='bold'>&nbsp;Procedure: </span><span class='text'>" .
294 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
301 //borrowed from diagnosis.php
304 <table border="1" cellpadding=5>
305 <?php
306 if ($result = getBillingByEncounter($pid, $encounter, "*")) {
307 $billing_html = array();
308 $total = 0.0;
309 $copay = 0.0;
311 //test
312 // foreach ($result as $key => $val) {
313 // print "<h2>$key</h2>";
314 // foreach($val as $key2 => $val2) {
315 // print "<p> $key2 = $val2 </p>\n";
316 // }
317 // }
318 //end test
320 foreach ($result as $iter) {
321 $html = '';
322 if ($iter["code_type"] == "ICD9") {
323 $html .= "<tr><td>".$iter[code_type].
324 "</td><td>".$iter[code]."</td><td>"
325 .$iter["code_text"]."</td></tr>\n";
326 $billing_html[$iter["code_type"]] .= $html;
327 $counter++;
328 } elseif ($iter["code_type"] == "COPAY") {
329 $html .= "<tr><td>".xl('Payment').":</td><td>".xl('Thank You')."!</td><td>"
330 .$iter["code_text"]."</td><td>"
331 . oeFormatMoney($iter["code"]) . "</td></tr>\n";
332 if ($iter["code"] > 0.00) {
333 $copay += $iter["code"];
334 $billing_html[$iter["code_type"]] .= $html;
336 } else {
337 $html .= "<tr><td>".$iter[code_type].
338 "</td><td>".$iter[code]."</td><td>"
339 .$iter["code_text"].' '.$iter['modifier']
340 ."</td><td>" . oeFormatMoney($iter['fee']) . "</td></tr>\n";
341 $billing_html[$iter["code_type"]] .= $html;
342 $total += $iter['fee'];
343 $js = explode(":", $iter['justify']);
344 $counter = 0;
345 foreach ($js as $j) {
346 if (!empty($j)) {
347 if ($counter == 0) {
348 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
349 } else {
350 $billing_html[$iter["code_type"]] .= " ($j)";
353 $counter++;
358 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
362 $billing_html["CPT4"] .= "<tr><td>".xl('total')."</td><td></td><td></td><td>" . oeFormatMoney($total) . "</td></tr>\n";
364 <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>
365 <?php
366 $key = "ICD9";
367 $val = $billing_html[$key];
368 print $val;
369 $key = "CPT4";
370 $val = $billing_html[$key];
371 print $val;
372 $key = "COPAY";
373 $val = $billing_html[$key];
374 print $val;
375 $balance = $total-$copay;
376 if ($balance != 0.00) {
377 print "<tr><td>".xl('balance')."</td><td></td><td>".xl('Please pay this amount').":</td><td>" . oeFormatMoney($balance) . "</td></tr>\n";
381 </tr></table>
382 <?php
383 //if ($balance != 0.00) {
384 // 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>";
388 </body>
389 </html>