d503e7af8eb871cd6f793c18795d1bc0b19edab3
[openemr.git] / interface / patient_file / summary / pnotes_full_add.php
blobd503e7af8eb871cd6f793c18795d1bc0b19edab3
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");
24 if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) {
25 require_once("$srcdir/pid.inc");
26 setpid($_GET['set_pid']);
28 // Check authorization.
29 if (!acl_check('patients','notes','',array('write','addonly') ))
30 die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES));
31 $tmp = getPatientData($pid, "squad");
32 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
33 die(htmlspecialchars( xl('Not authorized for this squad.'), ENT_NOQUOTES));
35 //the number of records to display per screen
36 $N = 25;
38 $mode = $_REQUEST['mode'];
39 $offset = $_REQUEST['offset'];
40 $form_active = $_REQUEST['form_active'];
41 $form_inactive = $_REQUEST['form_inactive'];
42 $noteid = $_REQUEST['noteid'];
43 $form_doc_only = isset($_POST['mode']) ? (empty($_POST['form_doc_only']) ? 0 : 1) : 1;
45 if (!isset($offset)) $offset = 0;
47 // if (!isset($active)) $active = "all";
49 $active = 'all';
50 if ($form_active) {
51 if (!$form_inactive) $active = '1';
53 else {
54 if ($form_inactive)
55 $active = '0';
56 else
57 $form_active = $form_inactive = '1';
60 // form parameter docid can be passed to restrict the display to a document.
61 $docid = empty($_REQUEST['docid']) ? 0 : 0 + $_REQUEST['docid'];
63 // this code handles changing the state of activity tags when the user updates
64 // them through the interface
65 if (isset($mode)) {
66 if ($mode == "update") {
67 foreach ($_POST as $var => $val) {
68 if (strncmp($var, 'act', 3) == 0) {
69 $id = str_replace("act", "", $var);
70 if ($_POST["chk$id"]) {
71 reappearPnote($id);
72 } else {
73 disappearPnote($id);
75 if ($docid) {
76 setGpRelation(1, $docid, 6, $id, !empty($_POST["lnk$id"]));
81 elseif ($mode == "new") {
82 $note = $_POST['note'];
83 if ($noteid) {
84 updatePnote($noteid, $note, $_POST['form_note_type'], $_POST['assigned_to']);
85 $noteid = '';
87 else {
88 addPnote($pid, $note, $userauthorized, '1', $_POST['form_note_type'],
89 $_POST['assigned_to']);
92 elseif ($mode == "delete") {
93 if ($noteid) {
94 deletePnote($noteid);
95 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], "pnotes: id ".$noteid);
97 $noteid = '';
101 $title = '';
102 $assigned_to = $_SESSION['authUser'];
103 if ($noteid) {
104 $prow = getPnoteById($noteid, 'title,assigned_to,body');
105 $title = $prow['title'];
106 $assigned_to = $prow['assigned_to'];
109 // Get the users list. The "Inactive" test is a kludge, we should create
110 // a separate column for this.
111 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
112 "WHERE username != '' AND active = 1 AND " .
113 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
114 "ORDER BY lname, fname");
116 $pres = getPatientData($pid, "lname, fname");
117 $patientname = $pres['lname'] . ", " . $pres['fname'];
119 //retrieve all notes
120 $result = getPnotesByDate("", $active, 'id,date,body,user,activity,title,assigned_to',
121 $pid, $N, $offset);
124 <html>
125 <head>
126 <?php html_header_show();?>
128 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
130 <!-- supporting javascript code -->
131 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
132 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
133 <script type="text/javascript" src="../../../library/dialog.js"></script>
134 <script type="text/javascript" src="../../../library/js/jquery.1.3.2.js"></script>
135 <script type="text/javascript" src="../../../library/js/common.js"></script>
136 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
137 <script type="text/javascript">
138 function submitform(attr) {
139 if (attr="newnote")
140 document.forms[0].submit();
142 </script>
143 </head>
144 <body class="body_top">
146 <div id="pnotes"> <!-- large outer DIV -->
148 <form border='0' method='post' name='new_note' id="new_note" target="_parent" action='pnotes_full.php?docid=<?php echo htmlspecialchars( $docid, ENT_QUOTES); ?>'>
150 <div>
151 <div style='float:left; margin-right: 5px'>
152 <span class="title"><?php echo htmlspecialchars( xl('Patient Note'), ENT_NOQUOTES); ?></span>
153 </div>
154 <div>
155 <?php if ($noteid) { ?>
156 <!-- existing note -->
157 <a href="#" class="css_button" id="printnote"><span><?php echo htmlspecialchars( xl('Print'), ENT_NOQUOTES); ?></span></a>
158 <?php } ?>
159 <a class="css_button large_button" id='cancel' href='javascript:;'>
160 <span class='css_button_span large_button_span'><?php echo htmlspecialchars( xl('Cancel'), ENT_NOQUOTES);?></span>
161 </a>
162 </div>
163 </div>
165 <br/>
167 <?php
168 $title_docname = "";
169 if ($docid) {
170 $title_docname = " " . xl("linked to document") . " ";
171 $d = new Document($docid);
172 $title_docname .= $d->get_url_file();
175 <input type='hidden' name='mode' id="mode" value="new">
176 <input type='hidden' name='trigger' id="trigger" value="add">
177 <input type='hidden' name='offset' id="offset" value="<?php echo $offset ?>">
178 <input type='hidden' name='form_active' id="form_active" value="<?php echo htmlspecialchars( $form_active, ENT_QUOTES) ?>">
179 <input type='hidden' name='form_inactive' id="form_inactive" value="<?php echo htmlspecialchars( $form_inactive, ENT_QUOTES) ?>">
180 <input type='hidden' name='noteid' id="noteid" value="<?php echo htmlspecialchars( $noteid, ENT_QUOTES) ?>">
181 <input type='hidden' name='form_doc_only' id="form_doc_only" value="<?php echo htmlspecialchars( $form_doc_only, ENT_QUOTES) ?>">
182 <table border='0' cellspacing='8'>
183 <tr>
184 <td class='text'>
185 <?php
186 if ($noteid) {
187 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
188 echo htmlspecialchars( xl('Amend Existing Note'), ENT_NOQUOTES) .
189 "<b> &quot;" . generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $title) . "&quot;</b>\n";
190 } else {
191 echo htmlspecialchars( xl('Add New Note'), ENT_NOQUOTES) . "\n";
194 </td>
195 </tr>
196 <tr>
197 <td class='text'>
198 <br/>
200 <b><?php echo htmlspecialchars( xl('Type'), ENT_NOQUOTES); ?>:</b>
201 <?php
202 // Added 6/2009 by BM to incorporate the patient notes into the list_options listings
203 generate_form_field(array('data_type'=>1,'field_id'=>'note_type','list_id'=>'note_type','empty_title'=>'SKIP'), $title);
205 &nbsp; &nbsp;
206 <b><?php echo htmlspecialchars( xl('To'), ENT_NOQUOTES); ?>:</b>
207 <select name='assigned_to'>
208 <option value=''>** <?php echo htmlspecialchars( xl('Close'), ENT_NOQUOTES); ?> **</option>
209 <?php
210 while ($urow = sqlFetchArray($ures)) {
211 echo " <option value='" . htmlspecialchars( $urow['username'], ENT_QUOTES) . "'";
212 if ($urow['username'] == $assigned_to) echo " selected";
213 echo ">" . htmlspecialchars( $urow['lname'], ENT_NOQUOTES);
214 if ($urow['fname']) echo htmlspecialchars( ", ".$urow['fname'], ENT_NOQUOTES);
215 echo "</option>\n";
218 </select>
219 </td>
220 </tr>
221 <tr>
222 <td>
223 <?php
224 if ($noteid) {
225 $body = $prow['body'];
226 $body = preg_replace(array('/(\sto\s)-patient-(\))/','/(:\d{2}\s\()'.$pid.'(\sto\s)/'),'${1}'.$patientname.'${2}',$body);
227 $body = nl2br(htmlspecialchars( $body, ENT_NOQUOTES));
228 echo "<div class='text'>".$body."</div>";
231 <br/>
232 <textarea name='note' id='note' rows='4' cols='58'></textarea>
234 <?php if ($noteid) { ?>
235 <!-- existing note -->
236 <a href="#" class="css_button" id="newnote" title="<?php echo htmlspecialchars( xl('Add as a new note'), ENT_QUOTES); ?>" ><span><?php echo htmlspecialchars( xl('Save as new note'), ENT_NOQUOTES); ?></span></a>
237 <a href="#" class="css_button" id="appendnote" title="<?php echo htmlspecialchars( xl('Append to the existing note'), ENT_QUOTES); ?>"><span><?php echo htmlspecialchars( xl('Append this note'), ENT_NOQUOTES); ?></span></a>
238 <?php } else { ?>
239 <a href="#" class="css_button" id="newnote" title="<?php echo htmlspecialchars( xl('Add as a new note'), ENT_QUOTES); ?>" ><span><?php echo htmlspecialchars( xl('Save as new note'), ENT_NOQUOTES); ?></span></a>
240 <?php } ?>
242 </td>
243 </tr>
244 </table>
245 <br>
246 </form>
247 <form border='0' method='post' name='update_activity' id='update_activity'
248 action="pnotes_full.php?docid=<?php echo htmlspecialchars( $docid, ENT_QUOTES); ?>">
250 <!-- start of previous notes DIV -->
251 <div class=pat_notes>
254 <input type='hidden' name='mode' value="update">
255 <input type='hidden' name='offset' id='noteid' value="<?php echo $offset;?>">
256 <input type='hidden' name='noteid' id='noteid' value="0">
257 </form>
259 <table width='400' border='0' cellpadding='0' cellspacing='0'>
260 <tr>
261 <td>
262 <?php
263 if ($offset > ($N-1)) {
264 echo " <a class='link' href='pnotes_full.php" .
265 "?docid=" . htmlspecialchars( $docid, ENT_QUOTES) .
266 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
267 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
268 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
269 "&offset=" . ($offset-$N) . "' onclick='top.restoreSession()'>[" .
270 htmlspecialchars( xl('Previous'), ENT_NOQUOTES) . "]</a>\n";
273 </td>
274 <td align='right'>
275 <?php
276 if ($result_count == $N) {
277 echo " <a class='link' href='pnotes_full.php" .
278 "?docid=" . htmlspecialchars( $docid, ENT_QUOTES) .
279 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
280 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
281 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
282 "&offset=" . ($offset+$N) . "' onclick='top.restoreSession()'>[" .
283 htmlspecialchars( xl('Next'), ENT_NOQUOTES) . "]</a>\n";
286 </td>
287 </tr>
288 </table>
290 </div> <!-- close the previous-notes DIV -->
292 <script language='JavaScript'>
294 <?php
295 if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) {
296 $ndata = getPatientData($pid, "fname, lname, pubpid");
298 parent.left_nav.setPatient(<?php echo "'" . htmlspecialchars( $ndata['fname']." ".$ndata['lname'], ENT_QUOTES) . "',$pid,'" . htmlspecialchars( $ndata['pubpid'], ENT_QUOTES) . "',window.name"; ?>);
299 parent.left_nav.setRadio(window.name, 'pno');
300 <?php
303 // If this note references a new patient document, pop up a display
304 // of that document.
306 if ($noteid /* && $title == 'New Document' */ ) {
307 $prow = getPnoteById($noteid, 'body');
308 if (preg_match('/New scanned document (\d+): [^\n]+\/([^\n]+)/', $prow['body'], $matches)) {
309 $docid = $matches[1];
310 $docname = $matches[2];
312 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',
313 '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
314 <?php
319 </script>
321 </div> <!-- end outer 'pnotes' -->
323 </body>
325 <script language="javascript">
327 // jQuery stuff to make the page a little easier to use
329 $(document).ready(function(){
330 $("#appendnote").click(function() { AppendNote(); });
331 $("#newnote").click(function() { NewNote(); });
332 $("#printnote").click(function() { PrintNote(); });
334 $(".change_activity").click(function() { top.restoreSession(); $("#update_activity").submit(); });
336 $(".deletenote").click(function() { DeleteNote(this); });
338 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
339 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
340 $(".notecell").click(function() { EditNote(this); });
342 $("#note").focus();
344 var EditNote = function(note) {
345 top.restoreSession();
346 $("#noteid").val(note.id);
347 $("#mode").val("");
348 $("#new_note").submit();
351 var NewNote = function () {
352 top.restoreSession();
353 $("#noteid").val('');
354 $("#new_note").submit();
357 var AppendNote = function () {
358 top.restoreSession();
359 $("#new_note").submit();
362 var PrintNote = function () {
363 top.restoreSession();
364 window.open('pnotes_print.php?noteid=<?php echo htmlspecialchars( $noteid, ENT_QUOTES); ?>', '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
367 var DeleteNote = function(note) {
368 if (confirm("<?php echo htmlspecialchars( xl('Are you sure you want to delete this note?','','','\n ').xl('This action CANNOT be undone.'), ENT_QUOTES); ?>")) {
369 top.restoreSession();
370 // strip the 'del' part of the object's ID
371 $("#noteid").val(note.id.replace(/del/, ""));
372 $("#mode").val("delete");
373 $("#new_note").submit();
378 $(document).ready(function(){
379 $("#cancel").click(function() {
380 parent.$.fn.fancybox.close();
384 </script>
386 </html>