Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / interface / patient_file / encounter / cash_receipt.php
blob704d027d0e2a60f1c571c7cff39d4b71fa704383
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");
14 require_once("$srcdir/formatting.inc.php");
16 $N = 6;
17 $first_issue = 1;
19 function postToGet($arin) {
20 $getstring="";
21 foreach ($arin as $key => $val) {
22 $getstring.=urlencode($key)."=".urlencode($val)."&";
24 return $getstring;
27 <html>
28 <head>
29 <?php html_header_show();?>
30 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
31 </head>
33 <body bgcolor="#ffffff" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
34 <p>
35 <?php
36 if (sizeof($_GET) > 0) {
37 $ar = $_GET;
38 } else {
39 $ar = $_POST;
42 $titleres = getPatientData($pid, "fname,lname,providerID");
43 // $sql = "select * from facility where billing_location = 1";
44 $sql = "select f.* from facility f ".
45 "LEFT JOIN form_encounter fe on fe.facility_id = f.id ".
46 "where fe.encounter = " . $encounter;
47 $db = $GLOBALS['adodb']['db'];
48 $results = $db->Execute($sql);
49 $facility = array();
50 if (!$results->EOF) {
51 $facility = $results->fields;
54 $practice_logo = "../../../custom/practice_logo.gif";
55 if (file_exists($practice_logo)) {
56 echo "<img src='$practice_logo' align='left'>\n";
59 <h2><?php echo $facility['name']?></h2>
60 <?php echo $facility['street']?><br>
61 <?php echo $facility['city']?>, <?php echo $facility['state']?> <?php echo $facility['postal_code']?><br clear='all'>
62 <?php echo $facility['phone']?><br>
64 </p>
66 <a href="javascript:window.close();"><font class=title><?php print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br><br>
68 <table>
69 <tr><td><?php xl('Generated on','e'); ?>:</td><td> <?php print oeFormatShortDate(date("Y-m-d"));?></td></tr>
70 <?php
71 if ($date_result = sqlQuery("select date from form_encounter where encounter='" .
72 $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"}));
79 <tr><td><?php xl('Date Of Service','e'); ?>: </td><td> <?php print oeFormatShortDate($raw_encounter_date);?></td></tr>
80 </table>
81 <br><br>
82 <?php
83 //$provider = getProviderName($titleres['providerID']);
85 //print "Provider: " . $provider . "</br>";
87 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
88 while($result = sqlFetchArray($inclookupres)) {
89 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
92 $printed = false;
94 foreach ($ar as $key => $val) {
95 if (!$printed && strpos($key, "newpatient_") === 0) {
96 $billing = getPatientBillingEncounter($pid, $val);
97 foreach ($billing as $b) {
98 if(!empty($b['provider_name'])) {
99 echo "Provider: " . $b['provider_name'] . "<br>";
100 $printed = true;
101 break;
107 foreach ($ar as $key => $val) {
109 /****
110 // WTF?? Redo this.
111 if (!empty($ar['newpatient'])){
112 foreach ($ar['newpatient'] as $be) {
113 $ta = split(":", $be);
114 $billing = getPatientBillingEncounter($pid, $ta[1]);
115 if(!$printed) {
116 foreach ($billing as $b) {
117 if(!empty($b['provider_name'])) {
118 echo "Provider: " . $b['provider_name'] . "<br>";
119 $printed = true;
120 break;
126 ****/
128 if (stristr($key,"include_")) {
129 //print "include: $val<br>\n";
131 if ($val == "demographics") {
133 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
134 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
136 } elseif ($val == "history") {
138 print "<br><font class=bold>".xl('History Data').":</font><br>";
139 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
141 } elseif ($val == "employer") {
143 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
144 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
146 } elseif ($val == "insurance") {
148 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
149 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
150 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
151 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
152 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
153 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
155 } elseif ($val == "billing") {
157 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
158 if (count($ar['newpatient']) > 0) {
159 $billings = array();
160 echo "<table>";
161 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
162 $total = 0.00;
163 $copays = 0.00;
164 foreach ($ar['newpatient'] as $be) {
165 $ta = explode(":",$be);
166 $billing = getPatientBillingEncounter($pid,$ta[1]);
167 $billings[] = $billing;
168 foreach ($billing as $b) {
169 echo "<tr>\n";
170 echo "<td class=text>";
171 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
172 echo "</td>\n";
173 echo "<td class=text>";
174 echo oeFormatMoney($b['fee']);
175 echo "</td>\n";
176 echo "</tr>\n";
177 $total += $b['fee'];
178 if ($b['code_type'] == "COPAY") {
179 $copays += $b['fee'];
183 echo "<tr><td>&nbsp;</td></tr>";
184 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
185 echo "<tr><td class=bold>Paid</td><td class=text>" . oeFormatMoney($copays) . "</td></tr>";
186 echo "<tr><td class=bold>Total</td><td class=text>" . oeFormatMoney($total - $copays) . "</td></tr>";
187 echo "</table>";
188 echo "<pre>";
189 //print_r($billings);
190 echo "</pre>";
192 else {
193 printPatientBilling($pid);
197 /****
198 } elseif ($val == "allergies") {
199 print "<font class=bold>Patient Allergies:</font><br>";
200 printListData($pid, "allergy", "1");
201 } elseif ($val == "medications") {
202 print "<font class=bold>Patient Medications:</font><br>";
203 printListData($pid, "medication", "1");
204 } elseif ($val == "medical_problems") {
205 print "<font class=bold>Patient Medical Problems:</font><br>";
206 printListData($pid, "medical_problem", "1");
207 ****/
209 } elseif ($val == "immunizations") {
210 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
211 $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";
212 $result = sqlStatement($sql);
213 while ($row=sqlFetchArray($result)) {
214 echo "<span class=text> " . $row{'immunization_data'} .
215 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
216 "</span><br>\n";
219 } elseif ($val == "notes") {
221 print "<font class=bold>".xl('Patient Notes').":</font><br>";
222 printPatientNotes($pid);
224 } elseif ($val == "transactions") {
226 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
227 printPatientTransactions($pid);
231 } else {
233 if ($key == "documents") {
234 echo "<br><br>";
235 foreach($val as $valkey => $valvalue) {
236 $document_id = $valvalue;
237 if (!is_numeric($document_id)) continue;
238 $d = new Document($document_id);
239 $fname = basename($d->get_url());
240 $extension = substr($fname, strrpos($fname,"."));
241 echo "Document '" . $fname ."'<br>";
242 $n = new Note();
243 $notes = $n->notes_factory($d->get_id());
244 echo "<table>";
245 foreach ($notes as $note) {
246 echo '<tr>';
247 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
248 echo '</tr>';
249 echo '<tr>';
250 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
251 echo '</tr>';
252 echo '<tr>';
253 echo '<td>'.$note->get_note().'<br><br></td>';
254 echo '</tr>';
256 echo "</table>";
257 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
258 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
260 else {
261 echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."' ".xl('cannot be displayed inline becuase its type is not supported by the browser').".<br><br>";
266 else if (strpos($key, "issue_") === 0) {
268 if ($first_issue) {
269 $first_issue = 0;
270 echo "<br>\n";
272 preg_match('/^(.*)_(\d+)$/', $key, $res);
273 $rowid = $res[2];
274 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
275 "FROM lists WHERE id = '$rowid'");
276 $diagnosis = $irow['diagnosis'];
277 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
278 $irow['comments'] . "</span><br>\n";
279 // Show issue's chief diagnosis and its description:
280 if ($diagnosis) {
281 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
282 "code = '$diagnosis' AND " .
283 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
284 "LIMIT 1");
285 echo "<span class='bold'>&nbsp;Diagnosis: </span><span class='text'>" .
286 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
291 // Otherwise we have an "encounter form" form field whose name is like
292 // dirname_formid, with a value which is the encounter ID.
294 else {
296 $form_encounter = $val;
297 preg_match('/^(.*)_(\d+)$/', $key, $res);
298 $form_id = $res[2];
299 $formres = getFormNameByFormdir($res[1]);
300 $dateres = getEncounterDateByEncounter($form_encounter);
301 if ($res[1] == 'newpatient') print "<br>\n";
302 print "<span class='bold'>" . $formres{"form_name"} .
303 "</span><span class=text>(" . oeFormatShortDate(strtotime($dateres{"date"})) .
304 ")" . "</span><br>\n";
305 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
306 if ($res[1] == 'newpatient') {
307 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
308 "encounter = '$form_encounter' AND activity = 1 AND " .
309 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
310 "ORDER BY date");
311 while ($brow=sqlFetchArray($bres)) {
312 echo "<span class='bold'>&nbsp;Procedure: </span><span class='text'>" .
313 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
321 //borrowed from diagnosis.php
324 <table border="1" cellpadding=5>
325 <?php
326 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
327 $billing_html = array();
328 $total = 0.0;
329 $copay = 0.0;
331 //test
332 // foreach ($result as $key => $val) {
333 // print "<h2>$key</h2>";
334 // foreach($val as $key2 => $val2) {
335 // print "<p> $key2 = $val2 </p>\n";
336 // }
337 // }
338 //end test
340 foreach ($result as $iter) {
341 $html = '';
342 if ($iter["code_type"] == "ICD9") {
343 $html .= "<tr><td>".$iter[code_type].
344 "</td><td>".$iter[code]."</td><td>"
345 .$iter["code_text"]."</td></tr>\n";
346 $billing_html[$iter["code_type"]] .= $html;
347 $counter++;
349 elseif ($iter["code_type"] == "COPAY") {
350 $html .= "<tr><td>".xl('Payment').":</td><td>".xl('Thank You')."!</td><td>"
351 .$iter["code_text"]."</td><td>"
352 . oeFormatMoney($iter["code"]) . "</td></tr>\n";
353 if ($iter["code"] > 0.00) {
354 $copay += $iter["code"];
355 $billing_html[$iter["code_type"]] .= $html;
358 else {
359 $html .= "<tr><td>".$iter[code_type].
360 "</td><td>".$iter[code]."</td><td>"
361 .$iter["code_text"].' '.$iter['modifier']
362 ."</td><td>" . oeFormatMoney($iter['fee']) . "</td></tr>\n";
363 $billing_html[$iter["code_type"]] .= $html;
364 $total += $iter['fee'];
365 $js = explode(":",$iter['justify']);
366 $counter = 0;
367 foreach ($js as $j) {
368 if(!empty($j)) {
369 if ($counter == 0) {
370 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
372 else {
373 $billing_html[$iter["code_type"]] .= " ($j)";
375 $counter++;
380 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
385 $billing_html["CPT4"] .= "<tr><td>".xl('total')."</td><td></td><td></td><td>" . oeFormatMoney($total) . "</td></tr>\n";
387 <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>
388 <?php
389 $key = "ICD9"; $val = $billing_html[$key];
390 print $val;
391 $key = "CPT4"; $val = $billing_html[$key];
392 print $val;
393 $key = "COPAY"; $val = $billing_html[$key];
394 print $val;
395 $balance = $total-$copay;
396 if ($balance != 0.00) {
397 print "<tr><td>".xl('balance')."</td><td></td><td>".xl('Please pay this amount').":</td><td>" . oeFormatMoney($balance) . "</td></tr>\n";
402 </tr></table>
403 <?php
404 //if ($balance != 0.00) {
405 // 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>";
409 </body>
410 </html>