Incorrect logic for determining if patient has no notes.
[openemr.git] / interface / patient_file / summary / pnotes_fragment.php
blob71c8cfd35be70479f9b0db55bcbf8bee07dca77a
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/acl.inc");
18 require_once("$srcdir/patient.inc");
19 require_once("$srcdir/options.inc.php");
20 require_once("$srcdir/classes/Document.class.php");
21 require_once("$srcdir/formatting.inc.php");
23 // form parameter docid can be passed to restrict the display to a document.
24 $docid = empty($_REQUEST['docid']) ? 0 : 0 + $_REQUEST['docid'];
26 <ul class="tabNav">
27 <li class="current" ><a href="#"><?php echo htmlspecialchars(xl('Inbox'),ENT_NOQUOTES); ?></a></li>
28 <li><a href="#"><?php echo htmlspecialchars(xl('Sent Items'),ENT_NOQUOTES); ?></a></li>
29 </ul>
30 <div class='tabContainer' >
31 <div class='tab current' >
32 <?php
33 //display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
34 $N = 3; ?>
36 <br/>
38 <?php
40 $has_notes = 0;
41 $thisauth = acl_check('patients', 'notes');
42 if ($thisauth) {
43 $tmp = getPatientData($pid, "squad");
44 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
45 $thisauth = 0;
47 if (!$thisauth) {
48 echo "<p>(" . htmlspecialchars(xl('Notes not authorized'),ENT_NOQUOTES) . ")</p>\n";
49 } else { ?>
50 <table width='100%' border='0' cellspacing='1' cellpadding='1' style='border-collapse:collapse;' >
51 <?php
53 $pres = sqlQuery("SELECT lname, fname " .
54 "FROM patient_data WHERE pid = ?", array($pid) );
55 $patientname = $pres['lname'] . ", " . $pres['fname'];
56 //retrieve all active notes
57 $result = getPnotesByDate("", 1, "id,date,body,user,title,assigned_to,message_status",
58 $pid, "$N", 0, '', $docid);
60 if ($result != null) {
61 $notes_count = 0;//number of notes so far displayed
62 echo "<tr class='text' style='border-bottom:2px solid #000;' >\n";
63 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('From'),ENT_NOQUOTES) ."</b></td>\n";
64 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Date'),ENT_NOQUOTES) ."</b></td>\n";
65 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Subject'),ENT_NOQUOTES) ."</b></td>\n";
66 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Content'),ENT_NOQUOTES) ."</b></td>\n";
67 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Status'),ENT_NOQUOTES) ."</b></td>\n";
68 echo "</tr>\n";
69 foreach ($result as $iter) {
70 $has_note = 1;
72 $body = $iter['body'];
73 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
74 $body = nl2br(htmlspecialchars(oeFormatPatientNote($body),ENT_NOQUOTES));
75 } else {
76 $body = htmlspecialchars(oeFormatSDFT(strtotime($iter['date'])) . date(' H:i', strtotime($iter['date'])) .
77 ' (' . $iter['user'] . ') ',ENT_NOQUOTES) .
78 nl2br(htmlspecialchars(oeFormatPatientNote($body),ENT_NOQUOTES));
80 $body = preg_replace('/(\sto\s)-patient-(\))/','${1}'.$patientname.'${2}',$body);
81 $body = strlen($body) > 120 ? substr($body,0,120)."<b>.......</b>" : $body;
82 echo " <tr class='text' id='".htmlspecialchars($iter['id'],ENT_QUOTES)."' style='border-bottom:1px dashed;height:30px;' >\n";
84 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
85 echo "<td valign='top' class='text'>".htmlspecialchars($iter['user'],ENT_NOQUOTES)."</td>\n";
86 echo "<td valign='top' class='text'>".htmlspecialchars($iter['date'],ENT_NOQUOTES)."</td>\n";
87 echo " <td valign='top' class='text'><b>";
88 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
89 echo "</b></td>\n";
91 echo " <td valign='top' class='text'>$body</td>\n";
92 echo " <td valign='top' class='text'>";
93 echo generate_display_field(array('data_type'=>'1','list_id'=>'message_status'), $iter['message_status']);
94 echo "</td>\n";
95 echo " </tr>\n";
97 $notes_count++;
99 } ?>
101 </table>
103 <?php
104 if ( !isset($has_note) || ($has_note < 1 )) { ?>
105 <span class='text'>
106 <?php echo htmlspecialchars(xl( "There are no notes on file for this patient."),ENT_NOQUOTES);
107 echo " ";
108 echo "<a href='pnotes_full.php'>";
109 echo htmlspecialchars(xl("To add notes, please click here"),ENT_NOQUOTES);
110 echo "</a>."; ?>
111 </span>
112 <?php } else {
114 <br/>
115 <span class='text'>
116 <?php echo htmlspecialchars(xl('Displaying the following number of most recent notes:'),ENT_NOQUOTES); ?>
117 <b><?php echo $N;?></b><br>
118 <a href='pnotes_full.php?s=0'><?php echo htmlspecialchars(xl('Click here to view them all.'),ENT_NOQUOTES); ?></a>
119 </span>
120 <?php
121 } ?>
123 <br/>
124 <br/>
126 <?php } ?>
127 </div>
128 <div class='tab'>
129 <?php
130 //display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
131 $M = 3; ?>
132 <br/>
133 <?php
134 $has_sent_notes = 0;
135 if (!$thisauth) {
136 echo "<p>(" . htmlspecialchars(xl('Notes not authorized'),ENT_NOQUOTES) . ")</p>\n";
137 } else { ?>
138 <table width='100%' border='0' cellspacing='1' cellpadding='1' style='border-collapse:collapse;' >
139 <?php
140 //retrieve all active notes
141 $result_sent = getSentPnotesByDate("", 1, "id,date,body,user,title,assigned_to,pid",
142 $pid, "$M", 0, '', $docid);
143 if ($result_sent != null) {
144 $notes_sent_count = 0;//number of notes so far displayed
145 echo "<tr class='text' style='border-bottom:2px solid #000;' >\n";
146 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('To'),ENT_NOQUOTES) ."</b></td>\n";
147 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Date'),ENT_NOQUOTES) ."</b></td>\n";
148 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Subject'),ENT_NOQUOTES) ."</b></td>\n";
149 echo "<td valign='top' class='text' ><b>". htmlspecialchars(xl('Content'),ENT_NOQUOTES) ."</b></td>\n";
150 echo "</tr>\n";
151 foreach ($result_sent as $iter) {
152 $has_sent_note = 1;
153 $body = $iter['body'];
154 if (preg_match('/^\d\d\d\d-\d\d-\d\d \d\d\:\d\d /', $body)) {
155 $body = nl2br(htmlspecialchars(oeFormatPatientNote($body),ENT_NOQUOTES));
156 } else {
157 $body = htmlspecialchars(oeFormatSDFT(strtotime($iter['date'])) . date(' H:i', strtotime($iter['date'])) .
158 ' (' . $iter['user'] . ') ',ENT_NOQUOTES) .
159 nl2br(htmlspecialchars(oeFormatPatientNote($body),ENT_NOQUOTES));
161 $body = preg_replace('/(:\d{2}\s\()'.$iter['pid'].'(\sto\s)/','${1}'.$patientname.'${2}',$body);
162 $body = strlen($body) > 120 ? substr($body,0,120)."<b>.......</b>" : $body;
163 echo " <tr class='text' id='".htmlspecialchars($iter['id'],ENT_QUOTES)."' style='border-bottom:1px dashed;height:30px;' >\n";
164 // Modified 6/2009 by BM to incorporate the patient notes into the list_options listings
165 echo "<td valign='top' class='text'>".htmlspecialchars($iter['assigned_to'],ENT_NOQUOTES)."</td>\n";
166 echo "<td valign='top' class='text'>".htmlspecialchars($iter['date'],ENT_NOQUOTES)."</td>\n";
167 echo " <td valign='top' class='text'><b>";
168 echo generate_display_field(array('data_type'=>'1','list_id'=>'note_type'), $iter['title']);
169 echo "</b></td>\n";
170 echo " <td valign='top' class='text'>$body</td>\n";
171 echo " </tr>\n";
172 $notes_sent_count++;
174 } ?>
175 </table>
176 <?php
177 if ( !isset($has_set_note) || ($has_sent_note < 1) ) { ?>
178 <span class='text'>
179 <?php echo htmlspecialchars(xl( "There are no notes on file for this patient."),ENT_NOQUOTES);
180 echo " ";
181 echo "<a href='pnotes_full.php'>";
182 echo htmlspecialchars(xl("To add notes, please click here"),ENT_NOQUOTES);
183 echo "</a>."; ?>
184 </span>
185 <?php } else {
187 <br/>
188 <span class='text'>
189 <?php echo htmlspecialchars(xl('Displaying the following number of most recent notes'),ENT_NOQUOTES).":"; ?>
190 <b><?php echo $M;?></b><br>
191 <a href='pnotes_full.php?s=1'><?php echo htmlspecialchars(xl('Click here to view them all.'),ENT_NOQUOTES); ?></a>
192 </span>
193 <?php
194 } ?>
195 <br/>
196 <br/>
197 <?php } ?>
198 </div>
199 </div>
201 <script language="javascript">
202 // jQuery stuff to make the page a little easier to use
204 tabbify();
206 $(document).ready(function(){
207 $(".noterow").mouseover(function() { $(this).toggleClass("highlight"); });
208 $(".noterow").mouseout(function() { $(this).toggleClass("highlight"); });
211 </script>