Added Cancel button to New Encounter form when creating a new encounter.
[openemr.git] / interface / forms / newpatient / common.php
blob67f44acf327e8124a60389cbfdd8e12222d4fed4
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 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
38 <html>
39 <head>
40 <?php html_header_show();?>
41 <title><?php xl('Patient Encounter','e'); ?></title>
43 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
45 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.css" media="screen" />
46 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.4.3.min.js"></script>
47 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
48 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.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>
58 <?php include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?>
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', 800, 600);
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 <?php if (!$GLOBALS['athletic_team']) { ?>
79 var category = document.forms[0].pc_catid.value;
80 if ( category == '_blank' ) {
81 alert("<?php echo xl('You must select a visit category'); ?>");
82 return;
84 <?php } ?>
86 <?php if (false /* $GLOBALS['ippf_specific'] */) { // ippf decided not to do this ?>
87 if (f['issues[]'].selectedIndex < 0) {
88 if (!confirm('There is no issue selected. If this visit relates to ' +
89 'contraception or abortion, click Cancel now and then select or ' +
90 'create the appropriate issue. Otherwise you can click OK.'))
92 return;
95 <?php } ?>
96 top.restoreSession();
97 f.submit();
100 $(document).ready(function(){
101 enable_big_modals();
103 function bill_loc(){
104 var pid=<?php echo $pid;?>;
105 var dte=document.getElementById('form_date').value;
106 var facility=document.forms[0].facility_id.value;
107 ajax_bill_loc(pid,dte,facility);
110 // Handler for Cancel clicked when creating a new encounter.
111 // Show demographics or encounters list depending on what frame we're in.
112 function cancelClicked() {
113 if (window.name == 'RBot') {
114 parent.left_nav.setRadio(window.name, 'ens');
115 parent.left_nav.loadFrame('ens1', window.name, 'patient_file/history/encounters.php');
117 else {
118 parent.left_nav.setRadio(window.name, 'dem');
119 parent.left_nav.loadFrame('dem1', window.name, 'patient_file/summary/demographics.php');
121 return false;
124 </script>
125 </head>
127 <?php if ($viewmode) { ?>
128 <body class="body_top">
129 <?php } else { ?>
130 <body class="body_top" onload="javascript:document.new_encounter.reason.focus();">
131 <?php } ?>
133 <!-- Required for the popup date selectors -->
134 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
136 <form method='post' action="<?php echo $rootdir ?>/forms/newpatient/save.php" name='new_encounter'
137 <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?>>
139 <div style = 'float:left'>
140 <?php if ($viewmode) { ?>
141 <input type=hidden name='mode' value='update'>
142 <input type=hidden name='id' value='<?php echo $_GET["id"] ?>'>
143 <span class=title><?php xl('Patient Encounter Form','e'); ?></span>
144 <?php } else { ?>
145 <input type='hidden' name='mode' value='new'>
146 <span class='title'><?php xl('New Encounter Form','e'); ?></span>
147 <?php } ?>
148 </div>
150 <div>
151 <div style = 'float:left; margin-left:8px;margin-top:-3px'>
152 <a href="javascript:saveClicked();" class="css_button link_submit"><span><?php xl('Save','e'); ?></span></a>
153 <?php if ($viewmode || !isset($_GET["autoloaded"]) || $_GET["autoloaded"] != "1") { ?>
154 </div>
156 <div style = 'float:left; margin-top:-3px'>
157 <?php if ($GLOBALS['concurrent_layout']) { ?>
158 <a href="<?php echo "$rootdir/patient_file/encounter/encounter_top.php"; ?>"
159 class="css_button link_submit" onClick="top.restoreSession()"><span><?php xl('Cancel','e'); ?></span></a>
160 <?php } else { ?>
161 <a href="<?php echo "$rootdir/patient_file/encounter/patient_encounter.php"; ?>"
162 class="css_button link_submit" target='Main' onClick="top.restoreSession()">
163 <span><?php xl('Cancel','e'); ?>]</span></a>
164 <?php } // end not concurrent layout ?>
165 <?php } else if ($GLOBALS['concurrent_layout']) { // not $viewmode ?>
166 <a href="" class="css_button link_submit" onClick="return cancelClicked()">
167 <span><?php xl('Cancel','e'); ?></span></a>
168 <?php } // end not $viewmode ?>
169 </div>
170 </div>
172 <br> <br>
174 <table width='96%'>
176 <tr>
177 <td width='33%' nowrap class='bold'><?php xl('Consultation Brief Description','e'); ?>:</td>
178 <td width='34%' rowspan='2' align='center' valign='center' class='text'>
179 <table>
181 <tr<?php if ($GLOBALS['athletic_team']) echo " style='visibility:hidden;'"; ?>>
182 <td class='bold' nowrap><?php xl('Visit Category:','e'); ?></td>
183 <td class='text'>
184 <select name='pc_catid' id='pc_catid'>
185 <option value='_blank'>-- Select One --</option>
186 <?php
187 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
188 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
189 while ($crow = sqlFetchArray($cres)) {
190 $catid = $crow['pc_catid'];
191 if ($catid < 9 && $catid != 5) continue;
192 echo " <option value='$catid'";
193 if ($viewmode && $crow['pc_catid'] == $result['pc_catid']) echo " selected";
194 echo ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
197 </select>
198 </td>
199 </tr>
201 <tr>
202 <td class='bold' nowrap><?php xl('Facility:','e'); ?></td>
203 <td class='text'>
204 <select name='facility_id' onChange="bill_loc()">
205 <?php
207 if ($viewmode) {
208 $def_facility = $result['facility_id'];
209 } else {
210 $dres = sqlStatement("select facility_id from users where username = '" . $_SESSION['authUser'] . "'");
211 $drow = sqlFetchArray($dres);
212 $def_facility = $drow['facility_id'];
214 $fres = sqlStatement("select * from facility where service_location != 0 order by name");
215 if ($fres) {
216 $fresult = array();
217 for ($iter = 0; $frow = sqlFetchArray($fres); $iter++)
218 $fresult[$iter] = $frow;
219 foreach($fresult as $iter) {
221 <option value="<?php echo $iter['id']; ?>" <?php if ($def_facility == $iter['id']) echo "selected";?>><?php echo $iter['name']; ?></option>
222 <?php
226 </select>
227 </td>
228 </tr>
229 <tr>
230 <td class='bold' nowrap><?php echo htmlspecialchars( xl('Billing Facility'), ENT_NOQUOTES); ?>:</td>
231 <td class='text'>
232 <div id="ajaxdiv">
233 <?php
234 billing_facility('billing_facility',$result['billing_facility']);
236 </div>
237 </td>
238 </tr>
239 <tr>
240 <?php
241 $sensitivities = acl_get_sensitivities();
242 if ($sensitivities && count($sensitivities)) {
243 usort($sensitivities, "sensitivity_compare");
245 <td class='bold' nowrap><?php xl('Sensitivity:','e'); ?></td>
246 <td class='text'>
247 <select name='form_sensitivity'>
248 <?php
249 foreach ($sensitivities as $value) {
250 // Omit sensitivities to which this user does not have access.
251 if (acl_check('sensitivities', $value[1])) {
252 echo " <option value='" . $value[1] . "'";
253 if ($viewmode && $result['sensitivity'] == $value[1]) echo " selected";
254 echo ">" . xl($value[3]) . "</option>\n";
257 echo " <option value=''";
258 if ($viewmode && !$result['sensitivity']) echo " selected";
259 echo ">" . xl('None'). "</option>\n";
261 </select>
262 </td>
263 <?php
264 } else {
266 <td colspan='2'><!-- sensitivities not used --></td>
267 <?php
270 </tr>
272 <tr<?php if (!$GLOBALS['gbl_visit_referral_source']) echo " style='visibility:hidden;'"; ?>>
273 <td class='bold' nowrap><?php xl('Referral Source','e'); ?>:</td>
274 <td class='text'>
275 <?php
276 echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', '');
278 </td>
279 </tr>
281 <tr>
282 <td class='bold' nowrap><?php xl('Date of Service:','e'); ?></td>
283 <td class='text' nowrap>
284 <input type='text' size='10' name='form_date' id='form_date' <?php echo $disabled ?>
285 value='<?php echo $viewmode ? substr($result['date'], 0, 10) : date('Y-m-d'); ?>'
286 title='<?php xl('yyyy-mm-dd Date of service','e'); ?>'
287 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
288 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
289 id='img_form_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
290 title='<?php xl('Click here to choose a date','e'); ?>'>
291 </td>
292 </tr>
294 <tr<?php if ($GLOBALS['ippf_specific'] || $GLOBALS['athletic_team']) echo " style='visibility:hidden;'"; ?>>
295 <td class='bold' nowrap><?php xl('Onset/hosp. date:','e'); ?></td>
296 <td class='text' nowrap><!-- default is blank so that while generating claim the date is blank. -->
297 <input type='text' size='10' name='form_onset_date' id='form_onset_date'
298 value='<?php echo $viewmode && $result['onset_date']!='0000-00-00 00:00:00' ? substr($result['onset_date'], 0, 10) : ''; ?>'
299 title='<?php xl('yyyy-mm-dd Date of onset or hospitalization','e'); ?>'
300 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
301 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
302 id='img_form_onset_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
303 title='<?php xl('Click here to choose a date','e'); ?>'>
304 </td>
305 </tr>
307 <tr>
308 <td class='text' colspan='2' style='padding-top:1em'>
309 <?php if ($GLOBALS['athletic_team']) { ?>
310 <p><i>Click [Add Issue] to add a new issue if:<br />
311 New injury likely to miss &gt; 1 day<br />
312 New significant illness/medical<br />
313 New allergy - only if nil exist</i></p>
314 <?php } ?>
315 </td>
316 </tr>
318 </table>
320 </td>
322 <td class='bold' width='33%' nowrap>
323 <div style='float:left'>
324 <?php xl('Issues (Injuries/Medical/Allergy)','e'); ?>
325 </div>
326 <div style='float:left;margin-left:8px;margin-top:-3px'>
327 <?php if ($GLOBALS['athletic_team']) { // they want the old-style popup window ?>
328 <a href="#" class="css_button_small link_submit"
329 onclick="return newissue()"><span><?php echo htmlspecialchars(xl('Add')); ?></span></a>
330 <?php } else { ?>
331 <a href="../../patient_file/summary/add_edit_issue.php" class="css_button_small link_submit iframe"
332 onclick="top.restoreSession()"><span><?php echo htmlspecialchars(xl('Add')); ?></span></a>
333 <?php } ?>
334 </div>
335 </td>
336 </tr>
338 <tr>
339 <td class='text' valign='top'>
340 <textarea name='reason' cols='40' rows='12' wrap='virtual' style='width:96%'
341 ><?php echo $viewmode ? htmlspecialchars($result['reason']) : $GLOBALS['default_chief_complaint']; ?></textarea>
342 </td>
343 <td class='text' valign='top'>
344 <select multiple name='issues[]' size='8' style='width:100%'
345 title='<?php xl('Hold down [Ctrl] for multiple selections or to unselect','e'); ?>'>
346 <?php
347 while ($irow = sqlFetchArray($ires)) {
348 $list_id = $irow['id'];
349 $tcode = $irow['type'];
350 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
351 echo " <option value='$list_id'";
352 if ($viewmode) {
353 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
354 "pid = '$pid' AND encounter = '$encounter' AND list_id = '$list_id'");
355 if ($perow['count']) echo " selected";
357 else {
358 // For new encounters the invoker may pass an issue ID.
359 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) echo " selected";
361 echo ">$tcode: " . $irow['begdate'] . " " .
362 htmlspecialchars(substr($irow['title'], 0, 40)) . "</option>\n";
365 </select>
367 <p><i><?php xl('To link this encounter/consult to an existing issue, click the '
368 . 'desired issue above to highlight it and then click [Save]. '
369 . 'Hold down [Ctrl] button to select multiple issues.','e'); ?></i></p>
371 </td>
372 </tr>
374 </table>
376 </form>
378 </body>
380 <script language="javascript">
381 /* required for popup calendar */
382 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_form_date"});
383 Calendar.setup({inputField:"form_onset_date", ifFormat:"%Y-%m-%d", button:"img_form_onset_date"});
384 <?php
385 if (!$viewmode) {
386 $erow = sqlQuery("SELECT count(*) AS count " .
387 "FROM form_encounter AS fe, forms AS f WHERE " .
388 "fe.pid = '$pid' AND fe.date = '" . date('Y-m-d 00:00:00') . "' AND " .
389 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0");
390 if ($erow['count'] > 0) {
391 echo "alert('" . xl('Warning: A visit was already created for this patient today!') . "');\n";
395 </script>
397 </html>