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