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.g.miller@gmail.com>
18 * @link http://www.open-emr.org
21 require_once("$srcdir/options.inc.php");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/lists.inc");
25 if($GLOBALS['enable_group_therapy']){
26 require_once("$srcdir/group.inc");
29 $months = array("01","02","03","04","05","06","07","08","09","10","11","12");
30 $days = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14",
31 "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
32 $thisyear = date("Y");
33 $years = array($thisyear-1, $thisyear, $thisyear+
1, $thisyear+
2);
36 $id = (isset($_REQUEST['id'])) ?
$_REQUEST['id'] : '';
37 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
38 $encounter = $result['encounter'];
39 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
40 echo "<body>\n<html>\n";
41 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
42 echo "</body>\n</html>\n";
47 // Sort comparison for sensitivities by their order attribute.
48 function sensitivity_compare($a, $b) {
49 return ($a[2] < $b[2]) ?
-1 : 1;
53 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
54 "pid = ? AND enddate IS NULL " .
55 "ORDER BY type, begdate", array($pid));
57 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
60 <?php
html_header_show();?
>
61 <title
><?php
echo xlt('Patient Encounter'); ?
></title
>
63 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
64 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
66 <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" />
67 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
68 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
69 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"></script
>
70 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
71 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
72 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
74 <!-- validation library
-->
76 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
78 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?
>
80 <?php
include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?
>
81 <script language
="JavaScript">
83 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
85 // Process click on issue title.
87 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 800, 600);
91 // callback from add_edit_issue.php:
92 function refreshIssue(issue
, title
) {
93 var s
= document
.forms
[0]['issues[]'];
94 s
.options
[s
.options
.length
] = new Option(title
, issue
, true, true);
98 //Gets validation rules from Page Validation list.
99 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
100 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
101 if (empty($collectthis)) {
102 $collectthis = "undefined";
105 $collectthis = $collectthis["new_encounter"]["rules"];
108 var collectvalidation
= <?php
echo($collectthis); ?
>;
109 $
(document
).ready(function(){
110 window
.saveClicked
= function(event
) {
111 var submit
= submitme(1, event
, 'new-encounter-form', collectvalidation
);
113 top
.restoreSession();
114 $
('#new-encounter-form').submit();
120 $
('.datepicker').datetimepicker({
121 <?php
$datetimepicker_timepicker = false; ?
>
122 <?php
$datetimepicker_showseconds = false; ?
>
123 <?php
$datetimepicker_formatInput = false; ?
>
124 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
125 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
130 var pid
=<?php
echo attr($pid);?
>;
131 var dte
=document
.getElementById('form_date').value
;
132 var facility
=document
.forms
[0].facility_id
.value
;
133 ajax_bill_loc(pid
,dte
,facility
);
136 // Handler for Cancel clicked when creating a new encounter.
137 // Show demographics or encounters list depending on what frame we're in.
138 function cancelClicked() {
139 if (window
.name
== 'RBot') {
140 parent
.left_nav
.loadFrame('ens1', window
.name
, 'patient_file/history/encounters.php');
143 parent
.left_nav
.loadFrame('dem1', window
.name
, 'patient_file/summary/demographics.php');
151 <?php
if ($viewmode) { ?
>
152 <body
class="body_top">
154 <body
class="body_top" onload
="javascript:document.new_encounter.reason.focus();">
157 <!-- Required
for the popup date selectors
-->
158 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
160 <form id
="new-encounter-form" method
='post' action
="<?php echo $rootdir ?>/forms/newpatient/save.php" name
='new_encounter'>
162 <div style
='float:left'>
163 <?php
if ($viewmode) { ?
>
164 <input type
=hidden name
='mode' value
='update'>
165 <input type
=hidden name
='id' value
='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>'>
166 <span
class=title
><?php
echo xlt('Patient Encounter Form'); ?
></span
>
168 <input type
='hidden' name
='mode' value
='new'>
169 <span
class='title'><?php
echo xlt('New Encounter Form'); ?
></span
>
174 <div style
= 'float:left; margin-left:8px;margin-top:-3px'>
175 <a href
="javascript:saveClicked(undefined);" class="css_button link_submit"><span
><?php
echo xlt('Save'); ?
></span
></a
>
176 <?php
if ($viewmode ||
!isset($_GET["autoloaded"]) ||
$_GET["autoloaded"] != "1") { ?
>
178 <div style
= 'float:left; margin-top:-3px'>
179 <a href
="<?php echo "$rootdir/patient_file
/encounter
/encounter_top
.php
"; ?>"
180 class="css_button link_submit" onClick
="top.restoreSession()"><span
><?php
echo xlt('Cancel'); ?
></span
></a
>
181 <?php
} else { // not $viewmode ?>
182 <a href
="" class="css_button link_submit" onClick
="return cancelClicked()">
183 <span
><?php
echo xlt('Cancel'); ?
></span
></a
>
184 <?php
} // end not $viewmode ?>
193 <td width
='33%' nowrap
class='bold'><?php
echo xlt('Consultation Brief Description'); ?
>:</td
>
194 <td width
='34%' rowspan
='2' align
='center' valign
='center' class='text'>
198 <td
class='bold' nowrap
><?php
echo xlt('Visit Category:'); ?
></td
>
200 <select name
='pc_catid' id
='pc_catid'>
201 <option value
='_blank'>-- <?php
echo xlt('Select One'); ?
> --</option
>
203 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_cattype " .
204 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq ");
205 $therapyGroupCategories = array();
206 while ($crow = sqlFetchArray($cres)) {
207 $catid = $crow['pc_catid'];
208 if($crow['pc_cattype'] == 3)$therapyGroupCategories[] = $catid;
209 // Show Thrapy group category only if global enable_group_therapy is true
210 if($crow['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) continue;
211 if ($catid < 9 && $catid != 5) continue;
212 echo " <option value='" . attr($catid) . "'";
213 if ($viewmode && $crow['pc_catid'] == $result['pc_catid']) echo " selected";
214 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
222 <td
class='bold' nowrap
><?php
echo xlt('Facility:'); ?
></td
>
224 <select name
='facility_id' onChange
="bill_loc()">
228 $def_facility = $result['facility_id'];
230 $dres = sqlStatement("select facility_id from users where username = ?", array($_SESSION['authUser']));
231 $drow = sqlFetchArray($dres);
232 $def_facility = $drow['facility_id'];
234 $fres = sqlStatement("select * from facility where service_location != 0 order by name");
237 for ($iter = 0; $frow = sqlFetchArray($fres); $iter++
)
238 $fresult[$iter] = $frow;
239 foreach($fresult as $iter) {
241 <option value
="<?php echo attr($iter['id']); ?>" <?php
if ($def_facility == $iter['id']) echo "selected";?
>><?php
echo text($iter['name']); ?
></option
>
250 <td
class='bold' nowrap
><?php
echo xlt('Billing Facility'); ?
>:</td
>
254 billing_facility('billing_facility',$result['billing_facility']);
259 <?php
if($GLOBALS['set_pos_code_encounter']){ ?
>
261 <td
><span
class='bold' nowrap
><?php
echo xlt('POS Code'); ?
>: </span
></td
>
263 <select name
="pos_code">
268 foreach ($pc->get_pos_ref() as $pos) {
269 echo "<option value=\"" . attr($pos["code"]) . "\" ";
270 if($pos["code"] == $result['pos_code']) echo "selected";
271 echo ">" . text($pos['code']) . ": ". xlt($pos['title']);
283 $sensitivities = acl_get_sensitivities();
284 if ($sensitivities && count($sensitivities)) {
285 usort($sensitivities, "sensitivity_compare");
287 <td
class='bold' nowrap
><?php
echo xlt('Sensitivity:'); ?
></td
>
289 <select name
='form_sensitivity'>
291 foreach ($sensitivities as $value) {
292 // Omit sensitivities to which this user does not have access.
293 if (acl_check('sensitivities', $value[1])) {
294 echo " <option value='" . attr($value[1]) . "'";
295 if ($viewmode && $result['sensitivity'] == $value[1]) echo " selected";
296 echo ">" . xlt($value[3]) . "</option>\n";
299 echo " <option value=''";
300 if ($viewmode && !$result['sensitivity']) echo " selected";
301 echo ">" . xlt('None'). "</option>\n";
308 <td colspan
='2'><!-- sensitivities not used
--></td
>
314 <tr
<?php
if (!$GLOBALS['gbl_visit_referral_source']) echo " style='visibility:hidden;'"; ?
>>
315 <td
class='bold' nowrap
><?php
echo xlt('Referral Source'); ?
>:</td
>
318 echo generate_select_list('form_referral_source', 'refsource', $viewmode ?
$result['referral_source'] : '', '');
323 <?php
if($GLOBALS['enable_group_therapy']) { ?
>
324 <!-- select group name
- showing just
if therapy group type is selected
-->
325 <tr id
="therapy_group_name" style
="display: none">
326 <td
class='bold' nowrap
><?php
echo xlt('Group name'); ?
>:</td
>
328 <input type
='text' size
='10' name
='form_group' id
="form_group" style
='width:100%;cursor:pointer;cursor:hand' placeholder
='<?php echo xla('Click to select
');?>' value
='<?php echo $viewmode && in_array($result['pc_catid
'], $therapyGroupCategories) ? attr(getGroup($result['external_id
'])['group_name
']) : ''; ?>' onclick
='sel_group()' title
='<?php echo xla('Click to select group
'); ?>' readonly
/>
329 <input type
='hidden' name
='form_gid' value
='<?php echo $viewmode && in_array($result['pc_catid
'], $therapyGroupCategories) ? attr($result['external_id
']) : '' ?>' />
335 <td
class='bold' nowrap
><?php
echo xlt('Date of Service:'); ?
></td
>
336 <td
class='text' nowrap
>
337 <input type
='text' size
='10' class='datepicker' name
='form_date' id
='form_date' <?php
echo $disabled ?
>
338 value
='<?php echo $viewmode ? substr($result['date
'], 0, 10) : date('Y
-m
-d
'); ?>'
339 title
='<?php echo xla('yyyy
-mm
-dd Date of service
'); ?>' />
343 <tr
<?php
if ($GLOBALS['ippf_specific']) echo " style='visibility:hidden;'"; ?
>>
344 <td
class='bold' nowrap
><?php
echo xlt('Onset/hosp. date:'); ?
></td
>
345 <td
class='text' nowrap
><!-- default is blank so that
while generating claim the date is blank
. -->
346 <input type
='text' size
='10' class='datepicker' name
='form_onset_date' id
='form_onset_date'
347 value
='<?php echo $viewmode && $result['onset_date
']!='0000-00-00 00:00:00' ? substr($result['onset_date
'], 0, 10) : ''; ?>'
348 title
='<?php echo xla('yyyy
-mm
-dd Date of onset
or hospitalization
'); ?>' />
352 <td
class='text' colspan
='2' style
='padding-top:1em'>
360 <td
class='bold' width
='33%' nowrap
>
363 // To see issues stuff user needs write access to all issue types.
365 foreach ($ISSUE_TYPES as $type => $dummy) {
366 if (!acl_check_issue($type, '', 'write')) {
373 <div style
='float:left'>
374 <?php
echo xlt('Issues (Injuries/Medical/Allergy)'); ?
>
376 <div style
='float:left;margin-left:8px;margin-top:-3px'>
377 <?php
if (acl_check('patients','med','','write')) { ?
>
378 <a href
="../../patient_file/summary/add_edit_issue.php" class="css_button_small link_submit iframe"
379 onclick
="top.restoreSession()"><span
><?php
echo xlt('Add'); ?
></span
></a
>
388 <td
class='text' valign
='top'>
389 <textarea name
='reason' cols
='40' rows
='12' wrap
='virtual' style
='width:96%'
390 ><?php
echo $viewmode ?
text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?
></textarea
>
392 <td
class='text' valign
='top'>
394 <?php
if ($issuesauth) { ?
>
395 <select multiple name
='issues[]' size
='8' style
='width:100%'
396 title
='<?php echo xla('Hold down
[Ctrl
] for multiple selections
or to unselect
'); ?>'>
398 while ($irow = sqlFetchArray($ires)) {
399 $list_id = $irow['id'];
400 $tcode = $irow['type'];
401 if ($ISSUE_TYPES[$tcode]) $tcode = $ISSUE_TYPES[$tcode][2];
402 echo " <option value='" . attr($list_id) . "'";
404 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
405 "pid = ? AND encounter = ? AND list_id = ?", array($pid,$encounter,$list_id));
406 if ($perow['count']) echo " selected";
409 // For new encounters the invoker may pass an issue ID.
410 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) echo " selected";
412 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
413 text(substr($irow['title'], 0, 40)) . "</option>\n";
417 <p
><i
><?php
echo xlt('To link this encounter/consult to an existing issue, click the '
418 . 'desired issue above to highlight it and then click [Save]. '
419 . 'Hold down [Ctrl] button to select multiple issues.'); ?
></i
></p
>
431 <script language
="javascript">
434 function duplicateVisit(enc
, datestr
) {
435 if (!confirm('<?php echo xls("A visit already exists for this patient today. Click Cancel to open it, or OK to proceed with creating a new one.") ?>')) {
436 // User pressed the cancel button, so re-direct to today's encounter
437 top
.restoreSession();
438 parent
.left_nav
.setEncounter(datestr
, enc
, window
.name
);
439 parent
.left_nav
.loadFrame('enc2', window
.name
, 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
442 // otherwise just continue normally
446 // Search for an encounter from today
447 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
448 "FROM form_encounter AS fe, forms AS f WHERE " .
450 " AND fe.date >= ? " .
451 " AND fe.date <= ? " .
453 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
454 "ORDER BY fe.encounter DESC LIMIT 1",array($pid,date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')));
456 if (!empty($erow['encounter'])) {
457 // If there is an encounter from today then present the duplicate visit dialog
458 echo "duplicateVisit('" . $erow['encounter'] . "', '" .
459 oeFormatShortDate(substr($erow['date'], 0, 10)) . "');\n";
464 <?php
if($GLOBALS['enable_group_therapy']) { ?
>
465 /* hide / show group name input */
466 var groupCategories
= <?php
echo json_encode($therapyGroupCategories); ?
>;
467 $
('#pc_catid').on('change', function () {
468 if(groupCategories
.indexOf($
(this
).val()) > -1){
469 $
('#therapy_group_name').show();
471 $
('#therapy_group_name').hide();
475 function sel_group() {
476 top
.restoreSession();
477 var url
= '<?php echo $GLOBALS['webroot
']?>/interface/main/calendar/find_group_popup.php';
478 dlgopen(url
, '_blank', 500, 400);
480 // This is for callback by the find-group popup.
481 function setgroup(gid
, name
) {
482 var f
= document
.forms
[0];
483 f
.form_group
.value
= name
;
484 f
.form_gid
.value
= gid
;
487 <?php
if($viewmode && in_array($result['pc_catid'], $therapyGroupCategories)) {?
>
488 $
('#therapy_group_name').show();