bug fix in code selector to ensure selected code set is persistent
[openemr.git] / interface / reports / cqm.php
blobbe16a350ba4bdad5a491219dc96412a445f9df2c
1 <?php
2 // Copyright (C) 2010 Brady Miller <brady@sparmy.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 //SANITIZE ALL ESCAPES
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 require_once("../globals.php");
18 require_once("../../library/patient.inc");
19 require_once("$srcdir/formatting.inc.php");
20 require_once "$srcdir/options.inc.php";
21 require_once "$srcdir/formdata.inc.php";
22 require_once "$srcdir/clinical_rules.php";
24 // Collect report type parameter (standard, amc, or cqm)
25 $type_report = (isset($_GET['type'])) ? trim($_GET['type']) : "standard";
27 // Collect form parameters (set defaults if empty)
28 if ($type_report == "amc") {
29 $begin_date = (isset($_POST['form_begin_date'])) ? trim($_POST['form_begin_date']) : "";
30 $labs_manual = (isset($_POST['labs_manual_entry'])) ? trim($_POST['labs_manual_entry']) : "0";
32 $target_date = (isset($_POST['form_target_date'])) ? trim($_POST['form_target_date']) : date('Y-m-d H:i:s');
33 $rule_filter = (isset($_POST['form_rule_filter'])) ? trim($_POST['form_rule_filter']) : "";
34 $plan_filter = (isset($_POST['form_plan_filter'])) ? trim($_POST['form_plan_filter']) : "";
35 $organize_method = (empty($plan_filter)) ? "default" : "plans";
36 $provider = trim($_POST['form_provider']);
40 <html>
42 <head>
43 <?php html_header_show();?>
45 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
47 <?php if ($type_report == "standard") { ?>
48 <title><?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></title>
49 <?php } ?>
50 <?php if ($type_report == "cqm") { ?>
51 <title><?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></title>
52 <?php } ?>
53 <?php if ($type_report == "amc") { ?>
54 <title><?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></title>
55 <?php } ?>
57 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
58 <script type="text/javascript" src="../../library/textformat.js"></script>
59 <script type="text/javascript" src="../../library/dialog.js"></script>
60 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
62 <script LANGUAGE="JavaScript">
64 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
66 function refreshme() {
67 // location.reload();
68 top.restoreSession();
69 document.forms[0].submit();
72 function GenXml(sNested) {
73 top.restoreSession();
74 var sLoc = '../../custom/export_registry_xml.php?&target_date=' + theform.form_target_date.value + '&nested=' + sNested;
75 dlgopen(sLoc, '_blank', 600, 500);
76 return false;
79 </script>
81 <style type="text/css">
83 /* specifically include & exclude from printing */
84 @media print {
85 #report_parameters {
86 visibility: hidden;
87 display: none;
89 #report_parameters_daterange {
90 visibility: visible;
91 display: inline;
93 #report_results table {
94 margin-top: 0px;
98 /* specifically exclude some from the screen */
99 @media screen {
100 #report_parameters_daterange {
101 visibility: hidden;
102 display: none;
106 </style>
107 </head>
109 <body class="body_top">
111 <!-- Required for the popup date selectors -->
112 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
114 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> -
116 <?php if ($type_report == "standard") { ?>
117 <?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></span>
118 <?php } ?>
119 <?php if ($type_report == "cqm") { ?>
120 <?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></span>
121 <?php } ?>
122 <?php if ($type_report == "amc") { ?>
123 <?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></span>
124 <?php } ?>
127 <form method='post' name='theform' id='theform' action='cqm.php?type=<?php echo htmlspecialchars($type_report,ENT_QUOTES) ;?>' onsubmit='return top.restoreSession()'>
129 <div id="report_parameters">
131 <table>
132 <tr>
133 <td width='470px'>
134 <div style='float:left'>
136 <table class='text'>
138 <?php if ($type_report == "amc") { ?>
139 <tr>
140 <td class='label'>
141 <?php echo htmlspecialchars( xl('Begin Date'), ENT_NOQUOTES); ?>:
142 </td>
143 <td>
144 <input type='text' name='form_begin_date' id="form_begin_date" size='20' value='<?php echo htmlspecialchars( $begin_date, ENT_QUOTES); ?>'
145 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
146 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
147 id='img_begin_date' border='0' alt='[?]' style='cursor:pointer'
148 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
149 </td>
150 </tr>
151 <?php } ?>
153 <tr>
154 <td class='label'>
155 <?php if ($type_report == "amc") { ?>
156 <?php echo htmlspecialchars( xl('End Date'), ENT_NOQUOTES); ?>:
157 <?php } else { ?>
158 <?php echo htmlspecialchars( xl('Target Date'), ENT_NOQUOTES); ?>:
159 <?php } ?>
160 </td>
161 <td>
162 <input type='text' name='form_target_date' id="form_target_date" size='20' value='<?php echo htmlspecialchars( $target_date, ENT_QUOTES); ?>'
163 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
164 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
165 id='img_target_date' border='0' alt='[?]' style='cursor:pointer'
166 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
167 </td>
168 </tr>
170 <?php if ($type_report == "cqm") { ?>
171 <input type='hidden' name='form_rule_filter' value='cqm'>
172 <?php } ?>
173 <?php if ($type_report == "amc") { ?>
174 <input type='hidden' name='form_rule_filter' value='amc'>
175 <?php } ?>
176 <?php if ($type_report == "standard") { ?>
177 <tr>
178 <td class='label'>
179 <?php echo htmlspecialchars( xl('Rule Set'), ENT_NOQUOTES); ?>:
180 </td>
181 <td>
182 <select name='form_rule_filter'>
183 <option value='passive_alert' <?php if ($rule_filter == "passive_alert") echo "selected"; ?>>
184 <?php echo htmlspecialchars( xl('Passive Alert Rules'), ENT_NOQUOTES); ?></option>
185 <option value='active_alert' <?php if ($rule_filter == "active_alert") echo "selected"; ?>>
186 <?php echo htmlspecialchars( xl('Active Alert Rules'), ENT_NOQUOTES); ?></option>
187 <option value='patient_reminder' <?php if ($rule_filter == "patient_reminder") echo "selected"; ?>>
188 <?php echo htmlspecialchars( xl('Patient Reminder Rules'), ENT_NOQUOTES); ?></option>
189 </select>
190 </td>
191 </tr>
192 <?php } ?>
194 <?php if ($type_report == "amc") { ?>
195 <input type='hidden' name='form_plan_filter' value=''>
196 <?php } else { ?>
197 <tr>
198 <td class='label'>
199 <?php echo htmlspecialchars( xl('Plan Set'), ENT_NOQUOTES); ?>:
200 </td>
201 <td>
202 <select name='form_plan_filter'>
203 <option value=''>-- <?php echo htmlspecialchars( xl('Ignore'), ENT_NOQUOTES); ?> --</option>
204 <?php if ($type_report == "cqm") { ?>
205 <option value='cqm' <?php if ($plan_filter == "cqm") echo "selected"; ?>>
206 <?php echo htmlspecialchars( xl('Official Clinical Quality Measures (CQM) Measure Groups'), ENT_NOQUOTES); ?></option>
207 <?php } ?>
208 <?php if ($type_report == "standard") { ?>
209 <option value='normal' <?php if ($plan_filter == "normal") echo "selected"; ?>>
210 <?php echo htmlspecialchars( xl('Active Plans'), ENT_NOQUOTES); ?></option>
211 <?php } ?>
212 </td>
213 </tr>
214 <?php } ?>
216 <tr>
217 <td class='label'>
218 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
219 </td>
220 <td>
221 <?php
223 // Build a drop-down list of providers.
226 $query = "SELECT id, lname, fname FROM users WHERE ".
227 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
229 $ures = sqlStatement($query);
231 echo " <select name='form_provider'>\n";
232 echo " <option value=''>-- " . htmlspecialchars( xl('All (Cumulative)'), ENT_NOQUOTES) . " --\n";
234 echo " <option value='collate_outer'";
235 if ($_POST['form_provider'] == 'collate_outer') echo " selected";
236 echo ">-- " . htmlspecialchars( xl('All (Collated Format A)'), ENT_NOQUOTES) . " --\n";
238 echo " <option value='collate_inner'";
239 if ($_POST['form_provider'] == 'collate_inner') echo " selected";
240 echo ">-- " . htmlspecialchars( xl('All (Collated Format B)'), ENT_NOQUOTES) . " --\n";
242 while ($urow = sqlFetchArray($ures)) {
243 $provid = $urow['id'];
244 echo " <option value='".htmlspecialchars( $provid, ENT_QUOTES)."'";
245 if ($provid == $_POST['form_provider']) echo " selected";
246 echo ">" . htmlspecialchars( $urow['lname'] . ", " . $urow['fname'], ENT_NOQUOTES) . "\n";
249 echo " </select>\n";
252 </td>
253 </tr>
255 <?php if ($type_report == "amc") { ?>
256 <tr>
257 <td>
258 <?php echo htmlspecialchars( xl('Number labs'), ENT_NOQUOTES); ?>:<br>
259 (<?php echo htmlspecialchars( xl('Non-electronic'), ENT_NOQUOTES); ?>)
260 </td>
261 <td>
262 <input type="text" name="labs_manual_entry" value="<?php echo htmlspecialchars($labs_manual,ENT_QUOTES); ?>">
263 </td>
264 </tr>
265 <?php } ?>
267 </table>
269 </div>
271 </td>
272 <td align='left' valign='middle' height="100%">
273 <table style='border-left:1px solid; width:100%; height:100%' >
274 <tr>
275 <td>
276 <div style='margin-left:15px'>
277 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); top.restoreSession(); $("#theform").submit();'>
278 <span>
279 <?php echo htmlspecialchars( xl('Submit'), ENT_NOQUOTES); ?>
280 </span>
281 </a>
282 <?php if ($type_report == "cqm") { ?>
283 <a href='#' class='css_button' onclick='return GenXml("false")'>
284 <span>
285 <?php echo htmlspecialchars( xl('Generate PQRI report (Method A)'), ENT_NOQUOTES); ?>
286 </span>
287 </a>
288 <a href='#' class='css_button' onclick='return GenXml("true")'>
289 <span>
290 <?php echo htmlspecialchars( xl('Generate PQRI report (Method E)'), ENT_NOQUOTES); ?>
291 </span>
292 </a>
293 <?php } ?>
294 <?php if ($_POST['form_refresh']) { ?>
295 <a href='#' class='css_button' onclick='window.print()'>
296 <span>
297 <?php echo htmlspecialchars( xl('Print'), ENT_NOQUOTES); ?>
298 </span>
299 </a>
300 <?php } ?>
301 </div>
302 </td>
303 </tr>
304 </table>
305 </td>
306 </tr>
307 </table>
309 </div> <!-- end of search parameters -->
311 <br>
313 <?php
314 if ($_POST['form_refresh']) {
318 <div id="report_results">
319 <table>
321 <thead>
322 <th>
323 <?php echo htmlspecialchars( xl('Title'), ENT_NOQUOTES); ?>
324 </th>
326 <th>
327 <?php echo htmlspecialchars( xl('Total Patients'), ENT_NOQUOTES); ?>
328 </th>
330 <th>
331 <?php if ($type_report == "amc") { ?>
332 <?php echo htmlspecialchars( xl('Denominator'), ENT_NOQUOTES); ?></a>
333 <?php } else { ?>
334 <?php echo htmlspecialchars( xl('Applicable Patients') .' (' . xl('Denominator') . ')', ENT_NOQUOTES); ?></a>
335 <?php } ?>
336 </th>
338 <?php if ($type_report != "amc") { ?>
339 <th>
340 <?php echo htmlspecialchars( xl('Excluded Patients'), ENT_NOQUOTES); ?></a>
341 </th>
342 <?php } ?>
344 <th>
345 <?php if ($type_report == "amc") { ?>
346 <?php echo htmlspecialchars( xl('Numerator'), ENT_NOQUOTES); ?></a>
347 <?php } else { ?>
348 <?php echo htmlspecialchars( xl('Passed Patients') . ' (' . xl('Numerator') . ')', ENT_NOQUOTES); ?></a>
349 <?php } ?>
350 </th>
352 <th>
353 <?php echo htmlspecialchars( xl('Performance Percentage'), ENT_NOQUOTES); ?></a>
354 </th>
356 </thead>
357 <tbody> <!-- added for better print-ability -->
358 <?php
360 if ($type_report == "amc") {
361 // For AMC:
362 // need to make $target_date an array with two elements ('dateBegin' and 'dateTarget')
363 // need to to send a manual data entry option (number of labs)
364 $array_date = array();
365 $array_date['dateBegin'] = $begin_date;
366 $array_date['dateTarget'] = $target_date;
367 $options = array('labs_manual'=>$labs_manual);
368 $dataSheet = test_rules_clinic($provider,$rule_filter,$array_date,"report",'',$plan_filter,$organize_method,$options);
370 else {
371 $dataSheet = test_rules_clinic($provider,$rule_filter,$target_date,"report",'',$plan_filter,$organize_method);
374 $firstProviderFlag = TRUE;
375 $firstPlanFlag = TRUE;
376 $existProvider = FALSE;
377 foreach ($dataSheet as $row) {
381 <tr bgcolor='<?php echo $bgcolor ?>'>
383 <?php
384 if (isset($row['is_main']) || isset($row['is_sub'])) {
385 echo "<td class='detail'>";
386 if (isset($row['is_main'])) {
387 echo "<b>".generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id'])."</b>";
388 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code']) || !empty($row['amc_code'])) {
389 echo " (";
390 if (!empty($row['cqm_pqri_code'])) {
391 echo " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES) . " ";
393 if (!empty($row['cqm_nqf_code'])) {
394 echo " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES) . " ";
396 if (!empty($row['amc_code'])) {
397 echo " " . htmlspecialchars( xl('AMC') . ":" . $row['amc_code'], ENT_NOQUOTES) . " ";
399 echo ")";
402 if ( !(empty($row['concatenated_label'])) ) {
403 echo ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES) . " ";
407 else { // isset($row['is_sub'])
408 echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$row['action_category']);
409 echo ": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$row['action_item']);
411 echo "</td>";
412 echo "<td align='center'>" . $row['total_patients'] . "</td>";
413 echo "<td align='center'>" . $row['pass_filter'] . "</td>";
414 if ($type_report != "amc") {
415 echo "<td align='center'>" . $row['excluded'] . "</td>";
417 echo "<td align='center'>" . $row['pass_target'] . "</td>";
418 echo "<td align='center'>" . $row['percentage'] . "</td>";
420 else if (isset($row['is_provider'])) {
421 // Display the provider information
422 if (!$firstProviderFlag && $_POST['form_provider'] == 'collate_outer') {
423 echo "<tr><td>&nbsp</td></tr>";
425 echo "<td class='detail' align='center'><b>";
426 echo htmlspecialchars( xl("Provider").": " . $row['prov_lname'] . "," . $row['prov_fname'], ENT_NOQUOTES);
427 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
428 echo " (";
429 if (!empty($row['npi'])) {
430 echo " " . htmlspecialchars( xl('NPI') . ":" . $row['npi'], ENT_NOQUOTES) . " ";
432 if (!empty($row['federaltaxid'])) {
433 echo " " . htmlspecialchars( xl('TID') . ":" . $row['federaltaxid'], ENT_NOQUOTES) . " ";
435 echo ")";
437 echo "</b></td>";
438 $firstProviderFlag = FALSE;
439 $existProvider = TRUE;
441 else { // isset($row['is_plan'])
442 if (!$firstPlanFlag && $_POST['form_provider'] != 'collate_outer') {
443 echo "<tr><td>&nbsp</td></tr>";
445 echo "<td class='detail' align='center'><b>";
446 echo htmlspecialchars( xl("Plan"), ENT_NOQUOTES) . ": ";
447 echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_plans'),$row['id']);
448 if (!empty($row['cqm_measure_group'])) {
449 echo " (". htmlspecialchars( xl('Measure Group Code') . ": " . $row['cqm_measure_group'], ENT_NOQUOTES) . ")";
451 echo "</b></td>";
452 $firstPlanFlag = FALSE;
455 </tr>
457 <?php
460 </tbody>
461 </table>
462 </div> <!-- end of search results -->
463 <?php } else { ?>
464 <div class='text'>
465 <?php echo htmlspecialchars( xl('Please input search criteria above, and click Submit to view results.'), ENT_NOQUOTES); ?>
466 </div>
467 <?php } ?>
469 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
471 </form>
473 </body>
475 <!-- stuff for the popup calendar -->
476 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
477 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
478 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
479 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
480 <script language="Javascript">
481 <?php if ($type_report == "amc") { ?>
482 Calendar.setup({inputField:"form_begin_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_begin_date", showsTime:'true'});
483 <?php } ?>
484 Calendar.setup({inputField:"form_target_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_target_date", showsTime:'true'});
485 </script>
487 </html>