PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/interface/patient_file/encounter/cash_receipt.php

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