Clean up and secure the messages-pnotes scripts and related functions-scripts (remove...
[openemr.git] / interface / patient_file / summary / pnotes_full.php
blob20bd9455d7751fb1b87a90b007712c935627cedf
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 //SANITIZE ALL ESCAPES
8 $sanitize_all_escapes=true;
9 //
11 //STOP FAKE REGISTER GLOBALS
12 $fake_register_globals=false;
15 require_once("../../globals.php");
16 require_once("$srcdir/pnotes.inc");
17 require_once("$srcdir/patient.inc");
18 require_once("$srcdir/acl.inc");
19 require_once("$srcdir/log.inc");
20 require_once("$srcdir/options.inc.php");
21 require_once("$srcdir/classes/Document.class.php");
22 require_once("$srcdir/gprelations.inc.php");
23 require_once("$srcdir/formatting.inc.php");
25 if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) {
26 require_once("$srcdir/pid.inc");
27 setpid($_GET['set_pid']);
30 // Check authorization.
31 $thisauth = acl_check('patients', 'notes');
32 if ($thisauth != 'write' && $thisauth != 'addonly')
33 die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES));
34 $tmp = getPatientData($pid, "squad");
35 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
36 die(htmlspecialchars( xl('Not authorized for this squad.'), ENT_NOQUOTES));
38 //the number of records to display per screen
39 $N = 25;
41 $mode = $_REQUEST['mode'];
42 $offset = $_REQUEST['offset'];
43 $form_active = $_REQUEST['form_active'];
44 $form_inactive = $_REQUEST['form_inactive'];
45 $noteid = $_REQUEST['noteid'];
46 $form_doc_only = isset($_POST['mode']) ? (empty($_POST['form_doc_only']) ? 0 : 1) : 1;
48 if (!isset($offset)) $offset = 0;
50 // if (!isset($active)) $active = "all";
52 $active = 'all';
53 if ($form_active) {
54 if (!$form_inactive) $active = '1';
56 else {
57 if ($form_inactive)
58 $active = '0';
59 else
60 $form_active = $form_inactive = '1';
63 // form parameter docid can be passed to restrict the display to a document.
64 $docid = empty($_REQUEST['docid']) ? 0 : 0 + $_REQUEST['docid'];
66 // this code handles changing the state of activity tags when the user updates
67 // them through the interface
68 if (isset($mode)) {
69 if ($mode == "update") {
70 foreach ($_POST as $var => $val) {
71 if (strncmp($var, 'act', 3) == 0) {
72 $id = str_replace("act", "", $var);
73 if ($_POST["chk$id"]) {
74 reappearPnote($id);
75 } else {
76 disappearPnote($id);
78 if ($docid) {
79 setGpRelation(1, $docid, 6, $id, !empty($_POST["lnk$id"]));
84 elseif ($mode == "new") {
85 $note = $_POST['note'];
87 if ($noteid) {
88 updatePnote($noteid, $note, $_POST['form_note_type'], $_POST['assigned_to']);
89 $noteid = '';
91 else {
92 addPnote($pid, $note, $userauthorized, '1', $_POST['form_note_type'],
93 $_POST['assigned_to']);
96 elseif ($mode == "delete") {
97 if ($noteid) {
98 deletePnote($noteid);
99 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "pnotes: id ".$noteid);
101 $noteid = '';
105 $title = '';
106 $assigned_to = $_SESSION['authUser'];
107 if ($noteid) {
108 $prow = getPnoteById($noteid, 'title,assigned_to,body');
109 $title = $prow['title'];
110 $assigned_to = $prow['assigned_to'];
113 // Get the users list. The "Inactive" test is a kludge, we should create
114 // a separate column for this.
115 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
116 "WHERE username != '' AND active = 1 AND " .
117 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
118 "ORDER BY lname, fname");
120 //retrieve all notes
121 $result = getPnotesByDate("", $active, 'id,date,body,user,activity,title,assigned_to',
122 $pid, $N, $offset);
125 <html>
126 <head>
127 <?php html_header_show();?>
129 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
131 <!-- supporting javascript code -->
132 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
133 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
134 <script type="text/javascript" src="../../../library/dialog.js"></script>
135 <script type="text/javascript" src="../../../library/js/jquery.1.3.2.js"></script>
136 <script type="text/javascript" src="../../../library/js/common.js"></script>
137 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
138 <script type="text/javascript">
139 /// todo, move this to a common library
141 $(document).ready(function(){
143 $("#dem_view").click( function() {
144 toggle( $(this), "#DEM" );
147 // load divs
148 $("#stats_div").load("stats.php");
149 $("#notes_div").load("pnotes_fragment.php");
151 // fancy box
152 enable_modals();
155 </script>
156 </head>
157 <body class="body_top">
159 <div id="pnotes"> <!-- large outer DIV -->
161 <form border='0' method='post' name='new_note' id="new_note" action='pnotes_full.php?docid=<?php echo htmlspecialchars( $docid, ENT_QUOTES); ?>'>
164 <div>
165 <span class="title"><?php echo htmlspecialchars( xl('Patient Notes'), ENT_NOQUOTES); ?></span>
166 </div>
167 <div style='float:left;margin-right:10px'>
168 <?php echo htmlspecialchars( xl('for'), ENT_NOQUOTES);?>&nbsp;<span class="title">
169 <a href="../summary/demographics.php" onclick="top.restoreSession()"><?php echo htmlspecialchars( getPatientName($pid), ENT_NOQUOTES); ?></a></span>
170 </div>
171 <div>
172 <a href="pnotes_full_add.php" class="css_button iframe"><span><?php echo htmlspecialchars( xl('Add'), ENT_NOQUOTES); ?></span></a>
173 <a href="demographics.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
174 <span><?php echo htmlspecialchars( xl('View Patient'), ENT_NOQUOTES);?></span>
175 </a>
176 </div>
177 <br/>
179 <?php
180 $title_docname = "";
181 if ($docid) {
182 $title_docname = " " . htmlspecialchars( xl("linked to document"), ENT_NOQUOTES) . " ";
183 $d = new Document($docid);
184 $title_docname .= $d->get_url_file();
187 <input type='hidden' name='mode' id="mode" value="new">
188 <input type='hidden' name='offset' id="offset" value="<?php echo $offset ?>">
189 <input type='hidden' name='form_active' id="form_active" value="<?php echo htmlspecialchars( $form_active, ENT_QUOTES); ?>">
190 <input type='hidden' name='form_inactive' id="form_inactive" value="<?php echo htmlspecialchars( $form_inactive, ENT_QUOTES); ?>">
191 <input type='hidden' name='noteid' id="noteid" value="<?php echo htmlspecialchars( $noteid, ENT_QUOTES); ?>">
192 <input type='hidden' name='form_doc_only' id="form_doc_only" value="<?php echo htmlspecialchars( $form_doc_only, ENT_QUOTES); ?>">
193 </form>
196 <?php
197 //display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
198 $N = 15;
200 // Get the billing note if there is one.
201 $billing_note = "";
202 $colorbeg = "";
203 $colorend = "";
204 $sql = "select genericname2, genericval2 " .
205 "from patient_data where pid = ? limit 1";
206 $resnote = sqlQuery($sql, array($pid) );
207 if($resnote && $resnote['genericname2'] == 'Billing') {
208 $billing_note = $resnote['genericval2'];
209 $colorbeg = "<span style='color:red'>";
210 $colorend = "</span>";
213 //Display what the patient owes
214 $balance = get_patient_balance($pid);
217 <?php if ($billing_note || $balance ) { ?>
219 <div style='margin-top:3px'>
220 <table width='80%'>
221 <?php
222 if ($balance != "0") {
223 // $formatted = sprintf((xl('$').'%01.2f'), $balance);
224 $formatted = oeFormatMoney($balance);
225 echo " <tr class='text billing'>\n";
226 echo " <td>".$colorbeg . htmlspecialchars( xl('Balance Due'), ENT_NOQUOTES) .
227 $colorend."&nbsp;".$colorbeg. htmlspecialchars( $formatted, ENT_NOQUOTES) .
228 $colorend."</td>\n";
229 echo " </tr>\n";
232 if ($billing_note) {
233 echo " <tr class='text billing'>\n";
234 echo " <td>".$colorbeg . htmlspecialchars( xl('Billing Note'), ENT_NOQUOTES) .
235 $colorend."&nbsp;".$colorbeg . htmlspecialchars( $billing_note, ENT_NOQUOTES) .
236 $colorend."</td>\n";
237 echo " </tr>\n";
240 </table>
241 </div>
242 <br>
243 <?php } ?>
245 <form border='0' method='post' name='update_activity' id='update_activity'
246 action="pnotes_full.php?docid=<?php echo htmlspecialchars( $docid, ENT_QUOTES); ?>">
247 <!-- start of previous notes DIV -->
248 <div class=pat_notes>
249 <input type='hidden' name='mode' value="update">
250 <input type='hidden' name='offset' id='noteid' value="<?php echo $offset;?>">
251 <input type='hidden' name='noteid' id='noteid' value="0">
252 <table border='0' cellpadding="1" class="text">
253 <?php if ($result != ""): ?>
254 <tr>
255 <td colspan='5' style="padding: 5px;" >
256 <a href="#" class="change_activity" ><span><?php echo htmlspecialchars( xl('Update Active'), ENT_NOQUOTES); ?></span></a>
258 <a href="pnotes_full.php" class="" id='Submit'><span><?php echo htmlspecialchars( xl('Refresh'), ENT_NOQUOTES); ?></span></a>
259 </td>
260 </tr></table>
261 <?php endif; ?>
263 <div>
264 <table border='0' cellpadding="1" class="text" width = "80%">
265 <?php
266 // display all of the notes for the day, as well as others that are active
267 // from previous dates, up to a certain number, $N
269 if ($result != "") {
270 echo " <tr class=showborder_head align='left'>\n";
271 echo " <th style='width:100px';>&nbsp;</th>\n";
272 echo " <th>" . htmlspecialchars( xl('Active'), ENT_NOQUOTES) . "&nbsp;</th>\n";
273 echo " <th>" . ($docid ? htmlspecialchars( xl('Linked'), ENT_NOQUOTES) : '') . "</th>\n";
274 echo " <th>" . htmlspecialchars( xl('Type'), ENT_NOQUOTES) . "</th>\n";
275 echo " <th>" . htmlspecialchars( xl('Content'), ENT_NOQUOTES) . "</th>\n";
276 echo " </tr>\n";
278 $result_count = 0;
279 foreach ($result as $iter) {
280 $result_count++;
281 $row_note_id = $iter['id'];
283 $linked = "";
284 if ($docid) {
285 if (isGpRelation(1, $docid, 6, $row_note_id)) {
286 $linked = "checked";
288 else {
289 // Skip unlinked notes if that is requested.
290 if ($form_doc_only) continue;
294 $body = $iter['body'];
295 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
296 $body = nl2br(htmlspecialchars( oeFormatPatientNote($body), ENT_NOQUOTES));
297 } else {
298 $body = htmlspecialchars( oeFormatSDFT(strtotime($iter['date'])).date(' H:i', strtotime($iter['date'])), ENT_NOQUOTES) .
299 ' (' . htmlspecialchars( $iter['user'], ENT_NOQUOTES) . ') ' . nl2br(htmlspecialchars( oeFormatPatientNote($body), ENT_NOQUOTES));
302 if ($iter{"activity"}) {
303 $checked = "checked";
304 } else {
305 $checked = "";
308 // highlight the row if it's been selected for updating
309 if ($_REQUEST['noteid'] == $row_note_id) {
310 echo " <tr height=20 class='noterow highlightcolor' id='".htmlspecialchars( $row_note_id, ENT_QUOTES)."'>\n";
312 else {
313 echo " <tr class='noterow' id='".htmlspecialchars( $row_note_id, ENT_QUOTES)."'>\n";
317 echo " <td><a href='pnotes_full_add.php?trigger=edit&noteid=".htmlspecialchars( $row_note_id, ENT_QUOTES).
318 "' class='css_button_small iframe'><span>". htmlspecialchars( xl('Edit'), ENT_NOQUOTES) ."</span></a>\n";
320 // display, or not, a button to delete the note
321 // if the user is an admin or if they are the author of the note, they can delete it
322 $thisauth = acl_check('admin', 'super');
323 if (($iter['user'] == $_SESSION['authUser']) || ($thisauth == 'write')) {
324 echo " <a href='#' class='deletenote css_button_small' id='del" . htmlspecialchars( $row_note_id, ENT_QUOTES) .
325 "' title='" . htmlspecialchars( xl('Delete this note'), ENT_QUOTES) . "'><span>" .
326 htmlspecialchars( xl('Delete'), ENT_NOQUOTES) . "</span>\n";
328 echo " </td>\n";
331 echo " <td class='text bold'>\n";
332 echo " <input type='hidden' name='act".htmlspecialchars( $row_note_id, ENT_QUOTES)."' value='1' />\n";
333 echo " <input type='checkbox' name='chk".htmlspecialchars( $row_note_id, ENT_QUOTES)."' $checked />\n";
334 echo " </td>\n";
336 echo " <td class='text bold'>\n";
337 if ($docid) {
338 echo " <input type='checkbox' name='lnk".htmlspecialchars( $row_note_id, ENT_QUOTES)."' $linked />\n";
340 echo " </td>\n";
342 echo " <td class='bold notecell' id='".htmlspecialchars( $row_note_id, ENT_QUOTES)."'>" .
343 "<a href='pnotes_full_add.php?trigger=edit&noteid=".htmlspecialchars( $row_note_id, ENT_QUOTES)."' class='iframe'>\n";
344 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
345 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
346 echo " </a></td>\n";
348 echo " <td class='notecell' id='".htmlspecialchars( $row_note_id, ENT_QUOTES)."'>\n";
349 echo " $body";
350 echo " </td>\n";
351 echo " </tr>\n";
353 $notes_count++;
355 } else {
356 //no results
357 print "<tr><td colspan='3' class='text'>" . htmlspecialchars( xl('None'), ENT_NOQUOTES) . ".</td></tr>\n";
362 </table>
363 </div>
364 </form>
366 <table width='400' border='0' cellpadding='0' cellspacing='0'>
367 <tr>
368 <td>
369 <?php
370 if ($offset > ($N-1)) {
371 echo " <a class='link' href='pnotes_full.php" .
372 "?docid=" . htmlspecialchars( $docid, ENT_QUOTES) .
373 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
374 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
375 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
376 "&offset=" . ($offset-$N) . "' onclick='top.restoreSession()'>[" .
377 htmlspecialchars( xl('Previous'), ENT_NOQUOTES) . "]</a>\n";
380 </td>
381 <td align='right'>
382 <?php
383 if ($result_count == $N) {
384 echo " <a class='link' href='pnotes_full.php" .
385 "?docid=" . htmlspecialchars( $docid, ENT_QUOTES) .
386 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
387 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
388 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
389 "&offset=" . ($offset+$N) . "' onclick='top.restoreSession()'>[" .
390 htmlspecialchars( xl('Next'), ENT_NOQUOTES) . "]</a>\n";
393 </td>
394 </tr>
395 </table>
397 </div> <!-- close the previous-notes DIV -->
399 </center>
401 <script language='JavaScript'>
403 <?php
404 if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) {
405 $ndata = getPatientData($pid, "fname, lname, pubpid");
407 parent.left_nav.setPatient(<?php echo "'" . htmlspecialchars( $ndata['fname']." ".$ndata['lname'], ENT_QUOTES) . "'," .
408 htmlspecialchars( $pid, ENT_QUOTES) . ",'" . htmlspecialchars( $ndata['pubpid'], ENT_QUOTES) . "',window.name"; ?>);
409 parent.left_nav.setRadio(window.name, 'pno');
410 <?php
413 // If this note references a new patient document, pop up a display
414 // of that document.
416 if ($noteid /* && $title == 'New Document' */ ) {
417 $prow = getPnoteById($noteid, 'body');
418 if (preg_match('/New scanned document (\d+): [^\n]+\/([^\n]+)/', $prow['body'], $matches)) {
419 $docid = $matches[1];
420 $docname = $matches[2];
422 window.open('../../../controller.php?document&retrieve&patient_id=<?php echo htmlspecialchars( $pid, ENT_QUOTES); ?>&document_id=<?php echo htmlspecialchars( $docid, ENT_QUOTES); ?>&<?php echo htmlspecialchars( $docname, ENT_QUOTES);?>&as_file=true',
423 '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
424 <?php
429 </script>
431 </div> <!-- end outer 'pnotes' -->
433 </body>
435 <script language="javascript">
437 // jQuery stuff to make the page a little easier to use
439 $(document).ready(function(){
440 $("#appendnote").click(function() { AppendNote(); });
441 $("#newnote").click(function() { NewNote(); });
442 $("#printnote").click(function() { PrintNote(); });
444 $(".change_activity").click(function() { top.restoreSession(); $("#update_activity").submit(); });
446 $(".deletenote").click(function() { DeleteNote(this); });
448 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
449 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
450 $(".notecell").click(function() { EditNote(this); });
452 $("#note").focus();
454 var EditNote = function(note) {
455 top.restoreSession();
456 $("#noteid").val(note.id);
457 $("#mode").val("");
458 $("#new_note").submit();
461 var NewNote = function () {
462 top.restoreSession();
463 $("#noteid").val('');
464 $("#new_note").submit();
467 var AppendNote = function () {
468 top.restoreSession();
469 $("#new_note").submit();
472 var PrintNote = function () {
473 top.restoreSession();
474 window.open('pnotes_print.php?noteid=<?php echo htmlspecialchars( $noteid, ENT_QUOTES); ?>', '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
477 var DeleteNote = function(note) {
478 if (confirm("<?php echo htmlspecialchars( xl('Are you sure you want to delete this note?','','','\n '), ENT_QUOTES) .
479 htmlspecialchars( xl('This action CANNOT be undone.'), ENT_QUOTES); ?>")) {
480 top.restoreSession();
481 // strip the 'del' part of the object's ID
482 $("#noteid").val(note.id.replace(/del/, ""));
483 $("#mode").val("delete");
484 $("#new_note").submit();
490 </script>
493 </html>