pending icon for the cqm/acm/rules reporting
[openemr.git] / interface / reports / cqm.php
blobe05a73c0183381284ae1c5265adf75f2e51692e4
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 //To improve performance and not freeze the session when running this
25 // report, turn off session writing. Note that php session variables
26 // can not be modified after the line below. So, if need to do any php
27 // session work in the future, then will need to remove this line.
28 session_write_close();
30 //Remove time limit, since script can take many minutes
31 set_time_limit(0);
33 // Collect report type parameter (standard, amc, or cqm)
34 $type_report = (isset($_GET['type'])) ? trim($_GET['type']) : "standard";
36 // Collect form parameters (set defaults if empty)
37 if ($type_report == "amc") {
38 $begin_date = (isset($_POST['form_begin_date'])) ? trim($_POST['form_begin_date']) : "";
39 $labs_manual = (isset($_POST['labs_manual_entry'])) ? trim($_POST['labs_manual_entry']) : "0";
41 $target_date = (isset($_POST['form_target_date'])) ? trim($_POST['form_target_date']) : date('Y-m-d H:i:s');
42 $rule_filter = (isset($_POST['form_rule_filter'])) ? trim($_POST['form_rule_filter']) : "";
43 $plan_filter = (isset($_POST['form_plan_filter'])) ? trim($_POST['form_plan_filter']) : "";
44 $organize_method = (empty($plan_filter)) ? "default" : "plans";
45 $provider = trim($_POST['form_provider']);
46 $pat_prov_rel = (empty($_POST['form_pat_prov_rel'])) ? "primary" : trim($_POST['form_pat_prov_rel']);
49 <html>
51 <head>
52 <?php html_header_show();?>
54 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
56 <?php if ($type_report == "standard") { ?>
57 <title><?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></title>
58 <?php } ?>
59 <?php if ($type_report == "cqm") { ?>
60 <title><?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></title>
61 <?php } ?>
62 <?php if ($type_report == "amc") { ?>
63 <title><?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></title>
64 <?php } ?>
66 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
67 <script type="text/javascript" src="../../library/textformat.js"></script>
68 <script type="text/javascript" src="../../library/dialog.js"></script>
69 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
71 <script LANGUAGE="JavaScript">
73 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
75 function refreshme() {
76 // location.reload();
77 top.restoreSession();
78 document.forms[0].submit();
81 function GenXml(sNested) {
82 top.restoreSession();
83 var sLoc = '../../custom/export_registry_xml.php?&target_date=' + theform.form_target_date.value + '&nested=' + sNested;
84 dlgopen(sLoc, '_blank', 600, 500);
85 return false;
88 </script>
90 <style type="text/css">
92 /* specifically include & exclude from printing */
93 @media print {
94 #report_parameters {
95 visibility: hidden;
96 display: none;
98 #report_parameters_daterange {
99 visibility: visible;
100 display: inline;
102 #report_results table {
103 margin-top: 0px;
107 /* specifically exclude some from the screen */
108 @media screen {
109 #report_parameters_daterange {
110 visibility: hidden;
111 display: none;
115 </style>
116 </head>
118 <body class="body_top">
120 <!-- Required for the popup date selectors -->
121 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
123 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> -
125 <?php if ($type_report == "standard") { ?>
126 <?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></span>
127 <?php } ?>
128 <?php if ($type_report == "cqm") { ?>
129 <?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></span>
130 <?php } ?>
131 <?php if ($type_report == "amc") { ?>
132 <?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></span>
133 <?php } ?>
136 <form method='post' name='theform' id='theform' action='cqm.php?type=<?php echo htmlspecialchars($type_report,ENT_QUOTES) ;?>' onsubmit='return top.restoreSession()'>
138 <div id="report_parameters">
140 <table>
141 <tr>
142 <td width='470px'>
143 <div style='float:left'>
145 <table class='text'>
147 <?php if ($type_report == "amc") { ?>
148 <tr>
149 <td class='label'>
150 <?php echo htmlspecialchars( xl('Begin Date'), ENT_NOQUOTES); ?>:
151 </td>
152 <td>
153 <input type='text' name='form_begin_date' id="form_begin_date" size='20' value='<?php echo htmlspecialchars( $begin_date, ENT_QUOTES); ?>'
154 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
155 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
156 id='img_begin_date' border='0' alt='[?]' style='cursor:pointer'
157 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
158 </td>
159 </tr>
160 <?php } ?>
162 <tr>
163 <td class='label'>
164 <?php if ($type_report == "amc") { ?>
165 <?php echo htmlspecialchars( xl('End Date'), ENT_NOQUOTES); ?>:
166 <?php } else { ?>
167 <?php echo htmlspecialchars( xl('Target Date'), ENT_NOQUOTES); ?>:
168 <?php } ?>
169 </td>
170 <td>
171 <input type='text' name='form_target_date' id="form_target_date" size='20' value='<?php echo htmlspecialchars( $target_date, ENT_QUOTES); ?>'
172 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
173 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
174 id='img_target_date' border='0' alt='[?]' style='cursor:pointer'
175 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
176 </td>
177 </tr>
179 <?php if ($type_report == "cqm") { ?>
180 <input type='hidden' name='form_rule_filter' value='cqm'>
181 <?php } ?>
182 <?php if ($type_report == "amc") { ?>
183 <input type='hidden' name='form_rule_filter' value='amc'>
184 <?php } ?>
185 <?php if ($type_report == "standard") { ?>
186 <tr>
187 <td class='label'>
188 <?php echo htmlspecialchars( xl('Rule Set'), ENT_NOQUOTES); ?>:
189 </td>
190 <td>
191 <select name='form_rule_filter'>
192 <option value='passive_alert' <?php if ($rule_filter == "passive_alert") echo "selected"; ?>>
193 <?php echo htmlspecialchars( xl('Passive Alert Rules'), ENT_NOQUOTES); ?></option>
194 <option value='active_alert' <?php if ($rule_filter == "active_alert") echo "selected"; ?>>
195 <?php echo htmlspecialchars( xl('Active Alert Rules'), ENT_NOQUOTES); ?></option>
196 <option value='patient_reminder' <?php if ($rule_filter == "patient_reminder") echo "selected"; ?>>
197 <?php echo htmlspecialchars( xl('Patient Reminder Rules'), ENT_NOQUOTES); ?></option>
198 </select>
199 </td>
200 </tr>
201 <?php } ?>
203 <?php if ($type_report == "amc") { ?>
204 <input type='hidden' name='form_plan_filter' value=''>
205 <?php } else { ?>
206 <tr>
207 <td class='label'>
208 <?php echo htmlspecialchars( xl('Plan Set'), ENT_NOQUOTES); ?>:
209 </td>
210 <td>
211 <select name='form_plan_filter'>
212 <option value=''>-- <?php echo htmlspecialchars( xl('Ignore'), ENT_NOQUOTES); ?> --</option>
213 <?php if ($type_report == "cqm") { ?>
214 <option value='cqm' <?php if ($plan_filter == "cqm") echo "selected"; ?>>
215 <?php echo htmlspecialchars( xl('Official Clinical Quality Measures (CQM) Measure Groups'), ENT_NOQUOTES); ?></option>
216 <?php } ?>
217 <?php if ($type_report == "standard") { ?>
218 <option value='normal' <?php if ($plan_filter == "normal") echo "selected"; ?>>
219 <?php echo htmlspecialchars( xl('Active Plans'), ENT_NOQUOTES); ?></option>
220 <?php } ?>
221 </td>
222 </tr>
223 <?php } ?>
225 <tr>
226 <td class='label'>
227 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
228 </td>
229 <td>
230 <?php
232 // Build a drop-down list of providers.
235 $query = "SELECT id, lname, fname FROM users WHERE ".
236 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
238 $ures = sqlStatement($query);
240 echo " <select name='form_provider'>\n";
241 echo " <option value=''>-- " . htmlspecialchars( xl('All (Cumulative)'), ENT_NOQUOTES) . " --\n";
243 echo " <option value='collate_outer'";
244 if ($_POST['form_provider'] == 'collate_outer') echo " selected";
245 echo ">-- " . htmlspecialchars( xl('All (Collated Format A)'), ENT_NOQUOTES) . " --\n";
247 echo " <option value='collate_inner'";
248 if ($_POST['form_provider'] == 'collate_inner') echo " selected";
249 echo ">-- " . htmlspecialchars( xl('All (Collated Format B)'), ENT_NOQUOTES) . " --\n";
251 while ($urow = sqlFetchArray($ures)) {
252 $provid = $urow['id'];
253 echo " <option value='".htmlspecialchars( $provid, ENT_QUOTES)."'";
254 if ($provid == $_POST['form_provider']) echo " selected";
255 echo ">" . htmlspecialchars( $urow['lname'] . ", " . $urow['fname'], ENT_NOQUOTES) . "\n";
258 echo " </select>\n";
261 </td>
262 </tr>
264 <tr>
265 <td class='label'>
266 <?php echo htmlspecialchars( xl('Provider Relationship'), ENT_NOQUOTES); ?>:
267 </td>
268 <td>
269 <?php
271 // Build a drop-down list of of patient provider relationships.
273 echo " <select name='form_pat_prov_rel' title='" . xlt('Only applicable if a provider or collated list was chosen above. PRIMARY only selects patients that the provider is the primary provider. ENCOUNTER selects all patients that the provider has seen.') . "'>\n";
274 echo " <option value='primary'";
275 if ($pat_prov_rel == 'primary') echo " selected";
276 echo ">" . xlt('Primary') . "\n";
277 echo " <option value='encounter'";
278 if ($pat_prov_rel == 'encounter') echo " selected";
279 echo ">" . xlt('Encounter') . "\n";
280 echo " </select>\n";
282 </td>
283 </tr>
285 <?php if ($type_report == "amc") { ?>
286 <tr>
287 <td>
288 <?php echo htmlspecialchars( xl('Number labs'), ENT_NOQUOTES); ?>:<br>
289 (<?php echo htmlspecialchars( xl('Non-electronic'), ENT_NOQUOTES); ?>)
290 </td>
291 <td>
292 <input type="text" name="labs_manual_entry" value="<?php echo htmlspecialchars($labs_manual,ENT_QUOTES); ?>">
293 </td>
294 </tr>
295 <?php } ?>
297 </table>
299 </div>
301 </td>
302 <td align='left' valign='middle' height="100%">
303 <table style='border-left:1px solid; width:100%; height:100%' >
304 <tr>
305 <td>
306 <div style='margin-left:15px'>
307 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); top.restoreSession(); $("#processing").show(); $("#theform").submit();'>
308 <span>
309 <?php echo htmlspecialchars( xl('Submit'), ENT_NOQUOTES); ?>
310 </span>
311 </a>
312 <div id='processing' style='margin:10px;display:none;'><img src='../pic/ajax-loader.gif'/></div>
313 <?php if ($type_report == "cqm") { ?>
314 <a href='#' class='css_button' onclick='return GenXml("false")'>
315 <span>
316 <?php echo htmlspecialchars( xl('Generate PQRI report (Method A)'), ENT_NOQUOTES); ?>
317 </span>
318 </a>
319 <a href='#' class='css_button' onclick='return GenXml("true")'>
320 <span>
321 <?php echo htmlspecialchars( xl('Generate PQRI report (Method E)'), ENT_NOQUOTES); ?>
322 </span>
323 </a>
324 <?php } ?>
325 <?php if ($_POST['form_refresh']) { ?>
326 <a href='#' class='css_button' onclick='window.print()'>
327 <span>
328 <?php echo htmlspecialchars( xl('Print'), ENT_NOQUOTES); ?>
329 </span>
330 </a>
331 <?php } ?>
332 </div>
333 </td>
334 </tr>
335 </table>
336 </td>
337 </tr>
338 </table>
340 </div> <!-- end of search parameters -->
342 <br>
344 <?php
345 if ($_POST['form_refresh']) {
349 <div id="report_results">
350 <table>
352 <thead>
353 <th>
354 <?php echo htmlspecialchars( xl('Title'), ENT_NOQUOTES); ?>
355 </th>
357 <th>
358 <?php echo htmlspecialchars( xl('Total Patients'), ENT_NOQUOTES); ?>
359 </th>
361 <th>
362 <?php if ($type_report == "amc") { ?>
363 <?php echo htmlspecialchars( xl('Denominator'), ENT_NOQUOTES); ?></a>
364 <?php } else { ?>
365 <?php echo htmlspecialchars( xl('Applicable Patients') .' (' . xl('Denominator') . ')', ENT_NOQUOTES); ?></a>
366 <?php } ?>
367 </th>
369 <?php if ($type_report != "amc") { ?>
370 <th>
371 <?php echo htmlspecialchars( xl('Excluded Patients'), ENT_NOQUOTES); ?></a>
372 </th>
373 <?php } ?>
375 <th>
376 <?php if ($type_report == "amc") { ?>
377 <?php echo htmlspecialchars( xl('Numerator'), ENT_NOQUOTES); ?></a>
378 <?php } else { ?>
379 <?php echo htmlspecialchars( xl('Passed Patients') . ' (' . xl('Numerator') . ')', ENT_NOQUOTES); ?></a>
380 <?php } ?>
381 </th>
383 <th>
384 <?php echo htmlspecialchars( xl('Performance Percentage'), ENT_NOQUOTES); ?></a>
385 </th>
387 </thead>
388 <tbody> <!-- added for better print-ability -->
389 <?php
391 // Process report and collect results
392 $options = array();
393 $array_date = array();
394 if ($type_report == "amc") {
395 // For AMC:
396 // need to make $target_date an array with two elements ('dateBegin' and 'dateTarget')
397 // need to send a manual data entry option (number of labs)
398 $array_date['dateBegin'] = $begin_date;
399 $array_date['dateTarget'] = $target_date;
400 $options = array('labs_manual'=>$labs_manual);
402 else {
403 // For others, use the unmodified target date array and send an empty options array
404 $array_date = $target_date;
407 // Collect results (note using the batch method to decrease memory overhead and improve performance)
408 $dataSheet = test_rules_clinic_batch_method($provider,$rule_filter,$array_date,"report",$plan_filter,$organize_method,$options,$pat_prov_rel);
410 $firstProviderFlag = TRUE;
411 $firstPlanFlag = TRUE;
412 $existProvider = FALSE;
413 foreach ($dataSheet as $row) {
417 <tr bgcolor='<?php echo $bgcolor ?>'>
419 <?php
420 if (isset($row['is_main']) || isset($row['is_sub'])) {
421 echo "<td class='detail'>";
422 if (isset($row['is_main'])) {
423 echo "<b>".generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id'])."</b>";
424 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code']) || !empty($row['amc_code'])) {
425 echo " (";
426 if (!empty($row['cqm_pqri_code'])) {
427 echo " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES) . " ";
429 if (!empty($row['cqm_nqf_code'])) {
430 echo " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES) . " ";
432 if (!empty($row['amc_code'])) {
433 echo " " . htmlspecialchars( xl('AMC') . ":" . $row['amc_code'], ENT_NOQUOTES) . " ";
435 echo ")";
438 if ( !(empty($row['concatenated_label'])) ) {
439 echo ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES) . " ";
443 else { // isset($row['is_sub'])
444 echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$row['action_category']);
445 echo ": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$row['action_item']);
447 echo "</td>";
448 echo "<td align='center'>" . $row['total_patients'] . "</td>";
449 echo "<td align='center'>" . $row['pass_filter'] . "</td>";
450 if ($type_report != "amc") {
451 echo "<td align='center'>" . $row['excluded'] . "</td>";
453 echo "<td align='center'>" . $row['pass_target'] . "</td>";
454 echo "<td align='center'>" . $row['percentage'] . "</td>";
456 else if (isset($row['is_provider'])) {
457 // Display the provider information
458 if (!$firstProviderFlag && $_POST['form_provider'] == 'collate_outer') {
459 echo "<tr><td>&nbsp</td></tr>";
461 echo "<td class='detail' align='center'><b>";
462 echo htmlspecialchars( xl("Provider").": " . $row['prov_lname'] . "," . $row['prov_fname'], ENT_NOQUOTES);
463 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
464 echo " (";
465 if (!empty($row['npi'])) {
466 echo " " . htmlspecialchars( xl('NPI') . ":" . $row['npi'], ENT_NOQUOTES) . " ";
468 if (!empty($row['federaltaxid'])) {
469 echo " " . htmlspecialchars( xl('TID') . ":" . $row['federaltaxid'], ENT_NOQUOTES) . " ";
471 echo ")";
473 echo "</b></td>";
474 $firstProviderFlag = FALSE;
475 $existProvider = TRUE;
477 else { // isset($row['is_plan'])
478 if (!$firstPlanFlag && $_POST['form_provider'] != 'collate_outer') {
479 echo "<tr><td>&nbsp</td></tr>";
481 echo "<td class='detail' align='center'><b>";
482 echo htmlspecialchars( xl("Plan"), ENT_NOQUOTES) . ": ";
483 echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_plans'),$row['id']);
484 if (!empty($row['cqm_measure_group'])) {
485 echo " (". htmlspecialchars( xl('Measure Group Code') . ": " . $row['cqm_measure_group'], ENT_NOQUOTES) . ")";
487 echo "</b></td>";
488 $firstPlanFlag = FALSE;
491 </tr>
493 <?php
496 </tbody>
497 </table>
498 </div> <!-- end of search results -->
499 <?php } else { ?>
500 <div class='text'>
501 <?php echo htmlspecialchars( xl('Please input search criteria above, and click Submit to view results.'), ENT_NOQUOTES); ?>
502 </div>
503 <?php } ?>
505 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
507 </form>
509 </body>
511 <!-- stuff for the popup calendar -->
512 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
513 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
514 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
515 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
516 <script language="Javascript">
517 <?php if ($type_report == "amc") { ?>
518 Calendar.setup({inputField:"form_begin_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_begin_date", showsTime:'true'});
519 <?php } ?>
520 Calendar.setup({inputField:"form_target_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_target_date", showsTime:'true'});
521 </script>
523 </html>