Improved/optimized CDR engine reports (and patient reminders) and added a
[openemr.git] / library / ajax / execute_cdr_report.php
blobe1a4a6e0392cc9929060d09617a548af20150145
1 <?php
2 /**
3 * Run a CDR engine report.
5 * Copyright (C) 2012 Brady Miller <brady@sparmy.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Brady Miller <brady@sparmy.com>
20 * @link http://www.open-emr.org
23 //SANITIZE ALL ESCAPES
24 $sanitize_all_escapes=true;
27 //STOP FAKE REGISTER GLOBALS
28 $fake_register_globals=false;
31 require_once(dirname(__FILE__) . "/../../interface/globals.php");
32 require_once(dirname(__FILE__) . "/../clinical_rules.php");
34 //To improve performance and not freeze the session when running this
35 // report, turn off session writing. Note that php session variables
36 // can not be modified after the line below. So, if need to do any php
37 // session work in the future, then will need to remove this line.
38 session_write_close();
40 //Remove time limit, since script can take many minutes
41 set_time_limit(0);
43 // Set the "nice" level of the process for these reports. When the "nice" level
44 // is increased, these cpu intensive reports will have less affect on the performance
45 // of other server activities, albeit it may negatively impact the performance
46 // of this report (note this is only applicable for linux).
47 if (!empty($GLOBALS['cdr_report_nice'])) {
48 proc_nice($GLOBALS['cdr_report_nice']);
51 // Start a report, which will be stored in the report_results sql table..
52 if (!empty($_POST['execute_report_id'])) {
54 $target_date = (!empty($_POST['date_target'])) ? $_POST['date_target'] : date('Y-m-d H:i:s');
55 $rule_filter = (!empty($_POST['type'])) ? $_POST['type'] : "";
56 $plan_filter = (!empty($_POST['plan'])) ? $_POST['plan'] : "";
57 $organize_method = (empty($plan_filter)) ? "default" : "plans";
58 $provider = $_POST['provider'];
59 $pat_prov_rel = (empty($_POST['pat_prov_rel'])) ? "primary" : $_POST['pat_prov_rel'];
62 // Process a new report and collect results
63 $options = array();
64 $array_date = array();
66 if ($_POST['type'] == "amc") {
67 // For AMC:
68 // need to make $target_date an array with two elements ('dateBegin' and 'dateTarget')
69 // need to send a manual data entry option (number of labs)
70 $array_date['dateBegin'] = $_POST['date_begin'];
71 $array_date['dateTarget'] = $target_date;
72 $options = array('labs_manual'=>$_POST['labs']);
74 else {
75 // For others, use the unmodified target date array and send an empty options array
76 $array_date = $target_date;
79 test_rules_clinic_batch_method($provider,$rule_filter,$array_date,"report",$plan_filter,$organize_method,$options,$pat_prov_rel,'',$_POST['execute_report_id']);
81 else {
82 echo "ERROR";