Change form select interface so picking form from select menu automatically jumps...
[openemr.git] / interface / patient_file / problem_encounter.php
blob9282cfb3c5a69ca18880c08f3c8e46ec4688c56d
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>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 // callback from add_edit_issue.php:
104 function refreshIssue(issue, title) {
105 location.reload();
108 // New Issue button is clicked.
109 function newIssue() {
110 var f = document.forms[0];
111 var tmp = (keyid && f.form_key[1].checked) ? ('?enclink=' + keyid) : '';
112 dlgopen('summary/add_edit_issue.php' + tmp, '_blank', 600, 475);
115 // New Encounter button is clicked.
116 function newEncounter() {
117 var f = document.forms[0];
118 if (!f.form_save.disabled) {
119 if (!confirm('This will abandon your unsaved changes. Are you sure?'))
120 return;
122 var tmp = (keyid && f.form_key[0].checked) ? ('&issue=' + keyid) : '';
123 opener.top.Title.location.href='encounter/encounter_title.php';
124 opener.top.Main.location.href='encounter/patient_encounter.php?mode=new' + tmp;
125 window.close();
128 // Determine if a given problem/encounter pair is currently linked.
129 // If yes, return the "resolved" character (Y or N), else an empty string.
130 function isPair(problem, encounter) {
131 var pelist = document.forms[0].form_pelist;
132 // var frag = '/' + problem + ',' + encounter + ',';
133 var frag = '/' + problem + ',' + encounter + '/';
134 var i = pelist.value.indexOf(frag);
135 if (i < 0) return '';
136 // return pelist.value.charAt(i + frag.length);
137 return 'V';
140 // Unlink a problem/encounter pair.
141 function removePair(problem, encounter) {
142 var pelist = document.forms[0].form_pelist;
143 // var frag = '/' + problem + ',' + encounter + ',';
144 var frag = '/' + problem + ',' + encounter + '/';
145 var i = pelist.value.indexOf(frag);
146 if (i >= 0) {
147 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
148 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length - 1);
149 document.forms[0].form_save.disabled = false;
153 // Link a new or modified problem/encounter pair.
154 // function addPair(problem, encounter, resolved) {
155 function addPair(problem, encounter) {
156 removePair(problem, encounter);
157 var pelist = document.forms[0].form_pelist;
158 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
159 pelist.value += '' + problem + ',' + encounter + '/';
160 document.forms[0].form_save.disabled = false;
163 // Clear displayed highlights.
164 function doclearall(pfx) {
165 var thisarr = (pfx == 'p') ? pselected : eselected;
166 for (var id in thisarr) {
167 var thistr = document.getElementById(pfx + '_' + id);
168 if (thisarr[id]) {
169 thisarr[id] = '';
170 thistr.style.color = trcolors['U'][0];
171 thistr.style.backgroundColor = trcolors['U'][1];
176 function clearall() {
177 doclearall('p');
178 doclearall('e');
179 keyid = null;
182 // Process clicks on table rows.
183 function doclick(pfx, id) {
184 var thisstyle = document.getElementById(pfx + '_' + id).style;
185 var thisarr = (pfx == 'p') ? pselected : eselected;
186 var piskey = document.forms[0].form_key[0].checked;
187 var thisiskey = (pfx == 'p') ? piskey : !piskey;
188 var wasset = thisarr[id];
189 if (thisiskey) { // they clicked in the key table
190 clearall();
191 if (!wasset) { // this item is not already hilited
192 keyid = id;
193 thisarr[id] = 'K';
194 thisstyle.color = trcolors['K'][0];
195 thisstyle.backgroundColor = trcolors['K'][1];
196 // Now hilite the related value table entries:
197 if (pfx == 'p') { // key is problems, values are encounters
198 for (key in eselected) {
199 var resolved = isPair(id, key);
200 if (resolved.length > 0) {
201 eselected[key] = resolved;
202 var valstyle = document.getElementById('e_' + key).style;
203 valstyle.color = trcolors[resolved][0];
204 valstyle.backgroundColor = trcolors[resolved][1];
207 } else { // key is encounters, values are problems
208 for (key in pselected) {
209 var resolved = isPair(key, id);
210 if (resolved.length > 0) {
211 pselected[key] = resolved;
212 var valstyle = document.getElementById('p_' + key).style;
213 valstyle.color = trcolors[resolved][0];
214 valstyle.backgroundColor = trcolors[resolved][1];
219 } else { // they clicked in the value table
220 if (keyid) {
221 var resolved = thisarr[id];
222 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
223 // thisarr[id] = 'N';
224 // thisstyle.color = trcolors['N'][0];
225 // thisstyle.backgroundColor = trcolors['N'][1];
226 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
227 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
228 if (resolved != '') { // hilited, so remove it
229 thisarr[id] = '';
230 thisstyle.color = trcolors['U'][0];
231 thisstyle.backgroundColor = trcolors['U'][1];
232 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
233 // } else { // not hilited, change to hilited and resolved
234 // thisarr[id] = 'Y';
235 // thisstyle.color = trcolors['Y'][0];
236 // thisstyle.backgroundColor = trcolors['Y'][1];
237 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
238 } else { // not hilited, change to hilited
239 thisarr[id] = 'V';
240 thisstyle.color = trcolors['V'][0];
241 thisstyle.backgroundColor = trcolors['V'][1];
242 if (pfx == 'p') addPair(id, keyid); else addPair(keyid, id);
244 } else {
245 alert('You must first select an item in the section whose radio button is checked.');
250 </script>
252 </head>
253 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'
254 bgcolor='#ffffff' onunload='imclosing()'>
255 <form method='post' action='problem_encounter.php'>
257 echo "<input type='hidden' name='form_pid' value='$pid' />\n";
258 // pelist looks like /problem,encounter/problem,encounter/[...].
259 echo "<input type='hidden' name='form_pelist' value='/";
260 while ($row = sqlFetchArray($peres)) {
261 // echo $row['list_id'] . "," . $row['encounter'] . "," .
262 // ($row['resolved'] ? "Y" : "N") . "/";
263 echo $row['list_id'] . "," . $row['encounter'] . "/";
265 echo "' />\n";
268 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
270 <tr>
271 <td colspan='2' align='center'>
272 <b><? xl('Issues and Encounters for','e'); ?> <? echo $patdata['fname'] . " " . $patdata['lname'] . " ($pid)</b>\n"; ?>
273 </td>
274 </tr>
276 <tr>
277 <td align='center' valign='top'>
278 <table width='100%' cellpadding='1' cellspacing='2'>
279 <tr class='head'>
280 <td colspan='3' align='center'>
281 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
282 <b><? xl('Issues Section','e'); ?></b>
283 </td>
284 </tr>
285 <tr class='head'>
286 <td><? xl('Type','e'); ?></td>
287 <td><? xl('Title','e'); ?></td>
288 <td><? xl('Description','e'); ?></td>
289 </tr>
291 while ($row = sqlFetchArray($pres)) {
292 $rowid = $row['id'];
293 echo " <tr class='detail' id='p_$rowid' onclick='doclick(\"p\", $rowid)'>\n";
294 echo " <td valign='top'>" . $row['type'] . "</td>\n";
295 echo " <td valign='top'>" . $row['title'] . "</td>\n";
296 echo " <td valign='top'>" . $row['comments'] . "</td>\n";
297 echo " </tr>\n";
298 $endjs .= "pselected['$rowid'] = '';\n";
301 </table>
302 </td>
303 <td align='center' valign='top'>
304 <table width='100%' cellpadding='1' cellspacing='2'>
305 <tr class='head'>
306 <td colspan='2' align='center'>
307 <input type='radio' name='form_key' value='e' onclick='clearall()' />
308 <b><? xl('Encounters Section','e'); ?></b>
309 </td>
310 </tr>
311 <tr class='head'>
312 <td><? xl('Date','e'); ?></td>
313 <td><? xl('Presenting Complaint','e'); ?></td>
314 </tr>
316 while ($row = sqlFetchArray($eres)) {
317 $rowid = $row['encounter'];
318 echo " <tr class='detail' id='e_$rowid' onclick='doclick(\"e\", $rowid)'>\n";
319 echo " <td valign='top'>" . substr($row['date'], 0, 10) . "</td>\n";
320 echo " <td valign='top'>" . $row['reason'] . "</td>\n";
321 echo " </tr>\n";
322 $endjs .= "eselected['$rowid'] = '';\n";
325 </table>
326 </td>
327 </tr>
329 <tr>
330 <td colspan='2' align='center'>
331 <input type='submit' name='form_save' value='Save' disabled /> &nbsp;
332 <input type='button' value='Add Issue' onclick='newIssue()' />
333 <input type='button' value='Add Encounter' onclick='newEncounter()' />
334 <input type='button' value='Cancel' onclick='window.close()' />
335 </td>
336 </tr>
338 </table>
340 </form>
342 <p><b><? xl('Instructions:','e'); ?></b> <? xl('Choose a section and click an item within it; then in
343 the other section you will see the related items highlighted, and you can click
344 in that section to add and delete relationships.','e'); ?>
345 </p>
347 <script>
349 echo $endjs;
350 if ($_REQUEST['issue']) {
351 echo "doclick('p', " . $_REQUEST['issue'] . ");\n";
353 if ($alertmsg) echo "alert('$alertmsg');\n";
355 </script>
356 </body>
357 </html>