Initial import.
[openemr.git] / interface / patient_file / report / print_custom_report.php
blob5e39cc0c7305fac3eb34dc2bf847775c79077965
1 <?
2 include_once("../../globals.php");
5 include_once("$srcdir/forms.inc");
6 include_once("$srcdir/billing.inc");
7 include_once("$srcdir/pnotes.inc");
8 include_once("$srcdir/patient.inc");
9 include_once("$srcdir/report.inc");
10 include_once(dirname(__file__) . "/../../../library/classes/Document.class.php");
11 include_once(dirname(__file__) . "/../../../library/classes/Note.class.php");
13 $N = 6;
14 function postToGet($arin) {
15 $getstring="";
16 foreach ($arin as $key => $val) {
17 $getstring.=urlencode($key)."=".urlencode($val)."&";
19 return $getstring;
23 <html>
24 <head>
27 <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>
34 if (sizeof($_GET) > 0) {
35 $ar = $_GET;
36 } else {
37 $ar = $_POST;
40 $titleres = getPatientData($pid, "fname,lname,providerID");
41 $sql = "select * from facility where billing_location = 1";
42 $db = $GLOBALS['adodb']['db'];
43 $results = $db->Execute($sql);
44 $facility = array();
45 if (!$results->EOF) {
46 $facility = $results->fields;
50 <p>
51 <h2><?=$facility['name']?></h2>
52 <?=$facility['street']?><br>
53 <?=$facility['city']?>, <?=$facility['state']?> <?=$facility['postal_code']?><br>
55 </p>
57 <a href="javascript:window.close();"><font class=title><?print $titleres{"fname"} . " " . $titleres{"lname"};?></font></a><br>
58 <span class=text>Generated on: <?print date("Y-m-d");?></span>
59 <br>
62 //$provider = getProviderName($titleres['providerID']);
64 //print "Provider: " . $provider . "</br>";
66 $inclookupres = sqlStatement("select distinct formdir from forms where pid='$pid'");
67 while($result = sqlFetchArray($inclookupres)) {
68 include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
71 $printed = false;
73 foreach ($ar as $key => $val) {
74 if(!empty($ar['newpatient'])){
75 foreach ($ar['newpatient'] as $be) {
77 $ta = split(":",$be);
78 $billing = getPatientBillingEncounter($pid,$ta[1]);
80 if(!$printed){
81 foreach ($billing as $b) {
82 if(!empty($b['provider_name'])){
83 echo "Provider: " . $b['provider_name'] . "<br>";
84 $printed = true;
85 break;
92 if (stristr($key,"include_")) {
93 //print "include: $val<br>\n";
95 if ($val == "demographics") {
97 print "<font class=bold>Patient Data:</font><br>";
98 printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
100 } elseif ($val == "history") {
102 print "<font class=bold>History Data:</font><br>";
103 printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
105 } elseif ($val == "employer") {
107 print "<font class=bold>Employer Data:</font><br>";
108 printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
110 } elseif ($val == "insurance") {
112 print "<font class=bold>Primary Insurance Data:</font><br>";
113 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
114 print "<font class=bold>Secondary Insurance Data:</font><br>";
115 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
117 print "<font class=bold>Tertiary Insurance Data:</font><br>";
118 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
120 } elseif ($val == "billing") {
121 print "<font class=bold>Billing Information:</font><br>";
122 if (count($ar['newpatient']) > 0) {
123 $billings = array();
124 echo "<table>";
125 echo "<tr><td width=\"400\" class=bold>Code</td><td class=bold>Fee</td></tr>\n";
126 $total = 0.00;
127 $copays = 0.00;
128 foreach ($ar['newpatient'] as $be) {
129 $ta = split(":",$be);
130 $billing = getPatientBillingEncounter($pid,$ta[1]);
131 $billings[] = $billing;
132 foreach ($billing as $b) {
133 echo "<tr>\n";
134 echo "<td class=text>";
135 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
136 echo "</td>\n";
137 echo "<td class=text>";
138 echo $b['fee'];
139 echo "</td>\n";
140 echo "</tr>\n";
141 $total += $b['fee'];
142 if ($b['code_type'] == "COPAY") {
143 $copays += $b['fee'];
147 echo "<tr><td>&nbsp;</td></tr>";
148 echo "<tr><td class=bold>Sub-Total</td><td class=text>" . sprintf("%0.2f",$total) . "</td></tr>";
149 echo "<tr><td class=bold>Paid</td><td class=text>" . sprintf("%0.2f",$copays) . "</td></tr>";
150 echo "<tr><td class=bold>Total</td><td class=text>" . sprintf("%0.2f",($total - $copays)) . "</td></tr>";
151 echo "</table>";
152 echo "<pre>";
153 //print_r($billings);
154 echo "</pre>";
156 else {
157 printPatientBilling($pid);
160 } elseif ($val == "allergies") {
161 print "<font class=bold>Patient Allergies:</font><br>";
162 printListData($pid, "allergy", "1");
163 } elseif ($val == "medications") {
164 print "<font class=bold>Patient Medications:</font><br>";
165 printListData($pid, "medication", "1");
166 } elseif ($val == "medical_problems") {
167 print "<font class=bold>Patient Medical Problems:</font><br>";
168 printListData($pid, "medical_problem", "1");
169 } elseif ($val == "immunizations") {
170 print "<font class=bold>Patient Immunization:</font><br>";
171 $sql = "select if(i1.administered_date,concat(i1.administered_date,' - ',i2.name) ,substring(i1.note,1,20) ) as immunization_data from immunizations i1 left join immunization i2 on i1.immunization_id = i2.id where i1.patient_id = $pid order by administered_date desc";
173 $result = sqlStatement($sql);
175 while ($row=sqlFetchArray($result)){
176 echo "<span class=text> " . $row{'immunization_data'} . "</span>
177 <br>\n";
179 } elseif ($val == "notes") {
180 print "<font class=bold>Patient Notes:</font><br>";
181 printPatientNotes($pid);
182 } elseif ($val == "transactions") {
183 print "<font class=bold>Patient Transactions:</font><br>";
184 printPatientTransactions($pid);
186 } else {
187 if ($key == "documents") {
188 echo "<br><br>";
189 foreach($val as $valkey => $valvalue) {
190 $document_id = $valvalue;
191 if (!is_numeric($document_id)) continue;
192 $d = new Document($document_id);
193 $fname = basename($d->get_url());
194 $extension = substr($fname, strrpos($fname,"."));
195 echo "Document '" . $fname ."'<br>";
196 $notes = Note::notes_factory($d->get_id());
197 echo "<table>";
198 foreach ($notes as $note) {
200 echo '<tr>';
201 echo '<td>Note #' . $note->get_id() . '</td>';
202 echo '</tr>';
203 echo '<tr>';
204 echo '<td>Date: '.$note->get_date().'</td>';
205 echo '</tr>';
206 echo '<tr>';
207 echo '<td>'.$note->get_note().'<br><br></td>';
208 echo '</tr>';
211 echo "</table>";
212 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
213 echo '<img src="' . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=&document_id=" . $document_id . '"><br><br>';
215 else {
216 echo "<b>NOTE</b>: Document '" . $fname ."' cannot be displayed inline becuase its type is not supported by the browser.<br><br>";
220 else {
221 //print "$key:$val<br>\n";
222 foreach ($val as $valkey => $valvalue ) {
223 preg_match_all('/^(\d+?)\:(\d+?)$/',$valvalue,$res);
225 $form_id = $res[1][0];
226 $form_encounter = $res[2][0];
227 //print $res[0][0] . " " . $res[1][0] . " " . $res[2][0] . "<br>\n";
229 $formres = getFormNameByFormdir($key);
230 $dateres = getEncounterDateByEncounter($form_encounter);
231 print "<span class=bold>" . $formres{"form_name"} . "</span><span class=text>(" . date("Y-m-d",strtotime($dateres{"date"})) . ")" . "</span><br>\n";
232 call_user_func($key . "_report", $pid, $form_encounter, $N, $form_id);
238 print "</br></br>Signature: _______________________________</br>";
243 </body>
244 </html>