fix: Update patient_tracker.php (#6595)
[openemr.git] / library / ajax / graph_track_anything.php
blob3ae60fe47d688cac8fb213b0abb59d8f1de5eac0
1 <?php
3 /**
4 * Trending script for graphing objects in track anything module.
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Joe Slam <joe@produnis.de>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 * @copyright Copyright (c) 2010-2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2011 Rod Roark <rod@sunsetsystems.com>
14 * @copyright Copyright (c) 2014 Joe Slam <joe@produnis.de>
17 require_once(dirname(__FILE__) . "/../../interface/globals.php");
19 use OpenEMR\Common\Csrf\CsrfUtils;
21 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
22 CsrfUtils::csrfNotVerified();
25 // get $_POSTed data
26 $titleGraph = json_decode($_POST['track'], true);
27 $the_date_array = json_decode($_POST['dates'], true);
28 $the_value_array = json_decode($_POST['values'], true);
29 $the_item_names = json_decode($_POST['items'], true);
30 $the_checked_cols = json_decode($_POST['thecheckboxes'], true);
31 // ++++++/end get POSTed data
33 // check if something was sent
34 // and quit if not
35 //-------------------------------
36 if ($the_checked_cols == null) {
37 // nothing to plot
38 echo "No item checked,\n";
39 echo "nothing to plot."; // DEBUG ONLY! COMMENT ME OUT!
40 exit;
43 // end check if NULL data
45 // build labels
46 $data_final = array();
47 $data_final = xl('Date');
48 foreach ($the_checked_cols as $col) {
49 if (is_numeric($the_value_array[$col][0])) {
50 $data_final .= "\t" . $the_item_names[$col];
51 } else {
52 // is NOT numeric, so skip column
56 $data_final .= "\n";
58 // build data
59 for ($i = 0; $i < count($the_date_array); $i++) {
60 $data_final .= $the_date_array[$i];
61 foreach ($the_checked_cols as $col) {
62 if (is_numeric($the_value_array[$col][0])) {
63 // is numeric
64 $data_final .= "\t" . $the_value_array[$col][$i];
65 } else {
66 // is NOT numeric, do nothing
70 $data_final .= "\n";
73 // Build and send back the json
74 $graph_build = array();
75 $graph_build['data_final'] = $data_final;
76 $graph_build['title'] = $titleGraph;
78 // Note need to also use " when building the $data_final rather
79 // than ' , or else JSON_UNESCAPED_SLASHES doesn't work and \n and
80 // \t get escaped.
81 echo json_encode($graph_build, JSON_UNESCAPED_SLASHES);