2 // Copyright (C) 2005-2008 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");
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;
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'";
44 function rbvalue($rbname) {
45 $tmp = $_POST[$rbname];
46 if (! $tmp) $tmp = '0';
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) {
64 $ret = "<input type='radio' name='$name' value='$value'";
65 if ($irow[$colname] == $value) $ret .= " checked";
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']) {
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'], '');
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' );
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 " .
122 "'" . $text_type . "', " .
123 "'" . $_POST['form_title'] . "', " .
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'] . "' " .
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";
166 $irow = sqlQuery("SELECT * FROM lists WHERE id = $issue");
167 foreach ($ISSUE_TYPES as $key => $value) {
168 if ($key == $irow['type']) break;
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 *******************************************************************/
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'>
198 td
, input
, select
, textarea
{
199 font
-family
: Arial
, Helvetica
, sans
-serif
;
206 border
-color
: #0000ff;
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
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");
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) {
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";
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
;
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
;
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);
309 // Called by the deleteme.php window on a successful delete.
310 function imdeleted() {
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];
320 f
.form_end
.value
= '';
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
;
334 if (s
.length
> 0) s +
= ';';
335 s +
= codetype +
':' + code
;
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!');
354 top
.restoreSession();
358 // Supports customizable forms (currently just for IPPF).
359 function divclick(cb
, divid
) {
360 var divstyle
= document
.getElementById(divid
).style
;
362 divstyle
.display
= 'block';
364 divstyle
.display
= 'none';
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%'>
381 <td valign
='top' width
='1%' nowrap
><b
><?php
xl('Type','e'); ?
>:</b
></td
>
385 foreach ($ISSUE_TYPES as $value) {
387 if ($index == $type_index) {
389 echo "<input type='hidden' name='form_type' value='$index'>\n";
392 echo " <input type='radio' name='form_type' value='$index' onclick='newtype($index)'";
393 if ($index == $type_index) echo " checked";
394 echo " />" . $value[1] . " \n";
403 <td valign
='top' nowrap
> 
;</td
>
405 <select name
='form_titles' size
='4' onchange
='set_text()'>
406 </select
> (Select one of these
, or type your own title
)
411 <td valign
='top' nowrap
><b
><?php
xl('Title','e'); ?
>:</b
></td
>
413 <input type
='text' size
='40' name
='form_title' value
='<?php echo $irow['title
'] ?>' style
='width:100%' />
418 <td valign
='top' nowrap
><b
><?php
xl('Begin Date','e'); ?
>:</b
></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
'); ?>' />
431 <tr id
='row_enddate'>
432 <td valign
='top' nowrap
><b
><?php
xl('End Date','e'); ?
>:</b
></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  
;(<?php
xl('leave blank if still active','e'); ?
>)
446 <td valign
='top' nowrap
><b
><?php
xl('Active','e'); ?
>:</b
></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
'); ?>' />
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
>
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  
;(<?php
xl('leave blank if still active','e'); ?
>)
468 <tr id
='row_diagnosis'>
469 <td valign
='top' nowrap
><b
><?php
xl('Diagnosis','e'); ?
>:</b
></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>
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";
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
/>
493 <tr id
='row_occurrence'>
494 <td valign
='top' nowrap
><b
><?php
xl('Occurrence','e'); ?
>:</b
></td
>
496 <select name
='form_occur'>
498 foreach ($ISSUE_OCCURRENCES as $key => $value) {
499 echo " <option value='$key'";
500 if ($key == $irow['occurrence']) echo " selected";
508 <tr id
='row_classification'>
509 <td valign
='top' nowrap
><b
><?php
xl('Classification','e'); ?
>:</b
></td
>
511 <select name
='form_classification'>
513 foreach ($ISSUE_CLASSIFICATIONS as $key => $value) {
514 echo " <option value='$key'";
515 if ($key == $irow['classification']) echo " selected";
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
>
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  
;<?php
xl('games/events','e'); ?
>
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
>
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
'); ?>' />
540 <tr id
='row_comments'>
541 <td valign
='top' nowrap
><b
><?php
xl('Comments','e'); ?
>:</b
></td
>
543 <textarea name
='form_comments' rows
='4' cols
='40' wrap
='virtual' style
='width:100%'><?php
echo $irow['comments'] ?
></textarea
>
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
>
550 <?php
echo rbinput('form_outcome', '1', 'Resolved' , 'outcome') ?
> 
;
551 <?php
echo rbinput('form_outcome', '2', 'Improved' , 'outcome') ?
> 
;
552 <?php
echo rbinput('form_outcome', '3', 'Status quo' , 'outcome') ?
> 
;
553 <?php
echo rbinput('form_outcome', '4', 'Worse' , 'outcome') ?
> 
;
554 <?php
echo rbinput('form_outcome', '5', 'Pending followup', 'outcome') ?
>
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
>
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') ?
> 
;
566 <?php
echo rbinput('form_destination', '2', 'Secondary care spec', 'destination') ?
> 
;
567 <?php
echo rbinput('form_destination', '3', 'GP via physio' , 'destination') ?
> 
;
568 <?php
echo rbinput('form_destination', '4', 'GP via podiatry' , 'destination') ?
>
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);
592 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
594 <?php
if ($issue && acl_check('admin', 'super')) { ?
>
596 <input type
='button' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' onclick
='deleteme()' />
600 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />
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"});