added cache clearing support for dialog.js (#411)
[openemr.git] / interface / forms / track_anything / new.php
blob58a70ac62bfba45b5fde06b6b62dc942cc14b55d
1 <?php
2 /**
3 * Encounter form to track any clinical parameter.
5 * Copyright (C) 2014 Joe Slam <trackanything@produnis.de>
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 Joe Slam <trackanything@produnis.de>
20 * @link http://www.open-emr.org
23 // Some initial api-inputs
24 $sanitize_all_escapes = true;
25 $fake_register_globals = false;
26 require_once("../../globals.php");
27 require_once("$srcdir/api.inc");
28 require_once("$srcdir/forms.inc");
29 require_once("$srcdir/acl.inc");
30 formHeader("Form: Track anything");
32 // check if we are inside an encounter
33 if (! $encounter) { // comes from globals.php
34 die("Internal error: we do not seem to be in an encounter!");
37 // get vars posted by FORMs
38 if (!$formid){
39 $formid = $_GET['id'];
40 if (!$formid){ $formid = $_POST['formid']; }
43 $myprocedureid = $_POST['procedure2track'];
45 echo "<html><head>";
46 ?>
47 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
48 <link rel="stylesheet" href="<?php echo $web_root; ?>/interface/forms/track_anything/style.css" type="text/css">
49 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
50 <script type="text/javascript" src="../../../library/textformat.js"></script>
51 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
52 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
53 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
54 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
56 <?php
57 echo "</head><body class='body_top'>";
58 echo "<div id='track_anything'>";
60 // check if this Track is new
61 if (!$formid){
62 // this is a new Track
64 // check if procedure is selcted
65 if ($_POST['bn_select']) {
66 // "save"-Button was clicked, saving Form into db
68 // save inbto db
69 if($myprocedureid){
70 $query = "INSERT INTO form_track_anything (procedure_type_id) VALUES (?)";
71 $formid = sqlInsert($query, $myprocedureid);
72 $spell = "SELECT name FROM form_track_anything_type WHERE track_anything_type_id = ?";
73 $myrow = sqlQuery($spell,array($myprocedureid));
74 $myprocedurename = $myrow["name"];
75 $register_as = "Track: " . $myprocedurename;
76 // adding Form
77 addForm($encounter, $register_as, $formid, "track_anything", $pid, $userauthorized);
78 } else {
79 echo xlt('No track selected'). ".<br>";
80 ?><input type='button' value='<?php echo xla('Back'); ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
83 }else{
84 // procedure is not yet selected
85 echo "<table>";
86 echo "<tr>";
87 echo "<th>" . xlt('Select Track') .":</th>";
88 echo "</tr><tr>";
89 echo "<td>";
90 echo "<form method='post' action='" . $rootdir . "/forms/track_anything/new.php' onsubmit='return top.restoreSession()'>";
92 echo "<select name='procedure2track' size='10' style='width: 300px'>";
93 $spell = "SELECT * FROM form_track_anything_type ";
94 $spell .= "WHERE parent = 0 AND active = 1 ";
95 $spell .= "ORDER BY position ASC, name ASC ";
96 $testi = sqlStatement($spell);
97 while($myrow = sqlFetchArray($testi)){
98 $myprocedureid = $myrow["track_anything_type_id"];
99 $myprocedurename = $myrow["name"];
100 echo "<option value='" . attr($myprocedureid) . "'>" . text($myprocedurename) . "</option>";
102 echo "</select>";
103 echo "</td></tr><tr><td align='center'>";
104 echo "<input type='submit' name='bn_select' value='" . xla('Select') . "' />";
105 ?><input type='button' value='<?php echo xla('Back'); ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
106 echo "</form>";
107 echo "<br>&nbsp;</td></tr>";
109 echo "<tr><td align='center'>";
110 echo "<input type='submit' name='create_track' value='" . xla('Configure tracks') . "' ";
111 ?> onclick="top.restoreSession();location='<?php echo $web_root ?>/interface/forms/track_anything/create.php'"<?php
112 echo " />";
113 echo "</td></tr>";
114 echo "</table>";
120 // instead of "else", we check again for "formid"
121 if ($formid){
122 // this is an existing Track
123 //----------------------------------------------------
124 // get submitted item-Ids
125 $mylist = $_POST['liste'];
126 #echo $mylist;
127 $length = count($mylist);
128 $thedate = $_POST['datetime'];
129 #echo $thedate;
130 //check if whole input is NULL
131 $all_are_null = 0;
132 for($i= 0; $i < $length; $i++){
133 #echo "beep";
134 $thisid = $mylist[$i];
135 $thisvalue = $_POST[$thisid];
136 if ($thisvalue != NULL && $thisvalue != '') {
137 $all_are_null++;
141 // if all of the input is NULL, we do nothing
142 // if at least one entrie is NOT NULL, we save all into db
143 if ($all_are_null > 0) {
144 for($i= 0; $i < $length; $i++){
145 $thisid = $mylist[$i];
146 $thisvalue = $_POST[$thisid];
148 // store data to track_anything_db
149 $query = "INSERT INTO form_track_anything_results (track_anything_id, track_timestamp, itemid, result) VALUES (?, ?, ?, ?)";
150 sqlInsert($query, array($formid,$thedate,$thisid,$thisvalue));
153 //----------------------------------------------------
157 // update corrected old items
158 // ---------------------------
160 // getting old entries from <form>
161 $old_id = $_POST['old_id'];
162 $old_time = $_POST['old_time'];
163 $old_value = $_POST['old_value'];
165 $how_many = count($old_time);
166 // do this for each data row
167 for ($x=0; $x<=$how_many; $x++) {
168 // how many columns do we have
169 $how_many_cols = count($old_value[$x]);
170 for($y=0; $y<$how_many_cols; $y++){
171 // here goes the UPDATE sql-spruch
172 $insertspell = "UPDATE form_track_anything_results ";
173 $insertspell .= "SET track_timestamp = ? , result = ? ";
174 $insertspell .= "WHERE id = ? ";
175 sqlStatement($insertspell, array($old_time[$x], $old_value[$x][$y], $old_id[$x][$y]));
179 //--------------------------------------------------
182 //get procedure ID
183 if (!$myprocedureid){
184 $spell = "SELECT procedure_type_id FROM form_track_anything WHERE id = ?";
185 $myrow = sqlQuery($spell, array($formid));
186 $myprocedureid = $myrow["procedure_type_id"];
189 echo "<br><b>" . xlt('Enter new data') . "</b>:<br>";
190 echo "<form method='post' action='" . $rootdir . "/forms/track_anything/new.php' onsubmit='return top.restoreSession()'>";
191 echo "<table>";
192 echo "<tr><th class='item'>" . xlt('Item') . "</th>";
193 echo "<th class='value'>" . xlt('Value') . "</th></tr>";
196 echo "<tr><td>" . xlt('Date Time') . "</td>";
197 echo "<td><input type='text' size='16' name='datetime' id='datetime'" .
198 "value='" . attr(date('Y-m-d H:i:s', time())) . "'" .
199 "onkeyup='datekeyup(this,mypcc,true)' onblur='dateblur(this,mypcc,true)' />" .
200 "<img src='" . $rootdir . "/pic/show_calendar.gif' id='img_date' align='absbottom'" .
201 "width='24' height='22' border='0' alt='[?]' style='cursor:pointer' /></td></tr>";
203 <script language="javascript">
204 Calendar.setup({inputField:"datetime", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_date", showsTime:true});
205 </script>
207 <?php
208 // get items to track
209 $liste = array();
210 $spell = "SELECT * FROM form_track_anything_type WHERE parent = ? AND active = 1 ORDER BY position ASC, name ASC ";
211 $query = sqlStatement($spell, array($myprocedureid));
212 while($myrow = sqlFetchArray($query)){
213 echo "<input type='hidden' name='liste[]' value='". attr($myrow['track_anything_type_id']) . "'>";
214 echo "<tr><td> " . text($myrow['name']) . "</td>";
215 echo "<td><input size='12' type='text' name='" . attr($myrow['track_anything_type_id']) . "'></td></tr>";
218 echo "</table>";
219 echo "<input type='hidden' name='formid' value='". attr($formid) . "'>";
220 echo "<input type='submit' name='bn_save' value='" . xla('Save') . "' />";
221 ?><input type='button' value='<?php echo xla('Stop'); ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
224 // show old entries of track
225 //-----------------------------------
226 // get unique timestamps of track
227 echo "<br><br><hr><br>";
228 echo "<b>" . xlt('Edit your entered data') . ":</b><br>";
229 $shownameflag = 0; // flag if this is <table>-headline
230 echo "<table border='1'>";
232 $spell0 = "SELECT DISTINCT track_timestamp FROM form_track_anything_results WHERE track_anything_id = ? ORDER BY track_timestamp DESC";
233 $query = sqlStatement($spell0,array($formid));
234 $main_counter=0; // this counts 'number of rows' of old entries
235 while($myrow = sqlFetchArray($query)){
236 $thistime = $myrow['track_timestamp'];
237 $shownameflag++;
239 $spell = "SELECT form_track_anything_results.id AS result_id, form_track_anything_results.itemid, form_track_anything_results.result, form_track_anything_type.name AS the_name ";
240 $spell .= "FROM form_track_anything_results ";
241 $spell .= "INNER JOIN form_track_anything_type ON form_track_anything_results.itemid = form_track_anything_type.track_anything_type_id ";
242 $spell .= "WHERE track_anything_id = ? AND track_timestamp = ? AND form_track_anything_type.active = 1 ";
243 $spell .= "ORDER BY form_track_anything_type.position ASC, the_name ASC ";
244 $query2 = sqlStatement($spell,array($formid ,$thistime));
246 // <table> heading line
247 if ($shownameflag==1){
248 echo "<tr><th class='time'>" . xlt('Time') . "</th>";
249 while($myrow2 = sqlFetchArray($query2)){
250 echo "<th class='item'>" . text($myrow2['the_name']) . "</th>";
252 echo "</tr>";
255 echo "<tr><td bgcolor=#eeeeec>";
256 $main_counter++; // next row
257 echo "<input type='text' size='12' name='old_time[" . attr($main_counter) . "]' value='" . attr($thistime) . "'></td>";
258 $query2 = sqlStatement($spell,array($formid ,$thistime));
260 $counter = 0; // this counts columns
261 while($myrow2 = sqlFetchArray($query2)){
262 echo "<td>";
263 echo "<input type='hidden' name='old_id[" . attr($main_counter) . "][" . attr($counter) . "]' value='". attr($myrow2['result_id']) . "'>";
264 echo "<input type='text' size='12' name='old_value[" . attr($main_counter) . "][" . attr($counter) . "]' value='" . attr($myrow2['result']) . "'></td>";
265 $counter++; // next cloumn
267 echo "</tr>";
270 echo "</tr></table>";
271 echo "<input type='hidden' name='formid' value='". attr($formid) . "'>";
272 echo "<input type='submit' name='bn_save' value='" . xla('Save') . "' />";
273 ?><input type='button' value='<?php echo xla('Stop'); ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
275 echo "</form>";
276 }//end if($formid)
277 echo "</div>";
278 formFooter();