Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / interface / patient_file / summary / stats.php
blob0218673c8a7cc8e21af51dcd385dc714f4df5478
1 <?php
3 //SANITIZE ALL ESCAPES
4 $sanitize_all_escapes=true;
5 //
7 //STOP FAKE REGISTER GLOBALS
8 $fake_register_globals=false;
9 //
11 include_once("../../globals.php");
12 include_once("$srcdir/lists.inc");
13 include_once("$srcdir/acl.inc");
14 include_once("$srcdir/options.inc.php");
17 <div id="patient_stats_summary">
19 <?php
20 $thisauth = acl_check('patients', 'med');
21 if ($thisauth) {
22 $tmp = getPatientData($pid, "squad");
23 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
24 $thisauth = 0;
26 if (!$thisauth) {
27 echo "<p>(".htmlspecialchars(xl('Issues not authorized'),ENT_NOQUOTES).")</p>\n";
28 echo "</body>\n</html>\n";
29 exit();
33 <script type='text/javascript'>
34 function load_location( location ) {
35 top.restoreSession();
36 if ( !top.frames["RTop"] ) {
37 document.location=location;
38 } else {
39 top.frames["RTop"].location=location;
42 </script>
44 <table id="patient_stats_issues">
46 <?php
47 $numcols = '1';
48 $erx_upload_complete = 0;
49 $old_key="";$display_current_medications_below=1;
50 foreach ($ISSUE_TYPES as $key => $arr) {
51 // $result = getListByType($pid, $key, "id,title,begdate,enddate,returndate,extrainfo", "all", "all", 0);
53 $query = "SELECT * FROM lists WHERE pid = ? AND type = ? AND ";
54 $query .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
55 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $key=='medication')
56 $query .= "and erx_uploaded != '1' ";
57 if($GLOBALS['erx_enable'] && $GLOBALS['erx_allergy_display'] && $key=='allergy')
58 $query .= "and erx_uploaded != '1' ";
59 $query .= "ORDER BY begdate";
60 $pres = sqlStatement($query, array($pid, $key) );
61 if($old_key=="medication" && $GLOBALS['erx_enable'] && $erx_upload_complete == 1)
63 $display_current_medications_below=0;
65 <div>
66 <table id="patient_stats_prescriptions">
67 <?php if($GLOBALS['erx_enable']){ ?>
68 <tr><td>
69 <?php if ($_POST['embeddedScreen']) {
70 $widgetTitle = '';
71 $widgetTitle = xl('Current Medications');
72 $widgetLabel = "current_prescriptions";
73 $widgetButtonLabel = '';
74 $widgetButtonLink = '';
75 $widgetAuth = false;
76 $widgetButtonClass = '';
77 $bodyClass = "summary_item small";
78 $fixedWidth = false;
79 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
83 <?php
84 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
86 <table>
87 <?php
88 if(sqlNumRows($res)==0)
91 <tr class=text>
92 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
93 </tr>
94 <?php
96 while($row_currentMed=sqlFetchArray($res))
98 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),htmlspecialchars($row_currentMed['unit'],ENT_NOQUOTES));
99 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),htmlspecialchars($row_currentMed['form'],ENT_NOQUOTES));
100 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),htmlspecialchars($row_currentMed['route'],ENT_NOQUOTES));
101 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),htmlspecialchars($row_currentMed['interval'],ENT_NOQUOTES));
103 <tr class=text >
104 <td><?php echo htmlspecialchars($row_currentMed['drug'],ENT_NOQUOTES);?></td>
105 <td><?php
106 $unit='';
107 if($row_currentMed['size']>0)
108 $unit=$row_currentMed['size']." ".$runit." ";
109 echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);
110 ?></td>
111 </tr>
112 <?php
115 </table>
116 </td></tr>
117 <?php }
118 $old_key='';
120 if (sqlNumRows($pres) > 0 || $arr[4] == 1) {
121 $old_key=$key;
122 if ($_POST['embeddedScreen']) {
124 if($GLOBALS['erx_enable'] && $key == "medication"){
125 $query_uploaded = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
126 $query_uploaded .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
127 $query_uploaded .= "and erx_uploaded != '1' ";
128 $query_uploaded .= "ORDER BY begdate";
129 $res_uploaded = sqlStatement($query_uploaded, array($pid) );
130 if(sqlNumRows($res_uploaded) == 0){
131 $erx_upload_complete = 1;
132 continue;
136 echo "<tr><td>";
137 // Issues expand collapse widget
138 $widgetTitle = $arr[0];
139 $widgetLabel = $key;
140 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
142 $widgetButtonLabel = xl("Add");
143 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
145 else
147 $widgetButtonLabel = xl("Edit");
148 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
150 $widgetButtonClass = "";
151 $linkMethod = "javascript";
152 $bodyClass = "summary_item small";
153 $widgetAuth = true;
154 $fixedWidth = false;
155 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
157 else { ?>
158 <tr class='issuetitle'>
159 <td colspan='$numcols'>
160 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
161 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
162 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
163 </a>
164 </td>
165 </tr>
166 <?php }
167 echo "<table>";
168 if (sqlNumRows($pres) == 0) {
169 if ( getListTouch($pid,$key) ) {
170 // Data entry has happened to this type, so can display an explicit None.
171 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
173 else {
174 // Data entry has not happened to this type, so show 'Nothing Recorded"
175 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
179 while ($row = sqlFetchArray($pres)) {
180 // output each issue for the $ISSUE_TYPE
181 if (!$row['enddate'] && !$row['returndate'])
182 $rowclass="noend_noreturn";
183 else if (!$row['enddate'] && $row['returndate'])
184 $rowclass="noend";
185 else if ($row['enddate'] && !$row['returndate'])
186 $rowclass = "noreturn";
188 echo " <tr class='text $rowclass;'>\n";
190 //turn allergies red and bold and show the reaction (if exist)
191 if ($key == "allergy") {
192 $reaction = "";
193 if (!empty($row['reaction'])) {
194 $reaction = " (" . $row['reaction'] . ")";
196 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
198 else {
199 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
202 echo " </tr>\n";
204 echo "</table>";
205 if ($_POST['embeddedScreen']) {
206 echo "</div></td></tr>";
212 </table> <!-- end patient_stats_issues -->
214 <table id="patient_stats_spreadsheets">
215 <?php
217 // Show spreadsheet forms if any are present.
219 $need_head = true;
220 foreach (array('treatment_protocols','injury_log') as $formname) {
221 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
222 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
223 "form_" . add_escape_custom($formname) .
224 " AS tp WHERE forms.pid = ? AND " .
225 "forms.formdir = ? AND tp.id = forms.form_id AND " .
226 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
227 "ORDER BY tp.value DESC", array($pid, $formname) );
228 if (sqlNumRows($dres) > 0 && $need_head) {
229 $need_head = false;
230 echo " <tr>\n";
231 echo " <td colspan='$numcols' valign='top'>\n";
232 echo " <span class='title'>Injury Log</span>\n";
233 echo " </td>\n";
234 echo " </tr>\n";
236 while ($row = sqlFetchArray($dres)) {
237 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
238 echo " <tr>\n";
239 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
240 echo "<a class='link' href='javascript:;' ";
241 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
242 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
243 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
244 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
245 echo " </tr>\n";
250 </table> <!-- end patient_stats_spreadsheets -->
252 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
253 <div>
254 <table id="patient_stats_imm">
255 <tr>
256 <?php if ($_POST['embeddedScreen']) {
257 echo "<td>";
258 // Issues expand collapse widget
259 $widgetTitle = xl('Immunizations');
260 $widgetLabel = "immunizations";
261 $widgetButtonLabel = xl("Edit");
262 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
263 $widgetButtonClass = "";
264 $linkMethod = "javascript";
265 $bodyClass = "summary_item small";
266 $widgetAuth = true;
267 $fixedWidth = false;
268 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
270 else { ?>
271 <td colspan='<?php echo $numcols ?>' valign='top'>
272 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
273 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
274 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
275 </a>
276 </td></tr>
277 <tr><td>
278 <?php } ?>
280 <?php
281 $sql = "select i1.id as id, i1.immunization_id as immunization_id, i1.cvx_code as cvx_code, c.code_text_short as cvx_text, ".
282 " if (i1.administered_date, concat(i1.administered_date,' - ',c.code_text_short), IF(i1.note,substring(i1.note,1,20),c.code_text_short)) as immunization_data ".
283 " from immunizations i1 ".
284 " left join code_types ct on ct.ct_key = 'CVX' ".
285 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
286 " where i1.patient_id = ? ".
287 " and i1.added_erroneously = 0".
288 " order by i1.administered_date desc";
290 $result = sqlStatement($sql, array($pid) );
292 if (sqlNumRows($result) == 0) {
293 echo " <table><tr>\n";
294 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
295 echo " </tr></table>\n";
298 while ($row=sqlFetchArray($result)){
299 echo "&nbsp;&nbsp;";
300 echo "<a class='link'";
301 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
302 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
304 // Figure out which name to use (ie. from cvx list or from the custom list)
305 if ($GLOBALS['use_custom_immun_list']) {
306 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
308 else {
309 if (!(empty($row['cvx_text']))) {
310 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
312 else {
313 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
316 echo "</a><br>\n";
320 <?php if ($_POST['embeddedScreen']) {
321 echo "</td></tr></div>";
322 } ?>
324 </td>
325 </tr>
326 </table> <!-- end patient_stats_imm-->
327 </div>
328 <?php } ?>
330 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
331 <div>
332 <table id="patient_stats_prescriptions">
333 <?php if($GLOBALS['erx_enable'] && $display_current_medications_below==1){ ?>
334 <tr><td>
335 <?php if ($_POST['embeddedScreen']) {
336 $widgetTitle = '';
337 $widgetTitle = xl('Current Medications');
338 $widgetLabel = "current_prescriptions";
339 $widgetButtonLabel = '';
340 $widgetButtonLink = '';
341 $widgetAuth = false;
342 $widgetButtonClass = '';
343 $bodyClass = "summary_item small";
344 $fixedWidth = false;
345 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
349 <?php
350 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
352 <table>
353 <?php
354 if(sqlNumRows($res)==0)
357 <tr class=text>
358 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
359 </tr>
360 <?php
362 while($row_currentMed=sqlFetchArray($res))
364 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),$row_currentMed['unit']);
365 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
366 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
367 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
369 <tr class=text >
370 <td><?php echo $row_currentMed['drug'];?></td>
371 <td><?php $unit=''; if($row_currentMed['size']>0) $unit=$row_currentMed['size']." ".$runit." "; echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);?></td>
372 </tr>
373 <?php
376 </table>
377 </td></tr>
378 <?php } ?>
379 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
381 <?php if ($_POST['embeddedScreen']) {
382 // Issues expand collapse widget
383 $widgetLabel = "prescriptions";
384 $linkMethod = "html";
385 if($GLOBALS['erx_enable'])
387 $widgetTitle = xl('Prescription History');
388 $widgetButtonLabel = xl("Add/Edit eRx");
389 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
390 $widgetButtonClass = "";
392 else
394 $widgetTitle = xl('Prescription');
395 $widgetButtonLabel = xl("Edit");
396 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
397 $widgetButtonClass = "iframe rx_modal";
399 $bodyClass = "summary_item small";
400 $widgetAuth = true;
401 $fixedWidth = false;
402 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
404 else { ?>
405 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
406 </td></tr>
407 </tr><td>
408 <?php } ?>
410 <?php
411 $cwd= getcwd();
412 chdir("../../../");
413 $c = new Controller();
414 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
417 <?php if ($_POST['embeddedScreen']) {
418 echo "</div>";
419 } ?>
421 </td></tr>
423 <?php }
425 if($erx_upload_complete == 1){
426 echo "<tr><td>";
427 // Old Medication Widget
428 $widgetTitle = "Old Medication";
429 $widgetLabel = "old_medication";
430 $widgetButtonLabel = xl("Edit");
431 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=medication\")";
432 $widgetButtonClass = "";
433 $linkMethod = "javascript";
434 $bodyClass = "summary_item small";
435 $widgetAuth = true;
436 $fixedWidth = false;
437 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
438 $query_uploaded_old = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
439 $query_uploaded_old .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
440 $query_uploaded_old .= "ORDER BY begdate";
441 $res_uploaded_old = sqlStatement($query_uploaded_old, array($pid) );
442 echo "<table>";
443 while ($row = sqlFetchArray($res_uploaded_old)) {
444 // output each issue for the $ISSUE_TYPE
445 if (!$row['enddate'] && !$row['returndate'])
446 $rowclass="noend_noreturn";
447 else if (!$row['enddate'] && $row['returndate'])
448 $rowclass="noend";
449 else if ($row['enddate'] && !$row['returndate'])
450 $rowclass = "noreturn";
451 echo " <tr class='text $rowclass;'>\n";
452 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
453 echo " </tr>\n";
455 echo "</table>";
456 echo "</div></td></tr>";
460 </table> <!-- end patient_stats_prescriptions -->
461 </div>
462 </div> <!-- end patient_stats_summary -->