2 // Copyright (C) 2005-2009 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 require_once("../../globals.php");
10 require_once("$srcdir/lists.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/acl.inc");
13 require_once("$srcdir/options.inc.php");
15 if ($ISSUE_TYPES['football_injury']) {
16 // Most of the logic for the "football injury" issue type comes from this
17 // included script. We might eventually refine this approach to support
18 // a plug-in architecture for custom issue types.
19 require_once("$srcdir/football_injury.inc.php");
21 if ($ISSUE_TYPES['ippf_gcac']) {
22 // Similarly for IPPF issues.
23 require_once("$srcdir/ippf_issues.inc.php");
26 $diagnosis_type = $GLOBALS['athletic_team'] ?
'OSICS10' : 'ICD9';
28 $issue = $_REQUEST['issue'];
29 $thispid = 0 +
(empty($_REQUEST['thispid']) ?
$pid : $_REQUEST['thispid']);
32 // A nonempty thisenc means we are to link the issue to the encounter.
33 $thisenc = 0 +
(empty($_REQUEST['thisenc']) ?
0 : $_REQUEST['thisenc']);
35 // A nonempty thistype is an issue type to be forced for a new issue.
36 $thistype = empty($_REQUEST['thistype']) ?
'' : $_REQUEST['thistype'];
38 $thisauth = acl_check('patients', 'med');
39 if ($issue && $thisauth != 'write') die("Edit is not authorized!");
40 if ($thisauth != 'write' && $thisauth != 'addonly') die("Add is not authorized!");
42 $tmp = getPatientData($thispid, "squad");
43 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
44 die("Not authorized for this squad!");
46 function QuotedOrNull($fld) {
47 if ($fld) return "'$fld'";
51 function rbvalue($rbname) {
52 $tmp = $_POST[$rbname];
53 if (! $tmp) $tmp = '0';
57 function cbvalue($cbname) {
58 return $_POST[$cbname] ?
'1' : '0';
61 function invalue($inname) {
62 return (int) trim($_POST[$inname]);
65 function txvalue($txname) {
66 return "'" . trim($_POST[$txname]) . "'";
69 function rbinput($name, $value, $desc, $colname) {
71 $ret = "<input type='radio' name='$name' value='$value'";
72 if ($irow[$colname] == $value) $ret .= " checked";
77 function rbcell($name, $value, $desc, $colname) {
78 return "<td width='25%' nowrap>" . rbinput($name, $value, $desc, $colname) . "</td>\n";
81 // If we are saving, then save and close the window.
83 if ($_POST['form_save']) {
86 $text_type = "unknown";
87 foreach ($ISSUE_TYPES as $key => $value) {
88 if ($i++
== $_POST['form_type']) $text_type = $key;
91 $form_begin = fixDate($_POST['form_begin'], '');
92 $form_end = fixDate($_POST['form_end'], '');
96 $query = "UPDATE lists SET " .
97 "type = '" . $text_type . "', " .
98 "title = '" . $_POST['form_title'] . "', " .
99 "comments = '" . $_POST['form_comments'] . "', " .
100 "begdate = " . QuotedOrNull($form_begin) . ", " .
101 "enddate = " . QuotedOrNull($form_end) . ", " .
102 "returndate = " . QuotedOrNull($form_return) . ", " .
103 "diagnosis = '" . $_POST['form_diagnosis'] . "', " .
104 "occurrence = '" . $_POST['form_occur'] . "', " .
105 "classification = '" . $_POST['form_classification'] . "', " .
106 "referredby = '" . $_POST['form_referredby'] . "', " .
107 "extrainfo = '" . $_POST['form_missed'] . "', " .
108 "outcome = '" . $_POST['form_outcome'] . "', " .
109 // "destination = " . rbvalue('form_destination') . " " . // radio button version
110 "destination = '" . $_POST['form_destination'] . "' " .
111 "WHERE id = '$issue'";
112 sqlStatement($query);
113 if ($text_type == "medication" && enddate
!= '') {
114 sqlStatement('UPDATE prescriptions SET '
115 . 'medication = 0 where patient_id = ' . $thispid
116 . " and upper(trim(drug)) = '" . strtoupper($_POST['form_title']) . "' "
117 . ' and medication = 1' );
122 $issue = sqlInsert("INSERT INTO lists ( " .
123 "date, pid, type, title, activity, comments, begdate, enddate, returndate, " .
124 "diagnosis, occurrence, classification, referredby, extrainfo, user, groupname, " .
125 "outcome, destination " .
129 "'" . $text_type . "', " .
130 "'" . $_POST['form_title'] . "', " .
132 "'" . $_POST['form_comments'] . "', " .
133 QuotedOrNull($form_begin) . ", " .
134 QuotedOrNull($form_end) . ", " .
135 QuotedOrNull($form_return) . ", " .
136 "'" . $_POST['form_diagnosis'] . "', " .
137 "'" . $_POST['form_occur'] . "', " .
138 "'" . $_POST['form_classification'] . "', " .
139 "'" . $_POST['form_referredby'] . "', " .
140 "'" . $_POST['form_missed'] . "', " .
141 "'" . $
$_SESSION['authUser'] . "', " .
142 "'" . $
$_SESSION['authProvider'] . "', " .
143 "'" . $_POST['form_outcome'] . "', " .
144 // rbvalue('form_destination') . " " . // radio button version
145 "'" . $_POST['form_destination'] . "' " .
150 if ($text_type == 'football_injury') issue_football_injury_save($issue);
151 if ($text_type == 'ippf_gcac' ) issue_ippf_gcac_save($issue);
152 if ($text_type == 'contraceptive' ) issue_ippf_con_save($issue);
153 // if ($text_type == 'ippf_srh' ) issue_ippf_srh_save($issue);
155 // If requested, link the issue to a specified encounter.
157 $query = "INSERT INTO issue_encounter ( " .
158 "pid, list_id, encounter " .
160 "'$thispid', '$issue', '$thisenc'" .
162 sqlStatement($query);
165 $tmp_title = $ISSUE_TYPES[$text_type][2] . ": $form_begin " .
166 substr($_POST['form_title'], 0, 40);
168 // Close this window and redisplay the updated list of issues.
170 echo "<html><body><script language='JavaScript'>\n";
171 if ($info_msg) echo " alert('$info_msg');\n";
172 echo " window.close();\n";
173 // echo " opener.location.reload();\n";
174 echo " if (parent.refreshIssue) parent.refreshIssue($issue,'$tmp_title'); parent.$.fn.fancybox.close();\n";
175 echo "</script></body></html>\n";
181 $irow = sqlQuery("SELECT * FROM lists WHERE id = $issue");
183 $irow['type'] = $thistype;
187 if (!empty($irow['type'])) {
188 foreach ($ISSUE_TYPES as $key => $value) {
189 if ($key == $irow['type']) break;
193 /*******************************************************************
194 // Get all of the eligible diagnoses.
195 // We include the pid in this search for better performance,
196 // because it's part of the primary key:
197 $bres = sqlStatement(
198 "SELECT DISTINCT billing.code, billing.code_text " .
199 "FROM issue_encounter, billing WHERE " .
200 "issue_encounter.pid = '$thispid' AND " .
201 "issue_encounter.list_id = '$issue' AND " .
202 "billing.encounter = issue_encounter.encounter AND " .
203 "( billing.code_type LIKE 'ICD%' OR " .
204 "billing.code_type LIKE 'OSICS' OR " .
205 "billing.code_type LIKE 'UCSMC' )"
207 *******************************************************************/
213 <?php
html_header_show();?
>
214 <title
><?php
echo $issue ?
xl('Edit') : xl('Add New'); ?
><?php
xl('Issue','e',' '); ?
></title
>
215 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
219 td
, input
, select
, textarea
{
220 font
-family
: Arial
, Helvetica
, sans
-serif
;
227 border
-color
: #0000ff;
234 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
235 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
236 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
237 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
238 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
239 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
241 <script language
="JavaScript">
243 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
245 var aitypes
= new Array(); // issue type attributes
246 var aopts
= new Array(); // Option objects
248 // "Clickoptions" is a feature by Mark Leeds that provides for one-click
249 // access to preselected lists of issues in each category. Here we get
250 // the issue titles from the user-customizable file and write JavaScript
251 // statements that will build an array of arrays of Option objects.
253 $clickoptions = array();
254 if (is_file("../../../custom/clickoptions.txt"))
255 $clickoptions = file("../../../custom/clickoptions.txt");
257 foreach ($ISSUE_TYPES as $key => $value) {
258 echo " aitypes[$i] = " . $value[3] . ";\n";
259 echo " aopts[$i] = new Array();\n";
260 foreach($clickoptions as $line) {
262 if (substr($line, 0, 1) != "#") {
263 if (strpos($line, $key) !== false) {
264 $text = addslashes(substr($line, strpos($line, "::") +
2));
265 echo " aopts[$i][aopts[$i].length] = new Option('$text', '$text', false, false);\n";
273 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
275 // React to selection of an issue type. This loads the associated
276 // shortcuts into the selection list of titles, and determines which
277 // rows are displayed or hidden.
278 function newtype(index
) {
279 var f
= document
.forms
[0];
280 var theopts
= f
.form_titles
.options
;
283 for (i
= 0; i
< aopts
[index
].length
; ++i
) {
284 theopts
[i
] = aopts
[index
][i
];
286 document
.getElementById('row_titles').style
.display
= i ?
'' : 'none';
287 // Show or hide various rows depending on issue type, except do not
288 // hide the comments or referred-by fields if they have data.
289 var comdisp
= (aitypes
[index
] == 1) ?
'none' : '';
290 var revdisp
= (aitypes
[index
] == 1) ?
'' : 'none';
291 var injdisp
= (aitypes
[index
] == 2) ?
'' : 'none';
292 document
.getElementById('row_enddate' ).style
.display
= comdisp
;
293 document
.getElementById('row_active' ).style
.display
= revdisp
;
294 document
.getElementById('row_diagnosis' ).style
.display
= comdisp
;
295 document
.getElementById('row_occurrence' ).style
.display
= comdisp
;
296 document
.getElementById('row_classification').style
.display
= injdisp
;
297 document
.getElementById('row_referredby' ).style
.display
= (f
.form_referredby
.value
) ?
'' : comdisp
;
298 document
.getElementById('row_comments' ).style
.display
= (f
.form_comments
.value
) ?
'' : revdisp
;
299 <?php
if ($GLOBALS['athletic_team']) { ?
>
300 document
.getElementById('row_returndate').style
.display
= comdisp
;
301 document
.getElementById('row_missed' ).style
.display
= comdisp
;
304 if ($ISSUE_TYPES['football_injury']) {
305 // Generate more of these for football injury fields.
306 issue_football_injury_newtype();
308 if ($ISSUE_TYPES['ippf_gcac'] && !$_POST['form_save']) {
309 // Generate more of these for gcac and contraceptive fields.
310 if (empty($issue) ||
$irow['type'] == 'ippf_gcac' ) issue_ippf_gcac_newtype();
311 if (empty($issue) ||
$irow['type'] == 'contraceptive') issue_ippf_con_newtype();
312 // if (empty($issue) || $irow['type'] == 'ippf_srh' ) issue_ippf_srh_newtype();
317 // If a clickoption title is selected, copy it to the title field.
318 function set_text() {
319 var f
= document
.forms
[0];
320 f
.form_title
.value
= f
.form_titles
.options
[f
.form_titles
.selectedIndex
].text
;
321 f
.form_titles
.selectedIndex
= -1;
324 // Process click on Delete link.
325 function deleteme() {
326 dlgopen('../deleter.php?issue=<?php echo $issue ?>', '_blank', 500, 450);
330 // Called by the deleteme.php window on a successful delete.
331 function imdeleted() {
335 // Called when the Active checkbox is clicked. For consistency we
336 // use the existence of an end date to indicate inactivity, even
337 // though the simple verion of the form does not show an end date.
338 function activeClicked(cb
) {
339 var f
= document
.forms
[0];
341 f
.form_end
.value
= '';
343 var today
= new Date();
344 f
.form_end
.value
= '' +
(today
.getYear() +
1900) +
'-' +
345 (today
.getMonth() +
1) +
'-' + today
.getDate();
349 // This is for callback by the find-code popup.
350 // Appends to or erases the current list of diagnoses.
351 function set_related(codetype
, code
, selector
, codedesc
) {
352 var f
= document
.forms
[0];
353 var s
= f
.form_diagnosis
.value
;
355 if (s
.length
> 0) s +
= ';';
356 s +
= codetype +
':' + code
;
360 f
.form_diagnosis
.value
= s
;
363 // This invokes the find-code popup.
364 function sel_diagnosis() {
365 dlgopen('../encounter/find_code_popup.php?codetype=<?php echo $diagnosis_type ?>', '_blank', 500, 400);
368 // Check for errors when the form is submitted.
369 function validate() {
370 var f
= document
.forms
[0];
371 if (! f
.form_title
.value
) {
372 alert("<?php xl('Please enter a title!','e'); ?>");
375 top
.restoreSession();
379 // Supports customizable forms (currently just for IPPF).
380 function divclick(cb
, divid
) {
381 var divstyle
= document
.getElementById(divid
).style
;
383 divstyle
.display
= 'block';
385 divstyle
.display
= 'none';
394 <body
class="body_top" style
="padding-right:0.5em">
396 <form method
='post' name
='theform' action
='add_edit_issue.php?issue=<?php echo $issue ?>&thisenc=<?php echo $thisenc ?>'
397 onsubmit
='return validate()'>
399 <table border
='0' width
='100%'>
402 <td valign
='top' width
='1%' nowrap
><b
><?php
xl('Type','e'); ?
>:</b
></td
>
406 foreach ($ISSUE_TYPES as $value) {
407 if ($issue ||
$thistype) {
408 if ($index == $type_index) {
410 echo "<input type='hidden' name='form_type' value='$index'>\n";
413 echo " <input type='radio' name='form_type' value='$index' onclick='newtype($index)'";
414 if ($index == $type_index) echo " checked";
415 echo " />" . $value[1] . " \n";
424 <td valign
='top' nowrap
> 
;</td
>
426 <select name
='form_titles' size
='4' onchange
='set_text()'>
427 </select
> <?php
xl('(Select one of these, or type your own title)','e'); ?
>
432 <td valign
='top' nowrap
><b
><?php
xl('Title','e'); ?
>:</b
></td
>
434 <input type
='text' size
='40' name
='form_title' value
='<?php echo $irow['title
'] ?>' style
='width:100%' />
439 <td valign
='top' nowrap
><b
><?php
xl('Begin Date','e'); ?
>:</b
></td
>
442 <input type
='text' size
='10' name
='form_begin' id
='form_begin'
443 value
='<?php echo $irow['begdate
'] ?>'
444 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
445 title
='<?php xl('yyyy
-mm
-dd date of onset
, surgery
or start of medication
','e
'); ?>' />
446 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
447 id
='img_begin' border
='0' alt
='[?]' style
='cursor:pointer'
448 title
='<?php xl('Click here to choose a date
','e
'); ?>' />
452 <tr id
='row_enddate'>
453 <td valign
='top' nowrap
><b
><?php
xl('End Date','e'); ?
>:</b
></td
>
455 <input type
='text' size
='10' name
='form_end' id
='form_end'
456 value
='<?php echo $irow['enddate
'] ?>'
457 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
458 title
='<?php xl('yyyy
-mm
-dd date of recovery
or end of medication
','e
'); ?>' />
459 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
460 id
='img_end' border
='0' alt
='[?]' style
='cursor:pointer'
461 title
='<?php xl('Click here to choose a date
','e
'); ?>' />
462  
;(<?php
xl('leave blank if still active','e'); ?
>)
467 <td valign
='top' nowrap
><b
><?php
xl('Active','e'); ?
>:</b
></td
>
469 <input type
='checkbox' name
='form_active' value
='1' <?php
echo $irow['enddate'] ?
"" : "checked"; ?
>
470 onclick
='activeClicked(this);'
471 title
='<?php xl('Indicates
if this issue is currently active
','e
'); ?>' />
475 <tr
<?php
if (! $GLOBALS['athletic_team']) echo " style='display:none;'"; ?
> id
='row_returndate'>
476 <td valign
='top' nowrap
><b
><?php
xl('Returned to Play','e'); ?
>:</b
></td
>
478 <input type
='text' size
='10' name
='form_return' id
='form_return'
479 value
='<?php echo $irow['returndate
'] ?>'
480 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
481 title
='<?php xl('yyyy
-mm
-dd date returned to play
','e
'); ?>' />
482 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
483 id
='img_return' border
='0' alt
='[?]' style
='cursor:pointer'
484 title
='<?php xl('Click here to choose a date
','e
'); ?>' />
485  
;(<?php
xl('leave blank if still active','e'); ?
>)
489 <tr id
='row_diagnosis'>
490 <td valign
='top' nowrap
><b
><?php
xl('Diagnosis','e'); ?
>:</b
></td
>
493 <?php
/************************************************************ ?>
494 <select name='form_diagnosis' title='<?php xl('Diagnosis must be coded into a linked encounter','e'); ?>'>
495 <option value=""><?php xl('Unknown or N/A','e'); ?></option>
497 while ($brow = sqlFetchArray($bres)) {
498 echo " <option value='" . $brow['code'] . "'";
499 if ($brow['code'] == $irow['diagnosis']) echo " selected";
500 echo ">" . $brow['code'] . " " . substr($brow['code_text'], 0, 40) . "</option>\n";
504 <?php ************************************************************/ ?
>
506 <input type
='text' size
='50' name
='form_diagnosis'
507 value
='<?php echo $irow['diagnosis
'] ?>' onclick
='sel_diagnosis()'
508 title
='<?php xl('Click to select
or change diagnoses
','e
'); ?>'
509 style
='width:100%' readonly
/>
514 <tr id
='row_occurrence'>
515 <td valign
='top' nowrap
><b
><?php
xl('Occurrence','e'); ?
>:</b
></td
>
518 // Modified 6/2009 by BM to incorporate the occurrence items into the list_options listings
519 generate_form_field(array('data_type'=>1,'field_id'=>'occur','list_id'=>'occurrence','empty_title'=>'SKIP'), $irow['occurrence']);
524 <tr id
='row_classification'>
525 <td valign
='top' nowrap
><b
><?php
xl('Classification','e'); ?
>:</b
></td
>
527 <select name
='form_classification'>
529 foreach ($ISSUE_CLASSIFICATIONS as $key => $value) {
530 echo " <option value='$key'";
531 if ($key == $irow['classification']) echo " selected";
539 <tr
<?php
if (! $GLOBALS['athletic_team']) echo " style='display:none;'"; ?
> id
='row_missed'>
540 <td valign
='top' nowrap
><b
><?php
xl('Missed','e'); ?
>:</b
></td
>
542 <input type
='text' size
='3' name
='form_missed' value
='<?php echo $irow['extrainfo
'] ?>'
543 title
='<?php xl('Number of games
or events missed
, if any
','e
'); ?>' />
544  
;<?php
xl('games/events','e'); ?
>
548 <tr
<?php
if ($GLOBALS['athletic_team']) echo " style='display:none;'"; ?
> id
='row_referredby'>
549 <td valign
='top' nowrap
><b
><?php
xl('Referred by','e'); ?
>:</b
></td
>
551 <input type
='text' size
='40' name
='form_referredby' value
='<?php echo $irow['referredby
'] ?>'
552 style
='width:100%' title
='<?php xl('Referring physician
and practice
','e
'); ?>' />
556 <tr id
='row_comments'>
557 <td valign
='top' nowrap
><b
><?php
xl('Comments','e'); ?
>:</b
></td
>
559 <textarea name
='form_comments' rows
='4' cols
='40' wrap
='virtual' style
='width:100%'><?php
echo $irow['comments'] ?
></textarea
>
563 <tr
<?php
if ($GLOBALS['athletic_team'] ||
$GLOBALS['ippf_specific']) echo " style='display:none;'"; ?
>>
564 <td valign
='top' nowrap
><b
><?php
xl('Outcome','e'); ?
>:</b
></td
>
567 // Modified 6/2009 by BM to incorporate the outcome items into the list_options listings
568 generate_form_field(array('data_type'=>1,'field_id'=>'outcome','list_id'=>'outcome','empty_title'=>'SKIP'), $irow['outcome']);
573 <tr
<?php
if ($GLOBALS['athletic_team'] ||
$GLOBALS['ippf_specific']) echo " style='display:none;'"; ?
>>
574 <td valign
='top' nowrap
><b
><?php
xl('Destination','e'); ?
>:</b
></td
>
577 <input type
='text' size
='40' name
='form_destination' value
='<?php echo $irow['destination
'] ?>'
578 style
='width:100%' title
='GP, Secondary care specialist, etc.' />
579 <?php
} else { // leave this here for now, please -- Rod ?>
580 <?php
echo rbinput('form_destination', '1', 'GP' , 'destination') ?
> 
;
581 <?php
echo rbinput('form_destination', '2', 'Secondary care spec', 'destination') ?
> 
;
582 <?php
echo rbinput('form_destination', '3', 'GP via physio' , 'destination') ?
> 
;
583 <?php
echo rbinput('form_destination', '4', 'GP via podiatry' , 'destination') ?
>
591 if ($ISSUE_TYPES['football_injury']) {
592 issue_football_injury_form($issue);
594 if ($ISSUE_TYPES['ippf_gcac']) {
595 if (empty($issue) ||
$irow['type'] == 'ippf_gcac')
596 issue_ippf_gcac_form($issue, $thispid);
597 if (empty($issue) ||
$irow['type'] == 'contraceptive')
598 issue_ippf_con_form($issue, $thispid);
599 // if (empty($issue) || $irow['type'] == 'ippf_srh')
600 // issue_ippf_srh_form($issue, $thispid);
607 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
609 <?php
if ($issue && acl_check('admin', 'super')) { ?
>
611 <input type
='button' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' onclick
='deleteme()' />
615 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />
621 <script language
='JavaScript'>
622 newtype(<?php
echo $type_index ?
>);
623 Calendar
.setup({inputField
:"form_begin", ifFormat
:"%Y-%m-%d", button
:"img_begin"});
624 Calendar
.setup({inputField
:"form_end", ifFormat
:"%Y-%m-%d", button
:"img_end"});
625 Calendar
.setup({inputField
:"form_return", ifFormat
:"%Y-%m-%d", button
:"img_return"});