Fixed php short tags
[openemr.git] / interface / patient_file / report / print_custom_report.php
blob33326771612111d922374b51dad82b5599174623
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 require_once("$srcdir/options.inc.php");
9 include_once(dirname(__file__) . "/../../../library/classes/Document.class.php");
10 include_once(dirname(__file__) . "/../../../library/classes/Note.class.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 <?php html_header_show();?>
26 <link rel=stylesheet href="<?php 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 /********************************************************************
40 $sql = "select * from facility where billing_location = 1";
41 ********************************************************************/
42 if ($_SESSION['pc_facility']) {
43 $sql = "select * from facility where id=" . $_SESSION['pc_facility'];
44 } else {
45 $sql = "select * from facility where billing_location = 1";
47 /*******************************************************************/
48 $db = $GLOBALS['adodb']['db'];
49 $results = $db->Execute($sql);
50 $facility = array();
51 if (!$results->EOF) {
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><?=$facility['name']?></h2>
61 <?=$facility['street']?><br>
62 <?=$facility['city']?>, <?=$facility['state']?> <?=$facility['postal_code']?><br clear='all'>
63 <?=$facility['phone']?><br>
64 </p>
66 <a href="javascript:window.close();"><font class=title><?print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br>
67 <span class=text><?php xl('Generated on','e'); ?>: <?print date("Y-m-d");?></span>
68 <br><br>
70 <?php
72 //$provider = getProviderName($titleres['providerID']);
74 //print "Provider: " . $provider . "</br>";
76 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
77 while($result = sqlFetchArray($inclookupres)) {
78 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
81 $printed = false;
83 foreach ($ar as $key => $val) {
84 if (!$printed && strpos($key, "newpatient_") === 0) {
85 $billing = getPatientBillingEncounter($pid, $val);
86 foreach ($billing as $b) {
87 if(!empty($b['provider_name'])) {
88 echo "Provider: " . $b['provider_name'] . "<br>";
89 $printed = true;
90 break;
96 foreach ($ar as $key => $val) {
98 /****
99 // WTF?? Redo this.
100 if (!empty($ar['newpatient'])){
101 foreach ($ar['newpatient'] as $be) {
102 $ta = split(":", $be);
103 $billing = getPatientBillingEncounter($pid, $ta[1]);
104 if(!$printed) {
105 foreach ($billing as $b) {
106 if(!empty($b['provider_name'])) {
107 echo "Provider: " . $b['provider_name'] . "<br>";
108 $printed = true;
109 break;
115 ****/
117 if (stristr($key,"include_")) {
118 //print "include: $val<br>\n";
120 if ($val == "demographics") {
122 print "<br><font class=bold>".xl('Patient Data').":</font><br>";
123 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
125 } elseif ($val == "history") {
127 print "<br><font class=bold>".xl('History Data').":</font><br>";
128 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
130 } elseif ($val == "employer") {
132 print "<br><font class=bold>".xl('Employer Data').":</font><br>";
133 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
135 } elseif ($val == "insurance") {
137 print "<br><font class=bold>".xl('Primary Insurance Data').":</font><br>";
138 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
139 print "<font class=bold>".xl('Secondary Insurance Data').":</font><br>";
140 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
141 print "<font class=bold>".xl('Tertiary Insurance Data').":</font><br>";
142 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
144 } elseif ($val == "billing") {
146 print "<br><font class=bold>".xl('Billing Information').":</font><br>";
147 if (count($ar['newpatient']) > 0) {
148 $billings = array();
149 echo "<table>";
150 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>".xl('Fee')."</td></tr>\n";
151 $total = 0.00;
152 $copays = 0.00;
153 foreach ($ar['newpatient'] as $be) {
154 $ta = split(":",$be);
155 $billing = getPatientBillingEncounter($pid,$ta[1]);
156 $billings[] = $billing;
157 foreach ($billing as $b) {
158 echo "<tr>\n";
159 echo "<td class=text>";
160 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
161 echo "</td>\n";
162 echo "<td class=text>";
163 echo $b['fee'];
164 echo "</td>\n";
165 echo "</tr>\n";
166 $total += $b['fee'];
167 if ($b['code_type'] == "COPAY") {
168 $copays += $b['fee'];
172 echo "<tr><td>&nbsp;</td></tr>";
173 echo "<tr><td class=bold>".xl('Sub-Total')."</td><td class=text>" . sprintf("%0.2f",$total) . "</td></tr>";
174 echo "<tr><td class=bold>".xl('Paid')."</td><td class=text>" . sprintf("%0.2f",$copays) . "</td></tr>";
175 echo "<tr><td class=bold>".xl('Total')."</td><td class=text>" . sprintf("%0.2f",($total - $copays)) . "</td></tr>";
176 echo "</table>";
177 echo "<pre>";
178 //print_r($billings);
179 echo "</pre>";
181 else {
182 printPatientBilling($pid);
186 /****
187 } elseif ($val == "allergies") {
188 print "<font class=bold>".xl('Patient Allergies').":</font><br>";
189 printListData($pid, "allergy", "1");
190 } elseif ($val == "medications") {
191 print "<font class=bold>".xl('Patient Medications').":</font><br>";
192 printListData($pid, "medication", "1");
193 } elseif ($val == "medical_problems") {
194 print "<font class=bold>".xl('Patient Medical Problems').":</font><br>";
195 printListData($pid, "medical_problem", "1");
196 ****/
198 } elseif ($val == "immunizations") {
199 print "<font class=bold>".xl('Patient Immunization').":</font><br>";
200 $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";
201 $result = sqlStatement($sql);
202 while ($row=sqlFetchArray($result)) {
203 echo "<span class=text> " . $row{'immunization_data'} .
204 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
205 "</span><br>\n";
208 } elseif ($val == "notes") {
210 print "<font class=bold>".xl('Patient Notes').":</font><br>";
211 printPatientNotes($pid);
213 } elseif ($val == "transactions") {
215 print "<font class=bold>".xl('Patient Transactions').":</font><br>";
216 printPatientTransactions($pid);
220 } else {
222 if ($key == "documents") {
223 echo "<br><br>";
224 foreach($val as $valkey => $valvalue) {
225 $document_id = $valvalue;
226 if (!is_numeric($document_id)) continue;
227 $d = new Document($document_id);
228 $fname = basename($d->get_url());
229 $extension = substr($fname, strrpos($fname,"."));
230 echo "Document '" . $fname ."'<br>";
231 $notes = Note::notes_factory($d->get_id());
232 echo "<table>";
233 foreach ($notes as $note) {
234 echo '<tr>';
235 echo '<td>Note #' . $note->get_id() . '</td>';
236 echo '</tr>';
237 echo '<tr>';
238 echo '<td>Date: '.$note->get_date().'</td>';
239 echo '</tr>';
240 echo '<tr>';
241 echo '<td>'.$note->get_note().'<br><br></td>';
242 echo '</tr>';
244 echo "</table>";
245 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
246 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
248 else {
249 // echo "<b>NOTE</b>: ".xl('Document')." '" . $fname ."'".xl('cannot be displayed inline becuase its type is not supported by the browser.')."<br><br>";
251 // This requires ImageMagick to be installed.
252 $from_file = $d->get_url_filepath();
253 if($d->get_storagemethod()==1 ){
254 $from_file = $d->get_couch_url($pid,$encounter);
256 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
257 if (! is_file($to_file)) exec("convert -density 200 '$from_file' -append -resize 850 '$to_file'");
258 if (is_file($to_file)) {
259 $to_url = $GLOBALS['webroot'] . "/sites/" . $_SESSION['site_id'] .
260 "/documents/$pid/" . basename($to_file);
261 echo "<img src='$to_url'><br><br>\n";
262 } else {
263 echo "<b>NOTE</b>: " . xl('Document') . "'" . $fname . "' " .
264 xl('cannot be converted to JPEG. Perhaps ImageMagick is not installed?') .
265 "<br><br>";
267 if($d->get_storagemethod()==1 ){
268 unlink($from_file);
274 else if (strpos($key, "issue_") === 0) {
276 if ($first_issue) {
277 $first_issue = 0;
278 echo "<br>\n";
280 preg_match('/^(.*)_(\d+)$/', $key, $res);
281 $rowid = $res[2];
282 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
283 "FROM lists WHERE id = '$rowid'");
284 $diagnosis = $irow['diagnosis'];
285 echo "<span class='bold'>" . $irow['title'] . ":</span><span class='text'> " .
286 $irow['comments'] . "</span><br>\n";
287 // Show issue's chief diagnosis and its description:
288 if ($diagnosis) {
289 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
290 "code = '$diagnosis' AND " .
291 "(code_type = 2 OR code_type = 4 OR code_type = 5)" .
292 "LIMIT 1");
293 echo "<span class='bold'>&nbsp;Diagnosis: </span><span class='text'>" .
294 $irow['diagnosis'] . " " . $crow['code_text'] . "</span><br>\n";
299 // Otherwise we have an "encounter form" form field whose name is like
300 // dirname_formid, with a value which is the encounter ID.
302 else {
304 $form_encounter = $val;
305 preg_match('/^(.*)_(\d+)$/', $key, $res);
306 $form_id = $res[2];
307 $formres = getFormNameByFormdir($res[1]);
308 $dateres = getEncounterDateByEncounter($form_encounter);
309 if ($res[1] == 'newpatient') print "<br>\n";
310 print "<span class='bold'>" . $formres{"form_name"} .
311 "</span><span class=text>(" . date("Y-m-d",strtotime($dateres{"date"})) .
312 ")" . "</span><br>\n";
313 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
314 if ($res[1] == 'newpatient') {
315 $bres = sqlStatement("SELECT date, code, code_text FROM billing WHERE " .
316 "pid = '$pid' AND encounter = '$form_encounter' AND activity = 1 AND " .
317 "(code_type = 'CPT4' OR code_type = 'OPCS') " .
318 "ORDER BY date");
319 while ($brow=sqlFetchArray($bres)) {
320 echo "<span class='bold'>&nbsp;Procedure: </span><span class='text'>" .
321 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
329 print "</br></br>".xl('Signature').": _______________________________</br>";
333 </body>
334 </html>