3 * Common script for the encounter form (new and view) scripts.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @author Brady Miller <brady@sparmy.com>
18 * @link http://www.open-emr.org
21 require_once("$srcdir/options.inc.php");
23 $months = array("01","02","03","04","05","06","07","08","09","10","11","12");
24 $days = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14",
25 "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
26 $thisyear = date("Y");
27 $years = array($thisyear-1, $thisyear, $thisyear+
1, $thisyear+
2);
30 $id = (isset($_REQUEST['id'])) ?
$_REQUEST['id'] : '';
31 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
32 $encounter = $result['encounter'];
33 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
34 echo "<body>\n<html>\n";
35 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
36 echo "</body>\n</html>\n";
41 // Sort comparison for sensitivities by their order attribute.
42 function sensitivity_compare($a, $b) {
43 return ($a[2] < $b[2]) ?
-1 : 1;
47 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
48 "pid = ? AND enddate IS NULL " .
49 "ORDER BY type, begdate", array($pid));
51 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
54 <?php
html_header_show();?
>
55 <title
><?php
echo xlt('Patient Encounter'); ?
></title
>
57 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
58 <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" />
59 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
60 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script
>
61 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"></script
>
62 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
63 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/overlib_mini.js"></script
>
64 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script
>
66 <!-- validation library
-->
68 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
70 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?
>
72 <!-- pop up calendar
-->
73 <style type
="text/css">@import
url(<?php
echo $GLOBALS['webroot'] ?
>/library
/dynarch_calendar
.css
);</style
>
74 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script
>
75 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
76 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script
>
77 <?php
include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?
>
78 <script language
="JavaScript">
80 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
82 // Process click on issue title.
84 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 800, 600);
88 // callback from add_edit_issue.php:
89 function refreshIssue(issue
, title
) {
90 var s
= document
.forms
[0]['issues[]'];
91 s
.options
[s
.options
.length
] = new Option(title
, issue
, true, true);
95 //Gets validation rules from Page Validation list.
96 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
97 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
98 if (empty($collectthis)) {
99 $collectthis = "undefined";
102 $collectthis = $collectthis["new_encounter"]["rules"];
105 var collectvalidation
= <?php
echo($collectthis); ?
>;
106 $
(document
).ready(function(){
107 window
.saveClicked
= function(event
) {
108 var submit
= submitme(1, event
, 'new-encounter-form', collectvalidation
);
110 top
.restoreSession();
111 $
('#new-encounter-form').submit();
119 var pid
=<?php
echo attr($pid);?
>;
120 var dte
=document
.getElementById('form_date').value
;
121 var facility
=document
.forms
[0].facility_id
.value
;
122 ajax_bill_loc(pid
,dte
,facility
);
125 // Handler for Cancel clicked when creating a new encounter.
126 // Show demographics or encounters list depending on what frame we're in.
127 function cancelClicked() {
128 if (window
.name
== 'RBot') {
129 parent
.left_nav
.loadFrame('ens1', window
.name
, 'patient_file/history/encounters.php');
132 parent
.left_nav
.loadFrame('dem1', window
.name
, 'patient_file/summary/demographics.php');
140 <?php
if ($viewmode) { ?
>
141 <body
class="body_top">
143 <body
class="body_top" onload
="javascript:document.new_encounter.reason.focus();">
146 <!-- Required
for the popup date selectors
-->
147 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
149 <form id
="new-encounter-form" method
='post' action
="<?php echo $rootdir ?>/forms/newpatient/save.php" name
='new_encounter'>
151 <div style
='float:left'>
152 <?php
if ($viewmode) { ?
>
153 <input type
=hidden name
='mode' value
='update'>
154 <input type
=hidden name
='id' value
='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>'>
155 <span
class=title
><?php
echo xlt('Patient Encounter Form'); ?
></span
>
157 <input type
='hidden' name
='mode' value
='new'>
158 <span
class='title'><?php
echo xlt('New Encounter Form'); ?
></span
>
163 <div style
= 'float:left; margin-left:8px;margin-top:-3px'>
164 <a href
="javascript:saveClicked(undefined);" class="css_button link_submit"><span
><?php
echo xlt('Save'); ?
></span
></a
>
165 <?php
if ($viewmode ||
!isset($_GET["autoloaded"]) ||
$_GET["autoloaded"] != "1") { ?
>
167 <div style
= 'float:left; margin-top:-3px'>
168 <a href
="<?php echo "$rootdir/patient_file
/encounter
/encounter_top
.php
"; ?>"
169 class="css_button link_submit" onClick
="top.restoreSession()"><span
><?php
echo xlt('Cancel'); ?
></span
></a
>
170 <?php
} else { // not $viewmode ?>
171 <a href
="" class="css_button link_submit" onClick
="return cancelClicked()">
172 <span
><?php
echo xlt('Cancel'); ?
></span
></a
>
173 <?php
} // end not $viewmode ?>
182 <td width
='33%' nowrap
class='bold'><?php
echo xlt('Consultation Brief Description'); ?
>:</td
>
183 <td width
='34%' rowspan
='2' align
='center' valign
='center' class='text'>
187 <td
class='bold' nowrap
><?php
echo xlt('Visit Category:'); ?
></td
>
189 <select name
='pc_catid' id
='pc_catid'>
190 <option value
='_blank'>-- <?php
echo xlt('Select One'); ?
> --</option
>
192 $cres = sqlStatement("SELECT pc_catid, pc_catname " .
193 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq ");
194 while ($crow = sqlFetchArray($cres)) {
195 $catid = $crow['pc_catid'];
196 if ($catid < 9 && $catid != 5) continue;
197 echo " <option value='" . attr($catid) . "'";
198 if ($viewmode && $crow['pc_catid'] == $result['pc_catid']) echo " selected";
199 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
207 <td
class='bold' nowrap
><?php
echo xlt('Facility:'); ?
></td
>
209 <select name
='facility_id' onChange
="bill_loc()">
213 $def_facility = $result['facility_id'];
215 $dres = sqlStatement("select facility_id from users where username = ?", array($_SESSION['authUser']));
216 $drow = sqlFetchArray($dres);
217 $def_facility = $drow['facility_id'];
219 $fres = sqlStatement("select * from facility where service_location != 0 order by name");
222 for ($iter = 0; $frow = sqlFetchArray($fres); $iter++
)
223 $fresult[$iter] = $frow;
224 foreach($fresult as $iter) {
226 <option value
="<?php echo attr($iter['id']); ?>" <?php
if ($def_facility == $iter['id']) echo "selected";?
>><?php
echo text($iter['name']); ?
></option
>
235 <td
class='bold' nowrap
><?php
echo xlt('Billing Facility'); ?
>:</td
>
239 billing_facility('billing_facility',$result['billing_facility']);
244 <?php
if($GLOBALS['set_pos_code_encounter']){ ?
>
246 <td
><span
class='bold' nowrap
><?php
echo xlt('POS Code'); ?
>: </span
></td
>
248 <select name
="pos_code">
253 foreach ($pc->get_pos_ref() as $pos) {
254 echo "<option value=\"" . attr($pos["code"]) . "\" ";
255 if($pos["code"] == $result['pos_code']) echo "selected";
256 echo ">" . text($pos['code']) . ": ". xlt($pos['title']);
268 $sensitivities = acl_get_sensitivities();
269 if ($sensitivities && count($sensitivities)) {
270 usort($sensitivities, "sensitivity_compare");
272 <td
class='bold' nowrap
><?php
echo xlt('Sensitivity:'); ?
></td
>
274 <select name
='form_sensitivity'>
276 foreach ($sensitivities as $value) {
277 // Omit sensitivities to which this user does not have access.
278 if (acl_check('sensitivities', $value[1])) {
279 echo " <option value='" . attr($value[1]) . "'";
280 if ($viewmode && $result['sensitivity'] == $value[1]) echo " selected";
281 echo ">" . xlt($value[3]) . "</option>\n";
284 echo " <option value=''";
285 if ($viewmode && !$result['sensitivity']) echo " selected";
286 echo ">" . xlt('None'). "</option>\n";
293 <td colspan
='2'><!-- sensitivities not used
--></td
>
299 <tr
<?php
if (!$GLOBALS['gbl_visit_referral_source']) echo " style='visibility:hidden;'"; ?
>>
300 <td
class='bold' nowrap
><?php
echo xlt('Referral Source'); ?
>:</td
>
303 echo generate_select_list('form_referral_source', 'refsource', $viewmode ?
$result['referral_source'] : '', '');
309 <td
class='bold' nowrap
><?php
echo xlt('Date of Service:'); ?
></td
>
310 <td
class='text' nowrap
>
311 <input type
='text' size
='10' name
='form_date' id
='form_date' <?php
echo $disabled ?
>
312 value
='<?php echo $viewmode ? substr($result['date
'], 0, 10) : date('Y
-m
-d
'); ?>'
313 title
='<?php echo xla('yyyy
-mm
-dd Date of service
'); ?>'
314 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
315 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
316 id
='img_form_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
317 title
='<?php echo xla('Click here to choose a date
'); ?>'>
321 <tr
<?php
if ($GLOBALS['ippf_specific']) echo " style='visibility:hidden;'"; ?
>>
322 <td
class='bold' nowrap
><?php
echo xlt('Onset/hosp. date:'); ?
></td
>
323 <td
class='text' nowrap
><!-- default is blank so that
while generating claim the date is blank
. -->
324 <input type
='text' size
='10' name
='form_onset_date' id
='form_onset_date'
325 value
='<?php echo $viewmode && $result['onset_date
']!='0000-00-00 00:00:00' ? substr($result['onset_date
'], 0, 10) : ''; ?>'
326 title
='<?php echo xla('yyyy
-mm
-dd Date of onset
or hospitalization
'); ?>'
327 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
328 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
329 id
='img_form_onset_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
330 title
='<?php echo xla('Click here to choose a date
'); ?>'>
334 <td
class='text' colspan
='2' style
='padding-top:1em'>
342 <td
class='bold' width
='33%' nowrap
>
343 <div style
='float:left'>
344 <?php
echo xlt('Issues (Injuries/Medical/Allergy)'); ?
>
346 <div style
='float:left;margin-left:8px;margin-top:-3px'>
347 <?php
if (acl_check('patients','med','','write')) { ?
>
348 <a href
="../../patient_file/summary/add_edit_issue.php" class="css_button_small link_submit iframe"
349 onclick
="top.restoreSession()"><span
><?php
echo xlt('Add'); ?
></span
></a
>
356 <td
class='text' valign
='top'>
357 <textarea name
='reason' cols
='40' rows
='12' wrap
='virtual' style
='width:96%'
358 ><?php
echo $viewmode ?
text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?
></textarea
>
360 <td
class='text' valign
='top'>
361 <select multiple name
='issues[]' size
='8' style
='width:100%'
362 title
='<?php echo xla('Hold down
[Ctrl
] for multiple selections
or to unselect
'); ?>'>
364 while ($irow = sqlFetchArray($ires)) {
365 $list_id = $irow['id'];
366 $tcode = $irow['type'];
367 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
368 echo " <option value='" . attr($list_id) . "'";
370 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
371 "pid = ? AND encounter = ? AND list_id = ?", array($pid,$encounter,$list_id));
372 if ($perow['count']) echo " selected";
375 // For new encounters the invoker may pass an issue ID.
376 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) echo " selected";
378 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
379 text(substr($irow['title'], 0, 40)) . "</option>\n";
384 <p
><i
><?php
echo xlt('To link this encounter/consult to an existing issue, click the '
385 . 'desired issue above to highlight it and then click [Save]. '
386 . 'Hold down [Ctrl] button to select multiple issues.'); ?
></i
></p
>
397 <script language
="javascript">
398 /* required for popup calendar */
399 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_form_date"});
400 Calendar
.setup({inputField
:"form_onset_date", ifFormat
:"%Y-%m-%d", button
:"img_form_onset_date"});
403 function duplicateVisit(enc
, datestr
) {
404 if (!confirm('<?php echo xl("A visit already exists for this patient today. Click Cancel to open it, or OK to proceed with creating a new one.") ?>')) {
405 // User pressed the cancel button, so re-direct to today's encounter
406 top
.restoreSession();
407 parent
.left_nav
.setEncounter(datestr
, enc
, window
.name
);
408 parent
.left_nav
.loadFrame('enc2', window
.name
, 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
411 // otherwise just continue normally
415 // Search for an encounter from today
416 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
417 "FROM form_encounter AS fe, forms AS f WHERE " .
419 " AND fe.date >= ? " .
420 " AND fe.date <= ? " .
422 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
423 "ORDER BY fe.encounter DESC LIMIT 1",array($pid,date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')));
425 if (!empty($erow['encounter'])) {
426 // If there is an encounter from today then present the duplicate visit dialog
427 echo "duplicateVisit('" . $erow['encounter'] . "', '" .
428 oeFormatShortDate(substr($erow['date'], 0, 10)) . "');\n";