Highway to PSR2
[openemr.git] / library / ajax / execute_cdr_report.php
blobbd33073be59588966ea9ec74deca6dc50e9b6a0e
1 <?php
2 /**
3 * Run a CDR engine report.
5 * Copyright (C) 2012 Brady Miller <brady.g.miller@gmail.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.g.miller@gmail.com>
20 * @link http://www.open-emr.org
25 require_once(dirname(__FILE__) . "/../../interface/globals.php");
26 require_once(dirname(__FILE__) . "/../clinical_rules.php");
28 //To improve performance and not freeze the session when running this
29 // report, turn off session writing. Note that php session variables
30 // can not be modified after the line below. So, if need to do any php
31 // session work in the future, then will need to remove this line.
32 session_write_close();
34 //Remove time limit, since script can take many minutes
35 set_time_limit(0);
37 // Set the "nice" level of the process for these reports. When the "nice" level
38 // is increased, these cpu intensive reports will have less affect on the performance
39 // of other server activities, albeit it may negatively impact the performance
40 // of this report (note this is only applicable for linux).
41 if (!empty($GLOBALS['cdr_report_nice'])) {
42 proc_nice($GLOBALS['cdr_report_nice']);
45 // Start a report, which will be stored in the report_results sql table..
46 if (!empty($_POST['execute_report_id'])) {
47 $target_date = (!empty($_POST['date_target'])) ? $_POST['date_target'] : date('Y-m-d H:i:s');
48 $rule_filter = (!empty($_POST['type'])) ? $_POST['type'] : "";
49 $plan_filter = (!empty($_POST['plan'])) ? $_POST['plan'] : "";
50 $organize_method = (empty($plan_filter)) ? "default" : "plans";
51 $provider = $_POST['provider'];
52 $pat_prov_rel = (empty($_POST['pat_prov_rel'])) ? "primary" : $_POST['pat_prov_rel'];
55 // Process a new report and collect results
56 $options = array();
57 $array_date = array();
59 if (($rule_filter == "amc") || ($rule_filter == "amc_2011") || ($rule_filter == "amc_2014") || ($rule_filter == "amc_2014_stage1") || ($rule_filter == "amc_2014_stage2")) {
60 // For AMC:
61 // need to make $target_date an array with two elements ('dateBegin' and 'dateTarget')
62 // need to send a manual data entry option (number of labs)
63 $array_date['dateBegin'] = $_POST['date_begin'];
64 $array_date['dateTarget'] = $target_date;
65 $options = array('labs_manual'=>$_POST['labs']);
66 } else {
67 // For others, use the unmodified target date array and send an empty options array
68 $array_date = $target_date;
71 test_rules_clinic_batch_method($provider, $rule_filter, $array_date, "report", $plan_filter, $organize_method, $options, $pat_prov_rel, '', $_POST['execute_report_id']);
72 } else {
73 echo "ERROR";