2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
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 " .
35 "$form_pid, $list_id, $encounter, $resolved " .
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";
49 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
50 "ORDER BY type, date");
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");
61 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
62 <title
>Issues
and Encounters
</title
>
65 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
66 tr
.detail
{ font
-size
:10pt
; background
-color
:#eeeeee; }
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
);
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
);
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
);
119 thistr
.style
.color
= trcolors
['U'][0];
120 thistr
.style
.backgroundColor
= trcolors
['U'][1];
125 function clearall() {
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
140 if (!wasset
) { // this item is not already hilited
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
170 var resolved
= thisarr
[id
];
171 if (resolved
== 'Y') { // it was hilited and resolved, change to unresolved
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
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
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');
188 alert('You must first select an item in the section whose radio button is checked.');
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") . "/";
209 <table border
='0' cellpadding
='5' cellspacing
='0' width
='100%'>
212 <td colspan
='2' align
='center'>
213 <b
>Issues
and Encounters
for <?
echo $patdata['fname'] . " " . $patdata['lname'] . " ($pid)</b>\n"; ?
>
218 <td align
='center' valign
='top'>
219 <table width
='100%' cellpadding
='1' cellspacing
='2'>
221 <td colspan
='3' align
='center'>
222 <input type
='radio' name
='form_key' value
='p' onclick
='clearall()' checked
/>
223 <b
>Issues Section
</b
>
232 while ($row = sqlFetchArray($pres)) {
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";
239 $endjs .= "pselected['$rowid'] = '';\n";
244 <td align
='center' valign
='top'>
245 <table width
='100%' cellpadding
='1' cellspacing
='2'>
247 <td colspan
='2' align
='center'>
248 <input type
='radio' name
='form_key' value
='e' onclick
='clearall()' />
249 <b
>Encounters Section
</b
>
254 <td
>Presenting Complaint
</td
>
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";
263 $endjs .= "eselected['$rowid'] = '';\n";
271 <td colspan
='2' align
='center'>
272 <input type
='submit' name
='form_save' value
='Save' disabled
/>  
;
273 <input type
='button' value
='Cancel' onclick
='window.close()' />
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
.
291 if ($alertmsg) echo "alert('$alertmsg');\n";