Dated Reminders Module changes:
[openemr.git] / interface / main / dated_reminders / dated_reminders_add.php
blob55bd848cf678108e277b9ba2584cf66984878869
1 <?php
2 // ------------------------------------------------------------------------ //
3 // OpenEMR Electronic Medical Records System //
4 // Copyright (c) 2012 tajemo.co.za //
5 // <http://www.tajemo.co.za/> //
6 // ------------------------------------------------------------------------ //
7 // This program is free software; you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation; either version 2 of the License, or //
10 // (at your option) any later version. //
11 // //
12 // You may not change or alter any portion of this comment or credits //
13 // of supporting developers from this source code or any supporting //
14 // source code which is considered copyrighted (c) material of the //
15 // original comment or credit authors. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details. //
21 // //
22 // You should have received a copy of the GNU General Public License //
23 // along with this program; if not, write to the Free Software //
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
25 // --------------------------------------------------------------------------//
26 // Original Author of this file: Craig Bezuidenhout (Tajemo Enterprises) //
27 // Purpose of this file: Used for adding dated reminders //
28 // --------------------------------------------------------------------------//
30 $fake_register_globals=false;
31 $sanitize_all_escapes=true;
33 require_once("../../globals.php");
34 require_once("$srcdir/htmlspecialchars.inc.php");
35 require_once("$srcdir/dated_reminders.php");
37 $dateRanges = array();
38 // $dateranges = array ( number_period => text to display ) == period is always in the singular
39 // eg. $dateRanges['4_week'] = '4 Weeks From Now';
40 $dateRanges['1_day'] = xl('1 Day From Now');
41 $dateRanges['2_day'] = xl('2 Days From Now');
42 $dateRanges['3_day'] = xl('3 Days From Now');
43 $dateRanges['4_day'] = xl('4 Days From Now');
44 $dateRanges['5_day'] = xl('5 Days From Now');
45 $dateRanges['6_day'] = xl('6 Days From Now');
46 $dateRanges['1_week'] = xl('1 Week From Now');
47 $dateRanges['2_week'] = xl('2 Weeks From Now');
48 $dateRanges['3_week'] = xl('3 Weeks From Now');
49 $dateRanges['4_week'] = xl('4 Weeks From Now');
50 $dateRanges['5_week'] = xl('5 Weeks From Now');
51 $dateRanges['6_week'] = xl('6 Weeks From Now');
52 $dateRanges['1_month'] = xl('1 Month From Now');
53 $dateRanges['2_month'] = xl('2 Months From Now');
54 $dateRanges['3_month'] = xl('3 Months From Now');
55 $dateRanges['4_month'] = xl('4 Months From Now');
56 $dateRanges['5_month'] = xl('5 Months From Now');
57 $dateRanges['6_month'] = xl('6 Months From Now');
58 $dateRanges['7_month'] = xl('7 Months From Now');
59 $dateRanges['8_month'] = xl('8 Months From Now');
60 $dateRanges['9_month'] = xl('9 Months From Now');
61 $dateRanges['1_year'] = xl('1 Year From Now');
62 $dateRanges['2_year'] = xl('2 Years From Now');
64 // --- need to add a check to ensure the post is being sent from the correct location ???
66 // default values for $this_message
67 $this_message = array('message'=>'','message_priority'=>3,'dueDate'=>'');
68 $forwarding = false;
70 // ---------------- FOR FORWARDING MESSAGES ------------->
71 if(isset($_GET['mID']) and is_numeric($_GET['mID'])){
72 $forwarding = true;
73 $this_message = getReminderById($_GET['mID']);
76 // ---------------END FORWARDING MESSAGES ----------------
80 // --- add reminders
81 if($_POST){
82 // --- initialize $output as blank
83 $output = '';
84 // ------ fills an array with all recipients
85 $sendTo = $_POST['sendTo'];
87 // for incase of data error, this allows the previously entered data to re-populate the boxes
88 $this_message['message'] = (isset($_POST['message']) ? $_POST['message'] : '');
89 $this_message['priority'] = (isset($_POST['priority']) ? $_POST['priority'] : '');
90 $this_message['dueDate'] = (isset($_POST['dueDate']) ? $_POST['dueDate'] : '');
93 // --------------------------------------------------------------------------------------------------------------------------
94 // --- check for the post, if it is valid, commit to the database, close this window and run opener.Handeler
95 if(
96 // ------- check sendTo is not empty
97 !empty($sendTo) and
98 // ------- check dueDate, only allow valid dates, todo -> enhance date checker
99 isset($_POST['dueDate']) and preg_match('/\d{4}[-]\d{2}[-]\d{2}/',$_POST['dueDate']) and
100 // ------- check priority, only allow 1-3
101 isset($_POST['priority']) and intval($_POST['priority']) <= 3 and
102 // ------- check message, only up to 144 characters
103 isset($_POST['message']) and strlen($_POST['message']) <= 144 and strlen($_POST['message']) > 0 and
104 // ------- check if PatientID is set and in numeric
105 isset($_POST['PatientID']) and is_numeric($_POST['PatientID'])
107 $dueDate = $_POST['dueDate'];
108 $priority = intval($_POST['priority']);
109 $message = $_POST['message'];
110 $fromID = $_SESSION['authId'];
111 $patID = $_POST['PatientID'];
112 if(isset($_POST['sendSeperately']) and $_POST['sendSeperately']){
113 foreach($sendTo as $st){
114 $ReminderSent = sendReminder(array($st),$fromID,$message,$dueDate,$patID,$priority);
117 else{
118 // -------- Send the reminder
119 $ReminderSent = sendReminder($sendTo,$fromID,$message,$dueDate,$patID,$priority);
121 // --------------------------------------------------------------------------------------------------------------------------
122 if(!$ReminderSent){
123 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Please select a valid recipient').'</div> ';
124 }else{
125 // --------- echo javascript
126 echo '<html><body><script language="JavaScript">';
127 // ------------ 1) refresh parent window this updates if sent to self
128 echo ' if (opener && !opener.closed && opener.updateme) opener.updateme("new");';
129 // ------------ 2) communicate with user
130 echo ' alert("'.addslashes(xl('Message Sent')).'");';
131 // ------------ 3) close this window
132 echo ' window.close();';
133 echo '</script></body></html>';
134 // --------- stop script from executing further
135 exit;
137 // --------------------------------------------------------------------------------------------------------------------------
139 // --------------------------------------------------------------------------------------------------------------------------
141 else{
142 // ------- if POST error
143 $output .= '<div style="text-size:2em; text-align:center; color:red">* '.xlt('Data Error').'</div> ';
145 // ------- if any errors, communicate with the user
146 echo $output;
148 // end add reminders
150 // get current patient, first check if this is a forwarded message, if it is use the original pid
151 if(isset($this_message['pid'])) $patientID = (isset($this_message['pid']) ? $this_message['pid'] : 0);
152 else $patientID = (isset($pid) ? $pid : 0);
154 <html>
155 <head>
156 <title><?php echo xlt('Send a Reminder') ?></title>
157 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
158 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
159 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
160 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
161 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.4.3.min.js"></script>
162 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-calendar.js"></script>
163 <script language="JavaScript">
164 $(document).ready(function (){
166 $('#timeSpan').change(function(){
167 var value = $(this).val();
168 var arr = value.split('_');
169 var span = arr[1];
170 var period = parseInt(arr[0]);
171 var d=new Date();
172 if(span == 'day'){
173 d.setDate(d.getDate()+period);
175 else if(span == 'week'){
176 var weekInDays = period * 7;
177 d.setDate(d.getDate()+weekInDays);
179 else if(span == 'month'){
180 d.setMonth(d.getMonth()+period);
182 else if(span == 'year'){
183 var yearsInMonths = period * 12;
184 d.setMonth(d.getMonth()+yearsInMonths);
186 var curr_date = d.getDate().toString();
187 if(curr_date.length == 1){
188 curr_date = '0'+curr_date;
190 var curr_month = d.getMonth() + 1; //months are zero based
191 curr_month = curr_month.toString();
192 if(curr_month.length == 1){
193 curr_month = '0'+curr_month;
195 var curr_year = d.getFullYear();
196 $('#dueDate').val(curr_year + "-" + curr_month + "-" + curr_date);
200 $("#sendButton").click(function(){
201 $('#errorMessage').html('');
202 errorMessage = '';
203 var PatientID = $('#PatientID').val();
204 var dueDate = $('#dueDate').val();
205 var priority = $('#priority:checked').val();
206 var message = $("#message").val();
207 // todo : check if PatientID is numeric , no rush as this is checked in the php after the post
209 // check to see if a recipient has been set
210 // todo : check if they are all numeric , no rush as this is checked in the php after the post
212 if (!$("#sendTo option:selected").length){
213 errorMessage = errorMessage + '* <?php echo xla('Please Select A Recipient') ?><br />';
217 // Check if Date is set
218 // todo : add check to see if dueDate is a valid date , no rush as this is checked in the php after the post
219 if(dueDate == ''){
220 errorMessage = errorMessage + '* <?php echo xla('Please enter a due date') ?><br />';
223 // check if message is set
224 if(message == ''){
225 errorMessage = errorMessage + '* <?php echo xla('Please enter a message') ?><br />';
228 if(errorMessage != ''){
229 // handle invalid queries
230 $('#errorMessage').html(errorMessage);
232 else{
233 // handle valid queries
234 // post the form to self
235 top.restoreSession();
236 $("#addDR").submit();
238 return false;
241 $("#removePatient").click(function(){
242 $("#PatientID").val("0");
243 $("#patientName").val("<?php echo xla('Click to select patient'); ?>");
244 $(this).hide();
245 return false;
249 function sel_patient(){
250 window.open('../../main/calendar/find_patient_popup.php', '_newDRPat', '' + ",width=" + 500 + ",height=" + 400 + ",left=" + 25 + ",top=" + 25 + ",screenX=" + 25 + ",screenY=" + 25);
253 function setpatient(pid, lname, fname, dob){
254 $("#patientName").val(fname +' '+ lname)
255 $("#PatientID").val(pid);
256 $("#removePatient").show();
257 return false;
260 function limitText(limitField, limitCount, limitNum) {
261 if (limitField.value.length > limitNum) {
262 limitField.value = limitField.value.substring(0, limitNum);
263 } else {
264 limitCount.value = limitNum - limitField.value.length;
267 </script>
268 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
269 </head>
270 <body class="body_top">
271 <!-- Required for the popup date selectors -->
272 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
275 <h1><?php echo xlt('Send a Reminder') ?></h1>
276 <form id="addDR" style="margin-left:40px;" id="newMessage" method="post" onsubmit="return top.restoreSession()">
277 <div style="text-size:2em; text-align:center; color:red" id="errorMessage"></div>
279 <?php echo xlt('Link To Patient') ?> :
280 <input type='text' size='10' id='patientName' name='patientName' style='width:200px;cursor:pointer;cursor:hand'
281 value='<?php echo ($patientID > 0 ? attr(getPatName($patientID)) : xla('Click to select patient')); ?>' onclick='sel_patient()'
282 title='<?php xla('Click to select patient'); ?>' readonly />
283 <input name="PatientID" id="PatientID" value="<?php echo (isset($patientID) ? attr($patientID) : 0) ?>" />
284 <button <?php echo ($patientID > 0 ? '' : 'style="display:'.attr('none').'"') ?> id="removePatient"><?php echo xlt('unlink patient') ?></button>
287 <br /><br />
288 <?php echo xlt('Send to') ?> : <select id="sendTo" name="sendTo[]" multiple="multiple">
289 <option value="<?php echo attr(intval($_SESSION['authId'])); ?>"><?php echo xlt('Myself'); ?></option>
290 <?php //
291 $uSQL = sqlStatement('SELECT id, fname, mname, lname FROM `users` WHERE `active` = 1 AND `facility_id` > 0 AND id != ?',array(intval($_SESSION['authId'])));
292 for($i=2; $uRow=sqlFetchArray($uSQL); $i++){
293 echo '<option value="',attr($uRow['id']),'">',text($uRow['fname'].' '.$uRow['mname'].' '.$uRow['lname']),'</option>';
296 </select>
297 &nbsp;&nbsp;&nbsp; <label for="sendSeperately"><?php echo xlt('Each recipient must set their own messages as completed') ?></label> <input type="checkbox" name="sendSeperately" id="sendSeperately" />
299 <br /> <br />
300 <?php echo xlt('Due Date') ?> : <input type='text' name='dueDate' id="dueDate" size='20' value="<?php echo ($this_message['dueDate'] == '' ? date('Y-m-d') : attr($this_message['dueDate'])); ?>" onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>' />
301 <?php echo xlt('OR') ?>
302 <?php echo xlt('Select a time span') ?> : <select id="timeSpan">
303 <option value="__BLANK__"> -- <?php echo xlt('Select a Time Span') ?> -- </option>
304 <?php
305 $optionTxt = '';
306 foreach($dateRanges as $val=>$txt){
307 $optionTxt .= '<option value="'.attr($val).'">'.text($txt).'</option>';
309 echo $optionTxt;
311 </select>
312 <br />
313 <br />
314 <?php echo xlt('Priority') ?> :
315 <input <?php echo ($this_message['message_priority'] == 3 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_3" value='3'> <label for="priority_3"><?php echo xlt('Low') ?></label>
316 <input <?php echo ($this_message['message_priority'] == 2 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_2" value='2'> <label for="priority_2"><?php echo xlt('Medium') ?></label>
317 <input <?php echo ($this_message['message_priority'] == 1 ? 'checked="checked"' : '') ?> type="radio" name="priority" id="priority_1" value='1'> <label for="priority_1"><?php echo xlt('High') ?></label>
318 <br />
319 <br />
320 <?php echo xlt('Type Your message here') ?> : <br /><br />
321 <font size="1">(<?php echo xlt('Maximum characters') ?>: 144)<br>
322 <textarea onKeyDown="limitText(this.form.message,this.form.countdown,144);"
323 onKeyUp="limitText(this.form.message,this.form.countdown,144);"
324 style="width:98%; height:50px" name="message" id="message"><?php echo text($this_message['message']); ?></textarea>
325 <br>
326 <?php echo xlt('Characters Remaining') ?> : <input readonly type="text" name="countdown" size="3" value="144"> </font>
327 <br />
328 <br />
329 <input type="submit" id="sendButton" value="<?php echo xla('Send This Message') ?>" />
330 </form>
331 <?php
332 $_GET['sentBy_me'] = $_SESSION['authId'];
333 $_GET['sd'] = strtotime(date('Y/m/d'));
334 echo '<h2>',xlt('Messages You have sent Today'),'</h2>';
335 echo '<table border="1" width="100%" cellpadding="5px" id="logTable">
336 <thead>
337 <tr>
338 <th>'.xlt('ID').'</th>
339 <th>'.xlt('To').'</th>
340 <th>'.xlt('Patient').'</th>
341 <th>'.xlt('Message').'</th>
342 <th>'.xlt('Due Date').'</th>
343 </tr>
344 </thead>
345 <tbody>';
346 $remindersArray = logRemindersArray();
347 foreach($remindersArray as $RA){
348 echo '<tr class="heading">
349 <td>',text($RA['messageID']),'</td>
350 <td>',text($RA['ToName']),'</td>
351 <td>',text($RA['PatientName']),'</td>
352 <td>',text($RA['message']),'</td>
353 <td>',text($RA['dDate']),'</td>
354 </tr>';
356 echo '</tbody></table>';
358 </body>
359 <!-- stuff for the popup calendar -->
360 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
361 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
362 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
363 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
364 <script language="Javascript">
365 Calendar.setup({inputField:"dueDate", ifFormat:"%Y-%m-%d", button:"img_begin_date", showsTime:'false'});
366 </script>
367 </html>