Bug fix for provider Insurance Numbers
[openemr.git] / interface / patient_file / problem_encounter.php
blob310a41cc67a1f56ceda2a1210f588aa4fed609b3
1 <?php
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");
12 include_once("$srcdir/lists.inc");
14 $patdata = getPatientData($pid, "fname,lname,squad");
16 $thisauth = ((acl_check('encounters', 'notes') == 'write' ||
17 acl_check('encounters', 'notes_a') == 'write') &&
18 acl_check('patients', 'med') == 'write');
20 if ($patdata['squad'] && ! acl_check('squads', $patdata['squad']))
21 $thisauth = 0;
23 if (!$thisauth) {
24 echo "<html>\n<body>\n";
25 echo "<p>" .xl('You are not authorized for this.'). "</p>\n";
26 echo "</body>\n</html>\n";
27 exit();
30 $alertmsg = ""; // anything here pops up in an alert box
31 $endjs = ""; // holds javascript to write at the end
33 // If the Save button was clicked...
34 if ($_POST['form_save']) {
35 $form_pid = $_POST['form_pid'];
36 $form_pelist = $_POST['form_pelist'];
37 // $pattern = '|/(\d+),(\d+),([YN])|';
38 $pattern = '|/(\d+),(\d+)|';
40 preg_match_all($pattern, $form_pelist, $matches);
41 $numsets = count($matches[1]);
43 sqlQuery("DELETE FROM issue_encounter WHERE pid = '$form_pid'");
45 for ($i = 0; $i < $numsets; ++$i) {
46 $list_id = $matches[1][$i];
47 $encounter = $matches[2][$i];
48 // $resolved = ($matches[3][$i] == 'Y') ? 1 : 0;
49 $query = "INSERT INTO issue_encounter ( " .
50 "pid, list_id, encounter" . // , resolved " .
51 ") VALUES ( " .
52 "$form_pid, $list_id, $encounter" . // , $resolved " .
53 ")";
54 sqlQuery($query);
57 // All done.
58 echo "<html><body><script language='JavaScript'>\n";
59 if ($alertmsg) echo " alert('$alertmsg');\n";
60 echo " window.close();\n";
61 echo "</script></body></html>\n";
62 exit();
65 // get problems
66 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
67 "ORDER BY type, date");
69 // get encounters
70 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = $pid " .
71 "ORDER BY date DESC");
73 // get problem/encounter relations
74 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = $pid");
76 <html>
77 <head>
78 <?php html_header_show();?>
79 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
80 <title><?php xl('Issues and Encounters','e'); ?></title>
82 <style>
83 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
84 tr.detail { font-size:10pt; background-color:#eeeeee; }
85 </style>
87 <script type="text/javascript" src="../../library/topdialog.js"></script>
88 <script type="text/javascript" src="../../library/dialog.js"></script>
90 <script language="JavaScript">
92 // These are the possible colors for table rows.
93 var trcolors = new Object();
94 // Colors for: Foreground Background
95 trcolors['U'] = new Array('#000000', '#eeeeee'); // unselected
96 trcolors['K'] = new Array('#000000', '#eeee00'); // selected key
97 // trcolors['Y'] = new Array('#000000', '#99ff99'); // selected value resolved=Y
98 // trcolors['N'] = new Array('#000000', '#ff9999'); // selected value resolved=N
99 trcolors['V'] = new Array('#000000', '#9999ff'); // selected value
101 var pselected = new Object();
102 var eselected = new Object();
103 var keyid = null; // id of currently hilited key, if any
105 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
107 // callback from add_edit_issue.php:
108 function refreshIssue(issue, title) {
109 top.restoreSession();
110 location.reload();
113 // New Issue button is clicked.
114 function newIssue() {
115 var f = document.forms[0];
116 var tmp = (keyid && f.form_key[1].checked) ? ('?enclink=' + keyid) : '';
117 dlgopen('summary/add_edit_issue.php' + tmp, '_blank', 600, 475);
120 // New Encounter button is clicked.
121 function newEncounter() {
122 var f = document.forms[0];
123 if (!f.form_save.disabled) {
124 if (!confirm('This will abandon your unsaved changes. Are you sure?'))
125 return;
127 top.restoreSession();
128 var tmp = (keyid && f.form_key[0].checked) ? ('&issue=' + keyid) : '';
129 opener.top.Title.location.href='encounter/encounter_title.php';
130 opener.top.Main.location.href='encounter/patient_encounter.php?mode=new' + tmp;
131 window.close();
134 // Determine if a given problem/encounter pair is currently linked.
135 // If yes, return the "resolved" character (Y or N), else an empty string.
136 function isPair(problem, encounter) {
137 var pelist = document.forms[0].form_pelist;
138 // var frag = '/' + problem + ',' + encounter + ',';
139 var frag = '/' + problem + ',' + encounter + '/';
140 var i = pelist.value.indexOf(frag);
141 if (i < 0) return '';
142 // return pelist.value.charAt(i + frag.length);
143 return 'V';
146 // Unlink a problem/encounter pair.
147 function removePair(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) {
153 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
154 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length - 1);
155 document.forms[0].form_save.disabled = false;
159 // Link a new or modified problem/encounter pair.
160 // function addPair(problem, encounter, resolved) {
161 function addPair(problem, encounter) {
162 removePair(problem, encounter);
163 var pelist = document.forms[0].form_pelist;
164 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
165 pelist.value += '' + problem + ',' + encounter + '/';
166 document.forms[0].form_save.disabled = false;
169 // Clear displayed highlights.
170 function doclearall(pfx) {
171 var thisarr = (pfx == 'p') ? pselected : eselected;
172 for (var id in thisarr) {
173 var thistr = document.getElementById(pfx + '_' + id);
174 if (thisarr[id]) {
175 thisarr[id] = '';
176 thistr.style.color = trcolors['U'][0];
177 thistr.style.backgroundColor = trcolors['U'][1];
182 function clearall() {
183 doclearall('p');
184 doclearall('e');
185 keyid = null;
188 // Process clicks on table rows.
189 function doclick(pfx, id) {
190 var thisstyle = document.getElementById(pfx + '_' + id).style;
191 var thisarr = (pfx == 'p') ? pselected : eselected;
192 var piskey = document.forms[0].form_key[0].checked;
193 var thisiskey = (pfx == 'p') ? piskey : !piskey;
194 var wasset = thisarr[id];
195 if (thisiskey) { // they clicked in the key table
196 clearall();
197 if (!wasset) { // this item is not already hilited
198 keyid = id;
199 thisarr[id] = 'K';
200 thisstyle.color = trcolors['K'][0];
201 thisstyle.backgroundColor = trcolors['K'][1];
202 // Now hilite the related value table entries:
203 if (pfx == 'p') { // key is problems, values are encounters
204 for (key in eselected) {
205 var resolved = isPair(id, key);
206 if (resolved.length > 0) {
207 eselected[key] = resolved;
208 var valstyle = document.getElementById('e_' + key).style;
209 valstyle.color = trcolors[resolved][0];
210 valstyle.backgroundColor = trcolors[resolved][1];
213 } else { // key is encounters, values are problems
214 for (key in pselected) {
215 var resolved = isPair(key, id);
216 if (resolved.length > 0) {
217 pselected[key] = resolved;
218 var valstyle = document.getElementById('p_' + key).style;
219 valstyle.color = trcolors[resolved][0];
220 valstyle.backgroundColor = trcolors[resolved][1];
225 } else { // they clicked in the value table
226 if (keyid) {
227 var resolved = thisarr[id];
228 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
229 // thisarr[id] = 'N';
230 // thisstyle.color = trcolors['N'][0];
231 // thisstyle.backgroundColor = trcolors['N'][1];
232 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
233 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
234 if (resolved != '') { // hilited, so remove it
235 thisarr[id] = '';
236 thisstyle.color = trcolors['U'][0];
237 thisstyle.backgroundColor = trcolors['U'][1];
238 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
239 // } else { // not hilited, change to hilited and resolved
240 // thisarr[id] = 'Y';
241 // thisstyle.color = trcolors['Y'][0];
242 // thisstyle.backgroundColor = trcolors['Y'][1];
243 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
244 } else { // not hilited, change to hilited
245 thisarr[id] = 'V';
246 thisstyle.color = trcolors['V'][0];
247 thisstyle.backgroundColor = trcolors['V'][1];
248 if (pfx == 'p') addPair(id, keyid); else addPair(keyid, id);
250 } else {
251 alert('You must first select an item in the section whose radio button is checked.');
256 </script>
258 </head>
259 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'
260 bgcolor='#ffffff' onunload='imclosing()'>
261 <form method='post' action='problem_encounter.php' onsubmit='return top.restoreSession()'>
262 <?php
263 echo "<input type='hidden' name='form_pid' value='$pid' />\n";
264 // pelist looks like /problem,encounter/problem,encounter/[...].
265 echo "<input type='hidden' name='form_pelist' value='/";
266 while ($row = sqlFetchArray($peres)) {
267 // echo $row['list_id'] . "," . $row['encounter'] . "," .
268 // ($row['resolved'] ? "Y" : "N") . "/";
269 echo $row['list_id'] . "," . $row['encounter'] . "/";
271 echo "' />\n";
274 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
276 <tr>
277 <td colspan='2' align='center'>
278 <b><?php xl('Issues and Encounters for','e'); ?> <?php echo $patdata['fname'] . " " . $patdata['lname'] . " ($pid)</b>\n"; ?>
279 </td>
280 </tr>
282 <tr>
283 <td align='center' valign='top'>
284 <table width='100%' cellpadding='1' cellspacing='2'>
285 <tr class='head'>
286 <td colspan='3' align='center'>
287 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
288 <b><?php xl('Issues Section','e'); ?></b>
289 </td>
290 </tr>
291 <tr class='head'>
292 <td><?php xl('Type','e'); ?></td>
293 <td><?php xl('Title','e'); ?></td>
294 <td><?php xl('Description','e'); ?></td>
295 </tr>
296 <?php
297 while ($row = sqlFetchArray($pres)) {
298 $rowid = $row['id'];
299 echo " <tr class='detail' id='p_$rowid' onclick='doclick(\"p\", $rowid)'>\n";
300 echo " <td valign='top'>" . $ISSUE_TYPES[($row['type'])][1] . "</td>\n";
301 echo " <td valign='top'>" . $row['title'] . "</td>\n";
302 echo " <td valign='top'>" . $row['comments'] . "</td>\n";
303 echo " </tr>\n";
304 $endjs .= "pselected['$rowid'] = '';\n";
307 </table>
308 </td>
309 <td align='center' valign='top'>
310 <table width='100%' cellpadding='1' cellspacing='2'>
311 <tr class='head'>
312 <td colspan='2' align='center'>
313 <input type='radio' name='form_key' value='e' onclick='clearall()' />
314 <b><?php xl('Encounters Section','e'); ?></b>
315 </td>
316 </tr>
317 <tr class='head'>
318 <td><?php xl('Date','e'); ?></td>
319 <td><?php xl('Presenting Complaint','e'); ?></td>
320 </tr>
321 <?php
322 while ($row = sqlFetchArray($eres)) {
323 $rowid = $row['encounter'];
324 echo " <tr class='detail' id='e_$rowid' onclick='doclick(\"e\", $rowid)'>\n";
325 echo " <td valign='top'>" . substr($row['date'], 0, 10) . "</td>\n";
326 echo " <td valign='top'>" . $row['reason'] . "</td>\n";
327 echo " </tr>\n";
328 $endjs .= "eselected['$rowid'] = '';\n";
331 </table>
332 </td>
333 </tr>
335 <tr>
336 <td colspan='2' align='center'>
337 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' disabled /> &nbsp;
338 <input type='button' value='<?php xl('Add Issue','e'); ?>' onclick='newIssue()' />
339 <?php if (!$GLOBALS['concurrent_layout']) { ?>
340 <input type='button' value='<?php xl('Add Encounter','e'); ?>' onclick='newEncounter()' />
341 <?php } ?>
342 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
343 </td>
344 </tr>
346 </table>
348 </form>
350 <p><b><?php xl('Instructions:','e'); ?></b> <?php xl('Choose a section and click an item within it; then in
351 the other section you will see the related items highlighted, and you can click
352 in that section to add and delete relationships.','e'); ?>
353 </p>
355 <script>
356 <?php
357 echo $endjs;
358 if ($_REQUEST['issue']) {
359 echo "doclick('p', " . $_REQUEST['issue'] . ");\n";
361 if ($alertmsg) echo "alert('$alertmsg');\n";
363 </script>
364 </body>
365 </html>