Focus the search term on load
[openemr.git] / interface / patient_file / rules / patient_data.php
blob4bce0b3a9484fbb8e2d972f28f9b8a1de77de5ef
1 <?php
2 // Copyright (C) 2010 Brady Miller <brady@sparmy.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 //SANITIZE ALL ESCAPES
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 require_once("../../globals.php");
18 require_once("$srcdir/acl.inc");
19 require_once("$srcdir/options.inc.php");
22 <html>
23 <head>
24 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
25 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css" media="screen" />
26 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
27 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
28 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/dialog.js"></script>
29 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/textformat.js"></script>
30 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
31 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
32 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar.js"></script>
33 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
34 <script type="text/javascript" src="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar_setup.js"></script>
35 <SCRIPT LANGUAGE="JavaScript">
37 function validate(f) {
38 var bValid = true;
39 if (f.form_date.value == "") {
40 alert("<?php echo htmlspecialchars( xl('Please enter a date.'), ENT_QUOTES); ?>");
41 f.form_date.focus();
42 f.form_date.style.backgroundColor="red";
43 return false;
44 } else {
45 var form_date = f.form_date.value.split( " " );
46 var date_split = form_date[0].split( "-" );
47 var time_split = form_date[1].split( ":" );
48 var d = new Date( date_split[0], date_split[1]-1, date_split[2], time_split[0], time_split[1], time_split[2] );
49 var now = new Date();
50 if ( d > now &&
51 f.form_complete.value == "YES" ) {
52 alert("<?php echo htmlspecialchars( xl('You cannot enter a future date with a completed value of YES.'), ENT_QUOTES); ?>");
53 f.form_date.focus();
54 f.form_date.style.backgroundColor="red";
55 return false;
58 return true;
61 function submitme() {
62 var f = document.forms['patient_data'];
63 if (validate(f)) {
64 top.restoreSession();
65 f.submit();
69 $(document).ready(function(){
70 $("#cancel").click(function() { parent.$.fn.fancybox.close(); });
71 });
73 </script>
74 </head>
77 <body class="body_top">
78 <?php
80 // Ensure user is authorized
81 if (!acl_check('patients', 'med')) {
82 echo "<p>(" . htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES) . ")</p>\n";
83 echo "</body>\n</html>\n";
84 exit();
87 if ($_POST['form_complete']) {
88 // Save that form as a row in rule_patient_data table
89 // and then close the window/modul.
91 // Collect and trim variables
92 if (isset($_POST['form_entryID'])) $form_entryID = trim($_POST['form_entryID']);
93 $form_date = trim($_POST['form_date']);
94 $form_category = trim($_POST['form_category']);
95 $form_item = trim($_POST['form_item']);
96 $form_complete = trim($_POST['form_complete']);
97 $form_result = trim($_POST['form_result']);
99 if (!isset($form_entryID)) {
100 // Insert new row of data into rule_patient_data table
101 sqlInsert("INSERT INTO `rule_patient_data` (`date`, `pid`, `category`, `item`, `complete`, `result`) " .
102 "VALUES (?,?,?,?,?,?)", array($form_date, $pid, $form_category, $form_item, $form_complete, $form_result) );
104 else { // $form_mode == "edit"
105 // Modify selected row in rule_patient_data table
106 sqlStatement("UPDATE `rule_patient_data` " .
107 "SET `date`=?, `complete`=?, `result`=? " .
108 "WHERE `id`=?", array($form_date,$form_complete,$form_result,$form_entryID) );
111 // Close this window and refresh the patient summary display.
112 echo "<html>\n<body>\n<script language='JavaScript'>\n";
113 echo " window.close();\n";
114 echo " top.restoreSession();\n";
115 echo " if ( opener ) { opener.location.reload(); } else { parent.location.reload(); } \n";
116 echo "</script>\n</body>\n</html>\n";
117 exit();
120 // Display the form
121 // Collect and trim variables
122 $category = trim($_GET['category']);
123 $item = trim($_GET['item']);
124 if (isset($_GET['entryID'])) $entryID = trim($_GET['entryID']);
126 // Collect data if a specific entry is selected
127 if (isset($entryID)) {
128 $selectedEntry = sqlQuery("SELECT `date`, `complete`, `result` " .
129 "FROM `rule_patient_data` " .
130 "WHERE `id`=?", array($entryID) );
131 $form_date = $selectedEntry['date'];
132 $form_complete = $selectedEntry['complete'];
133 $form_result = $selectedEntry['result'];
137 <table cellspacing='0' cellpadding='0' border='0'>
138 <tr>
139 <td><span class="title"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$category) .
140 " - " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$item); ?></span>&nbsp;&nbsp;&nbsp;</td>
141 <td><a href="javascript:submitme();" class="css_button"><span><?php echo htmlspecialchars( xl('Save'), ENT_NOQUOTES);?></span></a></td>
142 <td><a href="#" id="cancel" class="css_button large_button"><span class='css_button_span large_button_span'><?php echo htmlspecialchars( xl('Cancel'), ENT_NOQUOTES);?></span></a></td>
143 </tr>
144 </table>
146 <br><br>
147 <form action='patient_data.php' name='patient_data' method='post' onsubmit='return top.restoreSession()'>
148 <table border=0 cellpadding=1 cellspacing=1>
149 <?php
150 echo "<tr><td class='required'>";
151 echo htmlspecialchars( xl('Date/Time'), ENT_NOQUOTES);
152 echo ":</td><td class='text'>";
153 echo "<input type='text' size='16' name='form_date' id='form_date' " .
154 "value='" . htmlspecialchars( $form_date, ENT_QUOTES) . "' " .
155 "onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' " .
156 "title='" . htmlspecialchars( xl('yyyy-mm-dd hh:mm:ss'), ENT_QUOTES) . "' />";
157 echo "<img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
158 "id='img_date' border='0' alt='[?]' style='cursor:pointer'" .
159 "title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
160 echo "<script language='JavaScript'>Calendar.setup({inputField:'form_date', ifFormat:'%Y-%m-%d %H:%M:%S', button:'img_date', showsTime:'true'});</script>";
161 echo "</td></tr>";
163 echo "<tr><td class='required'>";
164 echo htmlspecialchars( xl('Completed'), ENT_NOQUOTES);
165 echo ":</td><td class='text'>";
166 generate_form_field(array('data_type'=>1,'field_id'=>'complete','list_id'=>'yesno','empty_title'=>'SKIP'), ($form_complete) ? $form_complete : "YES");
167 echo "</td></tr>";
169 echo "<tr><td class='bold'>";
170 echo htmlspecialchars( xl('Results/Details'), ENT_NOQUOTES);
171 echo ":</td><td class='text'>";
172 echo "<textarea name='form_result' cols='40' rows='3'>";
173 echo htmlspecialchars( $form_result, ENT_NOQUOTES);
174 echo "</textarea>";
175 echo "</td></tr>";
176 echo "</table>";
177 echo "<input type='hidden' name='form_category' value='" .
178 htmlspecialchars( $category, ENT_QUOTES) . "' />";
179 echo "<input type='hidden' name='form_item' value='" .
180 htmlspecialchars( $item, ENT_QUOTES) . "' />";
181 if (isset($entryID)) {
182 echo "<input type='hidden' name='form_entryID' value='" .
183 htmlspecialchars( $entryID, ENT_QUOTES) . "' />";
186 </form>
187 <?php
189 // Display the table of previous entries
190 // Collect previous data to show as table below the form
191 $res = sqlStatement("SELECT `id`, `date`, `complete`, `result` " .
192 "FROM `rule_patient_data` " .
193 "WHERE `category`=? AND `item`=? AND `pid`=? " .
194 "ORDER BY `date` DESC", array($category,$item,$pid) );
196 <br>
197 <hr />
198 <br>
199 <div>
200 <?php
201 if (sqlNumRows($res) >= 1) { //display table ?>
202 <table class="showborder" cellspacing="0px" cellpadding="2px">
203 <tr class='showborder_head'>
204 <th>&nbsp;</th>
205 <th><?php echo htmlspecialchars( xl('Date/Time'), ENT_NOQUOTES); ?></th>
206 <th><?php echo htmlspecialchars( xl('Completed'), ENT_NOQUOTES); ?></th>
207 <th><?php echo htmlspecialchars( xl('Results/Details'), ENT_NOQUOTES); ?></th>
208 </tr>
209 <?php
210 while ($row = sqlFetchArray($res)) {
211 if (isset($entryID) && ($entryID == $row['id'])) {
212 echo "<tr class='text' style='background-color:LightGrey'>";
214 else {
215 echo "<tr class='text'>";
217 if (isset($entryID) && ($entryID == $row['id'])) {
218 // hide the edit button
219 echo "<td>&nbsp;</td>";
221 else { // show the edit button
222 echo "<td><a href='patient_data.php?category=" .
223 htmlspecialchars( $category, ENT_QUOTES) . "&item=" .
224 htmlspecialchars( $item, ENT_QUOTES) . "&entryID=" .
225 htmlspecialchars( $row['id'], ENT_QUOTES) .
226 "' onclick='top.restoreSession()' class='css_button_small'>" .
227 "<span>" . htmlspecialchars( xl('Edit'), ENT_NOQUOTES) . "</span></a>" .
228 "</td>";
230 echo "<td>" . htmlspecialchars( $row['date'], ENT_NOQUOTES) . "</td>";
231 echo "<td align='center'>" . htmlspecialchars( $row['complete'], ENT_NOQUOTES) . "</td>";
232 echo "<td>" . nl2br( htmlspecialchars( $row['result'], ENT_NOQUOTES) ) . "</td>";
233 echo "</tr>";
234 } ?>
235 </table>
236 <?php } //display table if statement
237 else { //no entries
238 echo "<p>" . htmlspecialchars( xl('No previous entries.'), ENT_NOQUOTES) . "</p>";
239 } ?>
240 </div>
242 </body>
243 </html>