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/options.inc.php");
13 require_once("$srcdir/acl.inc");
14 require_once("$srcdir/lists.inc");
15 require_once("$srcdir/report.inc");
16 require_once("$srcdir/classes/Document.class.php");
17 require_once("$srcdir/classes/Note.class.php");
18 require_once("$srcdir/formatting.inc.php");
19 require_once(dirname(__file__
) . "/../../../custom/code_types.inc.php");
21 // get various authorization levels
22 $auth_notes_a = acl_check('encounters', 'notes_a');
23 $auth_notes = acl_check('encounters', 'notes');
24 $auth_coding_a = acl_check('encounters', 'coding_a');
25 $auth_coding = acl_check('encounters', 'coding');
26 $auth_relaxed = acl_check('encounters', 'relaxed');
27 $auth_med = acl_check('patients' , 'med');
28 $auth_demo = acl_check('patients' , 'demo');
30 $printable = empty($_GET['printable']) ?
false : true;
31 unset($_GET['printable']);
36 function postToGet($arin) {
38 foreach ($arin as $key => $val) {
40 foreach ($val as $k => $v) {
41 $getstring .= urlencode($key . "[]") . "=" . urlencode($v) . "&";
45 $getstring .= urlencode($key) . "=" . urlencode($val) . "&";
53 <?php
html_header_show();?
>
54 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
56 <?php
// do not show stuff from report.php in forms that is encaspulated
57 // by div of navigateLink class. Specifically used for CAMOS, but
58 // can also be used by other forms that require output in the
59 // encounter listings output, but not in the custom report. ?>
60 <style
> div
.navigateLink
{display
:none
;} </style
>
64 <body
class="body_top">
65 <div id
="report_custom"> <!-- large outer DIV
-->
68 if (sizeof($_GET) > 0) { $ar = $_GET; }
69 else { $ar = $_POST; }
72 /*******************************************************************
73 $titleres = getPatientData($pid, "fname,lname,providerID");
74 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
75 *******************************************************************/
76 $titleres = getPatientData($pid, "fname,lname,providerID,DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
77 if ($_SESSION['pc_facility']) {
78 $sql = "select * from facility where id=" . $_SESSION['pc_facility'];
80 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
82 /******************************************************************/
83 $db = $GLOBALS['adodb']['db'];
84 $results = $db->Execute($sql);
87 $facility = $results->fields
;
89 $practice_logo = "../../../custom/practice_logo.gif";
90 if (file_exists($practice_logo)) {
91 echo "<img src='$practice_logo' align='left'>\n";
94 <h2
><?php
echo $facility['name'] ?
></h2
>
95 <?php
echo $facility['street'] ?
><br
>
96 <?php
echo $facility['city'] ?
>, <?php
echo $facility['state'] ?
> <?php
echo $facility['postal_code'] ?
><br clear
='all'>
97 <?php
echo $facility['phone'] ?
><br
>
99 <a href
="javascript:window.close();"><span
class='title'><?php
echo $titleres['fname'] . " " . $titleres['lname']; ?
></span
></a
><br
>
100 <span
class='text'><?php
xl('Generated on','e'); ?
>: <?php
echo oeFormatShortDate(); ?
></span
>
106 else { // not printable
110 <a href
="patient_report.php">
111 <span
class='title'><?php
xl('Patient Report','e'); ?
></span
>
112 <span
class='back'><?php
echo $tback;?
></span
>
114 <a href
="custom_report.php?printable=1&<?php print postToGet($ar); ?>" class='link_submit' target
='new'>
115 [<?php
xl('Printable Version','e'); ?
>]
118 <?php
} // end not printable ?>
122 // include ALL form's report.php files
123 $inclookupres = sqlStatement("select distinct formdir from forms where pid = '$pid' AND deleted=0");
124 while($result = sqlFetchArray($inclookupres)) {
125 // include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
126 $formdir = $result['formdir'];
127 if (substr($formdir,0,3) == 'LBF')
128 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
130 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
133 // For each form field from patient_report.php...
135 foreach ($ar as $key => $val) {
137 // These are the top checkboxes (demographics, allergies, etc.).
139 if (stristr($key,"include_")) {
141 if ($val == "demographics") {
144 echo "<div class='text demographics' id='DEM'>\n";
145 print "<h1>".xl('Patient Data').":</h1>";
146 // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
147 $result1 = getPatientData($pid);
148 $result2 = getEmployerData($pid);
150 display_layout_rows('DEM', $result1, $result2);
154 } elseif ($val == "history") {
157 echo "<div class='text history' id='HIS'>\n";
158 if (acl_check('patients', 'med')) {
159 print "<h1>".xl('History Data').":</h1>";
160 // printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
161 $result1 = getHistoryData($pid);
163 display_layout_rows('HIS', $result1);
168 // } elseif ($val == "employer") {
169 // print "<br><span class='bold'>".xl('Employer Data').":</span><br>";
170 // printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
172 } elseif ($val == "insurance") {
175 echo "<div class='text insurance'>";
176 echo "<h1>".xl('Insurance Data').":</h1>";
177 print "<br><span class=bold>".xl('Primary Insurance Data').":</span><br>";
178 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
179 print "<span class=bold>".xl('Secondary Insurance Data').":</span><br>";
180 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
181 print "<span class=bold>".xl('Tertiary Insurance Data').":</span><br>";
182 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
185 } elseif ($val == "billing") {
188 echo "<div class='text billing'>";
189 print "<h1>".xl('Billing Information').":</h1>";
190 if (count($ar['newpatient']) > 0) {
193 echo "<tr><td width='400' class='bold'>Code</td><td class='bold'>".xl('Fee')."</td></tr>\n";
196 foreach ($ar['newpatient'] as $be) {
197 $ta = split(":",$be);
198 $billing = getPatientBillingEncounter($pid,$ta[1]);
199 $billings[] = $billing;
200 foreach ($billing as $b) {
202 echo "<td class=text>";
203 echo $b['code_type'] . ":\t" . $b['code'] . " ". $b['modifier'] . " " . $b['code_text'] . " ";
205 echo "<td class=text>";
206 echo oeFormatMoney($b['fee']);
210 if ($b['code_type'] == "COPAY") {
211 $copays +
= $b['fee'];
215 echo "<tr><td> </td></tr>";
216 echo "<tr><td class=bold>".xl('Sub-Total')."</td><td class=text>" . oeFormatMoney($total +
abs($copays)) . "</td></tr>";
217 echo "<tr><td class=bold>".xl('Paid')."</td><td class=text>" . oeFormatMoney(abs($copays)) . "</td></tr>";
218 echo "<tr><td class=bold>".xl('Total')."</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
221 //print_r($billings);
224 printPatientBilling($pid);
226 echo "</div>\n"; // end of billing DIV
230 } elseif ($val == "allergies") {
232 print "<span class=bold>Patient Allergies:</span><br>";
233 printListData($pid, "allergy", "1");
235 } elseif ($val == "medications") {
237 print "<span class=bold>Patient Medications:</span><br>";
238 printListData($pid, "medication", "1");
240 } elseif ($val == "medical_problems") {
242 print "<span class=bold>Patient Medical Problems:</span><br>";
243 printListData($pid, "medical_problem", "1");
247 } elseif ($val == "immunizations") {
249 if (acl_check('patients', 'med')) {
251 echo "<div class='text immunizations'>\n";
252 print "<h1>".xl('Patient Immunization').":</h1>";
253 $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";
254 $result = sqlStatement($sql);
255 while ($row=sqlFetchArray($result)) {
256 echo $row{'immunization_data'} .
257 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
263 // communication report
264 } elseif ($val == "batchcom") {
267 echo "<div class='text transactions'>\n";
268 print "<h1>".xl('Patient Communication sent').":</h1>";
269 $sql="SELECT concat( 'Messsage Type: ', batchcom.msg_type, ', Message Subject: ', batchcom.msg_subject, ', Sent on:', batchcom.msg_date_sent ) AS batchcom_data, batchcom.msg_text, concat( users.fname, users.lname ) AS user_name FROM `batchcom` JOIN `users` ON users.id = batchcom.sent_by WHERE batchcom.patient_id='$pid'";
271 $result = sqlStatement($sql);
272 while ($row=sqlFetchArray($result)) {
273 echo $row{'batchcom_data'}.", By: ".$row{'user_name'}."<br>Text:<br> ".$row{'msg_txt'}."<br>\n";
277 } elseif ($val == "notes") {
280 echo "<div class='text notes'>\n";
281 print "<h1>".xl('Patient Notes').":</h1>";
282 printPatientNotes($pid);
285 } elseif ($val == "transactions") {
288 echo "<div class='text transactions'>\n";
289 print "<h1>".xl('Patient Transactions').":</h1>";
290 printPatientTransactions($pid);
297 // Documents is an array of checkboxes whose values are document IDs.
299 if ($key == "documents") {
302 echo "<div class='text documents'>";
303 foreach($val as $valkey => $valvalue) {
304 $document_id = $valvalue;
305 if (!is_numeric($document_id)) continue;
306 $d = new Document($document_id);
307 $fname = basename($d->get_url());
308 $extension = substr($fname, strrpos($fname,"."));
309 echo "<h1>" . xl('Document') . " '" . $fname ."'</h1>";
310 $notes = Note
::notes_factory($d->get_id());
312 foreach ($notes as $note) {
314 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
317 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
320 echo '<td>'.$note->get_note().'<br><br></td>';
324 if ($extension == ".png" ||
$extension == ".jpg" ||
$extension == ".jpeg" ||
$extension == ".gif") {
325 echo "<img src='" . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . "&as_file=false'><br><br>";
328 // echo "<b>NOTE</b>: ".xl('Document')."'" . $fname ."' ".xl('cannot be displayed inline because its type is not supported by the browser.')."<br><br>";
329 // This requires ImageMagick to be installed.
330 $url_file = $d->get_url_filepath();
331 // just grab the last two levels, which contain filename and patientid
332 $from_all = explode("/",$url_file);
333 $from_filename = array_pop($from_all);
334 $from_patientid = array_pop($from_all);
335 $from_file = $GLOBALS["fileroot"].'/documents/'.$from_patientid.'/'.$from_filename;
336 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
337 if (! is_file($to_file)) exec("convert -density 200 \"$from_file\" -append -resize 850 \"$to_file\"");
338 if (is_file($to_file)) {
339 echo "<img src='" . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . "&as_file=false&original_file=false'><br><br>";
341 echo "<b>NOTE</b>: " . xl('Document') . "'" . $fname . "' " .
342 xl('cannot be converted to JPEG. Perhaps ImageMagick is not installed?') .
346 } // end Documents loop
349 } else if (strpos($key, "issue_") === 0) {
350 // display patient Issues
353 $prevIssueType = 'asdf1234!@#$'; // random junk so as to not match anything
356 echo "<h1>".xl("Issues")."</h1>";
358 preg_match('/^(.*)_(\d+)$/', $key, $res);
360 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
361 "FROM lists WHERE id = '$rowid'");
362 $diagnosis = $irow['diagnosis'];
363 if ($prevIssueType != $irow['type']) {
364 // output a header for each Issue Type we encounter
365 $disptype = $ISSUE_TYPES[$irow['type']][0];
366 echo "<div class='issue_type'>" . $disptype . ":</div>\n";
367 $prevIssueType = $irow['type'];
369 echo "<div class='text issue'>";
370 echo "<span class='issue_title'>" . $irow['title'] . ":</span>";
371 echo "<span class='issue_comments'> " . $irow['comments'] . "</span>\n";
372 // Show issue's chief diagnosis and its description:
374 echo "<div class='text issue_diag'>";
375 echo "<span class='bold'>[".xl('Diagnosis')."]</span><br>";
376 $dcodes = explode(";", $diagnosis);
377 foreach ($dcodes as $dcode) {
378 echo "<span class='italic'>".$dcode."</span>: ";
379 echo lookup_code_descriptions($dcode)."<br>\n";
381 //echo $diagnosis." -- ".lookup_code_descriptions($diagnosis)."\n";
385 // Supplemental data for GCAC or Contraception issues.
386 if ($irow['type'] == 'ippf_gcac') {
388 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '$rowid'"));
391 else if ($irow['type'] == 'contraceptive') {
393 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '$rowid'"));
397 echo "</div>\n"; //end the issue DIV
400 // we have an "encounter form" form field whose name is like
401 // dirname_formid, with a value which is the encounter ID.
403 // display encounter forms, encoded as a POST variable
404 // in the format: <formdirname_formid>=<encounterID>
406 if (($auth_notes_a ||
$auth_notes ||
$auth_coding_a ||
$auth_coding ||
$auth_med ||
$auth_relaxed)) {
407 $form_encounter = $val;
408 preg_match('/^(.*)_(\d+)$/', $key, $res);
410 $formres = getFormNameByFormdirAndFormid($res[1],$form_id);
411 $dateres = getEncounterDateByEncounter($form_encounter);
413 if ($res[1] == 'newpatient') {
414 echo "<div class='text encounter'>\n";
415 echo "<h1>" . xl($formres["form_name"]) . "</h1>";
418 echo "<div class='text encounter_form'>";
419 echo "<h1>" . xl_form_title($formres["form_name"]) . "</h1>";
422 // show the encounter's date
423 echo "(" . oeFormatSDFT(strtotime($dateres["date"])) . ") ";
424 if ($res[1] == 'newpatient') {
425 // display the provider info
426 $tmp = sqlQuery("SELECT u.title, u.fname, u.mname, u.lname " .
427 "FROM forms AS f, users AS u WHERE " .
428 "f.pid = '$pid' AND f.encounter = '$form_encounter' AND " .
429 "f.formdir = 'newpatient' AND u.username = f.user " .
430 " AND f.deleted=0 ". //--JRM--
431 "ORDER BY f.id LIMIT 1");
432 echo ' '. xl('Provider') . ': ' . $tmp['title'] . ' ' .
433 $tmp['fname'] . ' ' . $tmp['mname'] . ' ' . $tmp['lname'];
437 // call the report function for the form
438 if (substr($res[1],0,3) == 'LBF')
439 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $res[1]);
441 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
443 if ($res[1] == 'newpatient') {
444 // display billing info
445 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
446 "pid = '$pid' AND encounter = '$form_encounter' AND activity = 1 AND " .
447 "( code_type = 'CPT4' OR code_type = 'OPCS' OR code_type = 'OSICS10' ) " .
449 while ($brow=sqlFetchArray($bres)) {
450 echo "<span class='bold'> ".xl('Procedure').": </span><span class='text'>" .
451 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
457 } // end auth-check for encounter forms
459 } // end if('issue_')... else...
461 } // end if('include_')... else...
466 echo "</br></br>" . xl('Signature') . ": _______________________________</br>";
469 </div
> <!-- end of report_custom DIV
-->