minor changes to prior commit
[openemr.git] / interface / patient_file / summary / pnotes_full.php
blob24b03c9bb790b3550ead3ddb112824e8b07be72d
1 <?php
2 /**
3 * Display, enter, modify and manage patient notes.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 3
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Brady Miller <brady.g.miller@gmail.com>
18 * @link http://www.open-emr.org
23 /* Include required globals */
24 require_once('../../globals.php');
25 require_once($GLOBALS['srcdir'].'/pnotes.inc');
26 require_once($GLOBALS['srcdir'].'/patient.inc');
27 require_once($GLOBALS['srcdir'].'/acl.inc');
28 require_once($GLOBALS['srcdir'].'/log.inc');
29 require_once($GLOBALS['srcdir'].'/options.inc.php');
30 require_once($GLOBALS['srcdir'].'/gprelations.inc.php');
32 use OpenEMR\Core\Header;
34 if ($_GET['set_pid']) {
35 require_once($GLOBALS['srcdir'].'/pid.inc');
36 setpid($_GET['set_pid']);
39 // form parameter docid can be passed to restrict the display to a document.
40 $docid = empty($_REQUEST['docid']) ? 0 : 0 + $_REQUEST['docid'];
42 // form parameter orderid can be passed to restrict the display to a procedure order.
43 $orderid = empty($_REQUEST['orderid']) ? 0 : intval($_REQUEST['orderid']);
45 $patient_id = $pid;
46 if ($docid) {
47 $row = sqlQuery("SELECT foreign_id FROM documents WHERE id = ?", array($docid));
48 $patient_id = intval($row['foreign_id']);
49 } else if ($orderid) {
50 $row = sqlQuery("SELECT patient_id FROM procedure_order WHERE procedure_order_id = ?", array($orderid));
51 $patient_id = intval($row['patient_id']);
54 // Check authorization.
55 if (!acl_check('patients', 'notes', '', array('write','addonly'))) {
56 die(htmlspecialchars(xl('Not authorized'), ENT_NOQUOTES));
59 $tmp = getPatientData($patient_id, "squad");
60 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
61 die(htmlspecialchars(xl('Not authorized for this squad.'), ENT_NOQUOTES));
64 //the number of records to display per screen
65 $N = 15;
66 $M = 15;
68 $mode = $_REQUEST['mode'];
69 $offset = $_REQUEST['offset'];
70 $offset_sent = $_REQUEST['offset_sent'];
71 $form_active = $_REQUEST['form_active'];
72 $form_inactive = $_REQUEST['form_inactive'];
73 $noteid = $_REQUEST['noteid'];
74 $form_doc_only = isset($_POST['mode']) ? (empty($_POST['form_doc_only']) ? 0 : 1) : 1;
75 if ($_REQUEST['s'] == '1') {
76 $inbox = "";
77 $outbox = "current";
78 $inbox_style = "style='display:none;border:5px solid #FFFFFF;'";
79 $outbox_style = "style='border:5px solid #FFFFFF;'";
80 } else {
81 $inbox = "current";
82 $outbox = "";
83 $inbox_style = "style='border:5px solid #FFFFFF;'";
85 $outbox_style = "style='display:none;border:5px solid #FFFFFF;'";
88 if (!isset($offset)) {
89 $offset = 0;
92 if (!isset($offset_sent)) {
93 $offset_sent = 0;
96 // Collect active variable and applicable html code for links
97 if ($form_active) {
98 $active = '1';
99 $activity_string_html = 'form_active=1';
100 } else if ($form_inactive) {
101 $active = '0';
102 $activity_string_html = 'form_inactive=1';
103 } else {
104 $active = 'all';
105 $activity_string_html = '';
106 $form_active = $form_inactive = '0';
109 // this code handles changing the state of activity tags when the user updates
110 // them through the interface
111 if (isset($mode)) {
112 if ($mode == "update") {
113 foreach ($_POST as $var => $val) {
114 if (strncmp($var, 'act', 3) == 0) {
115 $id = str_replace("act", "", $var);
116 if ($_POST["chk$id"]) {
117 reappearPnote($id);
118 } else {
119 disappearPnote($id);
122 if ($docid) {
123 setGpRelation(1, $docid, 6, $id, !empty($_POST["lnk$id"]));
126 if ($orderid) {
127 setGpRelation(2, $orderid, 6, $id, !empty($_POST["lnk$id"]));
131 } elseif ($mode == "new") {
132 $note = $_POST['note'];
133 if ($noteid) {
134 updatePnote($noteid, $note, $_POST['form_note_type'], $_POST['assigned_to'], '', !empty($_POST['form_datetime']) ? DateTimeToYYYYMMDDHHMMSS($_POST['form_datetime']) : '');
135 } else {
136 $noteid = addPnote(
137 $patient_id,
138 $note,
139 $userauthorized,
140 '1',
141 $_POST['form_note_type'],
142 $_POST['assigned_to'],
143 !empty($_POST['form_datetime']) ? DateTimeToYYYYMMDDHHMMSS($_POST['form_datetime']) : ''
147 if ($docid) {
148 setGpRelation(1, $docid, 6, $noteid);
151 if ($orderid) {
152 setGpRelation(2, $orderid, 6, $noteid);
155 $noteid = '';
156 } elseif ($mode == "delete") {
157 if ($noteid) {
158 deletePnote($noteid);
159 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "pnotes: id ".$noteid);
162 $noteid = '';
164 if ($mode != "delete" && $mode != "update") {
165 exit(); // add exit for ajax save from pnotes_full_add.php sjp 12/20/2017
169 $title = '';
170 $assigned_to = $_SESSION['authUser'];
171 if ($noteid) {
172 $prow = getPnoteById($noteid, 'title,assigned_to,body');
173 $title = $prow['title'];
174 $assigned_to = $prow['assigned_to'];
177 // Get the users list. The "Inactive" test is a kludge, we should create
178 // a separate column for this.
179 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
180 "WHERE username != '' AND active = 1 AND " .
181 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
182 "ORDER BY lname, fname");
184 $pres = getPatientData($patient_id, "lname, fname");
185 $patientname = $pres['lname'] . ", " . $pres['fname'];
187 //retrieve all notes
188 $result = getPnotesByDate(
190 $active,
191 'id,date,body,user,activity,title,assigned_to,message_status',
192 $patient_id,
194 $offset,
196 $docid,
198 $orderid
200 $result_sent = getSentPnotesByDate(
202 $active,
203 'id,date,body,user,activity,title,assigned_to,message_status',
204 $patient_id,
206 $offset_sent,
208 $docid,
210 $orderid
213 <!DOCTYPE html>
214 <html>
215 <head>
217 <?php Header::setupHeader(['common', 'jquery-ui']); ?>
219 <script type="text/javascript">
220 /// todo, move this to a common library
222 $(document).ready(function(){
224 $("#dem_view").click( function() {
225 toggle( $(this), "#DEM" );
228 // load divs
229 $("#stats_div").load("stats.php");
230 $("#notes_div").load("pnotes_fragment.php");
232 tabbify();
234 $(".note_modal").on('click', function(e) {
235 e.preventDefault();
236 e.stopPropagation();
237 dlgopen('', '', 650, 400, '', '', {
238 buttons: [
239 {text: '<?php echo xla('Close'); ?>', close: true, style: 'default btn-sm'}
241 allowResize: true,
242 allowDrag: true,
243 dialogId: '',
244 type: 'iframe',
245 url: $(this).attr('href')
251 function show_div(name){
252 if(name == 'inbox'){
253 document.getElementById('inbox_div').style.display = '';
254 document.getElementById('outbox_div').style.display = 'none';
255 }else{
256 document.getElementById('inbox_div').style.display = 'none';
257 document.getElementById('outbox_div').style.display = '';
261 function refreshme() {
262 top.restoreSession();
263 document.location.reload();
265 </script>
266 </head>
267 <body class="body_top">
269 <div id="pnotes"> <!-- large outer DIV -->
271 <form border='0' method='post' name='new_note' id="new_note" action='pnotes_full.php?docid=<?php echo htmlspecialchars($docid, ENT_QUOTES); ?>&orderid=<?php echo htmlspecialchars($orderid, ENT_QUOTES); ?>&<?php echo attr($activity_string_html);?>' onsubmit='return top.restoreSession()'>
273 <?php
274 $title_docname = "";
275 if ($docid) {
276 $title_docname .= " " . xl("linked to document") . " ";
277 $d = new Document($docid);
278 $title_docname .= $d->get_url_file();
281 if ($orderid) {
282 $title_docname .= " " . xl("linked to procedure order") . " $orderid";
284 $docid_esc=attr($docid);
285 $orderid_esc=attr($orderid);
287 $urlparms = "docid=$docid_esc&orderid=$orderid_esc";
290 <div>
291 <span class="title"><?php echo xlt('Patient Messages') . $title_docname; ?></span>
292 </div>
293 <div id='namecontainer_pnotes' class='namecontainer_pnotes'>
294 <?php echo htmlspecialchars(xl('for'), ENT_NOQUOTES);?>&nbsp;<span class="title">
295 <a href="../summary/demographics.php" onclick="return top.restoreSession()"><?php echo htmlspecialchars(getPatientName($patient_id), ENT_NOQUOTES); ?></a></span>
296 </div>
297 <div>
298 <a href="pnotes_full_add.php?<?php echo $urlparms; ?>" class="css_button note_modal" onclick='return top.restoreSession()'><span><?php echo xlt('Add'); ?></span></a>
299 <a href="demographics.php" class="css_button" onclick="top.restoreSession()">
300 <span><?php echo htmlspecialchars(xl('View Patient'), ENT_NOQUOTES);?></span>
301 </a>
302 </div>
303 <br/>
304 <br/>
305 <div>
306 <?php if ($active == "all") { ?>
307 <span><?php echo xlt('Show All'); ?></span>
308 <?php } else { ?>
309 <a href="pnotes_full.php?<?php echo $urlparms; ?>" class="link" onclick="return top.restoreSession()"><span><?php echo xlt('Show All'); ?></span></a>
310 <?php } ?>
312 <?php if ($active == '1') { ?>
313 <span><?php echo xlt('Show Active'); ?></span>
314 <?php } else { ?>
315 <a href="pnotes_full.php?form_active=1&<?php echo $urlparms; ?>" class="link" onclick="return top.restoreSession()"><span><?php echo xlt('Show Active'); ?></span></a>
316 <?php } ?>
318 <?php if ($active == '0') { ?>
319 <span><?php echo xlt('Show Inactive'); ?></span>
320 <?php } else { ?>
321 <a href="pnotes_full.php?form_inactive=1&<?php echo $urlparms; ?>" class="link" onclick="return top.restoreSession()"><span><?php echo xlt('Show Inactive'); ?></span></a>
322 <?php } ?>
323 </div>
325 <input type='hidden' name='mode' id="mode" value="new">
326 <input type='hidden' name='offset' id="offset" value="<?php echo attr($offset); ?>">
327 <input type='hidden' name='offset_sent' id="offset_sent" value="<?php echo attr($offset_sent); ?>">
328 <input type='hidden' name='form_active' id="form_active" value="<?php echo htmlspecialchars($form_active, ENT_QUOTES); ?>">
329 <input type='hidden' name='form_inactive' id="form_inactive" value="<?php echo htmlspecialchars($form_inactive, ENT_QUOTES); ?>">
330 <input type='hidden' name='noteid' id="noteid" value="<?php echo htmlspecialchars($noteid, ENT_QUOTES); ?>">
331 <input type='hidden' name='form_doc_only' id="form_doc_only" value="<?php echo htmlspecialchars($form_doc_only, ENT_QUOTES); ?>">
332 </form>
335 <?php
336 // Get the billing note if there is one.
337 $billing_note = "";
338 $colorbeg = "";
339 $colorend = "";
340 $resnote = getPatientData($patient_id, "billing_note");
341 if (!empty($resnote['billing_note'])) {
342 $billing_note = $resnote['billing_note'];
343 $colorbeg = "<span style='color:red'>";
344 $colorend = "</span>";
347 //Display what the patient owes
348 $balance = get_patient_balance($patient_id);
351 <?php if ($billing_note || $balance) { ?>
353 <div style='margin-top:3px'>
354 <table width='80%'>
355 <?php
356 if ($balance != "0") {
357 // $formatted = sprintf((xl('$').'%01.2f'), $balance);
358 $formatted = oeFormatMoney($balance);
359 echo " <tr class='text billing'>\n";
360 echo " <td>".$colorbeg . htmlspecialchars(xl('Balance Due'), ENT_NOQUOTES) .
361 $colorend."&nbsp;".$colorbeg. htmlspecialchars($formatted, ENT_NOQUOTES) .
362 $colorend."</td>\n";
363 echo " </tr>\n";
366 if ($billing_note) {
367 echo " <tr class='text billing'>\n";
368 echo " <td>".$colorbeg . htmlspecialchars(xl('Billing Note'), ENT_NOQUOTES) .
369 $colorend."&nbsp;".$colorbeg . htmlspecialchars($billing_note, ENT_NOQUOTES) .
370 $colorend."</td>\n";
371 echo " </tr>\n";
374 </table>
375 </div>
376 <br>
377 <?php } ?>
378 <ul class="tabNav">
379 <li class="<?php echo $inbox; ?>" ><a onclick="show_div('inbox')" href="#"><?php echo htmlspecialchars(xl('Inbox'), ENT_NOQUOTES); ?></a></li>
380 <li class="<?php echo $outbox; ?>" ><a onclick="show_div('outbox')" href="#"><?php echo htmlspecialchars(xl('Sent Items'), ENT_NOQUOTES); ?></a></li>
381 </ul>
382 <div class='tabContainer' >
383 <div id='inbox_div' <?php echo $inbox_style; ?> >
384 <form border='0' method='post' name='update_activity' id='update_activity'
385 action="pnotes_full.php?<?php echo $urlparms; ?>&<?php echo attr($activity_string_html);?>" onsubmit='return top.restoreSession()'>
386 <!-- start of previous notes DIV -->
387 <div class=pat_notes>
388 <input type='hidden' name='mode' value="update">
389 <input type='hidden' name='offset' id='offset' value="<?php echo attr($offset); ?>">
390 <input type='hidden' name='offset_sent' id='offset_sent' value="<?php echo attr($offset_sent); ?>">
391 <input type='hidden' name='noteid' id='noteid' value="0">
392 <table border='0' cellpadding="1" class="text">
393 <?php if ($result != "") : ?>
394 <tr>
395 <td colspan='5' style="padding: 5px;" >
396 <a href="#" class="change_activity" ><span><?php echo htmlspecialchars(xl('Update Active'), ENT_NOQUOTES); ?></span></a>
398 <a href="pnotes_full.php?<?php echo $urlparms; ?>&<?php echo attr($activity_string_html);?>" class="" id='Submit' onclick='return top.restoreSession()'><span><?php echo htmlspecialchars(xl('Refresh'), ENT_NOQUOTES); ?></span></a>
399 </td>
400 </tr></table>
401 <?php endif; ?>
403 <table border='0' cellpadding="1" class="text" width = "80%">
404 <?php
405 // display all of the notes for the day, as well as others that are active
406 // from previous dates, up to a certain number, $N
408 if ($result != "") {
409 echo " <tr class=showborder_head align='left'>\n";
410 echo " <th style='width:100px';>&nbsp;</th>\n";
411 echo " <th>" . xlt('Active') . "&nbsp;</th>\n";
412 echo " <th>" . (($docid || $orderid) ? xlt('Linked') : '') . "</th>\n";
413 echo " <th>" . xlt('Type') . "</th>\n";
414 echo " <th>" . xlt('Content') . "</th>\n";
415 echo " <th>" . xlt('Status') . "</th>\n";
416 echo " </tr>\n";
418 $result_count = 0;
419 foreach ($result as $iter) {
420 $result_count++;
421 $row_note_id = $iter['id'];
423 $linked = "";
424 if ($docid) {
425 if (isGpRelation(1, $docid, 6, $row_note_id)) {
426 $linked = "checked";
427 } else {
428 // Skip unlinked notes if that is requested.
429 if ($form_doc_only) {
430 continue;
433 } else if ($orderid) {
434 if (isGpRelation(2, $orderid, 6, $row_note_id)) {
435 $linked = "checked";
436 } else {
437 // Skip unlinked notes if that is requested.
438 if ($form_doc_only) {
439 continue;
444 $body = $iter['body'];
445 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
446 $body = nl2br(htmlspecialchars(oeFormatPatientNote($body), ENT_NOQUOTES));
447 } else {
448 $body = htmlspecialchars(oeFormatSDFT(strtotime($iter['date'])).date(' H:i', strtotime($iter['date'])), ENT_NOQUOTES) .
449 ' (' . htmlspecialchars($iter['user'], ENT_NOQUOTES) . ') ' . nl2br(htmlspecialchars(oeFormatPatientNote($body), ENT_NOQUOTES));
452 $body = preg_replace('/(\sto\s)-patient-(\))/', '${1}'.$patientname.'${2}', $body);
453 if (($iter{"activity"}) && ($iter['message_status'] != "Done")) {
454 $checked = "checked";
455 } else {
456 $checked = "";
459 // highlight the row if it's been selected for updating
460 if ($_REQUEST['noteid'] == $row_note_id) {
461 echo " <tr height=20 class='noterow highlightcolor' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
462 } else {
463 echo " <tr class='noterow' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
467 echo " <td><a href='pnotes_full_add.php?$urlparms&trigger=edit&noteid=".htmlspecialchars($row_note_id, ENT_QUOTES).
468 "' class='css_button_small note_modal' onclick='return top.restoreSession()'><span>". htmlspecialchars(xl('Edit'), ENT_NOQUOTES) ."</span></a>\n";
470 // display, or not, a button to delete the note
471 // if the user is an admin or if they are the author of the note, they can delete it
472 if (($iter['user'] == $_SESSION['authUser']) || (acl_check('admin', 'super', '', 'write'))) {
473 echo " <a href='#' class='deletenote css_button_small' id='del" . htmlspecialchars($row_note_id, ENT_QUOTES) .
474 "' title='" . htmlspecialchars(xl('Delete this note'), ENT_QUOTES) . "' onclick='return top.restoreSession()'><span>" .
475 htmlspecialchars(xl('Delete'), ENT_NOQUOTES) . "</span>\n";
478 echo " </td>\n";
481 echo " <td class='text bold'>\n";
482 echo " <input type='hidden' name='act".htmlspecialchars($row_note_id, ENT_QUOTES)."' value='1' />\n";
483 echo " <input type='checkbox' name='chk".htmlspecialchars($row_note_id, ENT_QUOTES)."' $checked />\n";
484 echo " </td>\n";
486 echo " <td class='text bold'>\n";
487 if ($docid || $orderid) {
488 echo " <input type='checkbox' name='lnk" . htmlspecialchars($row_note_id, ENT_QUOTES) . "' $linked />\n";
491 echo " </td>\n";
493 echo " <td class='bold notecell' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>" .
494 "<a href='pnotes_full_add.php?$urlparms&trigger=edit&noteid=".htmlspecialchars($row_note_id, ENT_QUOTES)."' class='note_modal' onclick='return top.restoreSession()'>\n";
495 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
496 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
497 echo " </a></td>\n";
499 echo " <td class='notecell' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
500 echo " $body";
501 echo " </td>\n";
502 echo " <td class='notecell' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
503 echo getListItemTitle("message_status", $iter['message_status']);
504 echo " </td>\n";
505 echo " </tr>\n";
507 $notes_count++;
509 } else {
510 //no results
511 print "<tr><td colspan='3' class='text'>" . htmlspecialchars(xl('None'), ENT_NOQUOTES) . ".</td></tr>\n";
516 </table>
517 </div>
518 </form>
520 <table width='400' border='0' cellpadding='0' cellspacing='0'>
521 <tr>
522 <td>
523 <?php
524 if ($offset > ($N-1)) {
525 $offsetN = $offset-$N;
526 echo " <a class='link' href='pnotes_full.php" .
527 "?$urlparms" .
528 "&form_active=" . htmlspecialchars($form_active, ENT_QUOTES) .
529 "&form_inactive=" . htmlspecialchars($form_inactive, ENT_QUOTES) .
530 "&form_doc_only=" . htmlspecialchars($form_doc_only, ENT_QUOTES) .
531 "&offset=" .attr($offsetN) . "&" . attr($activity_string_html) . "' onclick='return top.restoreSession()'>[" .
532 htmlspecialchars(xl('Previous'), ENT_NOQUOTES) . "]</a>\n";
535 </td>
536 <td align='right'>
537 <?php
538 if ($result_count == $N) {
539 $offsetN = $offset+$N;
540 echo " <a class='link' href='pnotes_full.php" .
541 "?$urlparms" .
542 "&form_active=" . htmlspecialchars($form_active, ENT_QUOTES) .
543 "&form_inactive=" . htmlspecialchars($form_inactive, ENT_QUOTES) .
544 "&form_doc_only=" . htmlspecialchars($form_doc_only, ENT_QUOTES) .
545 "&offset=" .attr($offsetN) . "&" . attr($activity_string_html) . "' onclick='return top.restoreSession()'>[" .
546 htmlspecialchars(xl('Next'), ENT_NOQUOTES) . "]</a>\n";
549 </td>
550 </tr>
551 </table>
553 </div>
554 <div id='outbox_div' <?php echo $outbox_style; ?> >
555 <table border='0' cellpadding="1" class="text">
556 <?php if ($result_sent != "") : ?>
557 <tr>
558 <td colspan='5' style="padding: 5px;" >
559 <a href="pnotes_full.php?<?php echo $urlparms; ?>&s=1&<?php echo attr($activity_string_html);?>"
560 class="" id='Submit' onclick='return top.restoreSession()'><span><?php echo xlt('Refresh'); ?></span></a>
561 </td>
562 </tr></table>
563 <?php endif; ?>
565 <table border='0' cellpadding="1" class="text" width = "80%">
566 <?php
567 // display all of the notes for the day, as well as others that are active
568 // from previous dates, up to a certain number, $N
570 if ($result_sent != "") {
571 echo " <tr class=showborder_head align='left'>\n";
572 echo " <th style='width:100px';>&nbsp;</th>\n";
573 echo " <th>" . htmlspecialchars(xl('Active'), ENT_NOQUOTES) . "&nbsp;</th>\n";
574 echo " <th>" . (($docid || $orderid) ? htmlspecialchars(xl('Linked'), ENT_NOQUOTES) : '') . "</th>\n";
575 echo " <th>" . htmlspecialchars(xl('Type'), ENT_NOQUOTES) . "</th>\n";
576 echo " <th>" . htmlspecialchars(xl('Content'), ENT_NOQUOTES) . "</th>\n";
577 echo " </tr>\n";
579 $result_sent_count = 0;
580 foreach ($result_sent as $iter) {
581 $result_sent_count++;
582 $row_note_id = $iter['id'];
584 $linked = "";
585 if ($docid) {
586 if (isGpRelation(1, $docid, 6, $row_note_id)) {
587 $linked = "checked";
588 } else {
589 // Skip unlinked notes if that is requested.
590 if ($form_doc_only) {
591 continue;
594 } else if ($orderid) {
595 if (isGpRelation(2, $orderid, 6, $row_note_id)) {
596 $linked = "checked";
597 } else {
598 // Skip unlinked notes if that is requested.
599 if ($form_doc_only) {
600 continue;
605 $body = $iter['body'];
606 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
607 $body = nl2br(htmlspecialchars(oeFormatPatientNote($body), ENT_NOQUOTES));
608 } else {
609 $body = htmlspecialchars(oeFormatSDFT(strtotime($iter['date'])).date(' H:i', strtotime($iter['date'])), ENT_NOQUOTES) .
610 ' (' . htmlspecialchars($iter['user'], ENT_NOQUOTES) . ') ' . nl2br(htmlspecialchars(oeFormatPatientNote($body), ENT_NOQUOTES));
613 $body = preg_replace('/(:\d{2}\s\()' . $patient_id . '(\sto\s)/', '${1}' . $patientname . '${2}', $body);
614 if (($iter{"activity"}) && ($iter['message_status'] != "Done")) {
615 $checked = "checked";
616 } else {
617 $checked = "";
620 // highlight the row if it's been selected for updating
621 if ($_REQUEST['noteid'] == $row_note_id) {
622 echo " <tr height=20 class='noterow highlightcolor' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
623 } else {
624 echo " <tr class='noterow' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
628 echo " <td><a href='pnotes_full_add.php?$urlparms&trigger=edit&noteid=".htmlspecialchars($row_note_id, ENT_QUOTES).
629 "' class='css_button_small note_modal' onclick='return top.restoreSession()'><span>". htmlspecialchars(xl('Edit'), ENT_NOQUOTES) ."</span></a>\n";
631 // display, or not, a button to delete the note
632 // if the user is an admin or if they are the author of the note, they can delete it
633 if (($iter['user'] == $_SESSION['authUser']) || (acl_check('admin', 'super', '', 'write'))) {
634 echo " <a href='#' class='deletenote css_button_small' id='del" . htmlspecialchars($row_note_id, ENT_QUOTES) .
635 "' title='" . htmlspecialchars(xl('Delete this note'), ENT_QUOTES) . "' onclick='return restoreSession()'><span>" .
636 htmlspecialchars(xl('Delete'), ENT_NOQUOTES) . "</span>\n";
639 echo " </td>\n";
642 echo " <td class='text bold'>\n";
643 echo " <input type='hidden' name='act".htmlspecialchars($row_note_id, ENT_QUOTES)."' value='1' />\n";
644 echo " <input type='checkbox' name='chk".htmlspecialchars($row_note_id, ENT_QUOTES)."' $checked />\n";
645 echo " </td>\n";
647 echo " <td class='text bold'>\n";
648 if ($docid || $orderid) {
649 echo " <input type='checkbox' name='lnk" . htmlspecialchars($row_note_id, ENT_QUOTES) . "' $linked />\n";
652 echo " </td>\n";
654 echo " <td class='bold notecell' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>" .
655 "<a href='pnotes_full_add.php?$urlparms&trigger=edit&noteid=".htmlspecialchars($row_note_id, ENT_QUOTES)."' class='note_modal' onclick='return top.restoreSession()'>\n";
656 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
657 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
658 echo " </a></td>\n";
660 echo " <td class='notecell' id='".htmlspecialchars($row_note_id, ENT_QUOTES)."'>\n";
661 echo " $body";
662 echo " </td>\n";
663 echo " </tr>\n";
665 $notes_sent_count++;
667 } else {
668 //no results
669 print "<tr><td colspan='3' class='text'>" . htmlspecialchars(xl('None'), ENT_NOQUOTES) . ".</td></tr>\n";
674 </table>
676 <table width='400' border='0' cellpadding='0' cellspacing='0'>
677 <tr>
678 <td>
679 <?php
680 if ($offset_sent > ($M-1)) {
681 $offsetSentM = $offset_sent-$M;
682 echo " <a class='link' href='pnotes_full.php" .
683 "?$urlparms" .
684 "&s=1" .
685 "&form_active=" . htmlspecialchars($form_active, ENT_QUOTES) .
686 "&form_inactive=" . htmlspecialchars($form_inactive, ENT_QUOTES) .
687 "&form_doc_only=" . htmlspecialchars($form_doc_only, ENT_QUOTES) .
688 "&offset_sent=" . attr($offsetSentM) . "&" . attr($activity_string_html) . "' onclick='return top.restoreSession()'>[" .
689 htmlspecialchars(xl('Previous'), ENT_NOQUOTES) . "]</a>\n";
692 </td>
693 <td align='right'>
694 <?php
695 if ($result_sent_count == $M) {
696 $offsetSentM = $offset_sent+$M;
697 echo " <a class='link' href='pnotes_full.php" .
698 "?$urlparms" .
699 "&s=1" .
700 "&form_active=" . htmlspecialchars($form_active, ENT_QUOTES) .
701 "&form_inactive=" . htmlspecialchars($form_inactive, ENT_QUOTES) .
702 "&form_doc_only=" . htmlspecialchars($form_doc_only, ENT_QUOTES) .
703 "&offset_sent=" . attr($offsetSentM) . "&" . attr($activity_string_html) . "' onclick='return top.restoreSession()'>[" .
704 htmlspecialchars(xl('Next'), ENT_NOQUOTES) . "]</a>\n";
707 </td>
708 </tr>
709 </table>
711 </div>
712 </div>
713 <script language='JavaScript'>
715 <?php
716 if ($_GET['set_pid']) {
717 $ndata = getPatientData($patient_id, "fname, lname, pubpid");
719 parent.left_nav.setPatient(<?php echo "'" . addslashes($ndata['fname']." ".$ndata['lname']) . "'," .
720 addslashes($patient_id) . ",'" . addslashes($ndata['pubpid']) . "',window.name"; ?>);
721 <?php
724 // If this note references a new patient document, pop up a display
725 // of that document.
727 if ($noteid /* && $title == 'New Document' */) {
728 $prow = getPnoteById($noteid, 'body');
729 if (preg_match('/New scanned document (\d+): [^\n]+\/([^\n]+)/', $prow['body'], $matches)) {
730 $docid = $matches[1];
731 $docname = $matches[2];
733 window.open('../../../controller.php?document&retrieve&patient_id=<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>&document_id=<?php echo htmlspecialchars($docid, ENT_QUOTES); ?>&<?php echo htmlspecialchars($docname, ENT_QUOTES);?>&as_file=true',
734 '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
735 <?php
740 </script>
742 </div> <!-- end outer 'pnotes' -->
744 </body>
746 <script language="javascript">
748 // jQuery stuff to make the page a little easier to use
750 $(document).ready(function(){
751 $("#appendnote").click(function() { AppendNote(); });
752 $("#newnote").click(function() { NewNote(); });
753 $("#printnote").click(function() { PrintNote(); });
755 $(".change_activity").click(function() { top.restoreSession(); $("#update_activity").submit(); });
757 $(".deletenote").click(function() { DeleteNote(this); });
759 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
760 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
761 $(".notecell").click(function() { EditNote(this); });
763 $("#note").focus();
765 var EditNote = function(note) {
766 top.restoreSession();
767 $("#noteid").val(note.id);
768 $("#mode").val("");
769 $("#new_note").submit();
772 var NewNote = function () {
773 top.restoreSession();
774 $("#noteid").val('');
775 $("#new_note").submit();
778 var AppendNote = function () {
779 top.restoreSession();
780 $("#new_note").submit();
783 var PrintNote = function () {
784 top.restoreSession();
785 window.open('pnotes_print.php?noteid=<?php echo htmlspecialchars($noteid, ENT_QUOTES); ?>', '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
788 var DeleteNote = function(note) {
789 if (confirm("<?php echo htmlspecialchars(xl('Are you sure you want to delete this note?', '', '', '\n '), ENT_QUOTES) .
790 htmlspecialchars(xl('This action CANNOT be undone.'), ENT_QUOTES); ?>")) {
791 top.restoreSession();
792 // strip the 'del' part of the object's ID
793 $("#noteid").val(note.id.replace(/del/, ""));
794 $("#mode").val("delete");
795 $("#new_note").submit();
801 </script>
803 </html>