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(dirname(__file__
) . "/../../../library/classes/Document.class.php");
14 require_once(dirname(__file__
) . "/../../../library/classes/Note.class.php");
15 require_once("$srcdir/options.inc.php");
16 require_once("$srcdir/formatting.inc.php");
21 function postToGet($arin) {
23 foreach ($arin as $key => $val) {
24 $getstring.=urlencode($key)."=".urlencode($val)."&";
31 <?php
html_header_show();?
>
32 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
35 <body bgcolor
="#ffffff" topmargin
=0 rightmargin
=0 leftmargin
=2 bottommargin
=0 marginwidth
=2 marginheight
=0>
38 if (sizeof($_GET) > 0) {
44 $titleres = getPatientData($pid, "fname,lname,providerID");
45 // $sql = "select * from facility where billing_location = 1";
46 $sql = "select f.* from facility f ".
47 "LEFT JOIN form_encounter fe on fe.facility_id = f.id ".
48 "where fe.encounter = " . $encounter;
49 $db = $GLOBALS['adodb']['db'];
50 $results = $db->Execute($sql);
53 $facility = $results->fields
;
56 $practice_logo = "../../../custom/practice_logo.gif";
57 if (file_exists($practice_logo)) {
58 echo "<img src='$practice_logo' align='left'>\n";
61 <h2
><?php
echo $facility['name']?
></h2
>
62 <?php
echo $facility['street']?
><br
>
63 <?php
echo $facility['city']?
>, <?php
echo $facility['state']?
> <?php
echo $facility['postal_code']?
><br clear
='all'>
64 <?php
echo $facility['phone']?
><br
>
68 <a href
="javascript:window.close();"><font
class=title
><?php
print $titleres{"fname"} . " " . $titleres{"lname"};?
></font
></a
><br
><br
>
71 <tr
><td
><?php
xl('Generated on','e'); ?
>:</td
><td
> <?php
print oeFormatShortDate(date("Y-m-d"));?
></td
></tr
>
73 if ($date_result = sqlQuery("select date from form_encounter where encounter='" .
74 $encounter . "' and pid='$pid'"))
76 $encounter_date = date("D F jS", strtotime($date_result{"date"}));
77 $raw_encounter_date = date("Y-m-d", strtotime($date_result{"date"}));
81 <tr
><td
><?php
xl('Date Of Service','e'); ?
>: </td
><td
> <?php
print oeFormatShortDate($raw_encounter_date);?
></td
></tr
>
85 //$provider = getProviderName($titleres['providerID']);
87 //print "Provider: " . $provider . "</br>";
89 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
90 while($result = sqlFetchArray($inclookupres)) {
91 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
96 foreach ($ar as $key => $val) {
97 if (!$printed && strpos($key, "newpatient_") === 0) {
98 $billing = getPatientBillingEncounter($pid, $val);
99 foreach ($billing as $b) {
100 if(!empty($b['provider_name'])) {
101 echo "Provider: " . $b['provider_name'] . "<br>";
109 foreach ($ar as $key => $val) {
113 if (!empty($ar['newpatient'])){
114 foreach ($ar['newpatient'] as $be) {
115 $ta = split(":", $be);
116 $billing = getPatientBillingEncounter($pid, $ta[1]);
118 foreach ($billing as $b) {
119 if(!empty($b['provider_name'])) {
120 echo "Provider: " . $b['provider_name'] . "<br>";
130 if (stristr($key,"include_")) {
131 //print "include: $val<br>\n";
133 if ($val == "demographics") {
135 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
136 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
138 } elseif ($val == "history") {
140 print "<br><font class=bold>".xl('History Data').":</font><br>";
141 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
143 } elseif ($val == "employer") {
145 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
146 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
148 } elseif ($val == "insurance") {
150 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
151 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
152 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
153 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
154 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
155 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
157 } elseif ($val == "billing") {
159 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
160 if (count($ar['newpatient']) > 0) {
163 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
166 foreach ($ar['newpatient'] as $be) {
167 $ta = split(":",$be);
168 $billing = getPatientBillingEncounter($pid,$ta[1]);
169 $billings[] = $billing;
170 foreach ($billing as $b) {
172 echo "<td class=text>";
173 echo $b['code_type'] . ":\t" . $b['code'] . " " . $b['code_text'] . " ";
175 echo "<td class=text>";
176 echo oeFormatMoney($b['fee']);
180 if ($b['code_type'] == "COPAY") {
181 $copays +
= $b['fee'];
185 echo "<tr><td> </td></tr>";
186 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
187 echo "<tr><td class=bold>Paid</td><td class=text>" . oeFormatMoney($copays) . "</td></tr>";
188 echo "<tr><td class=bold>Total</td><td class=text>" . oeFormatMoney($total - $copays) . "</td></tr>";
191 //print_r($billings);
195 printPatientBilling($pid);
200 } elseif ($val == "allergies") {
201 print "<font class=bold>Patient Allergies:</font><br>";
202 printListData($pid, "allergy", "1");
203 } elseif ($val == "medications") {
204 print "<font class=bold>Patient Medications:</font><br>";
205 printListData($pid, "medication", "1");
206 } elseif ($val == "medical_problems") {
207 print "<font class=bold>Patient Medical Problems:</font><br>";
208 printListData($pid, "medical_problem", "1");
211 } elseif ($val == "immunizations") {
212 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
213 $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";
214 $result = sqlStatement($sql);
215 while ($row=sqlFetchArray($result)) {
216 echo "<span class=text> " . $row{'immunization_data'} .
217 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
221 } elseif ($val == "notes") {
223 print "<font class=bold>".xl('Patient Notes').":</font><br>";
224 printPatientNotes($pid);
226 } elseif ($val == "transactions") {
228 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
229 printPatientTransactions($pid);
235 if ($key == "documents") {
237 foreach($val as $valkey => $valvalue) {
238 $document_id = $valvalue;
239 if (!is_numeric($document_id)) continue;
240 $d = new Document($document_id);
241 $fname = basename($d->get_url());
242 $extension = substr($fname, strrpos($fname,"."));
243 echo "Document '" . $fname ."'<br>";
244 $notes = Note
::notes_factory($d->get_id());
246 foreach ($notes as $note) {
248 echo '<td>'.xl('Note').' #' . $note->get_id() . '</td>';
251 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
254 echo '<td>'.$note->get_note().'<br><br></td>';
258 if ($extension == ".png" ||
$extension == ".jpg" ||
$extension == ".jpeg" ||
$extension == ".gif") {
259 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
262 echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."' ".xl('cannot be displayed inline becuase its type is not supported by the browser').".<br><br>";
267 else if (strpos($key, "issue_") === 0) {
273 preg_match('/^(.*)_(\d+)$/', $key, $res);
275 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
276 "FROM lists WHERE id = '$rowid'");
277 $diagnosis = $irow['diagnosis'];
278 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
279 $irow['comments'] . "</span><br>\n";
280 // Show issue's chief diagnosis and its description:
282 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
283 "code = '$diagnosis' AND " .
284 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
286 echo "<span class='bold'> Diagnosis: </span><span class='text'>" .
287 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
292 // Otherwise we have an "encounter form" form field whose name is like
293 // dirname_formid, with a value which is the encounter ID.
297 $form_encounter = $val;
298 preg_match('/^(.*)_(\d+)$/', $key, $res);
300 $formres = getFormNameByFormdir($res[1]);
301 $dateres = getEncounterDateByEncounter($form_encounter);
302 if ($res[1] == 'newpatient') print "<br>\n";
303 print "<span class='bold'>" . $formres{"form_name"} .
304 "</span><span class=text>(" . oeFormatShortDate(strtotime($dateres{"date"})) .
305 ")" . "</span><br>\n";
306 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
307 if ($res[1] == 'newpatient') {
308 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
309 "encounter = '$form_encounter' AND activity = 1 AND " .
310 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
312 while ($brow=sqlFetchArray($bres)) {
313 echo "<span class='bold'> Procedure: </span><span class='text'>" .
314 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
322 //borrowed from diagnosis.php
325 <table border
="1" cellpadding
=5>
327 if ($result = getBillingByEncounter($pid,$encounter,"*") ) {
328 $billing_html = array();
333 // foreach ($result as $key => $val) {
334 // print "<h2>$key</h2>";
335 // foreach($val as $key2 => $val2) {
336 // print "<p> $key2 = $val2 </p>\n";
341 foreach ($result as $iter) {
343 if ($iter["code_type"] == "ICD9") {
344 $html .= "<tr><td>".$iter[code_type
].
345 "</td><td>".$iter[code
]."</td><td>"
346 .$iter["code_text"]."</td></tr>\n";
347 $billing_html[$iter["code_type"]] .= $html;
350 elseif ($iter["code_type"] == "COPAY") {
351 $html .= "<tr><td>".xl('Payment').":</td><td>".xl('Thank You')."!</td><td>"
352 .$iter["code_text"]."</td><td>"
353 . oeFormatMoney($iter["code"]) . "</td></tr>\n";
354 if ($iter["code"] > 0.00) {
355 $copay +
= $iter["code"];
356 $billing_html[$iter["code_type"]] .= $html;
360 $html .= "<tr><td>".$iter[code_type
].
361 "</td><td>".$iter[code
]."</td><td>"
362 .$iter["code_text"].' '.$iter['modifier']
363 ."</td><td>" . oeFormatMoney($iter['fee']) . "</td></tr>\n";
364 $billing_html[$iter["code_type"]] .= $html;
365 $total +
= $iter['fee'];
366 $js = split(":",$iter['justify']);
368 foreach ($js as $j) {
371 $billing_html[$iter["code_type"]] .= " (<b>$j</b>)";
374 $billing_html[$iter["code_type"]] .= " ($j)";
381 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
386 $billing_html["CPT4"] .= "<tr><td>".xl('total')."</td><td></td><td></td><td>" . oeFormatMoney($total) . "</td></tr>\n";
388 <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
>
390 $key = "ICD9"; $val = $billing_html[$key];
392 $key = "CPT4"; $val = $billing_html[$key];
394 $key = "COPAY"; $val = $billing_html[$key];
396 $balance = $total-$copay;
397 if ($balance != 0.00) {
398 print "<tr><td>".xl('balance')."</td><td></td><td>".xl('Please pay this amount').":</td><td>" . oeFormatMoney($balance) . "</td></tr>\n";
405 //if ($balance != 0.00) {
406 // 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>";