minor changes to prior commit
[openemr.git] / interface / patient_file / problem_encounter.php
blobf982667d5817d7b4957d79deca06d3e284621240
1 <?php
2 /**
4 * This script add and delete Issues and Encounters relationships.
6 * Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
8 * Copyright (C) 2015 Brady Miller <brady.g.miller@gmail.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @author Roberto Vasquez <robertogagliotta@gmail.com>
24 * @author Brady Miller <brady.g.miller@gmail.com>
25 * @link http://www.open-emr.org
28 include_once("../globals.php");
29 include_once("$srcdir/patient.inc");
30 include_once("$srcdir/acl.inc");
31 include_once("$srcdir/lists.inc");
33 use OpenEMR\Core\Header;
35 $patdata = getPatientData($pid, "fname,lname,squad");
37 $thisauth = ((acl_check('encounters', 'notes', '', 'write') ||
38 acl_check('encounters', 'notes_a', '', 'write')) &&
39 acl_check('patients', 'med', '', 'write'));
41 if ($patdata['squad'] && ! acl_check('squads', $patdata['squad'])) {
42 $thisauth = 0;
45 if (!$thisauth) {
46 echo "<html>\n<body>\n";
47 echo "<p>" .xlt('You are not authorized for this.'). "</p>\n";
48 echo "</body>\n</html>\n";
49 exit();
52 $alertmsg = ""; // anything here pops up in an alert box
53 $endjs = ""; // holds javascript to write at the end
55 // If the Save button was clicked...
56 if ($_POST['form_save']) {
57 $form_pid = $_POST['form_pid'];
58 $form_pelist = $_POST['form_pelist'];
59 // $pattern = '|/(\d+),(\d+),([YN])|';
60 $pattern = '|/(\d+),(\d+)|';
62 preg_match_all($pattern, $form_pelist, $matches);
63 $numsets = count($matches[1]);
65 $query = "DELETE FROM issue_encounter WHERE pid = ?";
66 sqlQuery($query, array($form_pid));
67 for ($i = 0; $i < $numsets; ++$i) {
68 $list_id = $matches[1][$i];
69 $encounter = $matches[2][$i];
70 $query = "INSERT INTO issue_encounter ( " .
71 "pid, list_id, encounter" .
72 ") VALUES ( " .
73 " ?, ?, ?" .
74 ")";
75 sqlQuery($query, array($form_pid, $list_id, $encounter));
78 echo "<html><body>"
79 ."<script type=\"text/javascript\" src=\"". $webroot ."/interface/main/tabs/js/include_opener.js\"></script>"
80 . "<script language='JavaScript'>\n";
81 if ($alertmsg) {
82 echo " alert('" . addslashes($alertmsg) . "');\n";
85 echo " var myboss = opener ? opener : parent;\n";
86 echo " myboss.location.reload();\n";
87 echo " dlgclose();\n";
88 echo "</script></body></html>\n";
89 exit();
92 // get problems
93 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? " .
94 "ORDER BY type, date", array($pid));
96 // get encounters
97 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = ? " .
98 "ORDER BY date DESC", array($pid));
100 // get problem/encounter relations
101 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = ?", array($pid));
103 <!DOCTYPE html>
104 <html>
105 <head>
106 <?php Header::setupHeader(['opener', 'topdialog', 'dialog']); ?>
108 <title><?php echo xlt('Issues and Encounters'); ?></title>
110 <style>
111 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
112 tr.detail { font-size:10pt; background-color:#eeeeee; }
113 </style>
115 <script language="JavaScript">
117 // These are the possible colors for table rows.
118 var trcolors = new Object();
119 // Colors for: Foreground Background
120 trcolors['U'] = new Array('#000000', '#eeeeee'); // unselected
121 trcolors['K'] = new Array('#000000', '#eeee00'); // selected key
122 // trcolors['Y'] = new Array('#000000', '#99ff99'); // selected value resolved=Y
123 // trcolors['N'] = new Array('#000000', '#ff9999'); // selected value resolved=N
124 trcolors['V'] = new Array('#000000', '#9999ff'); // selected value
126 var pselected = new Object();
127 var eselected = new Object();
128 var keyid = null; // id of currently hilited key, if any
130 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
132 // callback from add_edit_issue.php:
133 function refreshIssue(issue, title) {
134 top.restoreSession();
135 location.reload();
138 // New Issue button is clicked.
139 function newIssue() {
140 var f = document.forms[0];
141 var tmp = (keyid && f.form_key[1].checked) ? ('?enclink=' + keyid) : '';
142 dlgopen('summary/add_edit_issue.php' + tmp, '_blank', 600, 625);
145 // Determine if a given problem/encounter pair is currently linked.
146 // If yes, return the "resolved" character (Y or N), else an empty string.
147 function isPair(problem, encounter) {
148 var pelist = document.forms[0].form_pelist;
149 // var frag = '/' + problem + ',' + encounter + ',';
150 var frag = '/' + problem + ',' + encounter + '/';
151 var i = pelist.value.indexOf(frag);
152 if (i < 0) return '';
153 // return pelist.value.charAt(i + frag.length);
154 return 'V';
157 // Unlink a problem/encounter pair.
158 function removePair(problem, encounter) {
159 var pelist = document.forms[0].form_pelist;
160 // var frag = '/' + problem + ',' + encounter + ',';
161 var frag = '/' + problem + ',' + encounter + '/';
162 var i = pelist.value.indexOf(frag);
163 if (i >= 0) {
164 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
165 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length - 1);
166 document.forms[0].form_save.disabled = false;
170 // Link a new or modified problem/encounter pair.
171 // function addPair(problem, encounter, resolved) {
172 function addPair(problem, encounter) {
173 removePair(problem, encounter);
174 var pelist = document.forms[0].form_pelist;
175 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
176 pelist.value += '' + problem + ',' + encounter + '/';
177 document.forms[0].form_save.disabled = false;
180 // Clear displayed highlights.
181 function doclearall(pfx) {
182 var thisarr = (pfx == 'p') ? pselected : eselected;
183 for (var id in thisarr) {
184 var thistr = document.getElementById(pfx + '_' + id);
185 if (thisarr[id]) {
186 thisarr[id] = '';
187 thistr.style.color = trcolors['U'][0];
188 thistr.style.backgroundColor = trcolors['U'][1];
193 function clearall() {
194 doclearall('p');
195 doclearall('e');
196 keyid = null;
199 // Process clicks on table rows.
200 function doclick(pfx, id) {
201 var thisstyle = document.getElementById(pfx + '_' + id).style;
202 var thisarr = (pfx == 'p') ? pselected : eselected;
203 var piskey = document.forms[0].form_key[0].checked;
204 var thisiskey = (pfx == 'p') ? piskey : !piskey;
205 var wasset = thisarr[id];
206 if (thisiskey) { // they clicked in the key table
207 clearall();
208 if (!wasset) { // this item is not already hilited
209 keyid = id;
210 thisarr[id] = 'K';
211 thisstyle.color = trcolors['K'][0];
212 thisstyle.backgroundColor = trcolors['K'][1];
213 // Now hilite the related value table entries:
214 if (pfx == 'p') { // key is problems, values are encounters
215 for (key in eselected) {
216 var resolved = isPair(id, key);
217 if (resolved.length > 0) {
218 eselected[key] = resolved;
219 var valstyle = document.getElementById('e_' + key).style;
220 valstyle.color = trcolors[resolved][0];
221 valstyle.backgroundColor = trcolors[resolved][1];
224 } else { // key is encounters, values are problems
225 for (key in pselected) {
226 var resolved = isPair(key, id);
227 if (resolved.length > 0) {
228 pselected[key] = resolved;
229 var valstyle = document.getElementById('p_' + key).style;
230 valstyle.color = trcolors[resolved][0];
231 valstyle.backgroundColor = trcolors[resolved][1];
236 } else { // they clicked in the value table
237 if (keyid) {
238 var resolved = thisarr[id];
239 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
240 // thisarr[id] = 'N';
241 // thisstyle.color = trcolors['N'][0];
242 // thisstyle.backgroundColor = trcolors['N'][1];
243 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
244 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
245 if (resolved != '') { // hilited, so remove it
246 thisarr[id] = '';
247 thisstyle.color = trcolors['U'][0];
248 thisstyle.backgroundColor = trcolors['U'][1];
249 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
250 // } else { // not hilited, change to hilited and resolved
251 // thisarr[id] = 'Y';
252 // thisstyle.color = trcolors['Y'][0];
253 // thisstyle.backgroundColor = trcolors['Y'][1];
254 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
255 } else { // not hilited, change to hilited
256 thisarr[id] = 'V';
257 thisstyle.color = trcolors['V'][0];
258 thisstyle.backgroundColor = trcolors['V'][1];
259 if (pfx == 'p') addPair(id, keyid); else addPair(keyid, id);
261 } else {
262 alert('<?php echo xls('You must first select an item in the section whose radio button is checked.') ;?>');
267 </script>
269 </head>
270 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' bgcolor='#ffffff'>
271 <form method='post' action='problem_encounter.php' onsubmit='return top.restoreSession()'>
272 <?php
273 echo "<input type='hidden' name='form_pid' value='" . attr($pid) . "' />\n";
274 // pelist looks like /problem,encounter/problem,encounter/[...].
275 echo "<input type='hidden' name='form_pelist' value='/";
276 while ($row = sqlFetchArray($peres)) {
277 // echo $row['list_id'] . "," . $row['encounter'] . "," .
278 // ($row['resolved'] ? "Y" : "N") . "/";
279 echo text($row['list_id']) . "," . text($row['encounter']) . "/";
282 echo "' />\n";
285 <table class="table">
287 <tr>
288 <td colspan='2' align='center'>
289 <b><?php echo xlt('Issues and Encounters for'); ?> <?php echo text($patdata['fname']) . " " . text($patdata['lname']) . " (" . text($pid) . ")</b>\n"; ?>
290 </td>
291 </tr>
293 <tr>
294 <td align='center' valign='top' style="padding: 0 0 0 5px;">
295 <table class="table table-condensed">
296 <tr class='head'>
297 <td colspan='3' align='center'>
298 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
299 <b><?php echo xlt('Issues Section'); ?></b>
300 </td>
301 </tr>
302 <tr class='head'>
303 <td><?php echo xlt('Type'); ?></td>
304 <td><?php echo xlt('Title'); ?></td>
305 <td><?php echo xlt('Description'); ?></td>
306 </tr>
307 <?php
308 while ($row = sqlFetchArray($pres)) {
309 $rowid = $row['id'];
310 echo " <tr class='detail' id='p_" . attr($rowid) . "' onclick='doclick(\"p\", " . attr(addslashes($rowid)) . ")'>\n";
311 echo " <td valign='top'>" . text($ISSUE_TYPES[($row['type'])][1]) . "</td>\n";
312 echo " <td valign='top'>" . text($row['title']) . "</td>\n";
313 echo " <td valign='top'>" . text($row['comments']) . "</td>\n";
314 echo " </tr>\n";
315 $endjs .= "pselected['" . attr($rowid) . "'] = '';\n";
318 </table>
319 </td>
320 <td align='center' valign='top' style="padding: 0 5px 0 0;">
321 <table class="table table-condensed">
322 <tr class='head'>
323 <td colspan='2' align='center'>
324 <input type='radio' name='form_key' value='e' onclick='clearall()' />
325 <b><?php echo xlt('Encounters Section'); ?></b>
326 </td>
327 </tr>
328 <tr class='head'>
329 <td><?php echo xlt('Date'); ?></td>
330 <td><?php echo xlt('Presenting Complaint'); ?></td>
331 </tr>
332 <?php
333 while ($row = sqlFetchArray($eres)) {
334 $rowid = $row['encounter'];
335 echo " <tr class='detail' id='e_" . attr($rowid) . "' onclick='doclick(\"e\", " . attr(addslashes($rowid)) . ")'>\n";
336 echo " <td valign='top'>" . text(substr($row['date'], 0, 10)) . "</td>\n";
337 echo " <td valign='top'>" . text($row['reason']) . "</td>\n";
338 echo " </tr>\n";
339 $endjs .= "eselected['" . attr($rowid) . "'] = '';\n";
342 </table>
343 </td>
344 </tr>
346 <tr>
347 <td colspan='2' align='center'>
348 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' disabled /> &nbsp;
349 <input type='button' value='<?php echo xla('Add Issue'); ?>' onclick='newIssue()' />
350 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='dlgclose()' />
351 </td>
352 </tr>
354 </table>
356 </form>
358 <p><b><?php echo xlt('Instructions:'); ?></b> <?php echo xlt('Choose a section and click an item within it; then in
359 the other section you will see the related items highlighted, and you can click
360 in that section to add and delete relationships.'); ?>
361 </p>
363 <script>
364 <?php
365 echo $endjs;
366 if ($_REQUEST['issue']) {
367 echo "doclick('p', " . attr(addslashes($_REQUEST['issue'])) . ");\n";
370 if ($alertmsg) {
371 echo "alert('" . addslashes($alertmsg) . "');\n";
374 </script>
375 </body>
376 </html>