initial support for multiple browser windows
[openemr.git] / interface / patient_file / problem_encounter.php
blob8aa2b39e9be5591f2d2913dc1cd61205b99cce1d
1 <?
2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 include_once("../globals.php");
10 include_once("$srcdir/patient.inc");
11 include_once("$srcdir/acl.inc");
13 $patdata = getPatientData($pid, "fname,lname,squad");
15 $thisauth = ((acl_check('encounters', 'notes') == 'write' ||
16 acl_check('encounters', 'notes_a') == 'write') &&
17 acl_check('patients', 'med') == 'write');
19 if ($patdata['squad'] && ! acl_check('squads', $patdata['squad']))
20 $thisauth = 0;
22 if (!$thisauth) {
23 echo "<html>\n<body>\n";
24 echo "<p>" .xl('You are not authorized for this.'). "</p>\n";
25 echo "</body>\n</html>\n";
26 exit();
29 $alertmsg = ""; // anything here pops up in an alert box
30 $endjs = ""; // holds javascript to write at the end
32 // If the Save button was clicked...
33 if ($_POST['form_save']) {
34 $form_pid = $_POST['form_pid'];
35 $form_pelist = $_POST['form_pelist'];
36 // $pattern = '|/(\d+),(\d+),([YN])|';
37 $pattern = '|/(\d+),(\d+)|';
39 preg_match_all($pattern, $form_pelist, $matches);
40 $numsets = count($matches[1]);
42 sqlQuery("DELETE FROM issue_encounter WHERE pid = '$form_pid'");
44 for ($i = 0; $i < $numsets; ++$i) {
45 $list_id = $matches[1][$i];
46 $encounter = $matches[2][$i];
47 // $resolved = ($matches[3][$i] == 'Y') ? 1 : 0;
48 $query = "INSERT INTO issue_encounter ( " .
49 "pid, list_id, encounter" . // , resolved " .
50 ") VALUES ( " .
51 "$form_pid, $list_id, $encounter" . // , $resolved " .
52 ")";
53 sqlQuery($query);
56 // All done.
57 echo "<html><body><script language='JavaScript'>\n";
58 if ($alertmsg) echo " alert('$alertmsg');\n";
59 echo " window.close();\n";
60 echo "</script></body></html>\n";
61 exit();
64 // get problems
65 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
66 "ORDER BY type, date");
68 // get encounters
69 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = $pid " .
70 "ORDER BY date DESC");
72 // get problem/encounter relations
73 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = $pid");
75 <html>
76 <head>
77 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
78 <title><? xl('Issues and Encounters','e'); ?></title>
80 <style>
81 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
82 tr.detail { font-size:10pt; background-color:#eeeeee; }
83 </style>
85 <script type="text/javascript" src="../../library/topdialog.js"></script>
86 <script type="text/javascript" src="../../library/dialog.js"></script>
88 <script language="JavaScript">
90 // These are the possible colors for table rows.
91 var trcolors = new Object();
92 // Colors for: Foreground Background
93 trcolors['U'] = new Array('#000000', '#eeeeee'); // unselected
94 trcolors['K'] = new Array('#000000', '#eeee00'); // selected key
95 // trcolors['Y'] = new Array('#000000', '#99ff99'); // selected value resolved=Y
96 // trcolors['N'] = new Array('#000000', '#ff9999'); // selected value resolved=N
97 trcolors['V'] = new Array('#000000', '#9999ff'); // selected value
99 var pselected = new Object();
100 var eselected = new Object();
101 var keyid = null; // id of currently hilited key, if any
103 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
105 // callback from add_edit_issue.php:
106 function refreshIssue(issue, title) {
107 top.restoreSession();
108 location.reload();
111 // New Issue button is clicked.
112 function newIssue() {
113 var f = document.forms[0];
114 var tmp = (keyid && f.form_key[1].checked) ? ('?enclink=' + keyid) : '';
115 dlgopen('summary/add_edit_issue.php' + tmp, '_blank', 600, 475);
118 // New Encounter button is clicked.
119 function newEncounter() {
120 var f = document.forms[0];
121 if (!f.form_save.disabled) {
122 if (!confirm('This will abandon your unsaved changes. Are you sure?'))
123 return;
125 top.restoreSession();
126 var tmp = (keyid && f.form_key[0].checked) ? ('&issue=' + keyid) : '';
127 opener.top.Title.location.href='encounter/encounter_title.php';
128 opener.top.Main.location.href='encounter/patient_encounter.php?mode=new' + tmp;
129 window.close();
132 // Determine if a given problem/encounter pair is currently linked.
133 // If yes, return the "resolved" character (Y or N), else an empty string.
134 function isPair(problem, encounter) {
135 var pelist = document.forms[0].form_pelist;
136 // var frag = '/' + problem + ',' + encounter + ',';
137 var frag = '/' + problem + ',' + encounter + '/';
138 var i = pelist.value.indexOf(frag);
139 if (i < 0) return '';
140 // return pelist.value.charAt(i + frag.length);
141 return 'V';
144 // Unlink a problem/encounter pair.
145 function removePair(problem, encounter) {
146 var pelist = document.forms[0].form_pelist;
147 // var frag = '/' + problem + ',' + encounter + ',';
148 var frag = '/' + problem + ',' + encounter + '/';
149 var i = pelist.value.indexOf(frag);
150 if (i >= 0) {
151 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
152 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length - 1);
153 document.forms[0].form_save.disabled = false;
157 // Link a new or modified problem/encounter pair.
158 // function addPair(problem, encounter, resolved) {
159 function addPair(problem, encounter) {
160 removePair(problem, encounter);
161 var pelist = document.forms[0].form_pelist;
162 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
163 pelist.value += '' + problem + ',' + encounter + '/';
164 document.forms[0].form_save.disabled = false;
167 // Clear displayed highlights.
168 function doclearall(pfx) {
169 var thisarr = (pfx == 'p') ? pselected : eselected;
170 for (var id in thisarr) {
171 var thistr = document.getElementById(pfx + '_' + id);
172 if (thisarr[id]) {
173 thisarr[id] = '';
174 thistr.style.color = trcolors['U'][0];
175 thistr.style.backgroundColor = trcolors['U'][1];
180 function clearall() {
181 doclearall('p');
182 doclearall('e');
183 keyid = null;
186 // Process clicks on table rows.
187 function doclick(pfx, id) {
188 var thisstyle = document.getElementById(pfx + '_' + id).style;
189 var thisarr = (pfx == 'p') ? pselected : eselected;
190 var piskey = document.forms[0].form_key[0].checked;
191 var thisiskey = (pfx == 'p') ? piskey : !piskey;
192 var wasset = thisarr[id];
193 if (thisiskey) { // they clicked in the key table
194 clearall();
195 if (!wasset) { // this item is not already hilited
196 keyid = id;
197 thisarr[id] = 'K';
198 thisstyle.color = trcolors['K'][0];
199 thisstyle.backgroundColor = trcolors['K'][1];
200 // Now hilite the related value table entries:
201 if (pfx == 'p') { // key is problems, values are encounters
202 for (key in eselected) {
203 var resolved = isPair(id, key);
204 if (resolved.length > 0) {
205 eselected[key] = resolved;
206 var valstyle = document.getElementById('e_' + key).style;
207 valstyle.color = trcolors[resolved][0];
208 valstyle.backgroundColor = trcolors[resolved][1];
211 } else { // key is encounters, values are problems
212 for (key in pselected) {
213 var resolved = isPair(key, id);
214 if (resolved.length > 0) {
215 pselected[key] = resolved;
216 var valstyle = document.getElementById('p_' + key).style;
217 valstyle.color = trcolors[resolved][0];
218 valstyle.backgroundColor = trcolors[resolved][1];
223 } else { // they clicked in the value table
224 if (keyid) {
225 var resolved = thisarr[id];
226 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
227 // thisarr[id] = 'N';
228 // thisstyle.color = trcolors['N'][0];
229 // thisstyle.backgroundColor = trcolors['N'][1];
230 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
231 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
232 if (resolved != '') { // hilited, so remove it
233 thisarr[id] = '';
234 thisstyle.color = trcolors['U'][0];
235 thisstyle.backgroundColor = trcolors['U'][1];
236 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
237 // } else { // not hilited, change to hilited and resolved
238 // thisarr[id] = 'Y';
239 // thisstyle.color = trcolors['Y'][0];
240 // thisstyle.backgroundColor = trcolors['Y'][1];
241 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
242 } else { // not hilited, change to hilited
243 thisarr[id] = 'V';
244 thisstyle.color = trcolors['V'][0];
245 thisstyle.backgroundColor = trcolors['V'][1];
246 if (pfx == 'p') addPair(id, keyid); else addPair(keyid, id);
248 } else {
249 alert('You must first select an item in the section whose radio button is checked.');
254 </script>
256 </head>
257 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'
258 bgcolor='#ffffff' onunload='imclosing()'>
259 <form method='post' action='problem_encounter.php' onsubmit='return top.restoreSession()'>
261 echo "<input type='hidden' name='form_pid' value='$pid' />\n";
262 // pelist looks like /problem,encounter/problem,encounter/[...].
263 echo "<input type='hidden' name='form_pelist' value='/";
264 while ($row = sqlFetchArray($peres)) {
265 // echo $row['list_id'] . "," . $row['encounter'] . "," .
266 // ($row['resolved'] ? "Y" : "N") . "/";
267 echo $row['list_id'] . "," . $row['encounter'] . "/";
269 echo "' />\n";
272 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
274 <tr>
275 <td colspan='2' align='center'>
276 <b><? xl('Issues and Encounters for','e'); ?> <? echo $patdata['fname'] . " " . $patdata['lname'] . " ($pid)</b>\n"; ?>
277 </td>
278 </tr>
280 <tr>
281 <td align='center' valign='top'>
282 <table width='100%' cellpadding='1' cellspacing='2'>
283 <tr class='head'>
284 <td colspan='3' align='center'>
285 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
286 <b><? xl('Issues Section','e'); ?></b>
287 </td>
288 </tr>
289 <tr class='head'>
290 <td><? xl('Type','e'); ?></td>
291 <td><? xl('Title','e'); ?></td>
292 <td><? xl('Description','e'); ?></td>
293 </tr>
295 while ($row = sqlFetchArray($pres)) {
296 $rowid = $row['id'];
297 echo " <tr class='detail' id='p_$rowid' onclick='doclick(\"p\", $rowid)'>\n";
298 echo " <td valign='top'>" . $row['type'] . "</td>\n";
299 echo " <td valign='top'>" . $row['title'] . "</td>\n";
300 echo " <td valign='top'>" . $row['comments'] . "</td>\n";
301 echo " </tr>\n";
302 $endjs .= "pselected['$rowid'] = '';\n";
305 </table>
306 </td>
307 <td align='center' valign='top'>
308 <table width='100%' cellpadding='1' cellspacing='2'>
309 <tr class='head'>
310 <td colspan='2' align='center'>
311 <input type='radio' name='form_key' value='e' onclick='clearall()' />
312 <b><? xl('Encounters Section','e'); ?></b>
313 </td>
314 </tr>
315 <tr class='head'>
316 <td><? xl('Date','e'); ?></td>
317 <td><? xl('Presenting Complaint','e'); ?></td>
318 </tr>
320 while ($row = sqlFetchArray($eres)) {
321 $rowid = $row['encounter'];
322 echo " <tr class='detail' id='e_$rowid' onclick='doclick(\"e\", $rowid)'>\n";
323 echo " <td valign='top'>" . substr($row['date'], 0, 10) . "</td>\n";
324 echo " <td valign='top'>" . $row['reason'] . "</td>\n";
325 echo " </tr>\n";
326 $endjs .= "eselected['$rowid'] = '';\n";
329 </table>
330 </td>
331 </tr>
333 <tr>
334 <td colspan='2' align='center'>
335 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' disabled /> &nbsp;
336 <input type='button' value='<?php xl('Add Issue','e'); ?>' onclick='newIssue()' />
337 <?php if (!$GLOBALS['concurrent_layout']) { ?>
338 <input type='button' value='<?php xl('Add Encounter','e'); ?>' onclick='newEncounter()' />
339 <?php } ?>
340 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
341 </td>
342 </tr>
344 </table>
346 </form>
348 <p><b><? xl('Instructions:','e'); ?></b> <? xl('Choose a section and click an item within it; then in
349 the other section you will see the related items highlighted, and you can click
350 in that section to add and delete relationships.','e'); ?>
351 </p>
353 <script>
355 echo $endjs;
356 if ($_REQUEST['issue']) {
357 echo "doclick('p', " . $_REQUEST['issue'] . ");\n";
359 if ($alertmsg) echo "alert('$alertmsg');\n";
361 </script>
362 </body>
363 </html>