Some change to prior PR#7429 (#7447)
[openemr.git] / interface / patient_file / encounter / trend_form.php
blob1767810622a67ef28eae3e5bf7e363d028cb1550
1 <?php
3 /**
4 * Trending script for graphing objects.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
11 * @copyright Copyright (c) 2011 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2010-2018 Brady Miller <brady.g.miller@gmail.com>
15 require_once("../../globals.php");
17 use OpenEMR\Common\Csrf\CsrfUtils;
18 use OpenEMR\Core\Header;
20 $formname = $_GET["formname"];
21 $is_lbf = substr($formname, 0, 3) === 'LBF';
23 if ($is_lbf) {
24 // Determine the default field ID and its title for graphing.
25 // This is from the last graphable field in the form.
26 $default = sqlQuery(
27 "SELECT field_id, title FROM layout_options WHERE " .
28 "form_id = ? AND uor > 0 AND edit_options LIKE '%G%' " .
29 "ORDER BY group_id DESC, seq DESC, title DESC LIMIT 1",
30 array($formname)
34 //Bring in the style sheet
36 <?php require $GLOBALS['srcdir'] . '/js/xl/dygraphs.js.php'; ?>
38 <?php
39 // Special case where not setting up the header for a script, so using setupAssets function,
40 // which does not autoload anything. The actual header is set up in the script called at
41 // the bottom of this script.
42 Header::setupAssets(['dygraphs', 'jquery']);
45 <?php
46 // Hide the current value css entries. This is currently specific
47 // for the vitals form but could use this mechanism for other
48 // forms.
49 // Hiding classes:
50 // currentvalues - input boxes
51 // valuesunfocus - input boxes that are auto-calculated
52 // editonly - the edit and cancel buttons
53 // Showing class:
54 // readonly - the link back to summary screen
55 // Also customize the 'graph' class to look like links.
57 <style>
58 .currentvalues {
59 display: none;
61 .valuesunfocus {
62 display: none;
64 .editonly {
65 display: none !important;
68 .graph {
69 color: #0000cc;
72 #chart {
73 margin:0em 1em 2em 2em;
75 </style>
77 <script>
80 // Show the selected chart in the 'chart' div element
81 function show_graph(table_graph, name_graph, title_graph)
83 top.restoreSession();
84 $.ajax({ url: '../../../library/ajax/graphs.php',
85 type: 'POST',
86 data: ({
87 table: table_graph,
88 name: name_graph,
89 title: title_graph,
90 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
91 }),
92 dataType: "json",
93 success: function(returnData){
95 g2 = new Dygraph(
96 document.getElementById("chart"),
97 returnData.data_final,
99 title: returnData.title,
100 delimiter: '\t',
101 xRangePad: 20,
102 yRangePad: 20,
103 width: 480,
104 height: 320,
105 xlabel: xlabel_translate
109 // ensure show the chart div
110 $('#chart').show();
112 error: function() {
113 // hide the chart div
114 $('#chart').hide();
115 <?php if ($GLOBALS['graph_data_warning']) { ?>
116 if(!title_graph){
117 alert(<?php echo xlj('This item does not have enough data to graph');?> + ".\n" + <?php echo xlj('Please select an item that has more data');?> + ".");
119 else {
120 alert(title_graph + " " + <?php echo xlj('does not have enough data to graph');?> + ".\n" + <?php echo xlj('Please select an item that has more data');?> + ".");
122 <?php } ?>
128 $(function () {
130 // Use jquery to show the 'readonly' class entries
131 $('.readonly').show();
133 // Place click callback for graphing
134 <?php if ($is_lbf) { ?>
135 // For LBF the <td> has an id of label_id_$fieldid
136 $(".graph").on("click", function(e){ show_graph(<?php echo js_escape($formname); ?>, this.id.substring(9), $(this).text()) });
137 <?php } else { ?>
138 $(".graph").on("click", function(e){ show_graph('form_vitals', this.id, '$(this).text()') });
139 <?php } ?>
141 // Show hovering effects for the .graph links
142 $(".graph").on("mouseenter",
143 function(){
144 $(this).css({color:'#ff5555'});
145 }).on("mouseleave",
146 function(){
147 $(this).css({color:'#0000cc'});
151 // show blood pressure graph by default
152 <?php if ($is_lbf) { ?>
153 <?php if (!empty($default)) { ?>
154 show_graph(<?php echo js_escape($formname); ?>,<?php echo js_escape($default['field_id']); ?>,<?php echo js_escape($default['title']); ?>);
155 <?php } ?>
156 <?php } else { ?>
157 show_graph('form_vitals','bps','');
158 <?php } ?>
160 </script>
162 <?php
163 if ($is_lbf) {
164 // Use the List Based Forms engine for all LBFxxxxx forms.
165 include_once("$incdir/forms/LBF/new.php");
166 } else {
167 // ensure the path variable has no illegal characters
168 check_file_dir_name($formname);
170 include_once("$incdir/forms/$formname/new.php");