added optional visit-level referral source
[openemr.git] / interface / forms / newpatient / common.php
bloba869a4f7362173dccd06b61e29ca4b0c616e664b
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("$srcdir/options.inc.php");
9 $months = array("01","02","03","04","05","06","07","08","09","10","11","12");
10 $days = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14",
11 "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
12 $thisyear = date("Y");
13 $years = array($thisyear-1, $thisyear, $thisyear+1, $thisyear+2);
15 if ($viewmode) {
16 $id = $_REQUEST['id'];
17 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = '$id'");
18 $encounter = $result['encounter'];
19 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
20 echo "<body>\n<html>\n";
21 echo "<p>" . xl('You are not authorized to see this encounter.') . "</p>\n";
22 echo "</body>\n</html>\n";
23 exit();
27 // Sort comparison for sensitivities by their order attribute.
28 function sensitivity_compare($a, $b) {
29 return ($a[2] < $b[2]) ? -1 : 1;
32 // get issues
33 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
34 "pid = $pid AND enddate IS NULL " .
35 "ORDER BY type, begdate");
37 <html>
38 <head>
39 <?php html_header_show();?>
40 <title><?php xl('Patient Encounter','e'); ?></title>
42 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
44 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
45 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
46 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
47 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
49 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
50 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/overlib_mini.js"></script>
51 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
53 <!-- pop up calendar -->
54 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
55 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
56 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
57 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
59 <script language="JavaScript">
61 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
63 // Process click on issue title.
64 function newissue() {
65 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 600, 475);
66 return false;
69 // callback from add_edit_issue.php:
70 function refreshIssue(issue, title) {
71 var s = document.forms[0]['issues[]'];
72 s.options[s.options.length] = new Option(title, issue, true, true);
75 function saveClicked() {
76 var f = document.forms[0];
78 var category = document.forms[0].pc_catid.value;
80 if ( category == '_blank' ) {
81 alert("<?php echo xl('You must select a visit category.', 'e'); ?>");
82 return;
85 <?php if (false /* $GLOBALS['ippf_specific'] */) { // ippf decided not to do this ?>
86 if (f['issues[]'].selectedIndex < 0) {
87 if (!confirm('There is no issue selected. If this visit relates to ' +
88 'contraception or abortion, click Cancel now and then select or ' +
89 'create the appropriate issue. Otherwise you can click OK.'))
91 return;
94 <?php } ?>
95 top.restoreSession();
96 f.submit();
99 $(document).ready(function(){
100 // fancy box
101 enable_modals();
104 </script>
105 </head>
107 <?php if ($viewmode) { ?>
108 <body class="body_top">
109 <?php } else { ?>
110 <body class="body_top" onload="javascript:document.new_encounter.reason.focus();">
111 <?php } ?>
113 <!-- Required for the popup date selectors -->
114 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
116 <form method='post' action="<?php echo $rootdir ?>/forms/newpatient/save.php" name='new_encounter'
117 <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?>>
119 <div style = 'float:left'>
120 <?php if ($viewmode) { ?>
121 <input type=hidden name='mode' value='update'>
122 <input type=hidden name='id' value='<?php echo $_GET["id"] ?>'>
123 <span class=title><?php xl('Patient Encounter Form','e'); ?></span>
124 <?php } else { ?>
125 <input type='hidden' name='mode' value='new'>
126 <span class='title'><?php xl('New Encounter Form','e'); ?></span>
127 <?php } ?>
128 </div>
130 <div>
131 <div style = 'float:left; margin-left:8px;margin-top:-3px'>
132 <a href="javascript:saveClicked();" class="css_button link_submit"><span><?php xl('Save','e'); ?></span></a>
133 <?php if ($viewmode || !isset($_GET["autoloaded"]) || $_GET["autoloaded"] != "1") { ?>
134 </div>
136 <div style = 'float:left; margin-top:-3px'>
137 <?php if ($GLOBALS['concurrent_layout']) { ?>
138 <a href="<?php echo "$rootdir/patient_file/encounter/encounter_top.php"; ?>"
139 class="css_button link_submit" onclick="top.restoreSession()"><span><?php xl('Cancel','e'); ?></span></a>
140 <?php } else { ?>
141 <a href="<?php echo "$rootdir/patient_file/encounter/patient_encounter.php"; ?>"
142 class="css_button link_submit" target='Main' onclick="top.restoreSession()">
143 <span><?php xl('Cancel','e'); ?>]</span></a>
144 <?php } // end not concurrent layout ?>
145 <?php } // end not autoloading ?>
146 </div>
147 </div>
149 <br> <br>
151 <table width='96%'>
153 <tr>
154 <td width='33%' nowrap class='bold'><?php xl('Consultation Brief Description','e'); ?>:</td>
155 <td width='34%' rowspan='2' align='center' valign='center' class='text'>
156 <table>
158 <tr>
159 <td class='bold' nowrap><?php xl('Visit Category:','e'); ?></td>
160 <td class='text'>
161 <select name='pc_catid' id='pc_catid'>
162 <option value='_blank'>-- Select One --</option>
163 <?php
164 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
165 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
166 while ($crow = sqlFetchArray($cres)) {
167 $catid = $crow['pc_catid'];
168 if ($catid < 9 && $catid != 5) continue;
169 echo " <option value='$catid'";
170 if ($viewmode && $crow['pc_catid'] == $result['pc_catid']) echo " selected";
171 echo ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
174 </select>
175 </td>
176 </tr>
178 <tr>
179 <td class='bold' nowrap><?php xl('Facility:','e'); ?></td>
180 <td class='text'>
181 <select name='facility_id'>
182 <?php
184 if ($viewmode) {
185 $def_facility = $result['facility_id'];
186 } else {
187 $dres = sqlStatement("select facility_id from users where username = '" . $_SESSION['authUser'] . "'");
188 $drow = sqlFetchArray($dres);
189 $def_facility = $drow['facility_id'];
191 $fres = sqlStatement("select * from facility where service_location != 0 order by name");
192 if ($fres) {
193 $fresult = array();
194 for ($iter = 0; $frow = sqlFetchArray($fres); $iter++)
195 $fresult[$iter] = $frow;
196 foreach($fresult as $iter) {
198 <option value="<?php echo $iter['id']; ?>" <?php if ($def_facility == $iter['id']) echo "selected";?>><?php echo $iter['name']; ?></option>
199 <?php
203 </select>
204 </td>
205 </tr>
207 <tr>
208 <?php
209 $sensitivities = acl_get_sensitivities();
210 if ($sensitivities && count($sensitivities)) {
211 usort($sensitivities, "sensitivity_compare");
213 <td class='bold' nowrap><?php xl('Sensitivity:','e'); ?></td>
214 <td class='text'>
215 <select name='form_sensitivity'>
216 <?php
217 foreach ($sensitivities as $value) {
218 // Omit sensitivities to which this user does not have access.
219 if (acl_check('sensitivities', $value[1])) {
220 echo " <option value='" . $value[1] . "'";
221 if ($viewmode && $result['sensitivity'] == $value[1]) echo " selected";
222 echo ">" . xl($value[3]) . "</option>\n";
225 echo " <option value=''";
226 if ($viewmode && !$result['sensitivity']) echo " selected";
227 echo ">" . xl('None'). "</option>\n";
229 </select>
230 </td>
231 <?php
232 } else {
234 <td colspan='2'><!-- sensitivities not used --></td>
235 <?php
238 </tr>
240 <tr<?php if (!$GLOBALS['gbl_visit_referral_source']) echo " style='visibility:hidden;'"; ?>>
241 <td class='bold' nowrap><?php xl('Referral Source','e'); ?>:</td>
242 <td class='text'>
243 <?php
244 echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', '');
246 </td>
247 </tr>
249 <tr>
250 <td class='bold' nowrap><?php xl('Date of Service:','e'); ?></td>
251 <td class='text' nowrap>
252 <input type='text' size='10' name='form_date' id='form_date' <?php echo $disabled ?>
253 value='<?php echo $viewmode ? substr($result['date'], 0, 10) : date('Y-m-d'); ?>'
254 title='<?php xl('yyyy-mm-dd Date of service','e'); ?>'
255 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
256 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
257 id='img_form_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
258 title='<?php xl('Click here to choose a date','e'); ?>'>
259 </td>
260 </tr>
262 <tr<?php if ($GLOBALS['ippf_specific']) echo " style='visibility:hidden;'"; ?>>
263 <td class='bold' nowrap><?php xl('Onset/hosp. date:','e'); ?></td>
264 <td class='text' nowrap>
265 <input type='text' size='10' name='form_onset_date' id='form_onset_date'
266 value='<?php echo $viewmode ? substr($result['onset_date'], 0, 10) : date('Y-m-d'); ?>'
267 title='<?php xl('yyyy-mm-dd Date of onset or hospitalization','e'); ?>'
268 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
270 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
271 id='img_form_onset_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
272 title='<?php xl('Click here to choose a date','e'); ?>'>
274 </td>
275 </tr>
277 <tr>
278 <td class='text' colspan='2' style='padding-top:1em'>
280 <?php if ($GLOBALS['athletic_team']) { ?>
281 <p><i>Click [Add Issue] to add a new issue if:<br />
282 New injury likely to miss &gt; 1 day<br />
283 New significant illness/medical<br />
284 New allergy - only if nil exist</i></p>
285 <?php } ?>
288 </td>
289 </tr>
291 </table>
293 </td>
295 <td class='bold' width='33%' nowrap>
296 <div style='float:left'>
297 <?php xl('Issues (Injuries/Medical/Allergy)','e'); ?>
298 </div>
299 <div style='float:left;margin-left:8px;margin-top:-3px'>
300 <a href="../../patient_file/summary/add_edit_issue.php" class="css_button_small link_submit iframe"><span><?php xl('Add','e'); ?></span></a>
301 </div>
302 </td>
303 </tr>
305 <tr>
306 <td class='text' valign='top'>
307 <textarea name='reason' cols='40' rows='12' wrap='virtual' style='width:96%'
308 ><?php echo $viewmode ? htmlspecialchars($result['reason']) : $GLOBALS['default_chief_complaint']; ?></textarea>
309 </td>
310 <td class='text' valign='top'>
311 <select multiple name='issues[]' size='8' style='width:100%'
312 title='<?php xl('Hold down [Ctrl] for multiple selections or to unselect','e'); ?>'>
313 <?php
314 while ($irow = sqlFetchArray($ires)) {
315 $list_id = $irow['id'];
316 $tcode = $irow['type'];
317 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
319 if ($viewmode) {
320 echo " <option value='$list_id'";
321 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
322 "pid = '$pid' AND encounter = '$encounter' AND list_id = '$list_id'");
323 if ($perow['count']) echo " selected";
324 echo ">$tcode: " . $irow['begdate'] . " " .
325 htmlspecialchars(substr($irow['title'], 0, 40)) . "</option>\n";
327 else {
328 echo " <option value='$list_id'>$tcode: ";
329 echo $irow['begdate'] . " " . htmlspecialchars(substr($irow['title'], 0, 40)) . "</option>\n";
333 </select>
335 <p><i><?php xl('To link this encounter/consult to an existing issue, click the '
336 . 'desired issue above to highlight it and then click [Save]. '
337 . 'Hold down [Ctrl] button to select multiple issues.','e'); ?></i></p>
339 </td>
340 </tr>
342 </table>
344 </form>
346 </body>
348 <script language="javascript">
349 /* required for popup calendar */
350 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_form_date"});
351 Calendar.setup({inputField:"form_onset_date", ifFormat:"%Y-%m-%d", button:"img_form_onset_date"});
352 <?php
353 if (!$viewmode) {
354 $erow = sqlQuery("SELECT count(*) AS count " .
355 "FROM form_encounter AS fe, forms AS f WHERE " .
356 "fe.pid = '$pid' AND fe.date = '" . date('Y-m-d 00:00:00') . "' AND " .
357 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0");
358 if ($erow['count'] > 0) {
359 echo "alert('" . xl('Warning: A visit was already created for this patient today!') . "');\n";
363 </script>
365 </html>