Immunization_information_(MU2) changes, take 5.
[openemr.git] / interface / patient_file / summary / stats.php
blob7d89f8f0acb57813f2c4cc5a8d196b7e5daa6b0b
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 $erx_upload_complete = 0;
50 $old_key="";$display_current_medications_below=1;
51 foreach ($ISSUE_TYPES as $key => $arr) {
52 // $result = getListByType($pid, $key, "id,title,begdate,enddate,returndate,extrainfo", "all", "all", 0);
54 $query = "SELECT * FROM lists WHERE pid = ? AND type = ? AND ";
55 $query .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
56 if($GLOBALS['erx_enable'] && $GLOBALS['erx_medication_display'] && $key=='medication')
57 $query .= "and erx_uploaded != '1' ";
58 if($GLOBALS['erx_enable'] && $GLOBALS['erx_allergy_display'] && $key=='allergy')
59 $query .= "and erx_uploaded != '1' ";
60 $query .= "ORDER BY begdate";
61 $pres = sqlStatement($query, array($pid, $key) );
62 if($old_key=="medication" && $GLOBALS['erx_enable'] && $erx_upload_complete == 1)
64 $display_current_medications_below=0;
66 <div>
67 <table id="patient_stats_prescriptions">
68 <?php if($GLOBALS['erx_enable']){ ?>
69 <tr><td>
70 <?php if ($_POST['embeddedScreen']) {
71 $widgetTitle = '';
72 $widgetTitle = xl('Current Medications');
73 $widgetLabel = "current_prescriptions";
74 $widgetButtonLabel = '';
75 $widgetButtonLink = '';
76 $widgetAuth = false;
77 $widgetButtonClass = '';
78 $bodyClass = "summary_item small";
79 $fixedWidth = false;
80 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
84 <?php
85 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
87 <table>
88 <?php
89 if(sqlNumRows($res)==0)
92 <tr class=text>
93 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
94 </tr>
95 <?php
97 while($row_currentMed=sqlFetchArray($res))
99 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),htmlspecialchars($row_currentMed['unit'],ENT_NOQUOTES));
100 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),htmlspecialchars($row_currentMed['form'],ENT_NOQUOTES));
101 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),htmlspecialchars($row_currentMed['route'],ENT_NOQUOTES));
102 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),htmlspecialchars($row_currentMed['interval'],ENT_NOQUOTES));
104 <tr class=text >
105 <td><?php echo htmlspecialchars($row_currentMed['drug'],ENT_NOQUOTES);?></td>
106 <td><?php
107 $unit='';
108 if($row_currentMed['size']>0)
109 $unit=$row_currentMed['size']." ".$runit." ";
110 echo htmlspecialchars($unit." ".$row_currentMed['dosage']." ".$rin." ".$rroute." ".$rint,ENT_NOQUOTES);
111 ?></td>
112 </tr>
113 <?php
116 </table>
117 </td></tr>
118 <?php }
119 $old_key='';
121 if (sqlNumRows($pres) > 0 || $arr[4] == 1) {
122 $old_key=$key;
123 if ($_POST['embeddedScreen']) {
125 if($GLOBALS['erx_enable'] && $key == "medication"){
126 $query_uploaded = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
127 $query_uploaded .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
128 $query_uploaded .= "and erx_uploaded != '1' ";
129 $query_uploaded .= "ORDER BY begdate";
130 $res_uploaded = sqlStatement($query_uploaded, array($pid) );
131 if(sqlNumRows($res_uploaded) == 0){
132 $erx_upload_complete = 1;
133 continue;
137 echo "<tr><td>";
138 // Issues expand collapse widget
139 $widgetTitle = $arr[0];
140 $widgetLabel = $key;
141 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
143 $widgetButtonLabel = xl("Add");
144 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
146 else
148 $widgetButtonLabel = xl("Edit");
149 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
151 $widgetButtonClass = "";
152 $linkMethod = "javascript";
153 $bodyClass = "summary_item small";
154 $widgetAuth = true;
155 $fixedWidth = false;
156 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
158 else { ?>
159 <tr class='issuetitle'>
160 <td colspan='$numcols'>
161 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
162 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
163 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
164 </a>
165 </td>
166 </tr>
167 <?php }
168 echo "<table>";
169 if (sqlNumRows($pres) == 0) {
170 if ( getListTouch($pid,$key) ) {
171 // Data entry has happened to this type, so can display an explicit None.
172 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
174 else {
175 // Data entry has not happened to this type, so show 'Nothing Recorded"
176 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
180 while ($row = sqlFetchArray($pres)) {
181 // output each issue for the $ISSUE_TYPE
182 if (!$row['enddate'] && !$row['returndate'])
183 $rowclass="noend_noreturn";
184 else if (!$row['enddate'] && $row['returndate'])
185 $rowclass="noend";
186 else if ($row['enddate'] && !$row['returndate'])
187 $rowclass = "noreturn";
189 echo " <tr class='text $rowclass;'>\n";
191 //turn allergies red and bold and show the reaction (if exist)
192 if ($key == "allergy") {
193 $reaction = "";
194 if (!empty($row['reaction'])) {
195 $reaction = " (" . $row['reaction'] . ")";
197 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
199 else {
200 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
203 echo " </tr>\n";
205 echo "</table>";
206 if ($_POST['embeddedScreen']) {
207 echo "</div></td></tr>";
213 </table> <!-- end patient_stats_issues -->
215 <table id="patient_stats_spreadsheets">
216 <?php
218 // Show spreadsheet forms if any are present.
220 $need_head = true;
221 foreach (array('treatment_protocols','injury_log') as $formname) {
222 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
223 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
224 "form_" . add_escape_custom($formname) .
225 " AS tp WHERE forms.pid = ? AND " .
226 "forms.formdir = ? AND tp.id = forms.form_id AND " .
227 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
228 "ORDER BY tp.value DESC", array($pid, $formname) );
229 if (sqlNumRows($dres) > 0 && $need_head) {
230 $need_head = false;
231 echo " <tr>\n";
232 echo " <td colspan='$numcols' valign='top'>\n";
233 echo " <span class='title'>Injury Log</span>\n";
234 echo " </td>\n";
235 echo " </tr>\n";
237 while ($row = sqlFetchArray($dres)) {
238 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
239 echo " <tr>\n";
240 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
241 echo "<a class='link' href='javascript:;' ";
242 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
243 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
244 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
245 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
246 echo " </tr>\n";
251 </table> <!-- end patient_stats_spreadsheets -->
253 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
254 <div>
255 <table id="patient_stats_imm">
256 <tr>
257 <?php if ($_POST['embeddedScreen']) {
258 echo "<td>";
259 // Issues expand collapse widget
260 $widgetTitle = xl('Immunizations');
261 $widgetLabel = "immunizations";
262 $widgetButtonLabel = xl("Edit");
263 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
264 $widgetButtonClass = "";
265 $linkMethod = "javascript";
266 $bodyClass = "summary_item small";
267 $widgetAuth = true;
268 $fixedWidth = false;
269 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
271 else { ?>
272 <td colspan='<?php echo $numcols ?>' valign='top'>
273 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
274 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
275 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
276 </a>
277 </td></tr>
278 <tr><td>
279 <?php } ?>
281 <?php
282 $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, ".
283 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
284 " from immunizations i1 ".
285 " left join code_types ct on ct.ct_key = 'CVX' ".
286 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
287 " where i1.patient_id = ? ".
288 " and i1.added_erroneously = 0".
289 " order by i1.administered_date desc";
291 $result = sqlStatement($sql, array($pid) );
293 if (sqlNumRows($result) == 0) {
294 echo " <table><tr>\n";
295 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
296 echo " </tr></table>\n";
299 while ($row=sqlFetchArray($result)){
300 echo "&nbsp;&nbsp;";
301 echo "<a class='link'";
302 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
303 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
305 // Figure out which name to use (ie. from cvx list or from the custom list)
306 if ($GLOBALS['use_custom_immun_list']) {
307 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
309 else {
310 if (!(empty($row['cvx_text']))) {
311 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
313 else {
314 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
317 echo "</a><br>\n";
321 <?php if ($_POST['embeddedScreen']) {
322 echo "</td></tr></div>";
323 } ?>
325 </td>
326 </tr>
327 </table> <!-- end patient_stats_imm-->
328 </div>
329 <?php } ?>
331 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
332 <div>
333 <table id="patient_stats_prescriptions">
334 <?php if($GLOBALS['erx_enable'] && $display_current_medications_below==1){ ?>
335 <tr><td>
336 <?php if ($_POST['embeddedScreen']) {
337 $widgetTitle = '';
338 $widgetTitle = xl('Current Medications');
339 $widgetLabel = "current_prescriptions";
340 $widgetButtonLabel = '';
341 $widgetButtonLink = '';
342 $widgetAuth = false;
343 $widgetButtonClass = '';
344 $bodyClass = "summary_item small";
345 $fixedWidth = false;
346 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
350 <?php
351 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
353 <table>
354 <?php
355 if(sqlNumRows($res)==0)
358 <tr class=text>
359 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
360 </tr>
361 <?php
363 while($row_currentMed=sqlFetchArray($res))
365 $runit=generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'),$row_currentMed['unit']);
366 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
367 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
368 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
370 <tr class=text >
371 <td><?php echo $row_currentMed['drug'];?></td>
372 <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>
373 </tr>
374 <?php
377 </table>
378 </td></tr>
379 <?php } ?>
380 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
382 <?php if ($_POST['embeddedScreen']) {
383 // Issues expand collapse widget
384 $widgetLabel = "prescriptions";
385 $linkMethod = "html";
386 if($GLOBALS['erx_enable'])
388 $widgetTitle = xl('Prescription History');
389 $widgetButtonLabel = xl("Add/Edit eRx");
390 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
391 $widgetButtonClass = "";
393 else
395 $widgetTitle = xl('Prescription');
396 $widgetButtonLabel = xl("Edit");
397 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
398 $widgetButtonClass = "iframe rx_modal";
400 $bodyClass = "summary_item small";
401 $widgetAuth = true;
402 $fixedWidth = false;
403 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
405 else { ?>
406 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
407 </td></tr>
408 </tr><td>
409 <?php } ?>
411 <?php
412 $cwd= getcwd();
413 chdir("../../../");
414 require_once("library/classes/Controller.class.php");
415 $c = new Controller();
416 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
419 <?php if ($_POST['embeddedScreen']) {
420 echo "</div>";
421 } ?>
423 </td></tr>
425 <?php }
427 if($erx_upload_complete == 1){
428 echo "<tr><td>";
429 // Old Medication Widget
430 $widgetTitle = "Old Medication";
431 $widgetLabel = "old_medication";
432 $widgetButtonLabel = xl("Edit");
433 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=medication\")";
434 $widgetButtonClass = "";
435 $linkMethod = "javascript";
436 $bodyClass = "summary_item small";
437 $widgetAuth = true;
438 $fixedWidth = false;
439 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
440 $query_uploaded_old = "SELECT * FROM lists WHERE pid = ? AND type = 'medication' AND ";
441 $query_uploaded_old .= "(enddate is null or enddate = '' or enddate = '0000-00-00') ";
442 $query_uploaded_old .= "ORDER BY begdate";
443 $res_uploaded_old = sqlStatement($query_uploaded_old, array($pid) );
444 echo "<table>";
445 while ($row = sqlFetchArray($res_uploaded_old)) {
446 // output each issue for the $ISSUE_TYPE
447 if (!$row['enddate'] && !$row['returndate'])
448 $rowclass="noend_noreturn";
449 else if (!$row['enddate'] && $row['returndate'])
450 $rowclass="noend";
451 else if ($row['enddate'] && !$row['returndate'])
452 $rowclass = "noreturn";
453 echo " <tr class='text $rowclass;'>\n";
454 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
455 echo " </tr>\n";
457 echo "</table>";
458 echo "</div></td></tr>";
462 </table> <!-- end patient_stats_prescriptions -->
463 </div>
464 </div> <!-- end patient_stats_summary -->