Remove time limit for the AMC/CQM/CDR reports
[openemr.git] / interface / reports / cqm.php
blob6be92443844ae6c04172b3769ba8b6ddab2ffb8a
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 //Remove time limit, since script can take many minutes
25 set_time_limit(0);
27 // Collect report type parameter (standard, amc, or cqm)
28 $type_report = (isset($_GET['type'])) ? trim($_GET['type']) : "standard";
30 // Collect form parameters (set defaults if empty)
31 if ($type_report == "amc") {
32 $begin_date = (isset($_POST['form_begin_date'])) ? trim($_POST['form_begin_date']) : "";
33 $labs_manual = (isset($_POST['labs_manual_entry'])) ? trim($_POST['labs_manual_entry']) : "0";
35 $target_date = (isset($_POST['form_target_date'])) ? trim($_POST['form_target_date']) : date('Y-m-d H:i:s');
36 $rule_filter = (isset($_POST['form_rule_filter'])) ? trim($_POST['form_rule_filter']) : "";
37 $plan_filter = (isset($_POST['form_plan_filter'])) ? trim($_POST['form_plan_filter']) : "";
38 $organize_method = (empty($plan_filter)) ? "default" : "plans";
39 $provider = trim($_POST['form_provider']);
43 <html>
45 <head>
46 <?php html_header_show();?>
48 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
50 <?php if ($type_report == "standard") { ?>
51 <title><?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></title>
52 <?php } ?>
53 <?php if ($type_report == "cqm") { ?>
54 <title><?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></title>
55 <?php } ?>
56 <?php if ($type_report == "amc") { ?>
57 <title><?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></title>
58 <?php } ?>
60 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
61 <script type="text/javascript" src="../../library/textformat.js"></script>
62 <script type="text/javascript" src="../../library/dialog.js"></script>
63 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
65 <script LANGUAGE="JavaScript">
67 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
69 function refreshme() {
70 // location.reload();
71 top.restoreSession();
72 document.forms[0].submit();
75 function GenXml(sNested) {
76 top.restoreSession();
77 var sLoc = '../../custom/export_registry_xml.php?&target_date=' + theform.form_target_date.value + '&nested=' + sNested;
78 dlgopen(sLoc, '_blank', 600, 500);
79 return false;
82 </script>
84 <style type="text/css">
86 /* specifically include & exclude from printing */
87 @media print {
88 #report_parameters {
89 visibility: hidden;
90 display: none;
92 #report_parameters_daterange {
93 visibility: visible;
94 display: inline;
96 #report_results table {
97 margin-top: 0px;
101 /* specifically exclude some from the screen */
102 @media screen {
103 #report_parameters_daterange {
104 visibility: hidden;
105 display: none;
109 </style>
110 </head>
112 <body class="body_top">
114 <!-- Required for the popup date selectors -->
115 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
117 <span class='title'><?php echo htmlspecialchars( xl('Report'), ENT_NOQUOTES); ?> -
119 <?php if ($type_report == "standard") { ?>
120 <?php echo htmlspecialchars( xl('Standard Measures'), ENT_NOQUOTES); ?></span>
121 <?php } ?>
122 <?php if ($type_report == "cqm") { ?>
123 <?php echo htmlspecialchars( xl('Clinical Quality Measures (CQM)'), ENT_NOQUOTES); ?></span>
124 <?php } ?>
125 <?php if ($type_report == "amc") { ?>
126 <?php echo htmlspecialchars( xl('Automated Measure Calculations (AMC)'), ENT_NOQUOTES); ?></span>
127 <?php } ?>
130 <form method='post' name='theform' id='theform' action='cqm.php?type=<?php echo htmlspecialchars($type_report,ENT_QUOTES) ;?>' onsubmit='return top.restoreSession()'>
132 <div id="report_parameters">
134 <table>
135 <tr>
136 <td width='470px'>
137 <div style='float:left'>
139 <table class='text'>
141 <?php if ($type_report == "amc") { ?>
142 <tr>
143 <td class='label'>
144 <?php echo htmlspecialchars( xl('Begin Date'), ENT_NOQUOTES); ?>:
145 </td>
146 <td>
147 <input type='text' name='form_begin_date' id="form_begin_date" size='20' value='<?php echo htmlspecialchars( $begin_date, ENT_QUOTES); ?>'
148 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
149 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
150 id='img_begin_date' border='0' alt='[?]' style='cursor:pointer'
151 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
152 </td>
153 </tr>
154 <?php } ?>
156 <tr>
157 <td class='label'>
158 <?php if ($type_report == "amc") { ?>
159 <?php echo htmlspecialchars( xl('End Date'), ENT_NOQUOTES); ?>:
160 <?php } else { ?>
161 <?php echo htmlspecialchars( xl('Target Date'), ENT_NOQUOTES); ?>:
162 <?php } ?>
163 </td>
164 <td>
165 <input type='text' name='form_target_date' id="form_target_date" size='20' value='<?php echo htmlspecialchars( $target_date, ENT_QUOTES); ?>'
166 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES); ?>'>
167 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
168 id='img_target_date' border='0' alt='[?]' style='cursor:pointer'
169 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
170 </td>
171 </tr>
173 <?php if ($type_report == "cqm") { ?>
174 <input type='hidden' name='form_rule_filter' value='cqm'>
175 <?php } ?>
176 <?php if ($type_report == "amc") { ?>
177 <input type='hidden' name='form_rule_filter' value='amc'>
178 <?php } ?>
179 <?php if ($type_report == "standard") { ?>
180 <tr>
181 <td class='label'>
182 <?php echo htmlspecialchars( xl('Rule Set'), ENT_NOQUOTES); ?>:
183 </td>
184 <td>
185 <select name='form_rule_filter'>
186 <option value='passive_alert' <?php if ($rule_filter == "passive_alert") echo "selected"; ?>>
187 <?php echo htmlspecialchars( xl('Passive Alert Rules'), ENT_NOQUOTES); ?></option>
188 <option value='active_alert' <?php if ($rule_filter == "active_alert") echo "selected"; ?>>
189 <?php echo htmlspecialchars( xl('Active Alert Rules'), ENT_NOQUOTES); ?></option>
190 <option value='patient_reminder' <?php if ($rule_filter == "patient_reminder") echo "selected"; ?>>
191 <?php echo htmlspecialchars( xl('Patient Reminder Rules'), ENT_NOQUOTES); ?></option>
192 </select>
193 </td>
194 </tr>
195 <?php } ?>
197 <?php if ($type_report == "amc") { ?>
198 <input type='hidden' name='form_plan_filter' value=''>
199 <?php } else { ?>
200 <tr>
201 <td class='label'>
202 <?php echo htmlspecialchars( xl('Plan Set'), ENT_NOQUOTES); ?>:
203 </td>
204 <td>
205 <select name='form_plan_filter'>
206 <option value=''>-- <?php echo htmlspecialchars( xl('Ignore'), ENT_NOQUOTES); ?> --</option>
207 <?php if ($type_report == "cqm") { ?>
208 <option value='cqm' <?php if ($plan_filter == "cqm") echo "selected"; ?>>
209 <?php echo htmlspecialchars( xl('Official Clinical Quality Measures (CQM) Measure Groups'), ENT_NOQUOTES); ?></option>
210 <?php } ?>
211 <?php if ($type_report == "standard") { ?>
212 <option value='normal' <?php if ($plan_filter == "normal") echo "selected"; ?>>
213 <?php echo htmlspecialchars( xl('Active Plans'), ENT_NOQUOTES); ?></option>
214 <?php } ?>
215 </td>
216 </tr>
217 <?php } ?>
219 <tr>
220 <td class='label'>
221 <?php echo htmlspecialchars( xl('Provider'), ENT_NOQUOTES); ?>:
222 </td>
223 <td>
224 <?php
226 // Build a drop-down list of providers.
229 $query = "SELECT id, lname, fname FROM users WHERE ".
230 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
232 $ures = sqlStatement($query);
234 echo " <select name='form_provider'>\n";
235 echo " <option value=''>-- " . htmlspecialchars( xl('All (Cumulative)'), ENT_NOQUOTES) . " --\n";
237 echo " <option value='collate_outer'";
238 if ($_POST['form_provider'] == 'collate_outer') echo " selected";
239 echo ">-- " . htmlspecialchars( xl('All (Collated Format A)'), ENT_NOQUOTES) . " --\n";
241 echo " <option value='collate_inner'";
242 if ($_POST['form_provider'] == 'collate_inner') echo " selected";
243 echo ">-- " . htmlspecialchars( xl('All (Collated Format B)'), ENT_NOQUOTES) . " --\n";
245 while ($urow = sqlFetchArray($ures)) {
246 $provid = $urow['id'];
247 echo " <option value='".htmlspecialchars( $provid, ENT_QUOTES)."'";
248 if ($provid == $_POST['form_provider']) echo " selected";
249 echo ">" . htmlspecialchars( $urow['lname'] . ", " . $urow['fname'], ENT_NOQUOTES) . "\n";
252 echo " </select>\n";
255 </td>
256 </tr>
258 <?php if ($type_report == "amc") { ?>
259 <tr>
260 <td>
261 <?php echo htmlspecialchars( xl('Number labs'), ENT_NOQUOTES); ?>:<br>
262 (<?php echo htmlspecialchars( xl('Non-electronic'), ENT_NOQUOTES); ?>)
263 </td>
264 <td>
265 <input type="text" name="labs_manual_entry" value="<?php echo htmlspecialchars($labs_manual,ENT_QUOTES); ?>">
266 </td>
267 </tr>
268 <?php } ?>
270 </table>
272 </div>
274 </td>
275 <td align='left' valign='middle' height="100%">
276 <table style='border-left:1px solid; width:100%; height:100%' >
277 <tr>
278 <td>
279 <div style='margin-left:15px'>
280 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); top.restoreSession(); $("#theform").submit();'>
281 <span>
282 <?php echo htmlspecialchars( xl('Submit'), ENT_NOQUOTES); ?>
283 </span>
284 </a>
285 <?php if ($type_report == "cqm") { ?>
286 <a href='#' class='css_button' onclick='return GenXml("false")'>
287 <span>
288 <?php echo htmlspecialchars( xl('Generate PQRI report (Method A)'), ENT_NOQUOTES); ?>
289 </span>
290 </a>
291 <a href='#' class='css_button' onclick='return GenXml("true")'>
292 <span>
293 <?php echo htmlspecialchars( xl('Generate PQRI report (Method E)'), ENT_NOQUOTES); ?>
294 </span>
295 </a>
296 <?php } ?>
297 <?php if ($_POST['form_refresh']) { ?>
298 <a href='#' class='css_button' onclick='window.print()'>
299 <span>
300 <?php echo htmlspecialchars( xl('Print'), ENT_NOQUOTES); ?>
301 </span>
302 </a>
303 <?php } ?>
304 </div>
305 </td>
306 </tr>
307 </table>
308 </td>
309 </tr>
310 </table>
312 </div> <!-- end of search parameters -->
314 <br>
316 <?php
317 if ($_POST['form_refresh']) {
321 <div id="report_results">
322 <table>
324 <thead>
325 <th>
326 <?php echo htmlspecialchars( xl('Title'), ENT_NOQUOTES); ?>
327 </th>
329 <th>
330 <?php echo htmlspecialchars( xl('Total Patients'), ENT_NOQUOTES); ?>
331 </th>
333 <th>
334 <?php if ($type_report == "amc") { ?>
335 <?php echo htmlspecialchars( xl('Denominator'), ENT_NOQUOTES); ?></a>
336 <?php } else { ?>
337 <?php echo htmlspecialchars( xl('Applicable Patients') .' (' . xl('Denominator') . ')', ENT_NOQUOTES); ?></a>
338 <?php } ?>
339 </th>
341 <?php if ($type_report != "amc") { ?>
342 <th>
343 <?php echo htmlspecialchars( xl('Excluded Patients'), ENT_NOQUOTES); ?></a>
344 </th>
345 <?php } ?>
347 <th>
348 <?php if ($type_report == "amc") { ?>
349 <?php echo htmlspecialchars( xl('Numerator'), ENT_NOQUOTES); ?></a>
350 <?php } else { ?>
351 <?php echo htmlspecialchars( xl('Passed Patients') . ' (' . xl('Numerator') . ')', ENT_NOQUOTES); ?></a>
352 <?php } ?>
353 </th>
355 <th>
356 <?php echo htmlspecialchars( xl('Performance Percentage'), ENT_NOQUOTES); ?></a>
357 </th>
359 </thead>
360 <tbody> <!-- added for better print-ability -->
361 <?php
363 if ($type_report == "amc") {
364 // For AMC:
365 // need to make $target_date an array with two elements ('dateBegin' and 'dateTarget')
366 // need to to send a manual data entry option (number of labs)
367 $array_date = array();
368 $array_date['dateBegin'] = $begin_date;
369 $array_date['dateTarget'] = $target_date;
370 $options = array('labs_manual'=>$labs_manual);
371 $dataSheet = test_rules_clinic($provider,$rule_filter,$array_date,"report",'',$plan_filter,$organize_method,$options);
373 else {
374 $dataSheet = test_rules_clinic($provider,$rule_filter,$target_date,"report",'',$plan_filter,$organize_method);
377 $firstProviderFlag = TRUE;
378 $firstPlanFlag = TRUE;
379 $existProvider = FALSE;
380 foreach ($dataSheet as $row) {
384 <tr bgcolor='<?php echo $bgcolor ?>'>
386 <?php
387 if (isset($row['is_main']) || isset($row['is_sub'])) {
388 echo "<td class='detail'>";
389 if (isset($row['is_main'])) {
390 echo "<b>".generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id'])."</b>";
391 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code']) || !empty($row['amc_code'])) {
392 echo " (";
393 if (!empty($row['cqm_pqri_code'])) {
394 echo " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES) . " ";
396 if (!empty($row['cqm_nqf_code'])) {
397 echo " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES) . " ";
399 if (!empty($row['amc_code'])) {
400 echo " " . htmlspecialchars( xl('AMC') . ":" . $row['amc_code'], ENT_NOQUOTES) . " ";
402 echo ")";
405 if ( !(empty($row['concatenated_label'])) ) {
406 echo ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES) . " ";
410 else { // isset($row['is_sub'])
411 echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$row['action_category']);
412 echo ": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$row['action_item']);
414 echo "</td>";
415 echo "<td align='center'>" . $row['total_patients'] . "</td>";
416 echo "<td align='center'>" . $row['pass_filter'] . "</td>";
417 if ($type_report != "amc") {
418 echo "<td align='center'>" . $row['excluded'] . "</td>";
420 echo "<td align='center'>" . $row['pass_target'] . "</td>";
421 echo "<td align='center'>" . $row['percentage'] . "</td>";
423 else if (isset($row['is_provider'])) {
424 // Display the provider information
425 if (!$firstProviderFlag && $_POST['form_provider'] == 'collate_outer') {
426 echo "<tr><td>&nbsp</td></tr>";
428 echo "<td class='detail' align='center'><b>";
429 echo htmlspecialchars( xl("Provider").": " . $row['prov_lname'] . "," . $row['prov_fname'], ENT_NOQUOTES);
430 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
431 echo " (";
432 if (!empty($row['npi'])) {
433 echo " " . htmlspecialchars( xl('NPI') . ":" . $row['npi'], ENT_NOQUOTES) . " ";
435 if (!empty($row['federaltaxid'])) {
436 echo " " . htmlspecialchars( xl('TID') . ":" . $row['federaltaxid'], ENT_NOQUOTES) . " ";
438 echo ")";
440 echo "</b></td>";
441 $firstProviderFlag = FALSE;
442 $existProvider = TRUE;
444 else { // isset($row['is_plan'])
445 if (!$firstPlanFlag && $_POST['form_provider'] != 'collate_outer') {
446 echo "<tr><td>&nbsp</td></tr>";
448 echo "<td class='detail' align='center'><b>";
449 echo htmlspecialchars( xl("Plan"), ENT_NOQUOTES) . ": ";
450 echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_plans'),$row['id']);
451 if (!empty($row['cqm_measure_group'])) {
452 echo " (". htmlspecialchars( xl('Measure Group Code') . ": " . $row['cqm_measure_group'], ENT_NOQUOTES) . ")";
454 echo "</b></td>";
455 $firstPlanFlag = FALSE;
458 </tr>
460 <?php
463 </tbody>
464 </table>
465 </div> <!-- end of search results -->
466 <?php } else { ?>
467 <div class='text'>
468 <?php echo htmlspecialchars( xl('Please input search criteria above, and click Submit to view results.'), ENT_NOQUOTES); ?>
469 </div>
470 <?php } ?>
472 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
474 </form>
476 </body>
478 <!-- stuff for the popup calendar -->
479 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
480 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
481 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
482 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
483 <script language="Javascript">
484 <?php if ($type_report == "amc") { ?>
485 Calendar.setup({inputField:"form_begin_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_begin_date", showsTime:'true'});
486 <?php } ?>
487 Calendar.setup({inputField:"form_target_date", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_target_date", showsTime:'true'});
488 </script>
490 </html>