some optimization for IPPF forms
[openemr.git] / interface / patient_file / summary / add_edit_issue.php
blob17d035ac32d90e10ab511b9fe32285d68394a45e
1 <?php
2 // Copyright (C) 2005-2008 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 require_once("../../globals.php");
10 require_once("$srcdir/lists.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/acl.inc");
14 if ($ISSUE_TYPES['football_injury']) {
15 // Most of the logic for the "football injury" issue type comes from this
16 // included script. We might eventually refine this approach to support
17 // a plug-in architecture for custom issue types.
18 require_once("$srcdir/football_injury.inc.php");
20 if ($ISSUE_TYPES['ippf_gcac']) {
21 // Similarly for IPPF issues.
22 require_once("$srcdir/ippf_issues.inc.php");
25 $diagnosis_type = $GLOBALS['athletic_team'] ? 'OSICS10' : 'ICD9';
27 $issue = $_REQUEST['issue'];
28 $thispid = $_REQUEST['thispid'] ? $_REQUEST['thispid'] : $pid;
29 $info_msg = "";
31 $thisauth = acl_check('patients', 'med');
32 if ($issue && $thisauth != 'write') die("Edit is not authorized!");
33 if ($thisauth != 'write' && $thisauth != 'addonly') die("Add is not authorized!");
35 $tmp = getPatientData($thispid, "squad");
36 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
37 die("Not authorized for this squad!");
39 function QuotedOrNull($fld) {
40 if ($fld) return "'$fld'";
41 return "NULL";
44 function rbvalue($rbname) {
45 $tmp = $_POST[$rbname];
46 if (! $tmp) $tmp = '0';
47 return "'$tmp'";
50 function cbvalue($cbname) {
51 return $_POST[$cbname] ? '1' : '0';
54 function invalue($inname) {
55 return (int) trim($_POST[$inname]);
58 function txvalue($txname) {
59 return "'" . trim($_POST[$txname]) . "'";
62 function rbinput($name, $value, $desc, $colname) {
63 global $irow;
64 $ret = "<input type='radio' name='$name' value='$value'";
65 if ($irow[$colname] == $value) $ret .= " checked";
66 $ret .= " />$desc";
67 return $ret;
70 function rbcell($name, $value, $desc, $colname) {
71 return "<td width='25%' nowrap>" . rbinput($name, $value, $desc, $colname) . "</td>\n";
74 // If we are saving, then save and close the window.
76 if ($_POST['form_save']) {
78 $i = 0;
79 $text_type = "unknown";
80 foreach ($ISSUE_TYPES as $key => $value) {
81 if ($i++ == $_POST['form_type']) $text_type = $key;
84 $form_begin = fixDate($_POST['form_begin'], '');
85 $form_end = fixDate($_POST['form_end'], '');
87 if ($issue) {
89 $query = "UPDATE lists SET " .
90 "type = '" . $text_type . "', " .
91 "title = '" . $_POST['form_title'] . "', " .
92 "comments = '" . $_POST['form_comments'] . "', " .
93 "begdate = " . QuotedOrNull($form_begin) . ", " .
94 "enddate = " . QuotedOrNull($form_end) . ", " .
95 "returndate = " . QuotedOrNull($form_return) . ", " .
96 "diagnosis = '" . $_POST['form_diagnosis'] . "', " .
97 "occurrence = '" . $_POST['form_occur'] . "', " .
98 "classification = '" . $_POST['form_classification'] . "', " .
99 "referredby = '" . $_POST['form_referredby'] . "', " .
100 "extrainfo = '" . $_POST['form_missed'] . "', " .
101 "outcome = " . rbvalue('form_outcome') . ", " .
102 // "destination = " . rbvalue('form_destination') . " " . // radio button version
103 "destination = '" . $_POST['form_destination'] . "' " .
104 "WHERE id = '$issue'";
105 sqlStatement($query);
106 if ($text_type == "medication" && enddate != '') {
107 sqlStatement('UPDATE prescriptions SET '
108 . 'medication = 0 where patient_id = ' . $thispid
109 . " and upper(trim(drug)) = '" . strtoupper($_POST['form_title']) . "' "
110 . ' and medication = 1' );
113 } else {
115 $issue = sqlInsert("INSERT INTO lists ( " .
116 "date, pid, type, title, activity, comments, begdate, enddate, returndate, " .
117 "diagnosis, occurrence, classification, referredby, extrainfo, user, groupname, " .
118 "outcome, destination " .
119 ") VALUES ( " .
120 "NOW(), " .
121 "'$thispid', " .
122 "'" . $text_type . "', " .
123 "'" . $_POST['form_title'] . "', " .
124 "1, " .
125 "'" . $_POST['form_comments'] . "', " .
126 QuotedOrNull($form_begin) . ", " .
127 QuotedOrNull($form_end) . ", " .
128 QuotedOrNull($form_return) . ", " .
129 "'" . $_POST['form_diagnosis'] . "', " .
130 "'" . $_POST['form_occur'] . "', " .
131 "'" . $_POST['form_classification'] . "', " .
132 "'" . $_POST['form_referredby'] . "', " .
133 "'" . $_POST['form_missed'] . "', " .
134 "'" . $$_SESSION['authUser'] . "', " .
135 "'" . $$_SESSION['authProvider'] . "', " .
136 rbvalue('form_outcome') . ", " .
137 // rbvalue('form_destination') . " " . // radio button version
138 "'" . $_POST['form_destination'] . "' " .
139 ")");
143 if ($text_type == 'football_injury') issue_football_injury_save($issue);
144 if ($text_type == 'ippf_gcac' ) issue_ippf_gcac_save($issue);
145 if ($text_type == 'contraceptive' ) issue_ippf_con_save($issue);
146 // if ($text_type == 'ippf_srh' ) issue_ippf_srh_save($issue);
148 $tmp_title = $ISSUE_TYPES[$text_type][2] . ": $form_begin " .
149 substr($_POST['form_title'], 0, 40);
151 // Close this window and redisplay the updated list of issues.
153 echo "<html><body><script language='JavaScript'>\n";
154 if ($info_msg) echo " alert('$info_msg');\n";
155 echo " window.close();\n";
156 // echo " opener.location.reload();\n";
157 echo " if (opener.refreshIssue) opener.refreshIssue($issue,'$tmp_title');\n";
158 echo "</script></body></html>\n";
159 exit();
162 $irow = array();
163 $type_index = 0;
165 if ($issue) {
166 $irow = sqlQuery("SELECT * FROM lists WHERE id = $issue");
167 foreach ($ISSUE_TYPES as $key => $value) {
168 if ($key == $irow['type']) break;
169 ++$type_index;
172 /*******************************************************************
173 // Get all of the eligible diagnoses.
174 // We include the pid in this search for better performance,
175 // because it's part of the primary key:
176 $bres = sqlStatement(
177 "SELECT DISTINCT billing.code, billing.code_text " .
178 "FROM issue_encounter, billing WHERE " .
179 "issue_encounter.pid = '$thispid' AND " .
180 "issue_encounter.list_id = '$issue' AND " .
181 "billing.encounter = issue_encounter.encounter AND " .
182 "( billing.code_type LIKE 'ICD%' OR " .
183 "billing.code_type LIKE 'OSICS' OR " .
184 "billing.code_type LIKE 'UCSMC' )"
186 *******************************************************************/
190 <html>
191 <head>
192 <?php html_header_show();?>
193 <title><?php echo $issue ? "Edit" : "Add New" ?><?php xl('Issue','e'); ?></title>
194 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
196 <style>
198 td, input, select, textarea {
199 font-family: Arial, Helvetica, sans-serif;
200 font-size: 10pt;
203 div.section {
204 border: solid;
205 border-width: 1px;
206 border-color: #0000ff;
207 margin: 0 0 0 10pt;
208 padding: 5pt;
211 </style>
213 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
214 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
215 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
216 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
217 <script type="text/javascript" src="../../../library/textformat.js"></script>
218 <script type="text/javascript" src="../../../library/dialog.js"></script>
220 <script language="JavaScript">
222 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
224 var aitypes = new Array(); // issue type attributes
225 var aopts = new Array(); // Option objects
226 <?php
227 // "Clickoptions" is a feature by Mark Leeds that provides for one-click
228 // access to preselected lists of issues in each category. Here we get
229 // the issue titles from the user-customizable file and write JavaScript
230 // statements that will build an array of arrays of Option objects.
232 $clickoptions = array();
233 if (is_file("../../../custom/clickoptions.txt"))
234 $clickoptions = file("../../../custom/clickoptions.txt");
235 $i = 0;
236 foreach ($ISSUE_TYPES as $key => $value) {
237 echo " aitypes[$i] = " . $value[3] . ";\n";
238 echo " aopts[$i] = new Array();\n";
239 foreach($clickoptions as $line) {
240 $line = trim($line);
241 if (substr($line, 0, 1) != "#") {
242 if (strpos($line, $key) !== false) {
243 $text = addslashes(substr($line, strpos($line, "::") + 2));
244 echo " aopts[$i][aopts[$i].length] = new Option('$text', '$text', false, false);\n";
248 ++$i;
252 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
254 // React to selection of an issue type. This loads the associated
255 // shortcuts into the selection list of titles, and determines which
256 // rows are displayed or hidden.
257 function newtype(index) {
258 var f = document.forms[0];
259 var theopts = f.form_titles.options;
260 theopts.length = 0;
261 var i = 0;
262 for (i = 0; i < aopts[index].length; ++i) {
263 theopts[i] = aopts[index][i];
265 document.getElementById('row_titles').style.display = i ? '' : 'none';
266 // Show or hide various rows depending on issue type, except do not
267 // hide the comments or referred-by fields if they have data.
268 var comdisp = (aitypes[index] == 1) ? 'none' : '';
269 var revdisp = (aitypes[index] == 1) ? '' : 'none';
270 var injdisp = (aitypes[index] == 2) ? '' : 'none';
271 document.getElementById('row_enddate' ).style.display = comdisp;
272 document.getElementById('row_active' ).style.display = revdisp;
273 document.getElementById('row_diagnosis' ).style.display = comdisp;
274 document.getElementById('row_occurrence' ).style.display = comdisp;
275 document.getElementById('row_classification').style.display = injdisp;
276 document.getElementById('row_referredby' ).style.display = (f.form_referredby.value) ? '' : comdisp;
277 document.getElementById('row_comments' ).style.display = (f.form_comments.value ) ? '' : revdisp;
278 <?php if ($GLOBALS['athletic_team']) { ?>
279 document.getElementById('row_returndate').style.display = comdisp;
280 document.getElementById('row_missed' ).style.display = comdisp;
281 <?php } ?>
282 <?php
283 if ($ISSUE_TYPES['football_injury']) {
284 // Generate more of these for football injury fields.
285 issue_football_injury_newtype();
287 if ($ISSUE_TYPES['ippf_gcac'] && !$_POST['form_save']) {
288 // Generate more of these for gcac and contraceptive fields.
289 if (empty($issue) || $irow['type'] == 'ippf_gcac' ) issue_ippf_gcac_newtype();
290 if (empty($issue) || $irow['type'] == 'contraceptive') issue_ippf_con_newtype();
291 // if (empty($issue) || $irow['type'] == 'ippf_srh' ) issue_ippf_srh_newtype();
296 // If a clickoption title is selected, copy it to the title field.
297 function set_text() {
298 var f = document.forms[0];
299 f.form_title.value = f.form_titles.options[f.form_titles.selectedIndex].text;
300 f.form_titles.selectedIndex = -1;
303 // Process click on Delete link.
304 function deleteme() {
305 dlgopen('../deleter.php?issue=<?php echo $issue ?>', '_blank', 500, 450);
306 return false;
309 // Called by the deleteme.php window on a successful delete.
310 function imdeleted() {
311 window.close();
314 // Called when the Active checkbox is clicked. For consistency we
315 // use the existence of an end date to indicate inactivity, even
316 // though the simple verion of the form does not show an end date.
317 function activeClicked(cb) {
318 var f = document.forms[0];
319 if (cb.checked) {
320 f.form_end.value = '';
321 } else {
322 var today = new Date();
323 f.form_end.value = '' + (today.getYear() + 1900) + '-' +
324 (today.getMonth() + 1) + '-' + today.getDate();
328 // This is for callback by the find-code popup.
329 // Appends to or erases the current list of diagnoses.
330 function set_related(codetype, code, selector, codedesc) {
331 var f = document.forms[0];
332 var s = f.form_diagnosis.value;
333 if (code) {
334 if (s.length > 0) s += ';';
335 s += codetype + ':' + code;
336 } else {
337 s = '';
339 f.form_diagnosis.value = s;
342 // This invokes the find-code popup.
343 function sel_diagnosis() {
344 dlgopen('../encounter/find_code_popup.php?codetype=<?php echo $diagnosis_type ?>', '_blank', 500, 400);
347 // Check for errors when the form is submitted.
348 function validate() {
349 var f = document.forms[0];
350 if (! f.form_title.value) {
351 alert('Please enter a title!');
352 return false;
354 top.restoreSession();
355 return true;
358 // Supports customizable forms (currently just for IPPF).
359 function divclick(cb, divid) {
360 var divstyle = document.getElementById(divid).style;
361 if (cb.checked) {
362 divstyle.display = 'block';
363 } else {
364 divstyle.display = 'none';
366 return true;
369 </script>
371 </head>
373 <body class="body_top" style="padding-right:0.5em">
375 <form method='post' name='theform' action='add_edit_issue.php?issue=<?php echo $issue ?>'
376 onsubmit='return validate()'>
378 <table border='0' width='100%'>
380 <tr>
381 <td valign='top' width='1%' nowrap><b><?php xl('Type','e'); ?>:</b></td>
382 <td>
383 <?php
384 $index = 0;
385 foreach ($ISSUE_TYPES as $value) {
386 if ($issue) {
387 if ($index == $type_index) {
388 echo $value[1];
389 echo "<input type='hidden' name='form_type' value='$index'>\n";
391 } else {
392 echo " <input type='radio' name='form_type' value='$index' onclick='newtype($index)'";
393 if ($index == $type_index) echo " checked";
394 echo " />" . $value[1] . "&nbsp;\n";
396 ++$index;
399 </td>
400 </tr>
402 <tr id='row_titles'>
403 <td valign='top' nowrap>&nbsp;</td>
404 <td valign='top'>
405 <select name='form_titles' size='4' onchange='set_text()'>
406 </select> (Select one of these, or type your own title)
407 </td>
408 </tr>
410 <tr>
411 <td valign='top' nowrap><b><?php xl('Title','e'); ?>:</b></td>
412 <td>
413 <input type='text' size='40' name='form_title' value='<?php echo $irow['title'] ?>' style='width:100%' />
414 </td>
415 </tr>
417 <tr>
418 <td valign='top' nowrap><b><?php xl('Begin Date','e'); ?>:</b></td>
419 <td>
421 <input type='text' size='10' name='form_begin' id='form_begin'
422 value='<?php echo $irow['begdate'] ?>'
423 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
424 title='<?php xl('yyyy-mm-dd date of onset, surgery or start of medication','e'); ?>' />
425 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
426 id='img_begin' border='0' alt='[?]' style='cursor:pointer'
427 title='<?php xl('Click here to choose a date','e'); ?>' />
428 </td>
429 </tr>
431 <tr id='row_enddate'>
432 <td valign='top' nowrap><b><?php xl('End Date','e'); ?>:</b></td>
433 <td>
434 <input type='text' size='10' name='form_end' id='form_end'
435 value='<?php echo $irow['enddate'] ?>'
436 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
437 title='<?php xl('yyyy-mm-dd date of recovery or end of medication','e'); ?>' />
438 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
439 id='img_end' border='0' alt='[?]' style='cursor:pointer'
440 title='<?php xl('Click here to choose a date','e'); ?>' />
441 &nbsp;(<?php xl('leave blank if still active','e'); ?>)
442 </td>
443 </tr>
445 <tr id='row_active'>
446 <td valign='top' nowrap><b><?php xl('Active','e'); ?>:</b></td>
447 <td>
448 <input type='checkbox' name='form_active' value='1' <?php echo $irow['enddate'] ? "" : "checked"; ?>
449 onclick='activeClicked(this);'
450 title='<?php xl('Indicates if this issue is currently active','e'); ?>' />
451 </td>
452 </tr>
454 <tr<?php if (! $GLOBALS['athletic_team']) echo " style='display:none;'"; ?> id='row_returndate'>
455 <td valign='top' nowrap><b><?php xl('Returned to Play','e'); ?>:</b></td>
456 <td>
457 <input type='text' size='10' name='form_return' id='form_return'
458 value='<?php echo $irow['returndate'] ?>'
459 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
460 title='<?php xl('yyyy-mm-dd date returned to play','e'); ?>' />
461 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
462 id='img_return' border='0' alt='[?]' style='cursor:pointer'
463 title='<?php xl('Click here to choose a date','e'); ?>' />
464 &nbsp;(<?php xl('leave blank if still active','e'); ?>)
465 </td>
466 </tr>
468 <tr id='row_diagnosis'>
469 <td valign='top' nowrap><b><?php xl('Diagnosis','e'); ?>:</b></td>
470 <td>
472 <?php /************************************************************ ?>
473 <select name='form_diagnosis' title='<?php xl('Diagnosis must be coded into a linked encounter','e'); ?>'>
474 <option value=""><?php xl('Unknown or N/A','e'); ?></option>
475 <?php
476 while ($brow = sqlFetchArray($bres)) {
477 echo " <option value='" . $brow['code'] . "'";
478 if ($brow['code'] == $irow['diagnosis']) echo " selected";
479 echo ">" . $brow['code'] . " " . substr($brow['code_text'], 0, 40) . "</option>\n";
482 </select>
483 <?php ************************************************************/ ?>
485 <input type='text' size='50' name='form_diagnosis'
486 value='<?php echo $irow['diagnosis'] ?>' onclick='sel_diagnosis()'
487 title='<?php xl('Click to select or change diagnoses','e'); ?>'
488 style='width:100%' readonly />
490 </td>
491 </tr>
493 <tr id='row_occurrence'>
494 <td valign='top' nowrap><b><?php xl('Occurrence','e'); ?>:</b></td>
495 <td>
496 <select name='form_occur'>
497 <?php
498 foreach ($ISSUE_OCCURRENCES as $key => $value) {
499 echo " <option value='$key'";
500 if ($key == $irow['occurrence']) echo " selected";
501 echo ">$value\n";
504 </select>
505 </td>
506 </tr>
508 <tr id='row_classification'>
509 <td valign='top' nowrap><b><?php xl('Classification','e'); ?>:</b></td>
510 <td>
511 <select name='form_classification'>
512 <?php
513 foreach ($ISSUE_CLASSIFICATIONS as $key => $value) {
514 echo " <option value='$key'";
515 if ($key == $irow['classification']) echo " selected";
516 echo ">$value\n";
519 </select>
520 </td>
521 </tr>
523 <tr<?php if (! $GLOBALS['athletic_team']) echo " style='display:none;'"; ?> id='row_missed'>
524 <td valign='top' nowrap><b><?php xl('Missed','e'); ?>:</b></td>
525 <td>
526 <input type='text' size='3' name='form_missed' value='<?php echo $irow['extrainfo'] ?>'
527 title='<?php xl('Number of games or events missed, if any','e'); ?>' />
528 &nbsp;<?php xl('games/events','e'); ?>
529 </td>
530 </tr>
532 <tr<?php if ($GLOBALS['athletic_team']) echo " style='display:none;'"; ?> id='row_referredby'>
533 <td valign='top' nowrap><b><?php xl('Referred by','e'); ?>:</b></td>
534 <td>
535 <input type='text' size='40' name='form_referredby' value='<?php echo $irow['referredby'] ?>'
536 style='width:100%' title='<?php xl('Referring physician and practice','e'); ?>' />
537 </td>
538 </tr>
540 <tr id='row_comments'>
541 <td valign='top' nowrap><b><?php xl('Comments','e'); ?>:</b></td>
542 <td>
543 <textarea name='form_comments' rows='4' cols='40' wrap='virtual' style='width:100%'><?php echo $irow['comments'] ?></textarea>
544 </td>
545 </tr>
547 <tr<?php if ($GLOBALS['athletic_team'] || $GLOBALS['ippf_specific']) echo " style='display:none;'"; ?>>
548 <td valign='top' nowrap><b><?php xl('Outcome','e'); ?>:</b></td>
549 <td>
550 <?php echo rbinput('form_outcome', '1', 'Resolved' , 'outcome') ?>&nbsp;
551 <?php echo rbinput('form_outcome', '2', 'Improved' , 'outcome') ?>&nbsp;
552 <?php echo rbinput('form_outcome', '3', 'Status quo' , 'outcome') ?>&nbsp;
553 <?php echo rbinput('form_outcome', '4', 'Worse' , 'outcome') ?>&nbsp;
554 <?php echo rbinput('form_outcome', '5', 'Pending followup', 'outcome') ?>
555 </td>
556 </tr>
558 <tr<?php if ($GLOBALS['athletic_team'] || $GLOBALS['ippf_specific']) echo " style='display:none;'"; ?>>
559 <td valign='top' nowrap><b><?php xl('Destination','e'); ?>:</b></td>
560 <td>
561 <?php if (true) { ?>
562 <input type='text' size='40' name='form_destination' value='<?php echo $irow['destination'] ?>'
563 style='width:100%' title='GP, Secondary care specialist, etc.' />
564 <?php } else { // leave this here for now, please -- Rod ?>
565 <?php echo rbinput('form_destination', '1', 'GP' , 'destination') ?>&nbsp;
566 <?php echo rbinput('form_destination', '2', 'Secondary care spec', 'destination') ?>&nbsp;
567 <?php echo rbinput('form_destination', '3', 'GP via physio' , 'destination') ?>&nbsp;
568 <?php echo rbinput('form_destination', '4', 'GP via podiatry' , 'destination') ?>
569 <?php } ?>
570 </td>
571 </tr>
573 </table>
575 <?php
576 if ($ISSUE_TYPES['football_injury']) {
577 issue_football_injury_form($issue);
579 if ($ISSUE_TYPES['ippf_gcac']) {
580 if (empty($issue) || $irow['type'] == 'ippf_gcac')
581 issue_ippf_gcac_form($issue, $thispid);
582 if (empty($issue) || $irow['type'] == 'contraceptive')
583 issue_ippf_con_form($issue, $thispid);
584 // if (empty($issue) || $irow['type'] == 'ippf_srh')
585 // issue_ippf_srh_form($issue, $thispid);
589 <center>
592 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
594 <?php if ($issue && acl_check('admin', 'super')) { ?>
595 &nbsp;
596 <input type='button' value='<?php xl('Delete','e'); ?>' style='color:red' onclick='deleteme()' />
597 <?php } ?>
599 &nbsp;
600 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
602 </p>
603 </center>
605 </form>
606 <script language='JavaScript'>
607 newtype(<?php echo $type_index ?>);
608 Calendar.setup({inputField:"form_begin", ifFormat:"%Y-%m-%d", button:"img_begin"});
609 Calendar.setup({inputField:"form_end", ifFormat:"%Y-%m-%d", button:"img_end"});
610 Calendar.setup({inputField:"form_return", ifFormat:"%Y-%m-%d", button:"img_return"});
611 </script>
612 </body>
613 </html>