added support for issues-and-encounters
[openemr.git] / interface / patient_file / problem_encounter.php
blobd65a134fd0cadf9c77d0fa477167c63c21c8e8b7
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("../../library/patient.inc");
12 $patdata = getPatientData($pid, "fname,lname");
14 $alertmsg = ""; // anything here pops up in an alert box
15 $endjs = ""; // holds javascript to write at the end
17 // If the Save button was clicked...
18 if ($_POST['form_save']) {
19 $form_pid = $_POST['form_pid'];
20 $form_pelist = $_POST['form_pelist'];
21 $pattern = '|/(\d+),(\d+),([YN])|';
23 preg_match_all($pattern, $form_pelist, $matches);
24 $numsets = count($matches[1]);
26 sqlQuery("DELETE FROM issue_encounter WHERE pid = '$form_pid'");
28 for ($i = 0; $i < $numsets; ++$i) {
29 $list_id = $matches[1][$i];
30 $encounter = $matches[2][$i];
31 $resolved = ($matches[3][$i] == 'Y') ? 1 : 0;
32 $query = "INSERT INTO issue_encounter ( " .
33 "pid, list_id, encounter, resolved " .
34 ") VALUES ( " .
35 "$form_pid, $list_id, $encounter, $resolved " .
36 ")";
37 sqlQuery($query);
40 // All done.
41 echo "<html><body><script language='JavaScript'>\n";
42 if ($alertmsg) echo " alert('$alertmsg');\n";
43 echo " window.close();\n";
44 echo "</script></body></html>\n";
45 exit();
48 // get problems
49 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
50 "ORDER BY type, date");
52 // get encounters
53 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = $pid " .
54 "ORDER BY date DESC");
56 // get problem/encounter relations
57 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = $pid");
59 <html>
60 <head>
61 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
62 <title>Issues and Encounters</title>
64 <style>
65 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
66 tr.detail { font-size:10pt; background-color:#eeeeee; }
67 </style>
69 <script language="JavaScript">
71 // These are the possible colors for table rows.
72 var trcolors = new Object();
73 // Colors for: Foreground Background
74 trcolors['U'] = new Array('#000000', '#eeeeee'); // unselected
75 trcolors['K'] = new Array('#000000', '#eeee00'); // selected key
76 trcolors['Y'] = new Array('#000000', '#99ff99'); // selected value resolved=Y
77 trcolors['N'] = new Array('#000000', '#ff9999'); // selected value resolved=N
79 var pselected = new Object();
80 var eselected = new Object();
81 var keyid = null; // id of currently hilited key, if any
83 // Determine if a given problem/encounter pair is currently linked.
84 // If yes, return the "resolved" character (Y or N), else an empty string.
85 function isPair(problem, encounter) {
86 var pelist = document.forms[0].form_pelist;
87 var frag = '/' + problem + ',' + encounter + ',';
88 var i = pelist.value.indexOf(frag);
89 if (i < 0) return '';
90 return pelist.value.charAt(i + frag.length);
93 // Unlink a problem/encounter pair.
94 function removePair(problem, encounter) {
95 var pelist = document.forms[0].form_pelist;
96 var frag = '/' + problem + ',' + encounter + ',';
97 var i = pelist.value.indexOf(frag);
98 if (i >= 0) {
99 pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
100 document.forms[0].form_save.disabled = false;
104 // Link a new or modified problem/encounter pair.
105 function addPair(problem, encounter, resolved) {
106 removePair(problem, encounter);
107 var pelist = document.forms[0].form_pelist;
108 pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
109 document.forms[0].form_save.disabled = false;
112 // Clear displayed highlights.
113 function doclearall(pfx) {
114 var thisarr = (pfx == 'p') ? pselected : eselected;
115 for (var id in thisarr) {
116 var thistr = document.getElementById(pfx + '_' + id);
117 if (thisarr[id]) {
118 thisarr[id] = '';
119 thistr.style.color = trcolors['U'][0];
120 thistr.style.backgroundColor = trcolors['U'][1];
125 function clearall() {
126 doclearall('p');
127 doclearall('e');
128 keyid = null;
131 // Process clicks on table rows.
132 function doclick(pfx, id) {
133 var thisstyle = document.getElementById(pfx + '_' + id).style;
134 var thisarr = (pfx == 'p') ? pselected : eselected;
135 var piskey = document.forms[0].form_key[0].checked;
136 var thisiskey = (pfx == 'p') ? piskey : !piskey;
137 var wasset = thisarr[id];
138 if (thisiskey) { // they clicked in the key table
139 clearall();
140 if (!wasset) { // this item is not already hilited
141 keyid = id;
142 thisarr[id] = 'K';
143 thisstyle.color = trcolors['K'][0];
144 thisstyle.backgroundColor = trcolors['K'][1];
145 // Now hilite the related value table entries:
146 if (pfx == 'p') { // key is problems, values are encounters
147 for (key in eselected) {
148 var resolved = isPair(id, key);
149 if (resolved.length > 0) {
150 eselected[key] = resolved;
151 var valstyle = document.getElementById('e_' + key).style;
152 valstyle.color = trcolors[resolved][0];
153 valstyle.backgroundColor = trcolors[resolved][1];
156 } else { // key is encounters, values are problems
157 for (key in pselected) {
158 var resolved = isPair(key, id);
159 if (resolved.length > 0) {
160 pselected[key] = resolved;
161 var valstyle = document.getElementById('p_' + key).style;
162 valstyle.color = trcolors[resolved][0];
163 valstyle.backgroundColor = trcolors[resolved][1];
168 } else { // they clicked in the value table
169 if (keyid) {
170 var resolved = thisarr[id];
171 if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
172 thisarr[id] = 'N';
173 thisstyle.color = trcolors['N'][0];
174 thisstyle.backgroundColor = trcolors['N'][1];
175 if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
176 } else if (resolved == 'N') { // it was hilited and unresolved, remove it
177 thisarr[id] = '';
178 thisstyle.color = trcolors['U'][0];
179 thisstyle.backgroundColor = trcolors['U'][1];
180 if (pfx == 'p') removePair(id, keyid); else removePair(keyid, id);
181 } else { // not hilited, change to hilited and resolved
182 thisarr[id] = 'Y';
183 thisstyle.color = trcolors['Y'][0];
184 thisstyle.backgroundColor = trcolors['Y'][1];
185 if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
187 } else {
188 alert('You must first select an item in the section whose radio button is checked.');
193 </script>
195 </head>
196 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' bgcolor='#ffffff'>
197 <form method='post' action='problem_encounter.php'>
199 echo "<input type='hidden' name='form_pid' value='$pid' />\n";
200 // pelist looks like /problem,encounter,Y/problem,encounter,N/[...].
201 echo "<input type='hidden' name='form_pelist' value='/";
202 while ($row = sqlFetchArray($peres)) {
203 echo $row['list_id'] . "," . $row['encounter'] . "," .
204 ($row['resolved'] ? "Y" : "N") . "/";
206 echo "' />\n";
209 <table border='0' cellpadding='5' cellspacing='0' width='100%'>
211 <tr>
212 <td colspan='2' align='center'>
213 <b>Issues and Encounters for <? echo $patdata['fname'] . " " . $patdata['lname'] . " ($pid)</b>\n"; ?>
214 </td>
215 </tr>
217 <tr>
218 <td align='center' valign='top'>
219 <table width='100%' cellpadding='1' cellspacing='2'>
220 <tr class='head'>
221 <td colspan='3' align='center'>
222 <input type='radio' name='form_key' value='p' onclick='clearall()' checked />
223 <b>Issues Section</b>
224 </td>
225 </tr>
226 <tr class='head'>
227 <td>Type</td>
228 <td>Title</td>
229 <td>Description</td>
230 </tr>
232 while ($row = sqlFetchArray($pres)) {
233 $rowid = $row['id'];
234 echo " <tr class='detail' id='p_$rowid' onclick='doclick(\"p\", $rowid)'>\n";
235 echo " <td valign='top'>" . $row['type'] . "</td>\n";
236 echo " <td valign='top'>" . $row['title'] . "</td>\n";
237 echo " <td valign='top'>" . $row['comments'] . "</td>\n";
238 echo " </tr>\n";
239 $endjs .= "pselected['$rowid'] = '';\n";
242 </table>
243 </td>
244 <td align='center' valign='top'>
245 <table width='100%' cellpadding='1' cellspacing='2'>
246 <tr class='head'>
247 <td colspan='2' align='center'>
248 <input type='radio' name='form_key' value='e' onclick='clearall()' />
249 <b>Encounters Section</b>
250 </td>
251 </tr>
252 <tr class='head'>
253 <td>Date</td>
254 <td>Presenting Complaint</td>
255 </tr>
257 while ($row = sqlFetchArray($eres)) {
258 $rowid = $row['encounter'];
259 echo " <tr class='detail' id='e_$rowid' onclick='doclick(\"e\", $rowid)'>\n";
260 echo " <td valign='top'>" . substr($row['date'], 0, 10) . "</td>\n";
261 echo " <td valign='top'>" . $row['reason'] . "</td>\n";
262 echo " </tr>\n";
263 $endjs .= "eselected['$rowid'] = '';\n";
266 </table>
267 </td>
268 </tr>
270 <tr>
271 <td colspan='2' align='center'>
272 <input type='submit' name='form_save' value='Save' disabled /> &nbsp;
273 <input type='button' value='Cancel' onclick='window.close()' />
274 </td>
275 </tr>
277 </table>
279 </form>
281 <p><b>Instructions:</b> Choose a section and click an item within it; then in
282 the other section you will see the related items highlighted, and you can click
283 in that section to create, remove and change the relationships. Note that the
284 highlight color (green = resolved, red = unresolved) is an attribute of the
285 <i>relationship</i>, not of the item itself.
286 </p>
288 <script>
290 echo $endjs;
291 if ($alertmsg) echo "alert('$alertmsg');\n";
293 </script>
294 </body>
295 </html>