bug fixes in patient_files summary directory (#1964)
[openemr.git] / interface / patient_file / summary / pnotes_fragment.php
blobf071f659d95742061f1c7da8806a479d08647e61
1 <?php
2 /**
3 * Display patient notes.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../../globals.php");
14 require_once("$srcdir/pnotes.inc");
15 require_once("$srcdir/acl.inc");
16 require_once("$srcdir/patient.inc");
17 require_once("$srcdir/options.inc.php");
19 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
20 csrfNotVerified();
23 // form parameter docid can be passed to restrict the display to a document.
24 $docid = empty($_REQUEST['docid']) ? 0 : 0 + $_REQUEST['docid'];
26 //ajax for type 2 notes widget
27 if (isset($_GET['docUpdateId'])) {
28 return disappearPnote($_GET['docUpdateId']);
32 <?php if ($GLOBALS['portal_offsite_enable'] == 1) { ?>
33 <ul class="tabNav">
34 <li class="current" ><a href="#"><?php echo xlt('Inbox'); ?></a></li>
35 <li><a href="#"><?php echo xlt('Sent Items'); ?></a></li>
36 </ul>
37 <?php } ?>
38 <div class='tabContainer' >
39 <div class='tab current' >
40 <?php
41 //display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
42 $N = $GLOBALS['num_of_messages_displayed']; ?>
44 <br/>
46 <?php
48 $has_note = 0;
49 $thisauth = acl_check('patients', 'notes');
50 if ($thisauth) {
51 $tmp = getPatientData($pid, "squad");
52 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad'])) {
53 $thisauth = 0;
57 if (!$thisauth) {
58 echo "<p>(" . xlt('Notes not authorized') . ")</p>\n";
59 } else { ?>
60 <table width='100%' border='0' cellspacing='1' cellpadding='1' style='border-collapse:collapse;' >
61 <?php
63 $pres = getPatientData($pid, "lname, fname");
64 $patientname = $pres['lname'] . ", " . $pres['fname'];
65 //retrieve all active notes
66 $result = getPnotesByDate(
67 "",
69 "id,date,body,user,title,assigned_to,message_status",
70 $pid,
71 "$N",
73 '',
74 $docid
77 if ($result != null) {
78 $notes_count = 0;//number of notes so far displayed
79 echo "<tr class='text' style='border-bottom:2px solid #000;' >\n";
80 echo "<td valign='top' class='text' ><b>". xlt('From') . "</b></td>\n";
81 echo "<td valign='top' class='text' ><b>". xlt('To') . "</b></td>\n";
82 if ($GLOBALS['messages_due_date']) {
83 echo "<td valign='top' class='text' ><b>". xlt('Due date') . "</b></td>\n";
84 } else {
85 echo "<td valign='top' class='text' ><b>". xlt('Date') . "</b></td>\n";
87 echo "<td valign='top' class='text' ><b>". xlt('Subject') . "</b></td>\n";
88 echo "<td valign='top' class='text' ><b>". xlt('Content') . "</b></td>\n";
89 echo "<td valign='top' class='text' ></td>\n";
90 echo "</tr>\n";
91 foreach ($result as $iter) {
92 $has_note = 1;
94 $body = $iter['body'];
95 $body = preg_replace('/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}\s\([^)(]+\s)(to)(\s[^)(]+\))/', '', $body);
96 $body = preg_replace('/(\sto\s)-patient-(\))/', '${1}'.$patientname.'${2}', $body);
97 echo " <tr class='text' id='" . text($iter['id']) . "' style='border-bottom:1px dashed;height:30px;' >\n";
99 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
100 echo "<td valign='top' class='text'>" . text($iter['user']) . "</td>\n";
101 echo "<td valign='top' class='text'>" . text($iter['assigned_to']) . "</td>\n";
102 echo "<td valign='top' class='text'>" . text(oeFormatDateTime(date('Y-m-d H:i', strtotime($iter['date'])))) . "</td>\n";
103 echo " <td valign='top' class='text'><b>";
104 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
105 echo "</b></td>\n";
107 echo " <td valign='top' class='text'>" . text($body) . "</td>\n";
108 echo "<td valign='top' class='text'><button data-id='" . attr($iter['id']) . "' class='complete_btn'>" . xlt('Completed') . "</button></td>\n";
109 echo " </tr>\n";
111 $notes_count++;
113 } ?>
115 </table>
117 <?php
118 if ($has_note < 1) { ?>
119 <span class='text'>
120 <?php
121 echo xlt("There are no notes on file for this patient.");
122 if (acl_check('patients', 'notes', '', array('write', 'addonly'))) {
123 echo " ";
124 echo "<a href='pnotes_full.php' onclick='top.restoreSession()'>";
125 echo xlt("To add notes, please click here");
126 echo "</a>.";
129 </span><?php
130 } else { ?>
131 <br/>
132 <span class='text'>
133 <?php echo xlt('Displaying the following number of most recent notes:'); ?>
134 <b><?php echo text($N);?></b><br>
135 <a href='pnotes_full.php?s=0' onclick='top.restoreSession()'>
136 <?php echo xlt('Click here to view them all.'); ?></a>
137 </span><?php
138 } ?>
140 <br/>
141 <br/><?php
142 } ?>
143 </div>
144 <?php if ($GLOBALS['portal_offsite_enable'] == 1) { ?>
145 <div class='tab'>
146 <?php
147 //display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
148 $M = $GLOBALS['num_of_messages_displayed']; ?>
149 <br/>
150 <?php
151 $has_sent_note = 0;
152 if (!$thisauth) {
153 echo "<p>(" . xlt('Notes not authorized') . ")</p>\n";
154 } else { ?>
155 <table width='100%' border='0' cellspacing='1' cellpadding='1' style='border-collapse:collapse;' >
156 <?php
157 //retrieve all active notes
158 $result_sent = getSentPnotesByDate(
161 "id,date,body,user,title,assigned_to,pid",
162 $pid,
163 "$M",
166 $docid
168 if ($result_sent != null) {
169 $notes_sent_count = 0;//number of notes so far displayed
170 echo "<tr class='text' style='border-bottom:2px solid #000;' >\n";
171 echo "<td valign='top' class='text' ><b>". xlt('To') ."</b></td>\n";
172 if ($GLOBALS['messages_due_date']) {
173 echo "<td valign='top' class='text' ><b>". xlt('Due date') ."</b></td>\n";
174 } else {
175 echo "<td valign='top' class='text' ><b>". xlt('Date') ."</b></td>\n";
177 echo "<td valign='top' class='text' ><b>". xlt('Subject') ."</b></td>\n";
178 echo "<td valign='top' class='text' ><b>". xlt('Content') ."</b></td>\n";
179 echo "</tr>\n";
180 foreach ($result_sent as $iter) {
181 $has_sent_note = 1;
182 $body = $iter['body'];
183 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
184 $body = nl2br(text(oeFormatPatientNote($body)));
185 } else {
186 $body = text(oeFormatSDFT(strtotime($iter['date'])) . date(' H:i', strtotime($iter['date'])) .
187 ' (' . $iter['user'] . ') ') .
188 nl2br(text(oeFormatPatientNote($body)));
191 $body = preg_replace('/(:\d{2}\s\()'.$iter['pid'].'(\sto\s)/', '${1}'.$patientname.'${2}', $body);
192 $body = strlen($body) > 120 ? substr($body, 0, 120)."<b>.......</b>" : $body;
193 echo " <tr class='text' id='" . attr($iter['id']) . "' style='border-bottom:1px dashed;height:30px;' >\n";
194 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
195 echo "<td valign='top' class='text'>" . text($iter['assigned_to']) . "</td>\n";
196 echo "<td valign='top' class='text'>" . text($iter['date']) . "</td>\n";
197 echo " <td valign='top' class='text'><b>";
198 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
199 echo "</b></td>\n";
200 echo " <td valign='top' class='text'>" . text($body) . "</td>\n";
201 echo " </tr>\n";
202 $notes_sent_count++;
204 } ?>
205 </table>
206 <?php
207 if ($has_sent_note < 1) { ?>
208 <span class='text'>
209 <?php
210 echo xlt("There are no notes on file for this patient.");
211 if (acl_check('patients', 'notes', '', array('write', 'addonly'))) {
212 echo " ";
213 echo "<a href='pnotes_full.php' onclick='top.restoreSession()'>";
214 echo xlt("To add notes, please click here");
215 echo "</a>.";
218 </span><?php
219 } else { ?>
220 <br/>
221 <span class='text'>
222 <?php echo text('Displaying the following number of most recent notes') . ":"; ?>
223 <b><?php echo text($M);?></b><br>
224 <a href='pnotes_full.php?s=1' onclick='top.restoreSession()'><?php echo xlt('Click here to view them all.'); ?></a>
225 </span>
226 <?php
227 } ?>
228 <br/>
229 <br/><?php
230 } ?>
231 </div>
232 <?php } ?>
233 </div>
235 <script language="javascript">
236 // jQuery stuff to make the page a little easier to use
238 tabbify();
240 $(document).ready(function(){
241 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
242 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
244 //Ajax call for type 2 note widget
245 $(".complete_btn").on("click", function(){
246 //console.log($(this).attr('data-id'));
247 var btn = $(this);
248 $.ajax({
249 method: "POST",
250 url: "pnotes_fragment.php?docUpdateId=" + encodeURIComponent(btn.attr('data-id')),
251 data: {
252 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
255 .done(function() {
256 btn.prop("disabled",true);
257 btn.unbind('mouseenter mouseleave');
258 btn.css('background-color', 'gray');
264 </script>