3 * Encounter form to track any clinical parameter.
6 * @link http://www.open-emr.org
7 * @author Joe Slam <trackanything@produnis.de>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2014 Joe Slam <trackanything@produnis.de>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../../globals.php");
16 require_once("$srcdir/api.inc");
17 require_once("$srcdir/forms.inc");
18 require_once("$srcdir/acl.inc");
20 formHeader("Form: Track anything");
22 // check if we are inside an encounter
23 if (! $encounter) { // comes from globals.php
24 die("Internal error: we do not seem to be in an encounter!");
27 // get vars posted by FORMs
29 $formid = $_GET['id'];
31 $formid = $_POST['formid'];
35 $myprocedureid = $_POST['procedure2track'];
39 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
40 <link rel
="stylesheet" href
="<?php echo $web_root; ?>/interface/forms/track_anything/style.css" type
="text/css">
41 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
43 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script
>
44 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script
>
45 <script type
="text/javascript" src
="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
46 <script type
="text/javascript" src
="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
48 <script type
="text/javascript">
50 $
('.datetimepicker').datetimepicker({
51 <?php
$datetimepicker_timepicker = true; ?
>
52 <?php
$datetimepicker_showseconds = true; ?
>
53 <?php
$datetimepicker_formatInput = false; ?
>
54 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
55 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
61 echo "</head><body class='body_top'>";
62 echo "<div id='track_anything'>";
64 // check if this Track is new
66 // this is a new Track
68 // check if procedure is selcted
69 if ($_POST['bn_select']) {
70 // "save"-Button was clicked, saving Form into db
74 $query = "INSERT INTO form_track_anything (procedure_type_id) VALUES (?)";
75 $formid = sqlInsert($query, $myprocedureid);
76 $spell = "SELECT name FROM form_track_anything_type WHERE track_anything_type_id = ?";
77 $myrow = sqlQuery($spell, array($myprocedureid));
78 $myprocedurename = $myrow["name"];
79 $register_as = "Track: " . $myprocedurename;
81 addForm($encounter, $register_as, $formid, "track_anything", $pid, $userauthorized);
83 echo xlt('No track selected'). ".<br>";
84 ?
><input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
87 // procedure is not yet selected
90 echo "<th>" . xlt('Select Track') .":</th>";
93 echo "<form method='post' action='" . $rootdir . "/forms/track_anything/new.php' onsubmit='return top.restoreSession()'>";
95 echo "<select name='procedure2track' size='10' style='width: 300px'>";
96 $spell = "SELECT * FROM form_track_anything_type ";
97 $spell .= "WHERE parent = 0 AND active = 1 ";
98 $spell .= "ORDER BY position ASC, name ASC ";
99 $testi = sqlStatement($spell);
100 while ($myrow = sqlFetchArray($testi)) {
101 $myprocedureid = $myrow["track_anything_type_id"];
102 $myprocedurename = $myrow["name"];
103 echo "<option value='" . attr($myprocedureid) . "'>" . text($myprocedurename) . "</option>";
107 echo "</td></tr><tr><td align='center'>";
108 echo "<input type='submit' name='bn_select' value='" . xla('Select') . "' />";
109 ?
><input type
='button' value
='<?php echo xla('Back
'); ?>' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
111 echo "<br> </td></tr>";
113 echo "<tr><td align='center'>";
114 echo "<input type='submit' name='create_track' value='" . xla('Configure tracks') . "' ";
115 ?
> onclick
="top.restoreSession();location='<?php echo $web_root ?>/interface/forms/track_anything/create.php'"<?php
123 // instead of "else", we check again for "formid"
125 // this is an existing Track
126 //----------------------------------------------------
127 // get submitted item-Ids
128 $mylist = $_POST['liste'];
130 $length = count($mylist);
131 $thedate = $_POST['datetime'];
133 //check if whole input is NULL
135 for ($i= 0; $i < $length; $i++
) {
137 $thisid = $mylist[$i];
138 $thisvalue = $_POST[$thisid];
139 if ($thisvalue != null && $thisvalue != '') {
144 // if all of the input is NULL, we do nothing
145 // if at least one entrie is NOT NULL, we save all into db
146 if ($all_are_null > 0) {
147 for ($i= 0; $i < $length; $i++
) {
148 $thisid = $mylist[$i];
149 $thisvalue = $_POST[$thisid];
151 // store data to track_anything_db
152 $query = "INSERT INTO form_track_anything_results (track_anything_id, track_timestamp, itemid, result) VALUES (?, ?, ?, ?)";
153 sqlStatement($query, array($formid,$thedate,$thisid,$thisvalue));
157 //----------------------------------------------------
161 // update corrected old items
162 // ---------------------------
164 // getting old entries from <form>
165 $old_id = $_POST['old_id'];
166 $old_time = $_POST['old_time'];
167 $old_value = $_POST['old_value'];
169 $how_many = count($old_time);
170 // do this for each data row
171 for ($x=0; $x<=$how_many; $x++
) {
172 // how many columns do we have
173 $how_many_cols = count($old_value[$x]);
174 for ($y=0; $y<$how_many_cols; $y++
) {
175 // here goes the UPDATE sql-spruch
176 $insertspell = "UPDATE form_track_anything_results ";
177 $insertspell .= "SET track_timestamp = ? , result = ? ";
178 $insertspell .= "WHERE id = ? ";
179 sqlStatement($insertspell, array($old_time[$x], $old_value[$x][$y], $old_id[$x][$y]));
183 //--------------------------------------------------
187 if (!$myprocedureid) {
188 $spell = "SELECT procedure_type_id FROM form_track_anything WHERE id = ?";
189 $myrow = sqlQuery($spell, array($formid));
190 $myprocedureid = $myrow["procedure_type_id"];
193 echo "<br><b>" . xlt('Enter new data') . "</b>:<br>";
194 echo "<form method='post' action='" . $rootdir . "/forms/track_anything/new.php' onsubmit='return top.restoreSession()'>";
196 echo "<tr><th class='item'>" . xlt('Item') . "</th>";
197 echo "<th class='value'>" . xlt('Value') . "</th></tr>";
200 echo "<tr><td>" . xlt('Date Time') . "</td>";
201 echo "<td><input type='text' size='16' name='datetime' id='datetime'" .
202 "value='" . attr(date('Y-m-d H:i:s', time())) . "'" .
203 "class='datetimepicker' /></td></tr>";
207 // get items to track
209 $spell = "SELECT * FROM form_track_anything_type WHERE parent = ? AND active = 1 ORDER BY position ASC, name ASC ";
210 $query = sqlStatement($spell, array($myprocedureid));
211 while ($myrow = sqlFetchArray($query)) {
212 echo "<input type='hidden' name='liste[]' value='". attr($myrow['track_anything_type_id']) . "'>";
213 echo "<tr><td> " . text($myrow['name']) . "</td>";
214 echo "<td><input size='12' type='text' name='" . attr($myrow['track_anything_type_id']) . "'></td></tr>";
218 echo "<input type='hidden' name='formid' value='". attr($formid) . "'>";
219 echo "<input type='submit' name='bn_save' value='" . xla('Save') . "' />";
220 ?
><input type
='button' value
='<?php echo xla('Stop
'); ?>' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php
223 // show old entries of track
224 //-----------------------------------
225 // get unique timestamps of track
226 echo "<br><br><hr><br>";
227 echo "<b>" . xlt('Edit your entered data') . ":</b><br>";
228 $shownameflag = 0; // flag if this is <table>-headline
229 echo "<table border='1'>";
231 $spell0 = "SELECT DISTINCT track_timestamp FROM form_track_anything_results WHERE track_anything_id = ? ORDER BY track_timestamp DESC";
232 $query = sqlStatement($spell0, array($formid));
233 $main_counter=0; // this counts 'number of rows' of old entries
234 while ($myrow = sqlFetchArray($query)) {
235 $thistime = $myrow['track_timestamp'];
238 $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 ";
239 $spell .= "FROM form_track_anything_results ";
240 $spell .= "INNER JOIN form_track_anything_type ON form_track_anything_results.itemid = form_track_anything_type.track_anything_type_id ";
241 $spell .= "WHERE track_anything_id = ? AND track_timestamp = ? AND form_track_anything_type.active = 1 ";
242 $spell .= "ORDER BY form_track_anything_type.position ASC, the_name ASC ";
243 $query2 = sqlStatement($spell, array($formid ,$thistime));
245 // <table> heading line
246 if ($shownameflag==1) {
247 echo "<tr><th class='time'>" . xlt('Time') . "</th>";
248 while ($myrow2 = sqlFetchArray($query2)) {
249 echo "<th class='item'>" . text($myrow2['the_name']) . "</th>";
255 echo "<tr><td bgcolor=#eeeeec>";
256 $main_counter++
; // next row
257 echo "<input type='text' class='datetimepicker' size='16' 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)) {
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
271 echo "</tr></table>";
272 echo "<input type='hidden' name='formid' value='". attr($formid) . "'>";
273 echo "<input type='submit' name='bn_save' value='" . xla('Save') . "' />";
274 ?
><input type
='button' value
='<?php echo xla('Stop
'); ?>' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" /><?php