separating facility from user maintenance, improved support for multiple facilities...
[openemr.git] / interface / patient_file / encounter / cash_receipt.php
blob8ef9d1d7aa3a52d4ced9a4a8f07ac7b5a3af4f91
1 <?php
2 include_once("../../globals.php");
3 include_once("$srcdir/forms.inc");
4 include_once("$srcdir/billing.inc");
5 include_once("$srcdir/pnotes.inc");
6 include_once("$srcdir/patient.inc");
7 include_once("$srcdir/report.inc");
8 include_once(dirname(__file__) . "/../../../library/classes/Document.class.php");
9 include_once(dirname(__file__) . "/../../../library/classes/Note.class.php");
10 include_once("$srcdir/options.inc.php");
12 $N = 6;
13 $first_issue = 1;
15 function postToGet($arin) {
16 $getstring="";
17 foreach ($arin as $key => $val) {
18 $getstring.=urlencode($key)."=".urlencode($val)."&";
20 return $getstring;
23 <html>
24 <head>
25 <? html_header_show();?>
26 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
27 </head>
29 <body bgcolor="#ffffff" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
30 <p>
31 <?php
32 if (sizeof($_GET) > 0) {
33 $ar = $_GET;
34 } else {
35 $ar = $_POST;
38 $titleres = getPatientData($pid, "fname,lname,providerID");
39 // $sql = "select * from facility where billing_location = 1";
40 $sql = "select f.* from facility f ".
41 "LEFT JOIN form_encounter fe on fe.facility_id = f.id ".
42 "where fe.encounter = " . $encounter;
43 $db = $GLOBALS['adodb']['db'];
44 $results = $db->Execute($sql);
45 $facility = array();
46 if (!$results->EOF) {
47 $facility = $results->fields;
50 $practice_logo = "../../../custom/practice_logo.gif";
51 if (file_exists($practice_logo)) {
52 echo "<img src='$practice_logo' align='left'>\n";
55 <h2><?=$facility['name']?></h2>
56 <?=$facility['street']?><br>
57 <?=$facility['city']?>, <?=$facility['state']?> <?=$facility['postal_code']?><br clear='all'>
58 <?=$facility['phone']?><br>
60 </p>
62 <a href="javascript:window.close();"><font class=title><?php print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br><br>
64 <table>
65 <tr><td><?php xl('Generated on','e'); ?>:</td><td> <?php print date("Y-m-d");?></td></tr>
66 <?php
67 if ($date_result = sqlQuery("select date from form_encounter where encounter='" .
68 $encounter . "' and pid='$pid'"))
70 $encounter_date = date("D F jS", strtotime($date_result{"date"}));
71 $raw_encounter_date = date("Y-m-d", strtotime($date_result{"date"}));
75 <tr><td><?php xl('Date Of Service','e'); ?>: </td><td> <?php print $raw_encounter_date;?></td></tr>
76 </table>
77 <br><br>
78 <?php
79 //$provider = getProviderName($titleres['providerID']);
81 //print "Provider: " . $provider . "</br>";
83 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
84 while($result = sqlFetchArray($inclookupres)) {
85 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
88 $printed = false;
90 foreach ($ar as $key => $val) {
91 if (!$printed && strpos($key, "newpatient_") === 0) {
92 $billing = getPatientBillingEncounter($pid, $val);
93 foreach ($billing as $b) {
94 if(!empty($b['provider_name'])) {
95 echo "Provider: " . $b['provider_name'] . "<br>";
96 $printed = true;
97 break;
103 foreach ($ar as $key => $val) {
105 /****
106 // WTF?? Redo this.
107 if (!empty($ar['newpatient'])){
108 foreach ($ar['newpatient'] as $be) {
109 $ta = split(":", $be);
110 $billing = getPatientBillingEncounter($pid, $ta[1]);
111 if(!$printed) {
112 foreach ($billing as $b) {
113 if(!empty($b['provider_name'])) {
114 echo "Provider: " . $b['provider_name'] . "<br>";
115 $printed = true;
116 break;
122 ****/
124 if (stristr($key,"include_")) {
125 //print "include: $val<br>\n";
127 if ($val == "demographics") {
129 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
130 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
132 } elseif ($val == "history") {
134 print "<br><font class=bold>".xl('History Data').":</font><br>";
135 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
137 } elseif ($val == "employer") {
139 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
140 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
142 } elseif ($val == "insurance") {
144 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
145 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
146 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
147 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
148 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
149 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
151 } elseif ($val == "billing") {
153 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
154 if (count($ar['newpatient']) > 0) {
155 $billings = array();
156 echo "<table>";
157 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
158 $total = 0.00;
159 $copays = 0.00;
160 foreach ($ar['newpatient'] as $be) {
161 $ta = split(":",$be);
162 $billing = getPatientBillingEncounter($pid,$ta[1]);
163 $billings[] = $billing;
164 foreach ($billing as $b) {
165 echo "<tr>\n";
166 echo "<td class=text>";
167 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
168 echo "</td>\n";
169 echo "<td class=text>";
170 echo $b['fee'];
171 echo "</td>\n";
172 echo "</tr>\n";
173 $total += $b['fee'];
174 if ($b['code_type'] == "COPAY") {
175 $copays += $b['fee'];
179 echo "<tr><td>&nbsp;</td></tr>";
180 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . sprintf("%0.2f",$total) . "</td></tr>";
181 echo "<tr><td class=bold>Paid</td><td class=text>" . sprintf("%0.2f",$copays) . "</td></tr>";
182 echo "<tr><td class=bold>Total</td><td class=text>" . sprintf("%0.2f",($total - $copays)) . "</td></tr>";
183 echo "</table>";
184 echo "<pre>";
185 //print_r($billings);
186 echo "</pre>";
188 else {
189 printPatientBilling($pid);
193 /****
194 } elseif ($val == "allergies") {
195 print "<font class=bold>Patient Allergies:</font><br>";
196 printListData($pid, "allergy", "1");
197 } elseif ($val == "medications") {
198 print "<font class=bold>Patient Medications:</font><br>";
199 printListData($pid, "medication", "1");
200 } elseif ($val == "medical_problems") {
201 print "<font class=bold>Patient Medical Problems:</font><br>";
202 printListData($pid, "medical_problem", "1");
203 ****/
205 } elseif ($val == "immunizations") {
206 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
207 $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";
208 $result = sqlStatement($sql);
209 while ($row=sqlFetchArray($result)) {
210 echo "<span class=text> " . $row{'immunization_data'} .
211 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
212 "</span><br>\n";
215 } elseif ($val == "notes") {
217 print "<font class=bold>".xl('Patient Notes').":</font><br>";
218 printPatientNotes($pid);
220 } elseif ($val == "transactions") {
222 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
223 printPatientTransactions($pid);
227 } else {
229 if ($key == "documents") {
230 echo "<br><br>";
231 foreach($val as $valkey => $valvalue) {
232 $document_id = $valvalue;
233 if (!is_numeric($document_id)) continue;
234 $d = new Document($document_id);
235 $fname = basename($d->get_url());
236 $extension = substr($fname, strrpos($fname,"."));
237 echo "Document '" . $fname ."'<br>";
238 $notes = Note::notes_factory($d->get_id());
239 echo "<table>";
240 foreach ($notes as $note) {
241 echo '<tr>';
242 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
243 echo '</tr>';
244 echo '<tr>';
245 echo '<td>'.xl('Date').': '.$note->get_date().'</td>';
246 echo '</tr>';
247 echo '<tr>';
248 echo '<td>'.$note->get_note().'<br><br></td>';
249 echo '</tr>';
251 echo "</table>";
252 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
253 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
255 else {
256 echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."' ".xl('cannot be displayed inline becuase its type is not supported by the browser').".<br><br>";
261 else if (strpos($key, "issue_") === 0) {
263 if ($first_issue) {
264 $first_issue = 0;
265 echo "<br>\n";
267 preg_match('/^(.*)_(\d+)$/', $key, $res);
268 $rowid = $res[2];
269 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
270 "FROM lists WHERE id = '$rowid'");
271 $diagnosis = $irow['diagnosis'];
272 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
273 $irow['comments'] . "</span><br>\n";
274 // Show issue's chief diagnosis and its description:
275 if ($diagnosis) {
276 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
277 "code = '$diagnosis' AND " .
278 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
279 "LIMIT 1");
280 echo "<span class='bold'>&nbsp;Diagnosis: </span><span class='text'>" .
281 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
286 // Otherwise we have an "encounter form" form field whose name is like
287 // dirname_formid, with a value which is the encounter ID.
289 else {
291 $form_encounter = $val;
292 preg_match('/^(.*)_(\d+)$/', $key, $res);
293 $form_id = $res[2];
294 $formres = getFormNameByFormdir($res[1]);
295 $dateres = getEncounterDateByEncounter($form_encounter);
296 if ($res[1] == 'newpatient') print "<br>\n";
297 print "<span class='bold'>" . $formres{"form_name"} .
298 "</span><span class=text>(" . date("Y-m-d",strtotime($dateres{"date"})) .
299 ")" . "</span><br>\n";
300 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
301 if ($res[1] == 'newpatient') {
302 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
303 "encounter = '$form_encounter' AND activity = 1 AND " .
304 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
305 "ORDER BY date");
306 while ($brow=sqlFetchArray($bres)) {
307 echo "<span class='bold'>&nbsp;Procedure: </span><span class='text'>" .
308 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
316 //borrowed from diagnosis.php
319 <table border="1" cellpadding=5>
320 <?php
321 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
322 $billing_html = array();
323 $total = 0.0;
324 $copay = 0.0;
326 //test
327 // foreach ($result as $key => $val) {
328 // print "<h2>$key</h2>";
329 // foreach($val as $key2 => $val2) {
330 // print "<p> $key2 = $val2 </p>\n";
331 // }
332 // }
333 //end test
335 foreach ($result as $iter) {
336 $html = '';
337 if ($iter["code_type"] == "ICD9") {
338 $html .= "<tr><td>".$iter[code_type].
339 "</td><td>".$iter[code]."</td><td>"
340 .$iter["code_text"]."</td></tr>\n";
341 $billing_html[$iter["code_type"]] .= $html;
342 $counter++;
344 elseif ($iter["code_type"] == "COPAY") {
345 $html .= "<tr><td>".xl('Payment').":</td><td>".xl('Thank You')."!</td><td>"
346 .$iter["code_text"]."</td><td>"
347 .$iter["code"]."</td></tr>\n";
348 if ($iter["code"] > 0.00) {
349 $copay += $iter["code"];
350 $billing_html[$iter["code_type"]] .= $html;
353 else {
354 $html .= "<tr><td>".$iter[code_type].
355 "</td><td>".$iter[code]."</td><td>"
356 .$iter["code_text"].' '.$iter['modifier']
357 ."</td><td>".$iter['fee']."</td></tr>\n";
358 $billing_html[$iter["code_type"]] .= $html;
359 $total += $iter['fee'];
360 $js = split(":",$iter['justify']);
361 $counter = 0;
362 foreach ($js as $j) {
363 if(!empty($j)) {
364 if ($counter == 0) {
365 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
367 else {
368 $billing_html[$iter["code_type"]] .= " ($j)";
370 $counter++;
375 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
380 $billing_html["CPT4"] .= "<tr><td>".xl('total')."</td><td></td><td></td><td>" . sprintf("%01.2f",$total) . "</td></tr>\n";
382 <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>
383 <?php
384 $key = "ICD9"; $val = $billing_html[$key];
385 print $val;
386 $key = "CPT4"; $val = $billing_html[$key];
387 print $val;
388 $key = "COPAY"; $val = $billing_html[$key];
389 print $val;
390 $balance = $total-$copay;
391 if ($balance != 0.00) {
392 print "<tr><td>".xl('balance')."</td><td></td><td>".xl('Please pay this amount').":</td><td>" . sprintf("%01.2f",$balance) . "</td></tr>\n";
397 </tr></table>
398 <?php
399 //if ($balance != 0.00) {
400 // 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>";
404 </body>
405 </html>