migrated the immunization table to the list_options table along with applicable inter...
[openemr.git] / interface / patient_file / summary / stats.php
blob4683e57bed6b7b0e5af75a96e3e20cee1e821888
1 <?php
2 include_once("../../globals.php");
3 include_once("$srcdir/lists.inc");
4 include_once("$srcdir/acl.inc");
5 include_once("$srcdir/options.inc.php");
7 // We used to present a more complex list for "medical problem" issues
8 // for athletic teams. However we decided in May 2008 to stop that.
9 // The logic remains in case minds are again changed. -- Rod
11 $fancy_stats = false; // $GLOBALS['athletic_team'];
13 <html>
15 <head>
16 <?php html_header_show();?>
17 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
18 <style>
19 .link {
20 font-family: sans-serif;
21 text-decoration: none;
22 /* color: #000000; */
23 font-size: 8pt;
25 </style>
26 </head>
28 <body class="body_bottom">
30 <div id="patient_stats_summary">
32 <?php
33 $thisauth = acl_check('patients', 'med');
34 if ($thisauth) {
35 $tmp = getPatientData($pid, "squad");
36 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
37 $thisauth = 0;
39 if (!$thisauth) {
40 echo "<p>(".xl('Issues not authorized').")</p>\n";
41 echo "</body>\n</html>\n";
42 exit();
46 <table id="patient_stats_issues">
48 <?php
49 $numcols = $fancy_stats ? '7' : '1';
50 $ix = 0;
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 = $pid AND type = '$key' AND ";
55 if ($fancy_stats) {
56 $query .= "( enddate IS NULL OR returndate IS NULL ) ";
57 } else {
58 $query .= "enddate IS NULL ";
60 $query .= "ORDER BY begdate";
61 $pres = sqlStatement($query);
63 if (mysql_num_rows($pres) > 0 || $ix == 0) {
65 // output a header for the $ISSUE_TYPE
66 echo " <tr class='issuetitle'>\n";
67 echo " <td colspan='$numcols'>\n";
68 echo " <a href='stats_full.php?active=all' target='";
69 echo $GLOBALS['concurrent_layout'] ? "_parent" : "Main";
70 echo "' onclick='top.restoreSession()'><span class='title'>" .
71 $arr[0] . "</span> <span class='more'>$tmore</span></a>\n";
72 echo " </td>\n";
73 echo " </tr>\n";
75 // Show headers if this is a long line.
76 if ($fancy_stats && $arr[3] == 0 && mysql_num_rows($pres) > 0) {
77 echo " <tr class='issueheaders'>\n";
78 echo " <td>&nbsp;&nbsp;<b>" .xl('Title'). "</b></td>\n";
79 echo " <td>&nbsp;<b>" .xl('Diag'). "</b></td>\n";
80 echo " <td>&nbsp;<b>" .xl('Start'). "</b></td>\n";
81 echo " <td>&nbsp;<b>" .xl('Return'). "</b></td>\n";
82 echo " <td>&nbsp;<b>" .xl('Games'). "</b></td>\n";
83 echo " <td class='right'>&nbsp;<b>" .xl('Days'). "</b></td>\n";
84 echo " <td class='right'>&nbsp;<b>" .xl('Enc'). "</b></td>\n";
85 echo " </tr>\n";
88 while ($row = sqlFetchArray($pres)) {
89 // output each issue for the $ISSUE_TYPE
90 if (!$row['enddate'] && !$row['returndate'])
91 $rowclass="noend_noreturn";
92 else if (!$row['enddate'] && $row['returndate'])
93 $rowclass="noend";
94 else if ($row['enddate'] && !$row['returndate'])
95 $rowclass = "noreturn";
97 echo " <tr class='$rowclass;'>\n";
99 if ($fancy_stats && $arr[3] == 0) {
100 $endsecs = $row['returndate'] ? strtotime($row['returndate']) : time();
101 $daysmissed = round(($endsecs - strtotime($row['begdate'])) / (60 * 60 * 24));
102 $ierow = sqlQuery("SELECT count(*) AS count FROM issue_encounter " .
103 "WHERE list_id = '" . $row['id'] . "'");
104 // echo " <td><a class='link' target='Main' href='stats_full.php?active=1'>" .
105 // $row['title'] . "</a></td>\n";
106 echo " <td>&nbsp;&nbsp;" . $row['title'] . "</td>\n";
107 echo " <td>&nbsp;" . $row['diagnosis'] . "</td>\n";
108 echo " <td>&nbsp;" . $row['begdate'] . "</td>\n";
109 echo " <td>&nbsp;" . $row['returndate'] . "</td>\n";
110 echo " <td>&nbsp;" . $row['extrainfo'] . "</td>\n";
111 echo " <td class='right'>&nbsp;$daysmissed</td>\n";
112 echo " <td class='right'>&nbsp;" . $ierow['count'] . "</td>\n";
113 } else {
114 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . $row['title'] . "</td>\n";
117 echo " </tr>\n";
119 // echo " </td>\n";
120 // echo " </tr>\n";
123 ++$ix;
126 </table> <!-- end patient_stats_issues -->
128 <table id="patient_stats_spreadsheets">
129 <?php
131 // Show spreadsheet forms if any are present.
133 $need_head = true;
134 foreach (array('treatment_protocols','injury_log') as $formname) {
135 if (mysql_num_rows(sqlStatement("SHOW TABLES LIKE 'form_$formname'")) > 0) {
136 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
137 "form_$formname AS tp WHERE forms.pid = $pid AND " .
138 "forms.formdir = '$formname' AND tp.id = forms.form_id AND " .
139 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
140 "ORDER BY tp.value DESC");
141 if (mysql_num_rows($dres) > 0 && $need_head) {
142 $need_head = false;
143 echo " <tr>\n";
144 echo " <td colspan='$numcols' valign='top'>\n";
145 echo " <span class='title'>Injury Log</span>\n";
146 echo " </td>\n";
147 echo " </tr>\n";
149 while ($row = sqlFetchArray($dres)) {
150 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
151 echo " <tr>\n";
152 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
153 echo "<a class='link' target='_blank' ";
154 echo "href='../../forms/$formname/new.php?popup=1&id=";
155 echo $row['id'] . "' onclick='top.restoreSession()'>$start_date $template_name</a></td>\n";
156 echo " </tr>\n";
161 </table> <!-- end patient_stats_spreadsheets -->
163 <?php if (!$GLOBALS['weight_loss_clinic']) { ?>
164 <table id="patient_stats_imm">
165 <tr class='issuetitle'>
166 <td colspan='<?php echo $numcols ?>' valign='top'>
167 <a href="immunizations.php"
168 target="<?php echo $GLOBALS['concurrent_layout'] ? "_parent" : "Main"; ?>"
169 onclick="top.restoreSession()">
170 <span class="title"><?php xl('Immunizations','e'); ?></span>
171 <span class=more><?php echo $tmore;?></span></a>
172 </td></tr>
173 <tr><td>
175 <?php
176 $sql = "select i1.id as id, i1.immunization_id as immunization_id,".
177 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
178 " from immunizations i1 ".
179 " where i1.patient_id = $pid ".
180 " order by i1.immunization_id, i1.administered_date desc";
182 $result = sqlStatement($sql);
184 while ($row=sqlFetchArray($result)){
185 echo "&nbsp;&nbsp;";
186 echo "<a class='link' target='";
187 echo $GLOBALS['concurrent_layout'] ? "_parent" : "Main";
188 echo "' href='immunizations.php?mode=edit&id=".$row['id']."' onclick='top.restoreSession()'>" .
189 $row{'immunization_data'} .
190 generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']) .
191 "</a><br>\n";
194 </td>
195 </tr>
196 </table> <!-- end patient_stats_imm-->
197 <?php } ?>
200 <table id="patient_stats_prescriptions">
201 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
202 <span class='title'><?php echo xl('Prescriptions'); ?></span>
203 </td></tr>
204 </tr><td>
205 <?php
206 $cwd= getcwd();
207 chdir("../../../");
208 require_once("library/classes/Controller.class.php");
209 $c = new Controller();
210 echo $c->act(array("prescription" => "", "block" => "", "patient_id" => $pid));
212 </td></tr>
213 </table> <!-- end patient_stats_prescriptions -->
215 </div> <!-- end patient_stats_summary -->
217 </body>
218 </html>