revert composer from PR #5046 (#5058)
[openemr.git] / interface / patient_file / problem_encounter.php
blobd4d41df8995617eaaf9d409a0884187aa4a8ed71
1 <?php
3 /**
4 * This script add and delete Issues and Encounters relationships.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
13 * @copyright Copyright (c) 2015-2018 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/patient.inc");
19 require_once("$srcdir/lists.inc");
21 use OpenEMR\Common\Acl\AclMain;
22 use OpenEMR\Common\Csrf\CsrfUtils;
23 use OpenEMR\Core\Header;
25 $patdata = getPatientData($pid, "fname,lname,squad");
27 $thisauth = ((AclMain::aclCheckCore('encounters', 'notes', '', 'write') ||
28 AclMain::aclCheckCore('encounters', 'notes_a', '', 'write')) &&
29 AclMain::aclCheckCore('patients', 'med', '', 'write'));
31 if ($patdata['squad'] && ! AclMain::aclCheckCore('squads', $patdata['squad'])) {
32 $thisauth = 0;
35 if (!$thisauth) {
36 echo "<html>\n<body>\n";
37 echo "<p>" . xlt('You are not authorized for this.') . "</p>\n";
38 echo "</body>\n</html>\n";
39 exit();
42 $alertmsg = ""; // anything here pops up in an alert box
43 $endjs = ""; // holds javascript to write at the end
45 // If the Save button was clicked...
46 if (!empty($_POST['form_save'])) {
47 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
48 CsrfUtils::csrfNotVerified();
51 $form_pid = $_POST['form_pid'];
52 $form_pelist = $_POST['form_pelist'];
53 // $pattern = '|/(\d+),(\d+),([YN])|';
54 $pattern = '|/(\d+),(\d+)|';
56 preg_match_all($pattern, $form_pelist, $matches);
57 $numsets = count($matches[1]);
59 $query = "DELETE FROM issue_encounter WHERE pid = ?";
60 sqlQuery($query, array($form_pid));
61 for ($i = 0; $i < $numsets; ++$i) {
62 $list_id = $matches[1][$i];
63 $encounter = $matches[2][$i];
64 $query = "INSERT INTO issue_encounter ( " .
65 "pid, list_id, encounter" .
66 ") VALUES ( " .
67 " ?, ?, ?" .
68 ")";
69 sqlQuery($query, array($form_pid, $list_id, $encounter));
72 echo "<html><body>"
73 . "<script type=\"text/javascript\" src=\"" . $webroot . "/interface/main/tabs/js/include_opener.js\"></script>"
74 . "<script>\n";
75 if ($alertmsg) {
76 echo " alert(" . js_escape($alertmsg) . ");\n";
79 echo " var myboss = opener ? opener : parent;\n";
80 echo " myboss.location.reload();\n";
81 echo " dlgclose();\n";
82 echo "</script></body></html>\n";
83 exit();
86 // get problems
87 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? " .
88 "ORDER BY type, date", array($pid));
90 // get encounters
91 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = ? " .
92 "ORDER BY date DESC", array($pid));
94 // get problem/encounter relations
95 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = ?", array($pid));
97 <!DOCTYPE html>
98 <html>
99 <head>
100 <?php Header::setupHeader(['opener', 'topdialog', 'dialog']); ?>
102 <title><?php echo xlt('Issues and Encounters'); ?></title>
104 <style>
105 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
106 tr.detail { font-size:10pt; background-color:#eeeeee; }
107 </style>
109 <script>
111 // These are the possible colors for table rows.
112 var trcolors = new Object();
113 // Colors for: Foreground Background
114 trcolors['U'] = new Array('var(--black)', 'var(--gray200)'); // unselected
115 trcolors['K'] = new Array('var(--black)', 'var(--yellow)'); // selected key
116 trcolors['V'] = new Array('var(--black)', 'var(--indigo)'); // selected value
118 var pselected = new Object();
119 var eselected = new Object();
120 var keyid = null; // id of currently hilited key, if any
122 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
124 // callback from add_edit_issue.php:
125 function refreshIssue(issue, title) {
126 top.restoreSession();
127 location.reload();
130 // New Issue button is clicked.
131 function newIssue() {
132 var f = document.forms[0];
133 var tmp = (keyid && f.form_key[1].checked) ? ('?enclink=' + encodeURIComponent(keyid)) : '';
134 dlgopen('summary/add_edit_issue.php' + tmp, '_blank', 600, 625);
137 // Determine if a given problem/encounter pair is currently linked.
138 // If yes, return the "resolved" character (Y or N), else an empty string.
139 function isPair(problem, encounter) {
140 var pelist = document.forms[0].form_pelist;
141 // var frag = '/' + problem + ',' + encounter + ',';
142 var frag = '/' + problem + ',' + encounter + '/';
143 var i = pelist.value.indexOf(frag);
144 if (i < 0) return '';
145 // return pelist.value.charAt(i + frag.length);
146 return 'V';
149 // Unlink a problem/encounter pair.
150 function removePair(problem, encounter) {
151 var pelist = document.forms[0].form_pelist;
152 // var frag = '/' + problem + ',' + encounter + ',';
153 var frag = '/' + problem + ',' + encounter + '/';
154 var i = pelist.value.indexOf(frag);
155 if (i >= 0) {
156 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
157 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length - 1);
158 document.forms[0].form_save.disabled = false;
162 // Link a new or modified problem/encounter pair.
163 // function addPair(problem, encounter, resolved) {
164 function addPair(problem, encounter) {
165 removePair(problem, encounter);
166 var pelist = document.forms[0].form_pelist;
167 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
168 pelist.value += '' + problem + ',' + encounter + '/';
169 document.forms[0].form_save.disabled = false;
172 // Clear displayed highlights.
173 function doclearall(pfx) {
174 var thisarr = (pfx == 'p') ? pselected : eselected;
175 for (var id in thisarr) {
176 var thistr = document.getElementById(pfx + '_' + id);
177 if (thisarr[id]) {
178 thisarr[id] = '';
179 thistr.style.color = trcolors['U'][0];
180 thistr.style.backgroundColor = trcolors['U'][1];
185 function clearall() {
186 doclearall('p');
187 doclearall('e');
188 keyid = null;
191 // Process clicks on table rows.
192 function doclick(pfx, id) {
193 var thisstyle = document.getElementById(pfx + '_' + id).style;
194 var thisarr = (pfx == 'p') ? pselected : eselected;
195 var piskey = document.forms[0].form_key[0].checked;
196 var thisiskey = (pfx == 'p') ? piskey : !piskey;
197 var wasset = thisarr[id];
198 if (thisiskey) { // they clicked in the key table
199 clearall();
200 if (!wasset) { // this item is not already hilited
201 keyid = id;
202 thisarr[id] = 'K';
203 thisstyle.color = trcolors['K'][0];
204 thisstyle.backgroundColor = trcolors['K'][1];
205 // Now hilite the related value table entries:
206 if (pfx == 'p') { // key is problems, values are encounters
207 for (key in eselected) {
208 var resolved = isPair(id, key);
209 if (resolved.length > 0) {
210 eselected[key] = resolved;
211 var valstyle = document.getElementById('e_' + key).style;
212 valstyle.color = trcolors[resolved][0];
213 valstyle.backgroundColor = trcolors[resolved][1];
216 } else { // key is encounters, values are problems
217 for (key in pselected) {
218 var resolved = isPair(key, id);
219 if (resolved.length > 0) {
220 pselected[key] = resolved;
221 var valstyle = document.getElementById('p_' + key).style;
222 valstyle.color = trcolors[resolved][0];
223 valstyle.backgroundColor = trcolors[resolved][1];
228 } else { // they clicked in the value table
229 if (keyid) {
230 var resolved = thisarr[id];
231 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
232 // thisarr[id] = 'N';
233 // thisstyle.color = trcolors['N'][0];
234 // thisstyle.backgroundColor = trcolors['N'][1];
235 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
236 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
237 if (resolved != '') { // hilited, so remove it
238 thisarr[id] = '';
239 thisstyle.color = trcolors['U'][0];
240 thisstyle.backgroundColor = trcolors['U'][1];
241 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
242 // } else { // not hilited, change to hilited and resolved
243 // thisarr[id] = 'Y';
244 // thisstyle.color = trcolors['Y'][0];
245 // thisstyle.backgroundColor = trcolors['Y'][1];
246 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
247 } else { // not hilited, change to hilited
248 thisarr[id] = 'V';
249 thisstyle.color = trcolors['V'][0];
250 thisstyle.backgroundColor = trcolors['V'][1];
251 if (pfx == 'p') addPair(id, keyid); else addPair(keyid, id);
253 } else {
254 alert(<?php echo xlj('You must first select an item in the section whose radio button is checked.') ;?>);
259 </script>
261 </head>
262 <body>
263 <div class="container">
264 <form method='post' action='problem_encounter.php' onsubmit='return top.restoreSession()'>
265 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
266 <?php
267 echo "<input type='hidden' name='form_pid' value='" . attr($pid) . "' />\n";
268 // pelist looks like /problem,encounter/problem,encounter/[...].
269 echo "<input type='hidden' name='form_pelist' value='/";
270 while ($row = sqlFetchArray($peres)) {
271 // echo $row['list_id'] . "," . $row['encounter'] . "," .
272 // ($row['resolved'] ? "Y" : "N") . "/";
273 echo attr($row['list_id']) . "," . attr($row['encounter']) . "/";
275 echo "' />\n";
277 <div class="table-responsive">
278 <table class="table">
279 <tr>
280 <td colspan='2' class="text-center font-weight-bold">
281 <?php echo xlt('Issues and Encounters for'); ?> <?php echo text($patdata['fname']) . " " . text($patdata['lname']) . " (" . text($pid) . ")</b>\n"; ?>
282 </td>
283 </tr>
284 <tr>
285 <td class="text-center align-top p-0 pl-3">
286 <div class="table-responsive">
287 <table class="table table-sm">
288 <tr class='head'>
289 <td colspan='3' class="text-center">
290 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
291 <span class="font-weight-bold"><?php echo xlt('Issues Section'); ?></span>
292 </td>
293 </tr>
294 <tr class='head'>
295 <td><?php echo xlt('Type'); ?></td>
296 <td><?php echo xlt('Title'); ?></td>
297 <td><?php echo xlt('Description'); ?></td>
298 </tr>
299 <?php
300 while ($row = sqlFetchArray($pres)) {
301 $rowid = $row['id'];
302 echo " <tr class='detail' id='p_" . attr($rowid) . "' onclick='doclick(\"p\", " . attr_js($rowid) . ")'>\n";
303 echo " <td class='align-top'>" . text($ISSUE_TYPES[($row['type'])][1]) . "</td>\n";
304 echo " <td class='align-top'>" . text($row['title']) . "</td>\n";
305 echo " <td class='align-top'>" . text($row['comments']) . "</td>\n";
306 echo " </tr>\n";
307 $endjs .= "pselected[" . js_escape($rowid) . "] = '';\n";
310 </table>
311 </div>
312 </td>
313 <td class="text-center align-top p-0 pr-3">
314 <div class="table-responsive">
315 <table class="table table-sm">
316 <tr class='head'>
317 <td colspan='2' class="text-center">
318 <input type='radio' name='form_key' value='e' onclick='clearall()' />
319 <span class="font-weight-bold"><?php echo xlt('Encounters Section'); ?></span>
320 </td>
321 </tr>
322 <tr class='head'>
323 <td><?php echo xlt('Date'); ?></td>
324 <td><?php echo xlt('Presenting Complaint'); ?></td>
325 </tr>
326 <?php
327 while ($row = sqlFetchArray($eres)) {
328 $rowid = $row['encounter'];
329 echo " <tr class='detail' id='e_" . attr($rowid) . "' onclick='doclick(\"e\", " . attr_js($rowid) . ")'>\n";
330 echo " <td class='align-top'>" . text(substr($row['date'], 0, 10)) . "</td>\n";
331 echo " <td class='align-top'>" . text($row['reason']) . "</td>\n";
332 echo " </tr>\n";
333 $endjs .= "eselected[" . js_escape($rowid) . "] = '';\n";
336 </table>
337 </div>
338 </td>
339 </tr>
340 <tr>
341 <td colspan='2' class="text-center">
342 <div class="btn-group">
343 <button type="submit" class="btn btn-primary btn-sm btn-save" name='form_save' value='<?php echo xla('Save'); ?>' disabled>
344 <?php echo xlt('Save'); ?>
345 </button>
346 <button type="button" class="btn btn-primary btn-sm btn-add" value='<?php echo xla('Add Issue'); ?>' onclick='newIssue()'>
347 <?php echo xlt('Add Issue'); ?>
348 </button>
349 <button type="button" class='btn btn-secondary btn-sm btn-cancel' onclick='dlgclose()'><?php echo xla('Cancel'); ?></button>
350 </div>
351 </td>
352 </tr>
353 </table>
354 </div>
355 </form>
357 <span class="font-weight-bold"><?php echo xlt('Instructions:'); ?></span> <?php echo xlt('Choose a section and click an item within it; then in the other section you will see the related items highlighted, and you can click in that section to add and delete relationships.'); ?>
358 </p>
359 </div>
360 <script>
361 <?php
362 echo $endjs;
363 if (!empty($_REQUEST['issue'])) {
364 echo "doclick('p', " . js_escape($_REQUEST['issue']) . ");\n";
367 if ($alertmsg) {
368 echo "alert(" . js_escape($alertmsg) . ");\n";
371 </script>
372 </body>
373 </html>