simplified adding/removing issue types and added dental as a type
[openemr.git] / interface / patient_file / summary / add_edit_issue.php
blobf8e4082e9ef4bfa18b79093d6b509343f84f591e
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 $tmp = getPatientData($pid, "squad");
22 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
23 die("Not authorized for this squad!");
25 $arroccur = array(
26 0 => 'Unknown or N/A',
27 1 => 'First',
28 2 => 'Second',
29 3 => 'Third',
30 4 => 'Chronic/Recurrent',
31 5 => 'Acute on Chronic'
34 function QuotedOrNull($fld) {
35 if ($fld) return "'$fld'";
36 return "NULL";
40 <html>
41 <head>
42 <title><? echo $issue ? "Edit" : "Add New" ?> Issue</title>
43 <link rel=stylesheet href='<? echo $css_header ?>' type='text/css'>
45 <style>
46 td { font-size:10pt; }
47 </style>
49 <script type="text/javascript" src="../../../library/overlib_mini.js"></script>
50 <script type="text/javascript" src="../../../library/calendar.js"></script>
51 <script type="text/javascript" src="../../../library/textformat.js"></script>
53 <script language="JavaScript">
55 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
57 var aopts = new Array();
59 // "Clickoptions" is a feature by Mark Leeds that provides for one-click
60 // access to preselected lists of issues in each category. Here we get
61 // the issue titles from the user-customizable file and write JavaScript
62 // statements that will build an array of arrays of Option objects.
64 $clickoptions = array();
65 if (is_file("../../../custom/clickoptions.txt"))
66 $clickoptions = file("../../../custom/clickoptions.txt");
67 $i = 0;
68 foreach ($ISSUE_TYPES as $key => $value) {
69 echo " aopts[$i] = new Array();\n";
70 foreach($clickoptions as $line) {
71 $line = trim($line);
72 if (substr($line, 0, 1) != "#") {
73 if (strpos($line, $key) !== false) {
74 $text = addslashes(substr($line, strpos($line, "::") + 2));
75 echo " aopts[$i][aopts[$i].length] = new Option('$text', '$text', false, false);\n";
79 ++$i;
83 // React to selection of an issue type. This loads the associated
84 // shortcuts into the selection list of titles.
85 function newtype(index) {
86 var theopts = document.forms[0].form_titles.options;
87 theopts.length = 0;
88 for (i = 0; i < aopts[index].length; ++i) {
89 theopts[i] = aopts[index][i];
93 // If a clickoption title is selected, copy it to the title field.
94 function set_text() {
95 var f = document.forms[0];
96 f.form_title.value = f.form_titles.options[f.form_titles.selectedIndex].text;
97 f.form_titles.selectedIndex = -1;
100 </script>
102 </head>
104 <body <?echo $top_bg_line;?>>
106 // If we are saving, then save and close the window.
108 if ($_POST['form_save']) {
110 $i = 0;
111 $text_type = "unknown";
112 foreach ($ISSUE_TYPES as $key => $value) {
113 if ($i++ == $_POST['form_type']) $text_type = $key;
116 $form_begin = fixDate($_POST['form_begin'], '');
117 $form_end = fixDate($_POST['form_end'], '');
119 if ($issue) {
120 sqlStatement("UPDATE lists SET " .
121 "type = '" . $text_type . "', " .
122 "title = '" . $_POST['form_title'] . "', " .
123 "comments = '" . $_POST['form_comments'] . "', " .
124 "begdate = " . QuotedOrNull($form_begin) . ", " .
125 "enddate = " . QuotedOrNull($form_end) . ", " .
126 "diagnosis = '" . $_POST['form_diagnosis'] . "', " .
127 "occurrence = '" . $_POST['form_occur'] . "', " .
128 "referredby = '" . $_POST['form_referredby'] . "', " .
129 "extrainfo = '" . $_POST['form_missed'] . "' " .
130 "WHERE id = '$issue'");
131 } else {
132 $issue = sqlInsert("INSERT INTO lists ( " .
133 "date, pid, type, title, activity, comments, begdate, enddate, " .
134 "diagnosis, occurrence, referredby, extrainfo, user, groupname " .
135 ") VALUES ( " .
136 "NOW(), " .
137 "'$pid', " .
138 "'" . $text_type . "', " .
139 "'" . $_POST['form_title'] . "', " .
140 "1, " .
141 "'" . $_POST['form_comments'] . "', " .
142 QuotedOrNull($form_begin) . ", " .
143 QuotedOrNull($form_end) . ", " .
144 "'" . $_POST['form_diagnosis'] . "', " .
145 "'" . $_POST['form_occur'] . "', " .
146 "'" . $_POST['form_referredby'] . "', " .
147 "'" . $_POST['form_missed'] . "', " .
148 "'" . $$_SESSION['authUser'] . "', " .
149 "'" . $$_SESSION['authProvider'] . "' )");
152 $tmp_title = $ISSUE_TYPES[$text_type][2] . ": $form_begin " .
153 substr($_POST['form_title'], 0, 40);
155 // Close this window and redisplay the updated list of issues.
157 echo "<script language='JavaScript'>\n";
158 if ($info_msg) echo " alert('$info_msg');\n";
159 echo " window.close();\n";
160 // echo " opener.location.reload();\n";
161 echo " if (opener.refreshIssue) opener.refreshIssue($issue,'$tmp_title');\n";
162 echo "</script></body></html>\n";
163 exit();
166 $irow = array();
167 $type_index = 0;
169 if ($issue) {
170 $irow = sqlQuery("SELECT * FROM lists WHERE id = $issue");
171 foreach ($ISSUE_TYPES as $key => $value) {
172 if ($key == $irow['type']) break;
173 ++$type_index;
175 // Get all of the eligible diagnoses.
176 // We include the pid in this search for better performance,
177 // because it's part of the primary key:
178 $bres = sqlStatement(
179 "SELECT DISTINCT billing.code, billing.code_text " .
180 "FROM issue_encounter, billing WHERE " .
181 "issue_encounter.pid = '$pid' AND " .
182 "issue_encounter.list_id = '$issue' AND " .
183 "billing.encounter = issue_encounter.encounter AND " .
184 "( billing.code_type LIKE 'ICD%' OR " .
185 "billing.code_type LIKE 'OSICS' )"
189 <!-- Required for the popup date selectors -->
190 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
192 <form method='post' name='theform' action='add_edit_issue.php?issue=<? echo $issue ?>'>
193 <center>
195 <table border='0' width='100%'>
197 <tr>
198 <td valign='top' width='1%' nowrap><b>Type:</b></td>
199 <td>
201 $index = 0;
202 foreach ($ISSUE_TYPES as $value) {
203 echo " <input type='radio' name='form_type' value='$index' onclick='newtype($index)'";
204 if ($index == $type_index) echo " checked";
205 echo " />" . $value[1] . "&nbsp;\n";
206 ++$index;
209 </td>
210 </tr>
212 <tr>
213 <td valign='top' nowrap><b>Title:</b></td>
214 <td>
215 <select name='form_titles' size='4' onchange='set_text()' style='width:100%'>
216 </select><br>
217 <input type='text' size='40' name='form_title' value='<? echo $irow['title'] ?>' style='width:100%' />
218 </td>
219 </tr>
221 <tr>
222 <td valign='top' nowrap><b>Begin Date:</b></td>
223 <td>
224 <input type='text' size='10' name='form_begin' value='<? echo $irow['begdate'] ?>'
225 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
226 title='yyyy-mm-dd date of onset, surgery or start of medication' />
227 <a href="javascript:show_calendar('theform.form_begin')"
228 title="Click here to choose a date"
229 ><img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
230 </td>
231 </tr>
233 <tr>
234 <td valign='top' nowrap><b>End Date:</b></td>
235 <td>
236 <input type='text' size='10' name='form_end' value='<? echo $irow['enddate'] ?>'
237 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
238 title='yyyy-mm-dd date of recovery or end of medication' />
239 <a href="javascript:show_calendar('theform.form_end')"
240 title="Click here to choose a date"
241 ><img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
242 &nbsp;(leave blank if still active)
243 </td>
244 </tr>
246 <tr>
247 <td valign='top' nowrap><b>Diagnosis:</b></td>
248 <td>
249 <select name='form_diagnosis' title='Diagnosis must be coded into a linked encounter'>
250 <option value="">Unknown or N/A</option>
252 while ($brow = sqlFetchArray($bres)) {
253 echo " <option value='" . $brow['code'] . "'";
254 if ($brow['code'] == $irow['diagnosis']) echo " selected";
255 echo ">" . $brow['code'] . " " . substr($brow['code_text'], 0, 40) . "</option>\n";
258 </select>
259 </td>
260 </tr>
262 <tr>
263 <td valign='top' nowrap><b>Occurrence:</b></td>
264 <td>
265 <select name='form_occur'>
267 foreach ($arroccur as $key => $value) {
268 echo " <option value='$key'";
269 if ($key == $irow['occurrence']) echo " selected";
270 echo ">$value\n";
273 </select>
274 </td>
275 </tr>
277 <? if ($GLOBALS['athletic_team']) { ?>
278 <tr>
279 <td valign='top' nowrap><b>Missed:</b></td>
280 <td>
281 <input type='text' size='3' name='form_missed' value='<? echo $irow['extrainfo'] ?>'
282 title='Number of games or events missed, if any' />
283 &nbsp;games/events
284 </td>
285 </tr>
286 <? } else { ?>
287 <tr>
288 <td valign='top' nowrap><b>Referred by:</b></td>
289 <td>
290 <input type='text' size='40' name='form_referredby' value='<? echo $irow['referredby'] ?>'
291 style='width:100%' title='Referring physician and practice' />
292 </td>
293 </tr>
294 <? } ?>
296 <tr>
297 <td valign='top' nowrap><b>Comments:</b></td>
298 <td>
299 <textarea name='form_comments' rows='4' cols='40' wrap='virtual' style='width:100%'><? echo $irow['comments'] ?></textarea>
300 </td>
301 </tr>
303 </table>
306 <input type='submit' name='form_save' value='Save' />
307 &nbsp;
308 <input type='button' value='Cancel' onclick='window.close()' />
309 </p>
311 </center>
312 </form>
313 <script language='JavaScript'>
314 newtype(<? echo $type_index ?>);
315 </script>
316 </body>
317 </html>