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");
18 function postToGet($arin)
21 foreach ($arin as $key => $val) {
22 $getstring.=urlencode($key)."=".urlencode($val)."&";
30 <?php
html_header_show();?
>
31 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
34 <body bgcolor
="#ffffff" topmargin
=0 rightmargin
=0 leftmargin
=2 bottommargin
=0 marginwidth
=2 marginheight
=0>
37 if (sizeof($_GET) > 0) {
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);
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
>
67 <a href
="javascript:window.close();"><font
class=title
><?php
print $titleres{"fname"} . " " . $titleres{"lname"};?
></font
></a
><br
><br
>
70 <tr
><td
><?php
xl('Generated on', 'e'); ?
>:</td
><td
> <?php
print oeFormatShortDate(date("Y-m-d"));?
></td
></tr
>
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
>
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");
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>";
106 foreach ($ar as $key => $val) {
109 if (!empty($ar['newpatient'])){
110 foreach ($ar['newpatient'] as $be) {
111 $ta = split(":", $be);
112 $billing = getPatientBillingEncounter($pid, $ta[1]);
114 foreach ($billing as $b) {
115 if(!empty($b['provider_name'])) {
116 echo "Provider: " . $b['provider_name'] . "<br>";
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) {
150 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
153 foreach ($ar['newpatient'] as $be) {
154 $ta = explode(":", $be);
155 $billing = getPatientBillingEncounter($pid, $ta[1]);
156 $billings[] = $billing;
157 foreach ($billing as $b) {
159 echo "<td class=text>";
160 echo $b['code_type'] . ":\t" . $b['code'] . " " . $b['code_text'] . " ";
162 echo "<td class=text>";
163 echo oeFormatMoney($b['fee']);
167 if ($b['code_type'] == "COPAY") {
168 $copays +
= $b['fee'];
173 echo "<tr><td> </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>";
179 //print_r($billings);
182 printPatientBilling($pid);
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");
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']) .
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);
214 if ($key == "documents") {
216 foreach ($val as $valkey => $valvalue) {
217 $document_id = $valvalue;
218 if (!is_numeric($document_id)) {
222 $d = new Document($document_id);
223 $fname = basename($d->get_url());
224 $extension = substr($fname, strrpos($fname, "."));
225 echo "Document '" . $fname ."'<br>";
227 $notes = $n->notes_factory($d->get_id());
229 foreach ($notes as $note) {
231 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
234 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
237 echo '<td>'.$note->get_note().'<br><br></td>';
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>';
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) {
254 preg_match('/^(.*)_(\d+)$/', $key, $res);
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:
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)" .
267 echo "<span class='bold'> 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.
274 $form_encounter = $val;
275 preg_match('/^(.*)_(\d+)$/', $key, $res);
277 $formres = getFormNameByFormdir($res[1]);
278 $dateres = getEncounterDateByEncounter($form_encounter);
279 if ($res[1] == 'newpatient') {
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') " .
292 while ($brow=sqlFetchArray($bres)) {
293 echo "<span class='bold'> 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>
306 if ($result = getBillingByEncounter($pid, $encounter, "*")) {
307 $billing_html = array();
312 // foreach ($result as $key => $val) {
313 // print "<h2>$key</h2>";
314 // foreach($val as $key2 => $val2) {
315 // print "<p> $key2 = $val2 </p>\n";
320 foreach ($result as $iter) {
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;
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;
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']);
345 foreach ($js as $j) {
348 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
350 $billing_html[$iter["code_type"]] .= " ($j)";
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
>
367 $val = $billing_html[$key];
370 $val = $billing_html[$key];
373 $val = $billing_html[$key];
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";
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>";