Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / interface / patient_file / summary / pnotes_full_add.php
blob65d4b83a768d293825d5838d6b58784199e0f65a
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/gprelations.inc.php");
23 if ($_GET['set_pid']) {
24 require_once("$srcdir/pid.inc");
25 setpid($_GET['set_pid']);
28 // form parameter docid can be passed to restrict the display to a document.
29 $docid = empty($_REQUEST['docid']) ? 0 : intval($_REQUEST['docid']);
31 // form parameter orderid can be passed to restrict the display to a procedure order.
32 $orderid = empty($_REQUEST['orderid']) ? 0 : intval($_REQUEST['orderid']);
34 $patient_id = $pid;
35 if ($docid) {
36 $row = sqlQuery("SELECT foreign_id FROM documents WHERE id = ?", array($docid));
37 $patient_id = intval($row['foreign_id']);
39 else if ($orderid) {
40 $row = sqlQuery("SELECT patient_id FROM procedure_order WHERE procedure_order_id = ?", array($orderid));
41 $patient_id = intval($row['patient_id']);
44 // Check authorization.
45 if (!acl_check('patients','notes','',array('write','addonly') ))
46 die(htmlspecialchars( xl('Not authorized'), ENT_NOQUOTES));
47 $tmp = getPatientData($patient_id, "squad");
48 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
49 die(htmlspecialchars( xl('Not authorized for this squad.'), ENT_NOQUOTES));
51 //the number of records to display per screen
52 $N = 25;
54 $mode = $_REQUEST['mode'];
55 $offset = $_REQUEST['offset'];
56 $form_active = $_REQUEST['form_active'];
57 $form_inactive = $_REQUEST['form_inactive'];
58 $noteid = $_REQUEST['noteid'];
59 $form_doc_only = isset($_POST['mode']) ? (empty($_POST['form_doc_only']) ? 0 : 1) : 1;
61 if (!isset($offset)) $offset = 0;
63 // if (!isset($active)) $active = "all";
65 $active = 'all';
66 if ($form_active) {
67 if (!$form_inactive) $active = '1';
69 else {
70 if ($form_inactive)
71 $active = '0';
72 else
73 $form_active = $form_inactive = '1';
76 // this code handles changing the state of activity tags when the user updates
77 // them through the interface
78 if (isset($mode)) {
79 if ($mode == "update") {
80 foreach ($_POST as $var => $val) {
81 if (strncmp($var, 'act', 3) == 0) {
82 $id = str_replace("act", "", $var);
83 if ($_POST["chk$id"]) {
84 reappearPnote($id);
85 } else {
86 disappearPnote($id);
88 if ($docid) {
89 setGpRelation(1, $docid, 6, $id, !empty($_POST["lnk$id"]));
91 if ($orderid) {
92 setGpRelation(2, $orderid, 6, $id, !empty($_POST["lnk$id"]));
97 elseif ($mode == "new") {
98 $note = $_POST['note'];
99 if ($noteid) {
100 updatePnote($noteid, $note, $_POST['form_note_type'], $_POST['assigned_to']);
101 $noteid = '';
103 else {
104 $noteid = addPnote($patient_id, $note, $userauthorized, '1', $_POST['form_note_type'],
105 $_POST['assigned_to']);
107 if ($docid) {
108 setGpRelation(1, $docid, 6, $noteid);
110 if ($orderid) {
111 setGpRelation(2, $orderid, 6, $noteid);
113 $noteid = '';
115 elseif ($mode == "delete") {
116 if ($noteid) {
117 deletePnote($noteid);
118 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], "pnotes: id ".$noteid);
120 $noteid = '';
124 $title = '';
125 $assigned_to = $_SESSION['authUser'];
126 if ($noteid) {
127 $prow = getPnoteById($noteid, 'title,assigned_to,body');
128 $title = $prow['title'];
129 $assigned_to = $prow['assigned_to'];
132 // Get the users list. The "Inactive" test is a kludge, we should create
133 // a separate column for this.
134 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
135 "WHERE username != '' AND active = 1 AND " .
136 "( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
137 "ORDER BY lname, fname");
139 $pres = getPatientData($patient_id, "lname, fname");
140 $patientname = $pres['lname'] . ", " . $pres['fname'];
142 //retrieve all notes
143 $result = getPnotesByDate("", $active, 'id,date,body,user,activity,title,assigned_to',
144 $patient_id, $N, $offset);
147 <html>
148 <head>
149 <?php html_header_show();?>
151 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
153 <!-- supporting javascript code -->
154 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-1/index.js"></script>
155 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
156 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
157 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
158 <script type="text/javascript" src="../../../library/js/common.js"></script>
159 <script type="text/javascript" src="../../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
160 <script type="text/javascript">
161 function submitform(attr) {
162 if (attr="newnote")
163 document.forms[0].submit();
165 </script>
166 </head>
167 <body class="body_top">
169 <div id="pnotes"> <!-- large outer DIV -->
171 <?php
172 $title_docname = "";
173 if ($docid) {
174 $title_docname .= " " . xl("linked to document") . " ";
175 $d = new Document($docid);
176 $title_docname .= $d->get_url_file();
178 if ($orderid) {
179 $title_docname .= " " . xl("linked to procedure order") . " $orderid";
182 $urlparms = "docid=$docid&orderid=$orderid";
185 <form border='0' method='post' name='new_note' id="new_note" target="_parent"
186 action='pnotes_full.php?<?php echo $urlparms; ?>'>
188 <div>
189 <div style='float:left; margin-right: 5px'>
190 <span class="title"><?php echo xlt('Patient Note') . $title_docname; ?></span>
191 </div>
192 <div>
193 <?php if ($noteid) { ?>
194 <!-- existing note -->
195 <a href="#" class="css_button" id="printnote"><span><?php echo xlt('View Printable Version'); ?></span></a>
196 <?php } ?>
197 <a class="css_button large_button" id='cancel' href='javascript:;'>
198 <span class='css_button_span large_button_span'><?php echo htmlspecialchars( xl('Cancel'), ENT_NOQUOTES);?></span>
199 </a>
200 </div>
201 </div>
203 <br/>
205 <input type='hidden' name='mode' id="mode" value="new">
206 <input type='hidden' name='trigger' id="trigger" value="add">
207 <input type='hidden' name='offset' id="offset" value="<?php echo $offset ?>">
208 <input type='hidden' name='form_active' id="form_active" value="<?php echo htmlspecialchars( $form_active, ENT_QUOTES) ?>">
209 <input type='hidden' name='form_inactive' id="form_inactive" value="<?php echo htmlspecialchars( $form_inactive, ENT_QUOTES) ?>">
210 <input type='hidden' name='noteid' id="noteid" value="<?php echo htmlspecialchars( $noteid, ENT_QUOTES) ?>">
211 <input type='hidden' name='form_doc_only' id="form_doc_only" value="<?php echo htmlspecialchars( $form_doc_only, ENT_QUOTES) ?>">
212 <table border='0' cellspacing='8'>
213 <tr>
214 <td class='text'>
215 <?php
216 if ($noteid) {
217 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
218 echo htmlspecialchars( xl('Amend Existing Note'), ENT_NOQUOTES) .
219 "<b> &quot;" . generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $title) . "&quot;</b>\n";
220 } else {
221 echo htmlspecialchars( xl('Add New Note'), ENT_NOQUOTES) . "\n";
224 </td>
225 </tr>
226 <tr>
227 <td class='text'>
228 <br/>
230 <b><?php echo htmlspecialchars( xl('Type'), ENT_NOQUOTES); ?>:</b>
231 <?php
232 // Added 6/2009 by BM to incorporate the patient notes into the list_options listings
233 generate_form_field(array('data_type'=>1,'field_id'=>'note_type','list_id'=>'note_type','empty_title'=>'SKIP'), $title);
235 &nbsp; &nbsp;
236 <b><?php echo htmlspecialchars( xl('To'), ENT_NOQUOTES); ?>:</b>
237 <select name='assigned_to'>
238 <option value=''>** <?php echo htmlspecialchars( xl('Close'), ENT_NOQUOTES); ?> **</option>
239 <?php
240 while ($urow = sqlFetchArray($ures)) {
241 echo " <option value='" . htmlspecialchars( $urow['username'], ENT_QUOTES) . "'";
242 if ($urow['username'] == $assigned_to) echo " selected";
243 echo ">" . htmlspecialchars( $urow['lname'], ENT_NOQUOTES);
244 if ($urow['fname']) echo htmlspecialchars( ", ".$urow['fname'], ENT_NOQUOTES);
245 echo "</option>\n";
248 </select>
249 </td>
250 </tr>
251 <tr>
252 <td>
253 <?php
254 if ($noteid) {
255 $body = $prow['body'];
256 $body = preg_replace(array('/(\sto\s)-patient-(\))/', '/(:\d{2}\s\()' . $patient_id . '(\sto\s)/'), '${1}' . $patientname . '${2}', $body);
257 $body = nl2br(htmlspecialchars( $body, ENT_NOQUOTES));
258 echo "<div class='text'>".$body."</div>";
261 <br/>
262 <textarea name='note' id='note' rows='4' cols='58'></textarea>
264 <?php if ($noteid) { ?>
265 <!-- existing note -->
266 <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>
267 <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>
268 <?php } else { ?>
269 <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>
270 <?php } ?>
272 </td>
273 </tr>
274 </table>
275 <br>
276 </form>
277 <form border='0' method='post' name='update_activity' id='update_activity'
278 action="pnotes_full.php?<?php echo $urlparms; ?>">
280 <!-- start of previous notes DIV -->
281 <div class=pat_notes>
284 <input type='hidden' name='mode' value="update">
285 <input type='hidden' name='offset' id='noteid' value="<?php echo $offset;?>">
286 <input type='hidden' name='noteid' id='noteid' value="0">
287 </form>
289 <table width='400' border='0' cellpadding='0' cellspacing='0'>
290 <tr>
291 <td>
292 <?php
293 if ($offset > ($N-1)) {
294 echo " <a class='link' href='pnotes_full.php" .
295 "?$urlparms" .
296 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
297 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
298 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
299 "&offset=" . ($offset-$N) . "' onclick='top.restoreSession()'>[" .
300 htmlspecialchars( xl('Previous'), ENT_NOQUOTES) . "]</a>\n";
303 </td>
304 <td align='right'>
305 <?php
306 if ($result_count == $N) {
307 echo " <a class='link' href='pnotes_full.php" .
308 "?$urlparms" .
309 "&form_active=" . htmlspecialchars( $form_active, ENT_QUOTES) .
310 "&form_inactive=" . htmlspecialchars( $form_inactive, ENT_QUOTES) .
311 "&form_doc_only=" . htmlspecialchars( $form_doc_only, ENT_QUOTES) .
312 "&offset=" . ($offset+$N) . "' onclick='top.restoreSession()'>[" .
313 htmlspecialchars( xl('Next'), ENT_NOQUOTES) . "]</a>\n";
316 </td>
317 </tr>
318 </table>
320 </div> <!-- close the previous-notes DIV -->
322 <script language='JavaScript'>
324 <?php
325 if ($_GET['set_pid']) {
326 $ndata = getPatientData($patient_id, "fname, lname, pubpid");
328 parent.left_nav.setPatient(<?php echo "'" . addslashes($ndata['fname']." ".$ndata['lname']) . "'," . addslashes($patient_id) . ",'" . addslashes($ndata['pubpid']) . "',window.name"; ?>);
329 <?php
332 // If this note references a new patient document, pop up a display
333 // of that document.
335 if ($noteid /* && $title == 'New Document' */ ) {
336 $prow = getPnoteById($noteid, 'body');
337 if (preg_match('/New scanned document (\d+): [^\n]+\/([^\n]+)/', $prow['body'], $matches)) {
338 $docid = $matches[1];
339 $docname = $matches[2];
341 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',
342 '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
343 <?php
348 </script>
350 </div> <!-- end outer 'pnotes' -->
352 </body>
354 <script language="javascript">
356 // jQuery stuff to make the page a little easier to use
358 $(document).ready(function(){
359 $("#appendnote").click(function() { AppendNote(); });
360 $("#newnote").click(function() { NewNote(); });
361 $("#printnote").click(function() { PrintNote(); });
363 $(".change_activity").click(function() { top.restoreSession(); $("#update_activity").submit(); });
365 $(".deletenote").click(function() { DeleteNote(this); });
367 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
368 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
369 $(".notecell").click(function() { EditNote(this); });
371 $("#note").focus();
373 var EditNote = function(note) {
374 top.restoreSession();
375 $("#noteid").val(note.id);
376 $("#mode").val("");
377 $("#new_note").submit();
380 var NewNote = function () {
381 top.restoreSession();
382 $("#noteid").val('');
383 $("#new_note").submit();
386 var AppendNote = function () {
387 top.restoreSession();
388 $("#new_note").submit();
391 var PrintNote = function () {
392 top.restoreSession();
393 window.open('pnotes_print.php?noteid=<?php echo htmlspecialchars( $noteid, ENT_QUOTES); ?>', '_blank', 'resizable=1,scrollbars=1,width=600,height=500');
396 var DeleteNote = function(note) {
397 if (confirm("<?php echo htmlspecialchars( xl('Are you sure you want to delete this note?','','','\n ').xl('This action CANNOT be undone.'), ENT_QUOTES); ?>")) {
398 top.restoreSession();
399 // strip the 'del' part of the object's ID
400 $("#noteid").val(note.id.replace(/del/, ""));
401 $("#mode").val("delete");
402 $("#new_note").submit();
407 $(document).ready(function(){
408 $("#cancel").click(function() {
409 parent.$.fn.fancybox.close();
413 </script>
415 </html>