Fixes and enhancements of the newcrop erx module.
[openemr.git] / interface / patient_file / summary / stats.php
blobf91622df5d6a65ab0b24366c2520b9cc957a9ae9
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");
15 include_once("$srcdir/formdata.inc.php");
18 <div id="patient_stats_summary">
20 <?php
21 $thisauth = acl_check('patients', 'med');
22 if ($thisauth) {
23 $tmp = getPatientData($pid, "squad");
24 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
25 $thisauth = 0;
27 if (!$thisauth) {
28 echo "<p>(".htmlspecialchars(xl('Issues not authorized'),ENT_NOQUOTES).")</p>\n";
29 echo "</body>\n</html>\n";
30 exit();
34 <script type='text/javascript'>
35 function load_location( location ) {
36 top.restoreSession();
37 if ( !top.frames["RTop"] ) {
38 document.location=location;
39 } else {
40 top.frames["RTop"].location=location;
43 </script>
45 <table id="patient_stats_issues">
47 <?php
48 $numcols = '1';
49 $ix = 0;
50 $erx_upload_complete = 0;
51 $old_key="";$display_current_medications_below=1;
52 foreach ($ISSUE_TYPES as $key => $arr) {
53 // $result = getListByType($pid, $key, "id,title,begdate,enddate,returndate,extrainfo", "all", "all", 0);
55 $query = "SELECT * FROM lists WHERE pid = ? AND type = ? AND ";
56 $query .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
57 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $key=='medication')
58 $query .= "and erx_uploaded != '1' ";
59 if($GLOBALS['erx_enable'] && $GLOBALS['erx_allergy_display'] && $key=='allergy')
60 $query .= "and erx_uploaded != '1' ";
61 $query .= "ORDER BY begdate";
62 $pres = sqlStatement($query, array($pid, $key) );
63 if($old_key=="medication" && $GLOBALS['erx_enable'] && $erx_upload_complete == 1)
65 $display_current_medications_below=0;
67 <div>
68 <table id="patient_stats_prescriptions">
69 <?php if($GLOBALS['erx_enable']){ ?>
70 <tr><td>
71 <?php if ($_POST['embeddedScreen']) {
72 $widgetTitle = '';
73 $widgetTitle = xl('Current Medications');
74 $widgetLabel = "current_prescriptions";
75 $widgetButtonLabel = '';
76 $widgetButtonLink = '';
77 $widgetAuth = false;
78 $widgetButtonClass = '';
79 $bodyClass = "summary_item small";
80 $fixedWidth = false;
81 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
85 <?php
86 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
88 <table>
89 <?php
90 if(sqlNumRows($res)==0)
93 <tr class=text>
94 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
95 </tr>
96 <?php
98 while($row_currentMed=sqlFetchArray($res))
100 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),htmlspecialchars($row_currentMed['unit'],ENT_NOQUOTES));
101 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),htmlspecialchars($row_currentMed['form'],ENT_NOQUOTES));
102 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),htmlspecialchars($row_currentMed['route'],ENT_NOQUOTES));
103 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),htmlspecialchars($row_currentMed['interval'],ENT_NOQUOTES));
105 <tr class=text >
106 <td><?php echo htmlspecialchars($row_currentMed['drug'],ENT_NOQUOTES);?></td>
107 <td><?php
108 $unit='';
109 if($row_currentMed['size']>0)
110 $unit=$row_currentMed['size']." ".$runit." ";
111 echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);
112 ?></td>
113 </tr>
114 <?php
117 </table>
118 </td></tr>
119 <?php }
120 $old_key='';
122 if (sqlNumRows($pres) > 0 || $ix == 0 || $key == "allergy" || $key == "medication") {
123 $old_key=$key;
124 if ($_POST['embeddedScreen']) {
126 if($GLOBALS['erx_enable'] && $key == "medication"){
127 $query_uploaded = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
128 $query_uploaded .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
129 $query_uploaded .= "and erx_uploaded != '1' ";
130 $query_uploaded .= "ORDER BY begdate";
131 $res_uploaded = sqlStatement($query_uploaded, array($pid) );
132 if(sqlNumRows($res_uploaded) == 0){
133 $erx_upload_complete = 1;
134 continue;
138 echo "<tr><td>";
139 // Issues expand collapse widget
140 $widgetTitle = $arr[0];
141 $widgetLabel = $key;
142 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
144 $widgetButtonLabel = xl("Add");
145 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
147 else
149 $widgetButtonLabel = xl("Edit");
150 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
152 $widgetButtonClass = "";
153 $linkMethod = "javascript";
154 $bodyClass = "summary_item small";
155 $widgetAuth = true;
156 $fixedWidth = false;
157 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
159 else { ?>
160 <tr class='issuetitle'>
161 <td colspan='$numcols'>
162 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
163 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
164 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
165 </a>
166 </td>
167 </tr>
168 <?php }
169 echo "<table>";
170 if (sqlNumRows($pres) == 0) {
171 if ( getListTouch($pid,$key) ) {
172 // Data entry has happened to this type, so can display an explicit None.
173 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
175 else {
176 // Data entry has not happened to this type, so show 'Nothing Recorded"
177 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
181 while ($row = sqlFetchArray($pres)) {
182 // output each issue for the $ISSUE_TYPE
183 if (!$row['enddate'] && !$row['returndate'])
184 $rowclass="noend_noreturn";
185 else if (!$row['enddate'] && $row['returndate'])
186 $rowclass="noend";
187 else if ($row['enddate'] && !$row['returndate'])
188 $rowclass = "noreturn";
190 echo " <tr class='text $rowclass;'>\n";
192 //turn allergies red and bold and show the reaction (if exist)
193 if ($key == "allergy") {
194 $reaction = "";
195 if (!empty($row['reaction'])) {
196 $reaction = " (" . $row['reaction'] . ")";
198 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
200 else {
201 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
204 echo " </tr>\n";
206 echo "</table>";
207 if ($_POST['embeddedScreen']) {
208 echo "</div></td></tr>";
212 ++$ix;
215 </table> <!-- end patient_stats_issues -->
217 <table id="patient_stats_spreadsheets">
218 <?php
220 // Show spreadsheet forms if any are present.
222 $need_head = true;
223 foreach (array('treatment_protocols','injury_log') as $formname) {
224 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
225 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
226 "form_" . add_escape_custom($formname) .
227 " AS tp WHERE forms.pid = ? AND " .
228 "forms.formdir = ? AND tp.id = forms.form_id AND " .
229 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
230 "ORDER BY tp.value DESC", array($pid, $formname) );
231 if (sqlNumRows($dres) > 0 && $need_head) {
232 $need_head = false;
233 echo " <tr>\n";
234 echo " <td colspan='$numcols' valign='top'>\n";
235 echo " <span class='title'>Injury Log</span>\n";
236 echo " </td>\n";
237 echo " </tr>\n";
239 while ($row = sqlFetchArray($dres)) {
240 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
241 echo " <tr>\n";
242 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
243 echo "<a class='link' href='javascript:;' ";
244 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
245 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
246 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
247 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
248 echo " </tr>\n";
253 </table> <!-- end patient_stats_spreadsheets -->
255 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
256 <div>
257 <table id="patient_stats_imm">
258 <tr>
259 <?php if ($_POST['embeddedScreen']) {
260 echo "<td>";
261 // Issues expand collapse widget
262 $widgetTitle = xl('Immunizations');
263 $widgetLabel = "immunizations";
264 $widgetButtonLabel = xl("Edit");
265 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
266 $widgetButtonClass = "";
267 $linkMethod = "javascript";
268 $bodyClass = "summary_item small";
269 $widgetAuth = true;
270 $fixedWidth = false;
271 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
273 else { ?>
274 <td colspan='<?php echo $numcols ?>' valign='top'>
275 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
276 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
277 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
278 </a>
279 </td></tr>
280 <tr><td>
281 <?php } ?>
283 <?php
284 $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, ".
285 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
286 " from immunizations i1 ".
287 " left join codes c on CAST(IFNULL(i1.cvx_code,0) AS CHAR) = c.code ".
288 " left join code_types ct on c.code_type = ct.ct_id ".
289 " where i1.patient_id = ? ".
290 " AND (( i1.cvx_code = '0' OR i1.cvx_code IS NULL ) OR ".
291 " ( ( i1.cvx_code != '0' AND i1.cvx_code IS NOT NULL ) AND ct.ct_key = 'CVX') ) ".
292 " order by i1.administered_date desc";
294 $result = sqlStatement($sql, array($pid) );
296 if (sqlNumRows($result) == 0) {
297 echo " <table><tr>\n";
298 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
299 echo " </tr></table>\n";
302 while ($row=sqlFetchArray($result)){
303 echo "&nbsp;&nbsp;";
304 echo "<a class='link'";
305 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
306 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
308 // Figure out which name to use (ie. from cvx list or from the custom list)
309 if ($GLOBALS['use_custom_immun_list']) {
310 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
312 else {
313 if (!(empty($row['cvx_text']))) {
314 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
316 else {
317 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
320 echo "</a><br>\n";
324 <?php if ($_POST['embeddedScreen']) {
325 echo "</td></tr></div>";
326 } ?>
328 </td>
329 </tr>
330 </table> <!-- end patient_stats_imm-->
331 </div>
332 <?php } ?>
334 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
335 <div>
336 <table id="patient_stats_prescriptions">
337 <?php if($GLOBALS['erx_enable'] && $display_current_medications_below==1){ ?>
338 <tr><td>
339 <?php if ($_POST['embeddedScreen']) {
340 $widgetTitle = '';
341 $widgetTitle = xl('Current Medications');
342 $widgetLabel = "current_prescriptions";
343 $widgetButtonLabel = '';
344 $widgetButtonLink = '';
345 $widgetAuth = false;
346 $widgetButtonClass = '';
347 $bodyClass = "summary_item small";
348 $fixedWidth = false;
349 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
353 <?php
354 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
356 <table>
357 <?php
358 if(sqlNumRows($res)==0)
361 <tr class=text>
362 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
363 </tr>
364 <?php
366 while($row_currentMed=sqlFetchArray($res))
368 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),$row_currentMed['unit']);
369 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
370 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
371 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
373 <tr class=text >
374 <td><?php echo $row_currentMed['drug'];?></td>
375 <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>
376 </tr>
377 <?php
380 </table>
381 </td></tr>
382 <?php } ?>
383 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
385 <?php if ($_POST['embeddedScreen']) {
386 // Issues expand collapse widget
387 $widgetLabel = "prescriptions";
388 $linkMethod = "html";
389 if($GLOBALS['erx_enable'])
391 $widgetTitle = xl('Prescription History');
392 $widgetButtonLabel = xl("Add/Edit eRx");
393 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
394 $widgetButtonClass = "";
396 else
398 $widgetTitle = xl('Prescription');
399 $widgetButtonLabel = xl("Edit");
400 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
401 $widgetButtonClass = "iframe rx_modal";
403 $bodyClass = "summary_item small";
404 $widgetAuth = true;
405 $fixedWidth = false;
406 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
408 else { ?>
409 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
410 </td></tr>
411 </tr><td>
412 <?php } ?>
414 <?php
415 $cwd= getcwd();
416 chdir("../../../");
417 require_once("library/classes/Controller.class.php");
418 $c = new Controller();
419 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
422 <?php if ($_POST['embeddedScreen']) {
423 echo "</div>";
424 } ?>
426 </td></tr>
428 <?php }
430 if($erx_upload_complete == 1){
431 echo "<tr><td>";
432 // Old Medication Widget
433 $widgetTitle = "Old Medication";
434 $widgetLabel = "old_medication";
435 $widgetButtonLabel = xl("Edit");
436 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=medication\")";
437 $widgetButtonClass = "";
438 $linkMethod = "javascript";
439 $bodyClass = "summary_item small";
440 $widgetAuth = true;
441 $fixedWidth = false;
442 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
443 $query_uploaded_old = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
444 $query_uploaded_old .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
445 $query_uploaded_old .= "ORDER BY begdate";
446 $res_uploaded_old = sqlStatement($query_uploaded_old, array($pid) );
447 echo "<table>";
448 while ($row = sqlFetchArray($res_uploaded_old)) {
449 // output each issue for the $ISSUE_TYPE
450 if (!$row['enddate'] && !$row['returndate'])
451 $rowclass="noend_noreturn";
452 else if (!$row['enddate'] && $row['returndate'])
453 $rowclass="noend";
454 else if ($row['enddate'] && !$row['returndate'])
455 $rowclass = "noreturn";
456 echo " <tr class='text $rowclass;'>\n";
457 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
458 echo " </tr>\n";
460 echo "</table>";
461 echo "</div></td></tr>";
465 </table> <!-- end patient_stats_prescriptions -->
466 </div>
467 </div> <!-- end patient_stats_summary -->