Immunization bug fix when cvx_code sql entry is set to NULL. Contributed by ZH Health...
[openemr.git] / interface / patient_file / summary / stats.php
blob01ab576c204e75cc3cc502d2073cd6daf066cfc7
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 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 ";
55 $query .= "ORDER BY begdate";
56 $pres = sqlStatement($query, array($pid, $key) );
58 if (sqlNumRows($pres) > 0 || $ix == 0 || $key == "allergy" || $key == "medication") {
60 if ($_POST['embeddedScreen']) {
61 echo "<tr><td>";
62 // Issues expand collapse widget
63 $widgetTitle = $arr[0];
64 $widgetLabel = $key;
65 if(($key == "allergy" || $key == "medication") && $GLOBALS['erx_enable'])
67 $widgetButtonLabel = xl("Add");
68 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/eRx.php?page=medentry\")";
70 else
72 $widgetButtonLabel = xl("Edit");
73 $widgetButtonLink = "load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/stats_full.php?active=all&category=" . $key . "\")";
75 $widgetButtonClass = "";
76 $linkMethod = "javascript";
77 $bodyClass = "summary_item small";
78 $widgetAuth = true;
79 $fixedWidth = false;
80 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
82 else { ?>
83 <tr class='issuetitle'>
84 <td colspan='$numcols'>
85 <span class="text"><b><?php echo htmlspecialchars($arr[0],ENT_NOQUOTES); ?></b></span>
86 <a href="javascript:;" class="small" onclick="load_location('stats_full.php?active=all&category=" . $key . "')">
87 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES); ?></b>)
88 </a>
89 </td>
90 </tr>
91 <?php }
92 echo "<table>";
93 if (sqlNumRows($pres) == 0) {
94 if ( getListTouch($pid,$key) ) {
95 // Data entry has happened to this type, so can display an explicit None.
96 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td></tr>\n";
98 else {
99 // Data entry has not happened to this type, so show 'Nothing Recorded"
100 echo " <tr><td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('Nothing Recorded'), ENT_NOQUOTES) . "</td></tr>\n";
104 while ($row = sqlFetchArray($pres)) {
105 // output each issue for the $ISSUE_TYPE
106 if (!$row['enddate'] && !$row['returndate'])
107 $rowclass="noend_noreturn";
108 else if (!$row['enddate'] && $row['returndate'])
109 $rowclass="noend";
110 else if ($row['enddate'] && !$row['returndate'])
111 $rowclass = "noreturn";
113 echo " <tr class='text $rowclass;'>\n";
115 //turn allergies red and bold and show the reaction (if exist)
116 if ($key == "allergy") {
117 $reaction = "";
118 if (!empty($row['reaction'])) {
119 $reaction = " (" . $row['reaction'] . ")";
121 echo " <td colspan='$numcols' style='color:red;font-weight:bold;'>&nbsp;&nbsp;" . htmlspecialchars( $row['title'] . $reaction, ENT_NOQUOTES) . "</td>\n";
123 else {
124 echo " <td colspan='$numcols'>&nbsp;&nbsp;" . htmlspecialchars($row['title'],ENT_NOQUOTES) . "</td>\n";
127 echo " </tr>\n";
129 echo "</table>";
130 if ($_POST['embeddedScreen']) {
131 echo "</div></td></tr>";
136 ++$ix;
139 </table> <!-- end patient_stats_issues -->
141 <table id="patient_stats_spreadsheets">
142 <?php
144 // Show spreadsheet forms if any are present.
146 $need_head = true;
147 foreach (array('treatment_protocols','injury_log') as $formname) {
148 if (sqlNumRows(sqlStatement("SHOW TABLES LIKE ?", array("form_".$formname) )) > 0) {
149 $dres = sqlStatement("SELECT tp.id, tp.value FROM forms, " .
150 "form_" . add_escape_custom($formname) .
151 " AS tp WHERE forms.pid = ? AND " .
152 "forms.formdir = ? AND tp.id = forms.form_id AND " .
153 "tp.rownbr = -1 AND tp.colnbr = -1 AND tp.value LIKE '0%' " .
154 "ORDER BY tp.value DESC", array($pid, $formname) );
155 if (sqlNumRows($dres) > 0 && $need_head) {
156 $need_head = false;
157 echo " <tr>\n";
158 echo " <td colspan='$numcols' valign='top'>\n";
159 echo " <span class='title'>Injury Log</span>\n";
160 echo " </td>\n";
161 echo " </tr>\n";
163 while ($row = sqlFetchArray($dres)) {
164 list($completed, $start_date, $template_name) = explode('|', $row['value'], 3);
165 echo " <tr>\n";
166 echo " <td colspan='$numcols'>&nbsp;&nbsp;";
167 echo "<a class='link' href='javascript:;' ";
168 echo "onclick='load_location(\"../../forms/$formname/new.php?popup=1&id=";
169 echo htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
170 htmlspecialchars($start_date,ENT_NOQUOTES) . " " .
171 htmlspecialchars($template_name,ENT_NOQUOTES) . "</a></td>\n";
172 echo " </tr>\n";
177 </table> <!-- end patient_stats_spreadsheets -->
179 <?php if (!$GLOBALS['disable_immunizations'] && !$GLOBALS['weight_loss_clinic']) { ?>
180 <div>
181 <table id="patient_stats_imm">
182 <tr>
183 <?php if ($_POST['embeddedScreen']) {
184 echo "<td>";
185 // Issues expand collapse widget
186 $widgetTitle = xl('Immunizations');
187 $widgetLabel = "immunizations";
188 $widgetButtonLabel = xl("Edit");
189 $widgetButtonLink = "javascript:load_location(\"${GLOBALS['webroot']}/interface/patient_file/summary/immunizations.php\")";
190 $widgetButtonClass = "";
191 $linkMethod = "javascript";
192 $bodyClass = "summary_item small";
193 $widgetAuth = true;
194 $fixedWidth = false;
195 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
197 else { ?>
198 <td colspan='<?php echo $numcols ?>' valign='top'>
199 <span class="text"><b><?php echo htmlspecialchars(xl('Immunizations', 'e'),ENT_NOQUOTES); ?></b></span>
200 <a href="javascript:;" class="small" onclick="javascript:load_location('immunizations.php')">
201 (<b><?php echo htmlspecialchars(xl('Manage'),ENT_NOQUOTES) ?></b>)
202 </a>
203 </td></tr>
204 <tr><td>
205 <?php } ?>
207 <?php
208 $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, ".
209 " if (i1.administered_date, concat(i1.administered_date,' - '), substring(i1.note,1,20)) as immunization_data ".
210 " from immunizations i1 ".
211 " left join codes c on CAST(IFNULL(i1.cvx_code,0) AS CHAR) = c.code ".
212 " left join code_types ct on c.code_type = ct.ct_id ".
213 " where i1.patient_id = ? ".
214 " AND (( cvx_code = '0' OR cvx_code IS NULL ) OR ".
215 " ( cvx_code != '0' AND ct.ct_key = 'CVX')) ".
216 " order by i1.administered_date desc";
218 $result = sqlStatement($sql, array($pid) );
220 if (sqlNumRows($result) == 0) {
221 echo " <table><tr>\n";
222 echo " <td colspan='$numcols' class='text'>&nbsp;&nbsp;" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . "</td>\n";
223 echo " </tr></table>\n";
226 while ($row=sqlFetchArray($result)){
227 echo "&nbsp;&nbsp;";
228 echo "<a class='link'";
229 echo "' href='javascript:;' onclick='javascript:load_location(\"immunizations.php?mode=edit&id=".htmlspecialchars($row['id'],ENT_QUOTES) . "\")'>" .
230 htmlspecialchars($row{'immunization_data'},ENT_NOQUOTES);
232 // Figure out which name to use (ie. from cvx list or from the custom list)
233 if ($GLOBALS['use_custom_immun_list']) {
234 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
236 else {
237 if (!(empty($row['cvx_text']))) {
238 echo htmlspecialchars( xl($row['cvx_text']), ENT_NOQUOTES );
240 else {
241 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
244 echo "</a><br>\n";
248 <?php if ($_POST['embeddedScreen']) {
249 echo "</td></tr></div>";
250 } ?>
252 </td>
253 </tr>
254 </table> <!-- end patient_stats_imm-->
255 </div>
256 <?php } ?>
258 <?php if (!$GLOBALS['disable_prescriptions']) { ?>
259 <div>
260 <table id="patient_stats_prescriptions">
261 <?php if($GLOBALS['erx_enable']){ ?>
262 <tr><td>
263 <?php if ($_POST['embeddedScreen']) {
264 $widgetTitle = '';
265 $widgetTitle = xl('Current Medications');
266 $widgetLabel = "current_prescriptions";
267 $widgetButtonLabel = '';
268 $widgetButtonLink = '';
269 $widgetButtonClass = '';
270 $linkMethod = "";
271 $bodyClass = "summary_item small";
272 $widgetAuth = false;
273 $fixedWidth = false;
274 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
278 <?php
279 $res=sqlStatement("select * from prescriptions where patient_id=? and active='1'",array($pid));
281 <table>
282 <?php
283 if(sqlNumRows($res)==0)
286 <tr class=text>
287 <td><?php echo htmlspecialchars(xl('None'), ENT_NOQUOTES);?></td>
288 </tr>
289 <?php
291 while($row_currentMed=sqlFetchArray($res))
293 $rin=generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'),$row_currentMed['form']);
294 $rroute=generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'),$row_currentMed['route']);
295 $rint=generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'),$row_currentMed['interval']);
297 <tr class=text style='font-weight:bold;color:blue;'>
298 <td><?php echo $row_currentMed['drug'];?></td>
299 <td><?php echo htmlspecialchars($row_currentMed['dosage']." ".xl("in")." ".$rin['title']." ".$rint['title'],ENT_NOQUOTES);?></td>
300 </tr>
301 <?php
304 </table>
305 </td></tr>
306 <?php } ?>
307 <tr><td colspan='<?php echo $numcols ?>' class='issuetitle'>
309 <?php if ($_POST['embeddedScreen']) {
310 // Issues expand collapse widget
311 $widgetLabel = "prescriptions";
312 $linkMethod = "html";
313 if($GLOBALS['erx_enable'])
315 $widgetTitle = xl('Prescription History');
316 $widgetButtonLabel = xl("Add/Edit eRx");
317 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/eRx.php?page=compose";
318 $widgetButtonClass = "";
320 else
322 $widgetTitle = xl('Prescription');
323 $widgetButtonLabel = xl("Edit");
324 $widgetButtonLink = $GLOBALS['webroot'] . "/interface/patient_file/summary/rx_frameset.php";
325 $widgetButtonClass = "iframe rx_modal";
327 $bodyClass = "summary_item small";
328 $widgetAuth = true;
329 $fixedWidth = false;
330 expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth);
332 else { ?>
333 <span class='text'><b><?php echo htmlspecialchars(xl('Prescriptions'),ENT_NOQUOTES); ?></b></span>
334 </td></tr>
335 </tr><td>
336 <?php } ?>
338 <?php
339 $cwd= getcwd();
340 chdir("../../../");
341 require_once("library/classes/Controller.class.php");
342 $c = new Controller();
343 echo $c->act(array("prescription" => "", "fragment" => "", "patient_id" => $pid));
346 <?php if ($_POST['embeddedScreen']) {
347 echo "</div>";
348 } ?>
350 </td></tr>
351 </table> <!-- end patient_stats_prescriptions -->
352 </div>
353 <?php } ?>
355 </div> <!-- end patient_stats_summary -->