/
office_comments_full.php
185 lines (154 loc) · 7.74 KB
/
office_comments_full.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* Viewing and modification/creation of office notes.
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once("../../globals.php");
use OpenEMR\Common\Acl\AclMain;
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Core\Header;
use OpenEMR\Services\ONoteService;
// Control access
if (!AclMain::aclCheckCore('encounters', 'notes')) {
echo xlt('Not Authorized');
exit;
}
$oNoteService = new ONoteService();
//the number of records to display per screen
$N = 10;
$offset = (isset($_REQUEST['offset'])) ? $_REQUEST['offset'] : 0;
$active = (isset($_REQUEST['active'])) ? $_REQUEST['active'] : -1;
//this code handles changing the state of activity tags when the user updates them through the interface
if (isset($_POST['mode'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}
if ($_POST['mode'] == "update") {
foreach ($_POST as $var => $val) {
if ($val == "true" || $val == "false") {
$id = str_replace("act", "", $var);
if ($val == "true") {
$oNoteService->enableNoteById($id);
} elseif ($val == "false") {
$oNoteService->disableNoteById($id);
}
}
}
} elseif ($_POST['mode'] == "new") {
$oNoteService->add($_POST["note"]);
}
}
?>
<html>
<head>
<?php Header::setupHeader(); ?>
</head>
<body class="body_top">
<div id="officenotes_edit">
<form method="post" name="new_note" action="office_comments_full.php" onsubmit='return top.restoreSession()'>
<input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
<?php
/* BACK should go to the main Office Notes screen */
if ($userauthorized) {
$backurl = "office_comments.php";
} else {
$backurl = "../main_info.php";
}
?>
<a href="office_comments.php" onclick='top.restoreSession()'>
<span class="title"><?php echo xlt('Office Notes'); ?></span>
<span class="back"><?php echo text($tback); ?></span></a>
<br />
<input type="hidden" name="mode" value="new">
<input type="hidden" name="offset" value="<?php echo attr($offset); ?>">
<input type="hidden" name="active" value="<?php echo attr($active); ?>">
<textarea name="note" class="form-control" rows="3" placeholder="<?php echo xla("Enter new office note here"); ?>" required="required"></textarea>
<input class="btn btn-primary mt-3" type="submit" value="<?php echo xla('Add New Note'); ?>" />
</form>
<br/>
<hr>
<form method="post" name="update_activity" action="office_comments_full.php" onsubmit='return top.restoreSession()'>
<input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
<?php //change the view on the current mode, whether all, active, or inactive
if ($active === "1") {
$active_class = null;
$inactive_class = "_small";
$all_class = "_small";
} elseif ($active === "0") {
$active_class = "_small";
$inactive_class = null;
$all_class = "_small";
} else {
$active_class = "_small";
$inactive_class = "_small";
$all_class = null;
}
?>
<a href="office_comments_full.php?offset=0&active=-1" class="btn btn-primary<?php echo attr($all_class);?>" onclick='top.restoreSession()'><?php echo xlt('All'); ?></a>
<a href="office_comments_full.php?offset=0&active=1" class="btn btn-primary<?php echo attr($active_class);?>" onclick='top.restoreSession()'><?php echo xlt('Only Active'); ?></a>
<a href="office_comments_full.php?offset=0&active=0" class="btn btn-primary<?php echo attr($inactive_class);?>" onclick='top.restoreSession()'><?php echo xlt('Only Inactive'); ?></a>
<input type="hidden" name="mode" value="update">
<input type="hidden" name="offset" value="<?php echo attr($offset);?>">
<input type="hidden" name="active" value="<?php echo attr($active);?>">
<br/>
<table class="existingnotes table table-striped">
<?php
//display all of the notes for the day, as well as others that are active from previous dates, up to a certain number, $N
$notes = $oNoteService->getNotes($active, $offset, $N);
$result_count = 0;
//retrieve all notes
if (!empty($notes)) {
print "<thead><tr><th>" . xlt("Active") . "</th><th>" . xlt("Date") . " (" . xlt("Sender") . ")</th><th>" . xlt("Office Note") . "</th></tr></thead><tbody>";
foreach ($notes as $note) {
$result_count++;
$date = (new DateTime($note['date']))->format('Y-m-d');
$todaysDate = new DateTime();
if ($todaysDate->format('Y-m-d') == $date) {
$date_string = xl("Today") . ", " . oeFormatShortDate($date);
} else {
$date_string = oeFormatShortDate($date);
}
if ($note['activity'] == 1) {
$checked = "checked";
} else {
$checked = "";
}
print "<tr><td><input type=hidden value='' name='act" . attr($note['id']) . "' id='act" . attr($note['id']) . "'>";
print "<input name='box" . attr($note['id']) . "' id='box" . attr($note['id']) . "' onClick='javascript:document.update_activity.act" . attr($note['id']) . ".value=this.checked' type=checkbox $checked></td>";
print "<td><label for='box" . attr($note['id']) . "' class='bold'>" . text($date_string) . "</label>";
print " <label for='box" . attr($note['id']) . "' class='bold'>(" . text($note['user']) . ")</label></td>";
print "<td><label for='box" . attr($note['id']) . "' class='text'>" . nl2br(text($note['body'])) . " </label></td></tr>";
}
print "</tbody>\n";
} else {
//no results
print "<tr><td></td><td></td><td></td></tr>\n";
}
?>
</table>
<input class="btn btn-primary" type="submit" value="<?php echo xla('Save Activity'); ?>" />
</form>
<hr>
<table width="400" cellpadding="0" cellspacing="0" class="table">
<tr><td>
<?php
if ($offset > ($N - 1)) {
echo "<a class='btn btn-secondary' href=office_comments_full.php?active=" . attr_url($active) . "&offset=" . attr_url($offset - $N) . " onclick='top.restoreSession()'>" . xlt('Previous') . "</a>";
}
?>
</td><td align='right'>
<?php
if ($result_count == $N) {
echo "<a class='btn btn-secondary' href=office_comments_full.php?active=" . attr_url($active) . "&offset=" . attr_url($offset + $N) . " onclick='top.restoreSession()'>" . xlt('Next') . "</a>";
}
?>
</td></tr>
</table>
</div>
</body>
</html>