phpgacl implementation updates
[openemr.git] / interface / patient_file / summary / add_edit_issue.php
blobceff1a98bbd48f706e791011e1223731305b8191
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/lists.inc");
11 include_once("$srcdir/patient.inc");
12 include_once("$srcdir/acl.inc");
14 $issue = $_REQUEST['issue'];
15 $info_msg = "";
17 $thisauth = acl_check('patients', 'med');
18 if ($issue && $thisauth != 'write') die("Edit is not authorized!");
19 if ($thisauth != 'write' && $thisauth != 'addonly') die("Add is not authorized!");
21 $arrtype = array(
22 'medical_problem' => 'Problem',
23 'allergy' => 'Allergy',
24 'medication' => 'Medication',
25 'surgery' => 'Surgery'
28 $arroccur = array(
29 0 => 'Unknown or N/A',
30 1 => 'First',
31 2 => 'Second',
32 3 => 'Third',
33 4 => 'Chronic/Recurrent',
34 5 => 'Acute on Chronic'
37 function QuotedOrNull($fld) {
38 if ($fld) return "'$fld'";
39 return "NULL";
43 <html>
44 <head>
45 <title><? echo $issue ? "Edit" : "Add New" ?> Issue</title>
46 <link rel=stylesheet href='<? echo $css_header ?>' type='text/css'>
48 <style>
49 td { font-size:10pt; }
50 </style>
52 <script type="text/javascript" src="../../../library/overlib_mini.js"></script>
53 <script type="text/javascript" src="../../../library/calendar.js"></script>
54 <script type="text/javascript" src="../../../library/textformat.js"></script>
56 <script language="JavaScript">
58 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
60 var aopts = new Array();
62 // "Clickoptions" is a feature by Mark Leeds that provides for one-click
63 // access to preselected lists of issues in each category. Here we get
64 // the issue titles from the user-customizable file and write JavaScript
65 // statements that will build an array of arrays of Option objects.
67 $clickoptions = array();
68 if (is_file("../../../custom/clickoptions.txt"))
69 $clickoptions = file("../../../custom/clickoptions.txt");
70 $i = 0;
71 foreach ($arrtype as $key => $value) {
72 echo " aopts[$i] = new Array();\n";
73 foreach($clickoptions as $line) {
74 $line = trim($line);
75 if (substr($line, 0, 1) != "#") {
76 if (strpos($line, $key) !== false) {
77 $text = addslashes(substr($line, strpos($line, "::") + 2));
78 echo " aopts[$i][aopts[$i].length] = new Option('$text', '$text', false, false);\n";
82 ++$i;
86 // React to selection of an issue type. This loads the associated
87 // shortcuts into the selection list of titles.
88 function newtype(index) {
89 var theopts = document.forms[0].form_titles.options;
90 theopts.length = 0;
91 for (i = 0; i < aopts[index].length; ++i) {
92 theopts[i] = aopts[index][i];
96 // If a clickoption title is selected, copy it to the title field.
97 function set_text() {
98 var f = document.forms[0];
99 f.form_title.value = f.form_titles.options[f.form_titles.selectedIndex].text;
100 f.form_titles.selectedIndex = -1;
103 </script>
105 </head>
107 <body <?echo $top_bg_line;?>>
109 // If we are saving, then save and close the window.
111 if ($_POST['form_save']) {
113 $i = 0;
114 $text_type = "unknown";
115 foreach ($arrtype as $key => $value) {
116 if ($i++ == $_POST['form_type']) $text_type = $key;
119 $form_begin = fixDate($_POST['form_begin'], '');
120 $form_end = fixDate($_POST['form_end'], '');
122 if ($issue) {
123 sqlStatement("UPDATE lists SET " .
124 "type = '" . $text_type . "', " .
125 "title = '" . $_POST['form_title'] . "', " .
126 "comments = '" . $_POST['form_comments'] . "', " .
127 "begdate = " . QuotedOrNull($form_begin) . ", " .
128 "enddate = " . QuotedOrNull($form_end) . ", " .
129 "diagnosis = '" . $_POST['form_diagnosis'] . "', " .
130 "occurrence = '" . $_POST['form_occur'] . "', " .
131 "referredby = '" . $_POST['form_referredby'] . "', " .
132 "extrainfo = '" . $_POST['form_missed'] . "' " .
133 "WHERE id = '$issue'");
134 } else {
135 $issue = sqlInsert("INSERT INTO lists ( " .
136 "date, pid, type, title, activity, comments, begdate, enddate, " .
137 "diagnosis, occurrence, referredby, extrainfo, user, groupname " .
138 ") VALUES ( " .
139 "NOW(), " .
140 "'$pid', " .
141 "'" . $text_type . "', " .
142 "'" . $_POST['form_title'] . "', " .
143 "1, " .
144 "'" . $_POST['form_comments'] . "', " .
145 QuotedOrNull($form_begin) . ", " .
146 QuotedOrNull($form_end) . ", " .
147 "'" . $_POST['form_diagnosis'] . "', " .
148 "'" . $_POST['form_occur'] . "', " .
149 "'" . $_POST['form_referredby'] . "', " .
150 "'" . $_POST['form_missed'] . "', " .
151 "'" . $$_SESSION['authUser'] . "', " .
152 "'" . $$_SESSION['authProvider'] . "' )");
155 $tmp_title = substr($arrtype[$text_type], 0, 1) . ": $form_begin " .
156 substr($_POST['form_title'], 0, 40);
158 // Close this window and redisplay the updated list of issues.
160 echo "<script language='JavaScript'>\n";
161 if ($info_msg) echo " alert('$info_msg');\n";
162 echo " window.close();\n";
163 // echo " opener.location.reload();\n";
164 echo " if (opener.refreshIssue) opener.refreshIssue($issue,'$tmp_title');\n";
165 echo "</script></body></html>\n";
166 exit();
169 $irow = array();
170 $type_index = 0;
172 if ($issue) {
173 $irow = sqlQuery("SELECT * FROM lists WHERE id = $issue");
174 foreach ($arrtype as $key => $value) {
175 if ($key == $irow['type']) break;
176 ++$type_index;
178 // Get all of the eligible diagnoses.
179 // We include the pid in this search for better performance,
180 // because it's part of the primary key:
181 $bres = sqlStatement(
182 "SELECT DISTINCT billing.code, billing.code_text " .
183 "FROM issue_encounter, billing WHERE " .
184 "issue_encounter.pid = '$pid' AND " .
185 "issue_encounter.list_id = '$issue' AND " .
186 "billing.encounter = issue_encounter.encounter AND " .
187 "( billing.code_type LIKE 'ICD%' OR " .
188 "billing.code_type LIKE 'OSICS' )"
192 <!-- Required for the popup date selectors -->
193 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
195 <form method='post' name='theform' action='add_edit_issue.php?issue=<? echo $issue ?>'>
196 <center>
198 <table border='0' width='100%'>
200 <tr>
201 <td valign='top' width='1%' nowrap><b>Type:</b></td>
202 <td>
204 $index = 0;
205 foreach ($arrtype as $value) {
206 echo " <input type='radio' name='form_type' value='$index' onclick='newtype($index)'";
207 if ($index == $type_index) echo " checked";
208 echo " />$value&nbsp;\n";
209 ++$index;
212 </td>
213 </tr>
215 <tr>
216 <td valign='top' nowrap><b>Title:</b></td>
217 <td>
218 <select name='form_titles' size='4' onchange='set_text()' style='width:100%'>
219 </select><br>
220 <input type='text' size='40' name='form_title' value='<? echo $irow['title'] ?>' style='width:100%' />
221 </td>
222 </tr>
224 <tr>
225 <td valign='top' nowrap><b>Begin Date:</b></td>
226 <td>
227 <input type='text' size='10' name='form_begin' value='<? echo $irow['begdate'] ?>'
228 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
229 title='yyyy-mm-dd date of onset, surgery or start of medication' />
230 <a href="javascript:show_calendar('theform.form_begin')"
231 title="Click here to choose a date"
232 ><img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
233 </td>
234 </tr>
236 <tr>
237 <td valign='top' nowrap><b>End Date:</b></td>
238 <td>
239 <input type='text' size='10' name='form_end' value='<? echo $irow['enddate'] ?>'
240 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
241 title='yyyy-mm-dd date of recovery or end of medication' />
242 <a href="javascript:show_calendar('theform.form_end')"
243 title="Click here to choose a date"
244 ><img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
245 &nbsp;(leave blank if still active)
246 </td>
247 </tr>
249 <tr>
250 <td valign='top' nowrap><b>Diagnosis:</b></td>
251 <td>
252 <select name='form_diagnosis' title='Diagnosis must be coded into a linked encounter'>
253 <option value="">Unknown or N/A</option>
255 while ($brow = sqlFetchArray($bres)) {
256 echo " <option value='" . $brow['code'] . "'";
257 if ($brow['code'] == $irow['diagnosis']) echo " selected";
258 echo ">" . $brow['code'] . " " . substr($brow['code_text'], 0, 40) . "</option>\n";
261 </select>
262 </td>
263 </tr>
265 <tr>
266 <td valign='top' nowrap><b>Occurrence:</b></td>
267 <td>
268 <select name='form_occur'>
270 foreach ($arroccur as $key => $value) {
271 echo " <option value='$key'";
272 if ($key == $irow['occurrence']) echo " selected";
273 echo ">$value\n";
276 </select>
277 </td>
278 </tr>
280 <? if ($GLOBALS['athletic_team']) { ?>
281 <tr>
282 <td valign='top' nowrap><b>Missed:</b></td>
283 <td>
284 <input type='text' size='3' name='form_missed' value='<? echo $irow['extrainfo'] ?>'
285 title='Number of games or events missed, if any' />
286 &nbsp;games/events
287 </td>
288 </tr>
289 <? } else { ?>
290 <tr>
291 <td valign='top' nowrap><b>Referred by:</b></td>
292 <td>
293 <input type='text' size='40' name='form_referredby' value='<? echo $irow['referredby'] ?>'
294 style='width:100%' title='Referring physician and practice' />
295 </td>
296 </tr>
297 <? } ?>
299 <tr>
300 <td valign='top' nowrap><b>Comments:</b></td>
301 <td>
302 <textarea name='form_comments' rows='4' cols='40' wrap='virtual' style='width:100%'><? echo $irow['comments'] ?></textarea>
303 </td>
304 </tr>
306 </table>
309 <input type='submit' name='form_save' value='Save' />
310 &nbsp;
311 <input type='button' value='Cancel' onclick='window.close()' />
312 </p>
314 </center>
315 </form>
316 <script language='JavaScript'>
317 newtype(<? echo $type_index ?>);
318 </script>
319 </body>
320 </html>