fix: encounter pos_code to null to honor config (#6929)
[openemr.git] / interface / forms / newpatient / common.php
blob6367bb747c9e3b6fab5a3c0c22aaf3328199343c
1 <?php
3 /**
4 * Common script for the encounter form (new and view) scripts.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Ranganath Pathak <pathak@scrs1.org>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2019 Ranganath Pathak <pathak@scrs1.org>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("$srcdir/options.inc.php");
17 require_once("$srcdir/lists.inc.php");
19 use OpenEMR\Billing\MiscBillingOptions;
20 use OpenEMR\Common\Acl\AclExtended;
21 use OpenEMR\Common\Acl\AclMain;
22 use OpenEMR\Common\Csrf\CsrfUtils;
23 use OpenEMR\Core\Header;
24 use OpenEMR\Services\FacilityService;
25 use OpenEMR\Services\ListService;
26 use OpenEMR\Services\UserService;
27 use OpenEMR\OeUI\OemrUI;
28 use OpenEMR\OeUI\RenderFormFieldHelper;
30 $facilityService = new FacilityService();
32 if ($GLOBALS['enable_group_therapy']) {
33 require_once("$srcdir/group.inc.php");
36 $mode = (!empty($_GET['mode'])) ? $_GET['mode'] : null;
38 $viewmode = false;
39 if (!empty($_GET['id'])) {
40 $viewmode = true;
43 // "followup" mode is relevant when enable follow up encounters global is enabled
44 // it allows the user to duplicate past encounter and connect between the two
45 // under this mode the facility and the visit category will be same as the origin and in readonly
46 if ($mode === "followup") {
47 $encounter = (!empty($_GET['enc'])) ? (int)$_GET['enc'] : null;
48 if (!is_null($encounter)) {
49 $viewmode = true;
50 $_REQUEST['id'] = $encounter;
54 if ($viewmode) {
55 $id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : '';
56 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
57 $encounter = $result['encounter'];
58 $encounter_followup_id = $result['parent_encounter_id'] ?? null;
59 if ($encounter_followup_id) {
60 $q = "SELECT fe.date as date, fe.encounter as encounter FROM form_encounter AS fe " .
61 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
62 "WHERE fe.id = ? AND f.deleted = 0 ";
63 $followup_enc = sqlQuery($q, array($encounter_followup_id));
64 $followup_date = date("m/d/Y", strtotime($followup_enc['date']));
65 $encounter_followup = $followup_enc['encounter'];
67 // @todo why is this here?
68 if ($mode === "followup") {
69 $followup_date = date("m/d/Y", strtotime($result['date']));
70 $encounter_followup = $result['encounter'];
71 $result['reason'] = '';
72 $result['date'] = date('Y-m-d H:i:s');
73 $encounterId = $result['id'];
76 if ($result['sensitivity'] && !AclMain::aclCheckCore('sensitivities', $result['sensitivity'])) {
77 echo "<body>\n<html>\n";
78 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
79 echo "</body>\n</html>\n";
80 exit();
84 $displayMode = ($viewmode && $mode !== "followup") ? "edit" : "new";
86 function getDefinedFacility()
88 global $viewmode;
89 global $default_fac_override;
90 global $care_team_facility;
91 global $user_facility;
92 $care_team_facility = null;
93 if (!empty($GLOBALS['set_service_facility_encounter'])) {
94 $care_team_facility = sqlQuery("SELECT `care_team_facility` FROM `patient_data` WHERE `pid` = ?", array($_SESSION['pid']));
96 if ($viewmode) {
97 global $result;
98 $def_facility = $result['facility_id'];
99 } elseif (!empty($default_fac_override)) {
100 $def_facility = $default_fac_override;
101 } elseif (!empty($GLOBALS['set_service_facility_encounter']) && !empty($care_team_facility['care_team_facility'])) {
102 $def_facility = $care_team_facility['care_team_facility'];
103 } else {
104 $def_facility = $user_facility['id'] ?? null;
106 return $def_facility;
109 $posCode = '';
111 function getFacilityList()
113 global $viewmode;
114 global $facilityService;
115 global $posCode;
116 $def_facility = getDefinedFacility();
117 $facilities = $facilityService->getAllServiceLocations();
118 $results = [];
119 foreach ($facilities as $iter) {
120 $posCode = ((int) $def_facility === (int) $iter['id'] && !$viewmode) ? $iter['pos_code'] : $posCode;
122 $results[] = [
123 'id' => $iter['id'],
124 'selected' => ($def_facility == $iter['id']) ? true : false,
125 'name' => $iter['name'],
128 return $results;
132 * Helper function to show or hide a field based on the configuration setting.
134 * @param string $field
135 * @return string
137 function displayOption($field)
139 global $displayMode;
140 echo RenderFormFieldHelper::shouldDisplayFormField($GLOBALS[$field], $displayMode) ? '' : 'd-none';
143 // Sort comparison for sensitivities by their order attribute.
144 function sensitivity_compare($a, $b)
146 return ($a[2] < $b[2]) ? -1 : 1;
149 // get issues
150 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
151 "pid = ? AND enddate IS NULL " .
152 "ORDER BY type, begdate", array($pid));
154 <!DOCTYPE html>
155 <head>
156 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
157 <title><?php echo xlt('Patient Encounter'); ?></title>
160 <!-- validation library -->
161 <?php
162 //Non LBF forms use the new validation, please make sure you have the corresponding values in the list Page validation
163 $use_validate_js = 1;
164 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
166 <?php include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?>
167 <script>
168 const mypcc = '' + <?php echo js_escape($GLOBALS['phone_country_code']); ?>;
170 // Process click on issue title.
171 function newissue() {
172 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 700, 535, '', '', {
173 buttons: [
174 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
177 return false;
180 // callback from add_edit_issue.php:
181 function refreshIssue(issue, title) {
182 var s = document.forms[0]['issues[]'];
183 s.options[s.options.length] = new Option(title, issue, true, true);
186 <?php
187 //Gets validation rules from Page Validation list.
188 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
189 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
190 if (empty($collectthis)) {
191 $collectthis = "undefined";
192 } else {
193 $collectthis = json_sanitize($collectthis["new_encounter"]["rules"]);
196 let collectvalidation = <?php echo $collectthis; ?>;
197 $(function () {
198 window.saveClicked = function (event) {
199 const submit = submitme(1, event, 'new-encounter-form', collectvalidation);
200 if (submit) {
201 top.restoreSession();
202 $('#new-encounter-form').submit();
206 $(".enc_issue").on('click', function (e) {
207 e.preventDefault();
208 e.stopPropagation();
209 dlgopen('', '', 700, 650, '', '', {
210 allowResize: true,
211 allowDrag: true,
212 dialogId: '',
213 type: 'iframe',
214 url: $(this).attr('href')
218 $('.datepicker').datetimepicker({
219 <?php $datetimepicker_timepicker = true; ?>
220 <?php $datetimepicker_showseconds = false; ?>
221 <?php $datetimepicker_formatInput = true; ?>
222 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
223 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
227 const isPosEnabled = "" + <?php echo js_escape($GLOBALS['set_pos_code_encounter']); ?>;
229 function getPOS() {
230 if (!isPosEnabled) {
231 return false;
233 let facility = document.forms[0].facility_id.value;
234 $.ajax({
235 url: "./../../../library/ajax/facility_ajax_code.php",
236 method: "GET",
237 data: {
238 mode: "get_pos",
239 facility_id: facility,
240 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
242 }).done(function (fid) {
243 document.forms[0].pos_code.value = JSON.parse(fid);
244 }).fail(function (xhr) {
245 console.log('error', xhr);
249 function newUserSelected() {
250 let provider = document.getElementById('provider_id').value;
251 $.ajax({
252 url: "./../../../library/ajax/facility_ajax_code.php",
253 method: "GET",
254 data: {
255 mode: "get_user_data",
256 provider_id: provider,
257 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
259 }).done(function (data) {
260 let rtn = JSON.parse(data);
261 document.forms[0].facility_id.value = rtn[0];
262 if (isPosEnabled) {
263 document.forms[0].pos_code.value = rtn[1];
265 if (Number(rtn[2]) === 1) {
266 document.forms[0]['billing_facility'].value = rtn[0];
268 }).fail(function (xhr) {
269 console.log('error', xhr);
273 // Handler for Cancel clicked when creating a new encounter.
274 // Show demographics or encounters list depending on what frame we're in.
275 function cancelClickedNew() {
276 window.parent.left_nav.loadFrame('ens1', window.name, 'patient_file/history/encounters.php');
277 return false;
280 // Handler for cancel clicked when not creating a new encounter.
281 // Just reload the view mode.
282 function cancelClickedOld() {
283 location.href = '<?php echo "$rootdir/patient_file/encounter/forms.php"; ?>';
284 return false;
287 </script>
288 <style>
289 @media only screen and (max-width: 1024px) {
290 #visit-details [class*="col-"],
291 #visit-issues [class*="col-"] {
292 width: 100%;
293 text-align: <?php echo ($_SESSION['language_direction'] == 'rtl') ? 'right ' : 'left '?> !important;
296 </style>
297 <?php
298 if ($viewmode) {
299 $body_javascript = '';
300 $heading_caption = xl('Patient Encounter Form');
301 } else {
302 $body_javascript = 'onload="javascript:document.new_encounter.reason.focus();"';
303 $heading_caption = xl('New Encounter Form');
307 if ($GLOBALS['enable_help'] == 1) {
308 $help_icon = '<a class="float-right oe-help-redirect" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href" style="color:#676666" title="' . xla("Click to view Help") . '"><i class="fa fa-question-circle" aria-hidden="true"></i></a>';
309 } elseif ($GLOBALS['enable_help'] == 2) {
310 $help_icon = '<a class="float-right oe-help-redirect" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href" style="color:#DCD6D0 !Important" title="' . xla("To enable help - Go to Administration > Globals > Features > Enable Help Modal") . '"><i class="fa fa-question-circle" aria-hidden="true"></i></a>';
311 } elseif ($GLOBALS['enable_help'] == 0) {
312 $help_icon = '';
315 <?php
316 $arrOeUiSettings = array(
317 'heading_title' => $heading_caption,
318 'include_patient_name' => true,// use only in appropriate pages
319 'expandable' => false,
320 'expandable_files' => array(""),//all file names need suffix _xpd
321 'action' => "",//conceal, reveal, search, reset, link or back
322 'action_title' => "",
323 'action_href' => "",//only for actions - reset, link or back
324 'show_help_icon' => true,
325 'help_file_name' => "common_help.php"
327 $oemr_ui = new OemrUI($arrOeUiSettings);
329 $provider_id = $userauthorized ? $_SESSION['authUserID'] : 0;
330 if (!$viewmode) {
331 $now = date('Y-m-d');
332 $encnow = date('Y-m-d 00:00:00');
333 $time = date("H:i:00");
334 $q = "SELECT pc_aid, pc_facility, pc_billing_location, pc_catid, pc_startTime" .
335 " FROM openemr_postcalendar_events WHERE pc_pid=? AND pc_eventDate=?" .
336 " ORDER BY pc_startTime ASC";
337 $q_events = sqlStatement($q, array($pid, $now));
338 while ($override = sqlFetchArray($q_events)) {
339 $q = "SELECT fe.encounter as encounter FROM form_encounter AS fe " .
340 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
341 "WHERE fe.pid=? AND fe.date=? AND fe.provider_id=? AND f.deleted=0";
342 $q_enc = sqlQuery($q, array($pid, $encnow, $override['pc_aid']));
343 if (!empty($override) && is_array($override) && empty($q_enc['encounter'])) {
344 $provider_id = $override['pc_aid'];
345 $default_bill_fac_override = $override['pc_billing_location'];
346 $default_fac_override = $override['pc_facility'];
347 $default_catid_override = $override['pc_catid'];
351 $user_facility = $facilityService->getFacilityForUser($_SESSION['authUserID']);
352 $MBO = new OpenEMR\Billing\MiscBillingOptions();
354 </head>
355 <body <?php echo $body_javascript; ?>>
356 <div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?> mt-3">
357 <div class="row">
358 <div class="col-sm-12">
359 <!-- Required for the popup date selectors -->
360 <div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;"></div>
361 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
362 </div>
363 </div>
364 <form class="mt-3" id="new-encounter-form" method='post' action="<?php echo $rootdir ?>/forms/newpatient/save.php" name='new_encounter'>
365 <input type="hidden" id="facility_id" name="facility_id" value="<?php echo attr(getDefinedFacility()); ?>" />
366 <?php if ($viewmode && $mode !== "followup") { ?>
367 <input type='hidden' name='mode' value='update' />
368 <input type='hidden' name='id' value='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>' />
369 <?php } else { ?>
370 <input type='hidden' name='mode' value='new' />
371 <?php } ?>
372 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
374 <?php if ($mode === "followup") { ?>
375 <input type='hidden' name='parent_enc_id' value='<?php echo attr($encounterId); ?>' />
376 <?php } ?>
378 <fieldset>
379 <legend><?php echo xlt('Visit Details') ?>
380 <small>
381 <?php echo (!empty($encounter_followup)) ? (xlt("Follow up for") . ": " . text($encounter_followup) . " " . xlt("Dated") . ": " . text($followup_date)) : ''; ?>
382 </small>
383 </legend>
384 <div id="visit-details" class="px-3">
385 <div class="form-row align-items-center">
386 <div class="col-sm <?php displayOption('enc_enable_visit_category'); ?>">
387 <div class="form-group">
388 <label for="pc_catid" class="text-right"><?php echo xlt('Visit Category:'); ?></label>
389 <select name='pc_catid' id='pc_catid' class='form-control' <?php echo ($mode === "followup") ? 'disabled' : ''; ?>>
390 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
391 <?php
392 //Bring only patient and group categories
393 $visitSQL = "SELECT pc_catid, pc_catname, pc_cattype
394 FROM openemr_postcalendar_categories
395 WHERE pc_active = 1 and pc_cattype IN (0,3) and pc_constant_id != 'no_show' ORDER BY pc_seq";
397 $visitResult = sqlStatement($visitSQL);
398 $therapyGroupCategories = [];
400 while ($row = sqlFetchArray($visitResult)) {
401 $catId = $row['pc_catid'];
402 $name = $row['pc_catname'];
404 if ($row['pc_cattype'] == 3) {
405 $therapyGroupCategories[] = $catId;
408 if ($catId === "_blank") {
409 continue;
412 if ($row['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) {
413 continue;
416 // Fetch acl for category of given encounter. Only if has write auth for a category, then can create an encounter of that category.
417 $postCalendarCategoryACO = AclMain::fetchPostCalendarCategoryACO($catId);
418 if ($postCalendarCategoryACO) {
419 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
420 $authPostCalendarCategoryWrite = AclMain::aclCheckCore($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
421 } else { // if no aco is set for category
422 $authPostCalendarCategoryWrite = true;
425 //if no permission for category write, don't show in drop-down
426 if (!$authPostCalendarCategoryWrite) {
427 continue;
430 $optionStr = '<option value="%pc_catid%" %selected%>%pc_catname%</option>';
431 $optionStr = str_replace("%pc_catid%", attr($catId), $optionStr);
432 $optionStr = str_replace("%pc_catname%", text(xl_appt_category($name)), $optionStr);
433 if ($viewmode) {
434 $selected = ($result['pc_catid'] == $catId) ? " selected" : "";
435 } else {
436 $selected = ($GLOBALS['default_visit_category'] == $catId) ? " selected" : "";
439 $optionStr = str_replace("%selected%", $selected, $optionStr);
440 echo $optionStr;
443 </select>
444 <?php if ($mode === "followup") { ?>
445 <input name="pc_catid" value="<?php echo attr($result['pc_catid']); ?>" hidden />
446 <?php } ?>
447 </div>
448 </div>
449 <div class="col-sm <?php displayOption('enc_enable_class');?>">
450 <div class="form-group">
451 <label for='class' class="text-right"><?php echo xlt('Class'); ?>:</label>
452 <?php echo generate_select_list('class_code', '_ActEncounterCode', $viewmode ? $result['class_code'] : '', '', ''); ?>
453 </div>
454 </div>
455 <div class="col-sm <?php displayOption('enc_enable_type');?>">
456 <div class="form-group">
457 <label for='encounter_type' class="text-right"><?php echo xlt('Type'); ?>:</label>
458 <?php
459 // we need to convert from our selected code if we have one to our list type
460 $encounter_type_option = $result['encounter_type_code'] ?? '';
461 if (!empty($encounter_type_option)) {
462 $listService = new ListService();
463 $codes = $listService->getOptionsByListName('encounter-types', ['codes' => $result['encounter_type_code']]);
464 if (empty($codes[0])) {
465 // we may not have code types installed, in that case we will just use the option-id so we can remember the data
466 $option = $listService->getListOption('encounter-types', $encounter_type_option);
467 $encounter_type_option = $option['option_id'] ?? '';
468 } else {
469 $encounter_type_option = $codes[0]['option_id'];
473 <?php echo generate_select_list('encounter_type', 'encounter-types', $viewmode ? $encounter_type_option : '', '', '--' . xl('Select One') . '--'); ?>
474 </div>
475 </div>
476 <?php
477 $sensitivities = AclExtended::aclGetSensitivities();
478 if ($sensitivities && count($sensitivities)) :
479 usort($sensitivities, "sensitivity_compare");
481 <div class="col-sm <?php displayOption('enc_sensitivity_visibility');?>">
482 <div class="form-group">
483 <label for="pc_catid" class="text-right"><?php echo xlt('Sensitivity:'); ?> <i id='sensitivity-tooltip' class="fa fa-info-circle text-primary" aria-hidden="true"></i></label>
484 <select name='form_sensitivity' id='form_sensitivity' class='form-control'>
485 <?php
486 foreach ($sensitivities as $value) {
487 // Omit sensitivities to which this user does not have access.
488 if (!AclMain::aclCheckCore('sensitivities', $value[1])) {
489 continue;
492 $selected = ($viewmode && $result['sensitivity'] == $value[1]) ? 'selected' : '';
493 $value = attr($value[1]);
494 $display = xlt($value);
495 echo "<option value=\"$value\" $selected>$display</option>\n";
497 $selected = ($viewmode && !$result['sensitivity']) ? "selected" : "";
498 echo "<option value='' $selected>" . xlt('None{{Sensitivity}}') . "</option>\n";
500 </select>
501 </div>
502 </div>
503 <?php endif; ?>
504 </div>
506 <div class="form-row align-items-center">
507 <div class="col-sm">
508 <div class="form-group">
509 <label for='provider_id' class="text-right"><?php echo xlt('Encounter Provider'); ?>:</label>
510 <select name='provider_id' id='provider_id' class='form-control' onChange="newUserSelected()">
511 <?php
512 if ($viewmode) {
513 $provider_id = $result['provider_id'];
515 $userService = new UserService();
516 $users = $userService->getActiveUsers();
517 foreach ($users as $activeUser) {
518 $p_id = (int)$activeUser['id'];
519 // Check for the case where an encounter is created by non-auth user
520 // but has permissions to create/edit encounter.
521 $flag_it = "";
522 if ($activeUser['authorized'] != 1) {
523 if ($p_id === (int)($result['provider_id'] ?? null)) {
524 $flag_it = " (" . xlt("Non Provider") . ")";
525 } else {
526 continue;
529 echo "<option value='" . attr($p_id) . "'";
530 if ((int)$provider_id === $p_id) {
531 echo "selected";
533 echo ">" . text($activeUser['lname']) . ', ' .
534 ($activeUser['suffix'] ? text($activeUser['suffix']) . ', ' : '') .
535 ($activeUser['valedictory'] ? text($activeUser['valedictory']) . ', ' : '') .
536 text($activeUser['fname']) .
537 ($activeUser['mname'] ? ', ' . text($activeUser['mname']) : ' ') .
538 $flag_it . "</option>\n";
541 </select>
542 </div>
543 </div>
544 <div class="col-sm <?php displayOption('enc_enable_referring_provider');?>">
545 <div class="form-group">
546 <label for='referring_provider_id' class="text-right"><?php echo xlt('Referring Provider'); ?>:</label>
547 <?php
548 if ($viewmode && !empty($result["referring_provider_id"])) {
549 $MBO->genReferringProviderSelect('referring_provider_id', '-- ' . xl("Please Select") . ' --', $result["referring_provider_id"]);
550 } else { // defalut to the patient's referring provider from Demographics->Choices
551 $MBO->genReferringProviderSelect('referring_provider_id', '-- ' . xl("Please Select") . ' --', getPatientData($pid, "ref_providerID")['ref_providerID']);
552 } ?>
553 </select>
554 </div>
555 </div>
556 <div class="col-sm <?php displayOption('enc_enable_facility'); ?>">
557 <div class="form-group">
558 <label for='facility_id_sel' class="text-right"><?php echo xlt('Facility'); ?>:</label>
559 <select name='facility_id_sel' id='facility_id_sel' class='form-control' <?php echo ($mode === "followup") ? 'disabled' : ''; ?> >
560 <?php
561 $fac = getFacilityList();
562 foreach ($fac as $f) : ?>
563 <option value="<?php echo attr($f['id']); ?>" <?php echo ($f['selected'] == true) ? 'selected' : '';?>><?php echo text($f['name']); ?></option>
564 <?php endforeach; ?>
565 </select>
566 </div>
567 </div>
568 <div class="col-sm <?php echo ($GLOBALS['hide_billing_widget'] != 1) ?: 'd-none'; ?>">
569 <div class="form-group">
570 <label for='billing_facility' class="text-right"><?php echo xlt('Billing Facility'); ?>:</label>
571 <?php
572 if (!empty($default_bill_fac_override)) {
573 $default_bill_fac = $default_bill_fac_override;
574 } elseif (!$viewmode && $mode !== "followup") {
575 if ($user_facility['billing_location'] == '1') {
576 $default_bill_fac = $user_facility['id'] ;
577 } else {
578 $tmp_be = $facilityService->getPrimaryBusinessEntity();
579 $tmp_bl = $facilityService->getPrimaryBillingLocation();
580 $tmp = !empty($tmp_be['id']) ? $tmp_be['id'] : (!empty($tmp_bl['id']) ? $tmp_bl['id'] : null);
581 $default_bill_fac = !empty($tmp) ? $tmp : $def_facility;
583 } else {
584 $default_bill_fac = isset($result['billing_facility']) ? $result['billing_facility'] : $def_facility;
586 billing_facility('billing_facility', $default_bill_fac);
588 </div>
589 </div>
590 </div>
592 <div class="form-row align-items-center">
593 <div class="col-sm <?php displayOption('enc_service_date');?>">
594 <div class="form-group">
595 <label for='form_date' class="text-right"><?php echo xlt('Date of Service:'); ?></label>
596 <input type='text' class='form-control datepicker' name='form_date' id='form_date' <?php echo ($disabled ?? '') ?> value='<?php echo $viewmode ? attr(oeFormatDateTime($result['date'])) : attr(oeFormatDateTime(date('Y-m-d H:i:00'))); ?>' title='<?php echo xla('Date of service'); ?>' />
597 </div>
598 </div>
599 <div class="col-sm <?php echo ($GLOBALS['gbl_visit_onset_date'] == 1) ?: 'd-none'; ?>">
600 <div class="form-group">
601 <label for='form_onset_date' class="text-right"><?php echo xlt('Onset/hosp. date:'); ?> &nbsp;<i id='onset-tooltip' class="fa fa-info-circle text-primary" aria-hidden="true"></i></label>
602 <input type='text' class='form-control datepicker' name='form_onset_date' id='form_onset_date' value='<?php echo $viewmode && $result['onset_date'] !== '0000-00-00 00:00:00' ? attr(oeFormatDateTime($result['onset_date'])) : ''; ?>' title='<?php echo xla('Date of onset or hospitalization'); ?>' />
603 </div>
604 </div>
605 <div class="col-sm <?php echo ($GLOBALS['gbl_visit_referral_source'] == 1) ?: 'd-none';?>">
606 <div class="form-group">
607 <label for="form_referral_source" class="text-right"><?php echo xlt('Referral Source'); ?>:</label>
608 <?php echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', ''); ?>
609 </div>
610 </div>
611 <div class="col-sm <?php echo ($GLOBALS['set_pos_code_encounter'] == 1) ?: 'd-none';?>">
612 <div class="form-group">
613 <label for='pos_code' class="text-right"><?php echo xlt('POS Code'); ?>:</label>
614 <select name="pos_code" id="pos_code" class='form-control'>
615 <?php
616 $pc = new POSRef();
617 foreach ($pc->get_pos_ref() as $pos) {
618 echo "<option value=\"" . attr($pos["code"]) . "\"";
619 if (
620 ($pos["code"] == ($result['pos_code'] ?? '') && $viewmode)
621 || ($pos["code"] == ($posCode ?? '') && !$viewmode)
623 echo " selected";
625 echo ">" . text($pos['code']) . ": " . xlt($pos['title']);
626 echo "</option>\n";
629 </select>
630 </div>
631 </div>
632 <?php $collectionDisplay = ($GLOBALS['hide_billing_widget'] == 1) ? 'd-none' : displayOption('enc_in_collection'); ?>
633 <div class="col-sm <?php echo $collectionDisplay; ?>">
634 <div class="form-group">
635 <label for='in_collection' class="text-right"><?php echo xlt('In Collection'); ?>:</label>
636 <select class='form-control' name='in_collection' id='in_collection'>
637 <option value="1" <?php echo (($result["in_collection"] ?? null) == 1) ? "selected" : ""; ?>><?php echo xlt('Yes'); ?></option>
638 <option value="0" <?php echo (($result["in_collection"] ?? null) == 0) ? "selected" : ""; ?>><?php echo xlt('No'); ?></option>
639 </select>
640 </div>
641 </div>
642 </div>
644 <div class="form-row align-items-center">
645 <!-- Discharge Disposition -->
646 <div class="col-sm <?php displayOption('enc_enable_discharge_disposition'); ?>">
647 <div class="form-group">
648 <label for='facility_id' class="text-right"><?php echo xlt('Discharge Disposition'); ?>:</label>
649 <select name='discharge_disposition' id='discharge_disposition' class='form-control'>
650 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
651 <?php
652 $dischargeListDisposition = new ListService();
653 $dischargeDisposiitons = $dischargeListDisposition->getOptionsByListName('discharge-disposition') ?? [];
654 foreach ($dischargeDisposiitons as $dispositon) {
655 $selected = ($result['discharge_disposition'] ?? null) == $dispositon['option_id'] ? "selected='selected'" : "";
657 <option value="<?php echo attr($dispositon['option_id']); ?>" <?php echo $selected; ?> ><?php echo text($dispositon['title']); ?></option>
658 <?php } ?>
659 </select>
660 </div>
661 </div>
662 <div class="col-sm <?php echo ($GLOBALS['enable_group_therapy'] == 1) ?: 'd-none'; ?>">
663 <div class="form-group">
664 <label for="form_group" class="text-right"><?php echo xlt('Group name'); ?>:</label>
665 <input type='text' name='form_group' class='form-control' id="form_group" 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 />
666 <input type='hidden' name='form_gid' value='<?php echo $viewmode && in_array($result['pc_catid'], $therapyGroupCategories) ? attr($result['external_id']) : '' ?>' />
667 </div>
668 </div>
669 </div>
670 </div>
671 </fieldset>
673 <div class="form-row">
674 <div class="col-sm">
675 <fieldset>
676 <legend><?php echo xlt('Reason for Visit') ?></legend>
677 <div class="form-row mx-3 h-100">
678 <textarea name="reason" id="reason" class="form-control" cols="80" rows="4"><?php echo $viewmode ? text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?></textarea>
679 </div>
680 </fieldset>
681 </div>
682 <div class="col-sm <?php displayOption('enc_enable_issues');?>">
683 <?php
684 // Before we even check for auth, see if we will even display
685 // To see issues stuff user needs write access to all issue types.
686 $issuesauth = true;
687 foreach ($ISSUE_TYPES as $type => $dummy) {
688 if (!AclMain::aclCheckIssue($type, '', 'write')) {
689 $issuesauth = false;
690 break;
693 if ($issuesauth) {
695 <fieldset>
696 <legend>
697 <?php echo xlt('Link/Add Issues to This Visit') ?>
698 </legend>
699 <div id="visit-issues">
700 <div class="form-row px-3">
701 <div class="pb-1 col-sm">
702 <?php if (AclMain::aclCheckCore('patients', 'med', '', 'write')) { ?>
703 <a href="../../patient_file/summary/add_edit_issue.php" class="btn d-block btn-primary btn-add btn-sm enc_issue" onclick="top.restoreSession()"><?php echo xlt('Add Issue'); ?></a>
704 <?php } ?>
705 </div>
706 <select multiple name='issues[]' class='form-control' title='<?php echo xla('Hold down [Ctrl] for multiple selections or to unselect'); ?>' size='4'>
707 <?php
708 while ($irow = sqlFetchArray($ires)) {
709 $list_id = $irow['id'];
710 $tcode = $irow['type'];
711 if ($ISSUE_TYPES[$tcode]) {
712 $tcode = $ISSUE_TYPES[$tcode][2];
714 echo "<option value='" . attr($list_id) . "'";
715 if ($viewmode) {
716 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
717 "pid = ? AND encounter = ? AND list_id = ?", array($pid, $encounter, $list_id));
718 if ($perow['count']) {
719 echo " selected";
721 } else {
722 // For new encounters the invoker may pass an issue ID.
723 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) {
724 echo " selected";
727 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
728 text(substr($irow['title'], 0, 40)) . "</option>\n";
731 </select>
732 <p><i><?php echo xlt('To link this encounter/consult to an existing issue, click the '
733 . 'desired issue above to highlight it and then click [Save]. '
734 . 'Hold down [Ctrl] button to select multiple issues.'); ?></i></p>
735 </div>
736 </div>
737 </fieldset>
738 <?php
741 </div>
742 </div>
743 <?php //can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets ?>
744 <div class="form-row">
745 <div class="col-sm-12 text-left position-override pl-3">
746 <div class="btn-group" role="group">
747 <?php $link_submit = ($viewmode || empty($_GET['autoloaded'])) ? '' : 'link_submit';
748 $cancel_clicked = ($viewmode) ? 'cancelClickedOld()' : 'cancelClickedNew()';?>
749 <button type="button" class="btn btn-primary btn-save" onclick="top.restoreSession(); saveClicked(undefined);"><?php echo xlt('Save'); ?></button>
750 <button type="button" class="btn btn-cancel <?php echo $link_submit;?>" onClick="return <?php echo $cancel_clicked;?>"><?php echo xlt('Cancel'); ?></button>
751 </div>
752 </div>
753 </div>
754 </form>
755 </div><!--End of container div-->
756 <?php $oemr_ui->oeBelowContainerDiv(); ?>
757 <script>
758 const fac_id_sel = document.getElementById("facility_id_sel");
759 fac_id_sel.addEventListener("change", () => {
760 let fac_id = document.getElementById("facility_id");
761 fac_id.value = fac_id_sel[fac_id_sel.selectedIndex].value;
762 getPOS();
765 <?php
766 if (!$viewmode) { ?>
767 function duplicateVisit(enc, datestr) {
768 if (!confirm(<?php echo xlj("A visit already exists for this patient today. Click Cancel to open it, or OK to proceed with creating a new one.") ?>)) {
769 // User pressed the cancel button, so re-direct to today's encounter
770 top.restoreSession();
771 parent.left_nav.setEncounter(datestr, enc, window.name);
772 parent.left_nav.loadFrame('enc2', window.name, 'patient_file/encounter/encounter_top.php?set_encounter=' + encodeURIComponent(enc));
773 return;
775 // otherwise just continue normally
777 <?php
778 // Search for an encounter from today
779 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
780 "FROM form_encounter AS fe, forms AS f WHERE " .
781 "fe.pid = ? " .
782 " AND fe.date >= ? " .
783 " AND fe.date <= ? " .
784 " AND " .
785 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
786 "ORDER BY fe.encounter DESC LIMIT 1", array($pid, date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')));
788 if (!empty($erow['encounter'])) {
789 // If there is an encounter from today then present the duplicate visit dialog
790 echo "duplicateVisit(" . js_escape($erow['encounter']) . ", " .
791 js_escape(oeFormatShortDate(substr($erow['date'], 0, 10))) . ");\n";
795 <?php
796 if ($GLOBALS['enable_group_therapy']) { ?>
797 /* hide / show group name input */
798 let groupCategories = <?php echo json_encode($therapyGroupCategories); ?>;
799 $('#pc_catid').on('change', function () {
800 if (groupCategories.indexOf($(this).val()) > -1) {
801 $('#therapy_group_name').show();
802 } else {
803 $('#therapy_group_name').hide();
807 function sel_group() {
808 top.restoreSession();
809 const url = '<?php echo $GLOBALS['webroot']?>/interface/main/calendar/find_group_popup.php';
810 dlgopen(url, '_blank', 500, 400, '', '', {
811 buttons: [
812 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
817 // This is for callback by the find-group popup.
818 function setgroup(gid, name) {
819 var f = document.forms[0];
820 f.form_group.value = name;
821 f.form_gid.value = gid;
824 <?php
825 if ($viewmode && in_array($result['pc_catid'], $therapyGroupCategories)) {?>
826 $('#therapy_group_name').show();
827 <?php
828 } ?>
829 <?php
830 } ?>
832 $(function () {
833 $('#sensitivity-tooltip').attr({"title": <?php echo xlj('If set as high will restrict visibility of encounter to users belonging to certain groups (AROs). By default - Physicians and Administrators'); ?>, "data-toggle": "tooltip", "data-placement": "bottom"}).tooltip();
834 $('#onset-tooltip').attr({"title": <?php echo xlj('Hospital date needed for successful billing of hospital encounters'); ?>, "data-toggle": "tooltip", "data-placement": "bottom"}).tooltip();
837 </script>
839 <?php if (!empty($GLOBALS['text_templates_enabled'])) { ?>
840 <script src="<?php echo $GLOBALS['web_root'] ?>/library/js/CustomTemplateLoader.js"></script>
841 <?php } ?>
842 </body>
843 </html>