feat: expose suffix and valedictory in user admin and esign (#6814)
[openemr.git] / interface / forms / newpatient / common.php
blob245178f2da544ac4be06ca8521605267908d4dcf
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 $months = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
37 $days = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
38 $thisyear = date("Y");
39 $years = array($thisyear - 1, $thisyear, $thisyear + 1, $thisyear + 2);
41 $mode = (!empty($_GET['mode'])) ? $_GET['mode'] : null;
43 $viewmode = false;
44 if (!empty($_GET['id'])) {
45 $viewmode = true;
48 // "followup" mode is relevant when enable follow up encounters global is enabled
49 // it allows the user to duplicate past encounter and connect between the two
50 // under this mode the facility and the visit category will be same as the origin and in readonly
51 if ($mode === "followup") {
52 $encounter = (!empty($_GET['enc'])) ? (int)$_GET['enc'] : null;
53 if (!is_null($encounter)) {
54 $viewmode = true;
55 $_REQUEST['id'] = $encounter;
59 if ($viewmode) {
60 $id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : '';
61 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
62 $encounter = $result['encounter'];
63 $encounter_followup_id = $result['parent_encounter_id'] ?? null;
64 if ($encounter_followup_id) {
65 $q = "SELECT fe.date as date, fe.encounter as encounter FROM form_encounter AS fe " .
66 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
67 "WHERE fe.id = ? AND f.deleted = 0 ";
68 $followup_enc = sqlQuery($q, array($encounter_followup_id));
69 $followup_date = date("m/d/Y", strtotime($followup_enc['date']));
70 $encounter_followup = $followup_enc['encounter'];
72 // @todo why is this here?
73 if ($mode === "followup") {
74 $followup_date = date("m/d/Y", strtotime($result['date']));
75 $encounter_followup = $result['encounter'];
76 $result['reason'] = '';
77 $result['date'] = date('Y-m-d H:i:s');
78 $encounterId = $result['id'];
81 if ($result['sensitivity'] && !AclMain::aclCheckCore('sensitivities', $result['sensitivity'])) {
82 echo "<body>\n<html>\n";
83 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
84 echo "</body>\n</html>\n";
85 exit();
89 $displayMode = ($viewmode && $mode !== "followup") ? "edit" : "new";
91 function getDefinedFacility()
93 global $viewmode;
94 global $default_fac_override;
95 global $care_team_facility;
96 global $user_facility;
97 $care_team_facility = null;
98 if (!empty($GLOBALS['set_service_facility_encounter'])) {
99 $care_team_facility = sqlQuery("SELECT `care_team_facility` FROM `patient_data` WHERE `pid` = ?", array($_SESSION['pid']));
101 if ($viewmode) {
102 global $result;
103 $def_facility = $result['facility_id'];
104 } elseif (!empty($default_fac_override)) {
105 $def_facility = $default_fac_override;
106 } elseif (!empty($GLOBALS['set_service_facility_encounter']) && !empty($care_team_facility['care_team_facility'])) {
107 $def_facility = $care_team_facility['care_team_facility'];
108 } else {
109 $def_facility = $user_facility['id'] ?? null;
111 return $def_facility;
114 $posCode = '';
116 function getFacilityList()
118 global $viewmode;
119 global $facilityService;
120 global $posCode;
121 $def_facility = getDefinedFacility();
122 $facilities = $facilityService->getAllServiceLocations();
123 $results = [];
124 foreach ($facilities as $iter) {
125 $posCode = (($def_facility === $iter['id']) && !$viewmode) ? $iter['pos_code'] : $posCode;
127 $results[] = [
128 'id' => $iter['id'],
129 'selected' => ($def_facility == $iter['id']) ? true : false,
130 'name' => $iter['name'],
133 return $results;
137 * Helper function to show or hide a field based on the configuration setting.
139 * @param string $field
140 * @return string
142 function displayOption($field)
144 global $displayMode;
145 echo RenderFormFieldHelper::shouldDisplayFormField($GLOBALS[$field], $displayMode) ? '' : 'd-none';
148 // Sort comparison for sensitivities by their order attribute.
149 function sensitivity_compare($a, $b)
151 return ($a[2] < $b[2]) ? -1 : 1;
154 // get issues
155 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
156 "pid = ? AND enddate IS NULL " .
157 "ORDER BY type, begdate", array($pid));
159 <!DOCTYPE html>
160 <head>
161 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
162 <title><?php echo xlt('Patient Encounter'); ?></title>
165 <!-- validation library -->
166 <?php
167 //Non LBF forms use the new validation, please make sure you have the corresponding values in the list Page validation
168 $use_validate_js = 1;
169 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
171 <?php include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?>
172 <script>
173 const mypcc = '' + <?php echo js_escape($GLOBALS['phone_country_code']); ?>;
175 // Process click on issue title.
176 function newissue() {
177 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 700, 535, '', '', {
178 buttons: [
179 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
182 return false;
185 // callback from add_edit_issue.php:
186 function refreshIssue(issue, title) {
187 var s = document.forms[0]['issues[]'];
188 s.options[s.options.length] = new Option(title, issue, true, true);
191 <?php
192 //Gets validation rules from Page Validation list.
193 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
194 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
195 if (empty($collectthis)) {
196 $collectthis = "undefined";
197 } else {
198 $collectthis = json_sanitize($collectthis["new_encounter"]["rules"]);
201 let collectvalidation = <?php echo $collectthis; ?>;
202 $(function () {
203 window.saveClicked = function (event) {
204 const submit = submitme(1, event, 'new-encounter-form', collectvalidation);
205 if (submit) {
206 top.restoreSession();
207 $('#new-encounter-form').submit();
211 $(".enc_issue").on('click', function (e) {
212 e.preventDefault();
213 e.stopPropagation();
214 dlgopen('', '', 700, 650, '', '', {
215 allowResize: true,
216 allowDrag: true,
217 dialogId: '',
218 type: 'iframe',
219 url: $(this).attr('href')
223 $('.datepicker').datetimepicker({
224 <?php $datetimepicker_timepicker = true; ?>
225 <?php $datetimepicker_showseconds = false; ?>
226 <?php $datetimepicker_formatInput = true; ?>
227 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
228 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
232 const isPosEnabled = "" + <?php echo js_escape($GLOBALS['set_pos_code_encounter']); ?>;
234 function getPOS() {
235 if (!isPosEnabled) {
236 return false;
238 let facility = document.forms[0].facility_id.value;
239 $.ajax({
240 url: "./../../../library/ajax/facility_ajax_code.php",
241 method: "GET",
242 data: {
243 mode: "get_pos",
244 facility_id: facility,
245 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
247 }).done(function (fid) {
248 document.forms[0].pos_code.value = JSON.parse(fid);
249 }).fail(function (xhr) {
250 console.log('error', xhr);
254 function newUserSelected() {
255 let provider = document.getElementById('provider_id').value;
256 $.ajax({
257 url: "./../../../library/ajax/facility_ajax_code.php",
258 method: "GET",
259 data: {
260 mode: "get_user_data",
261 provider_id: provider,
262 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
264 }).done(function (data) {
265 let rtn = JSON.parse(data);
266 document.forms[0].facility_id.value = rtn[0];
267 if (isPosEnabled) {
268 document.forms[0].pos_code.value = rtn[1];
270 if (Number(rtn[2]) === 1) {
271 document.forms[0]['billing_facility'].value = rtn[0];
273 }).fail(function (xhr) {
274 console.log('error', xhr);
278 // Handler for Cancel clicked when creating a new encounter.
279 // Show demographics or encounters list depending on what frame we're in.
280 function cancelClickedNew() {
281 window.parent.left_nav.loadFrame('ens1', window.name, 'patient_file/history/encounters.php');
282 return false;
285 // Handler for cancel clicked when not creating a new encounter.
286 // Just reload the view mode.
287 function cancelClickedOld() {
288 location.href = '<?php echo "$rootdir/patient_file/encounter/forms.php"; ?>';
289 return false;
292 </script>
293 <style>
294 @media only screen and (max-width: 1024px) {
295 #visit-details [class*="col-"],
296 #visit-issues [class*="col-"] {
297 width: 100%;
298 text-align: <?php echo ($_SESSION['language_direction'] == 'rtl') ? 'right ' : 'left '?> !important;
301 </style>
302 <?php
303 if ($viewmode) {
304 $body_javascript = '';
305 $heading_caption = xl('Patient Encounter Form');
306 } else {
307 $body_javascript = 'onload="javascript:document.new_encounter.reason.focus();"';
308 $heading_caption = xl('New Encounter Form');
312 if ($GLOBALS['enable_help'] == 1) {
313 $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>';
314 } elseif ($GLOBALS['enable_help'] == 2) {
315 $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>';
316 } elseif ($GLOBALS['enable_help'] == 0) {
317 $help_icon = '';
320 <?php
321 $arrOeUiSettings = array(
322 'heading_title' => $heading_caption,
323 'include_patient_name' => true,// use only in appropriate pages
324 'expandable' => false,
325 'expandable_files' => array(""),//all file names need suffix _xpd
326 'action' => "",//conceal, reveal, search, reset, link or back
327 'action_title' => "",
328 'action_href' => "",//only for actions - reset, link or back
329 'show_help_icon' => true,
330 'help_file_name' => "common_help.php"
332 $oemr_ui = new OemrUI($arrOeUiSettings);
334 $provider_id = $userauthorized ? $_SESSION['authUserID'] : 0;
335 if (!$viewmode) {
336 $now = date('Y-m-d');
337 $encnow = date('Y-m-d 00:00:00');
338 $time = date("H:i:00");
339 $q = "SELECT pc_aid, pc_facility, pc_billing_location, pc_catid, pc_startTime" .
340 " FROM openemr_postcalendar_events WHERE pc_pid=? AND pc_eventDate=?" .
341 " ORDER BY pc_startTime ASC";
342 $q_events = sqlStatement($q, array($pid, $now));
343 while ($override = sqlFetchArray($q_events)) {
344 $q = "SELECT fe.encounter as encounter FROM form_encounter AS fe " .
345 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
346 "WHERE fe.pid=? AND fe.date=? AND fe.provider_id=? AND f.deleted=0";
347 $q_enc = sqlQuery($q, array($pid, $encnow, $override['pc_aid']));
348 if (!empty($override) && is_array($override) && empty($q_enc['encounter'])) {
349 $provider_id = $override['pc_aid'];
350 $default_bill_fac_override = $override['pc_billing_location'];
351 $default_fac_override = $override['pc_facility'];
352 $default_catid_override = $override['pc_catid'];
356 $user_facility = $facilityService->getFacilityForUser($_SESSION['authUserID']);
357 $MBO = new OpenEMR\Billing\MiscBillingOptions();
359 </head>
360 <body <?php echo $body_javascript; ?>>
361 <div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?> mt-3">
362 <div class="row">
363 <div class="col-sm-12">
364 <!-- Required for the popup date selectors -->
365 <div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;"></div>
366 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
367 </div>
368 </div>
369 <form class="mt-3" id="new-encounter-form" method='post' action="<?php echo $rootdir ?>/forms/newpatient/save.php" name='new_encounter'>
370 <input type="hidden" id="facility_id" name="facility_id" value="<?php echo attr(getDefinedFacility()); ?>" />
371 <?php if ($viewmode && $mode !== "followup") { ?>
372 <input type='hidden' name='mode' value='update' />
373 <input type='hidden' name='id' value='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>' />
374 <?php } else { ?>
375 <input type='hidden' name='mode' value='new' />
376 <?php } ?>
377 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
379 <?php if ($mode === "followup") { ?>
380 <input type='hidden' name='parent_enc_id' value='<?php echo attr($encounterId); ?>' />
381 <?php } ?>
383 <fieldset>
384 <legend><?php echo xlt('Visit Details') ?>
385 <small>
386 <?php echo (!empty($encounter_followup)) ? (xlt("Follow up for") . ": " . text($encounter_followup) . " " . xlt("Dated") . ": " . text($followup_date)) : ''; ?>
387 </small>
388 </legend>
389 <div id="visit-details" class="px-3">
390 <div class="form-row align-items-center">
391 <div class="col-sm <?php displayOption('enc_enable_visit_category'); ?>">
392 <div class="form-group">
393 <label for="pc_catid" class="text-right"><?php echo xlt('Visit Category:'); ?></label>
394 <select name='pc_catid' id='pc_catid' class='form-control' <?php echo ($mode === "followup") ? 'disabled' : ''; ?>>
395 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
396 <?php
397 //Bring only patient and group categories
398 $visitSQL = "SELECT pc_catid, pc_catname, pc_cattype
399 FROM openemr_postcalendar_categories
400 WHERE pc_active = 1 and pc_cattype IN (0,3) and pc_constant_id != 'no_show' ORDER BY pc_seq";
402 $visitResult = sqlStatement($visitSQL);
403 $therapyGroupCategories = [];
405 while ($row = sqlFetchArray($visitResult)) {
406 $catId = $row['pc_catid'];
407 $name = $row['pc_catname'];
409 if ($row['pc_cattype'] == 3) {
410 $therapyGroupCategories[] = $catId;
413 if ($catId === "_blank") {
414 continue;
417 if ($row['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) {
418 continue;
421 // Fetch acl for category of given encounter. Only if has write auth for a category, then can create an encounter of that category.
422 $postCalendarCategoryACO = AclMain::fetchPostCalendarCategoryACO($catId);
423 if ($postCalendarCategoryACO) {
424 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
425 $authPostCalendarCategoryWrite = AclMain::aclCheckCore($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
426 } else { // if no aco is set for category
427 $authPostCalendarCategoryWrite = true;
430 //if no permission for category write, don't show in drop-down
431 if (!$authPostCalendarCategoryWrite) {
432 continue;
435 $optionStr = '<option value="%pc_catid%" %selected%>%pc_catname%</option>';
436 $optionStr = str_replace("%pc_catid%", attr($catId), $optionStr);
437 $optionStr = str_replace("%pc_catname%", text(xl_appt_category($name)), $optionStr);
438 if ($viewmode) {
439 $selected = ($result['pc_catid'] == $catId) ? " selected" : "";
440 } else {
441 $selected = ($GLOBALS['default_visit_category'] == $catId) ? " selected" : "";
444 $optionStr = str_replace("%selected%", $selected, $optionStr);
445 echo $optionStr;
448 </select>
449 <?php if ($mode === "followup") { ?>
450 <input name="pc_catid" value="<?php echo attr($result['pc_catid']); ?>" hidden />
451 <?php } ?>
452 </div>
453 </div>
454 <div class="col-sm <?php displayOption('enc_enable_class');?>">
455 <div class="form-group">
456 <label for='class' class="text-right"><?php echo xlt('Class'); ?>:</label>
457 <?php echo generate_select_list('class_code', '_ActEncounterCode', $viewmode ? $result['class_code'] : '', '', ''); ?>
458 </div>
459 </div>
460 <div class="col-sm <?php displayOption('enc_enable_type');?>">
461 <div class="form-group">
462 <label for='encounter_type' class="text-right"><?php echo xlt('Type'); ?>:</label>
463 <?php
464 // we need to convert from our selected code if we have one to our list type
465 $encounter_type_option = $result['encounter_type_code'] ?? '';
466 if (!empty($encounter_type_option)) {
467 $listService = new ListService();
468 $codes = $listService->getOptionsByListName('encounter-types', ['codes' => $result['encounter_type_code']]);
469 if (empty($codes[0])) {
470 // we may not have code types installed, in that case we will just use the option-id so we can remember the data
471 $option = $listService->getListOption('encounter-types', $encounter_type_option);
472 $encounter_type_option = $option['option_id'] ?? '';
473 } else {
474 $encounter_type_option = $codes[0]['option_id'];
478 <?php echo generate_select_list('encounter_type', 'encounter-types', $viewmode ? $encounter_type_option : '', '', '--' . xl('Select One') . '--'); ?>
479 </div>
480 </div>
481 <?php
482 $sensitivities = AclExtended::aclGetSensitivities();
483 if ($sensitivities && count($sensitivities)) :
484 usort($sensitivities, "sensitivity_compare");
486 <div class="col-sm <?php displayOption('enc_sensitivity_visibility');?>">
487 <div class="form-group">
488 <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>
489 <select name='form_sensitivity' id='form_sensitivity' class='form-control'>
490 <?php
491 foreach ($sensitivities as $value) {
492 // Omit sensitivities to which this user does not have access.
493 if (!AclMain::aclCheckCore('sensitivities', $value[1])) {
494 continue;
497 $selected = ($viewmode && $result['sensitivity'] == $value[1]) ? 'selected' : '';
498 $value = attr($value[1]);
499 $display = xlt($value);
500 echo "<option value=\"$value\" $selected>$display</option>\n";
502 $selected = ($viewmode && !$result['sensitivity']) ? "selected" : "";
503 echo "<option value='' $selected>" . xlt('None{{Sensitivity}}') . "</option>\n";
505 </select>
506 </div>
507 </div>
508 <?php endif; ?>
509 </div>
510 <div class="form-row align-items-center">
511 <div class="col-sm <?php displayOption('enc_service_date');?>">
512 <div class="form-group">
513 <label for='form_date' class="text-right"><?php echo xlt('Date of Service:'); ?></label>
514 <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'); ?>' />
515 </div>
516 </div>
517 <div class="col-sm <?php echo ($GLOBALS['gbl_visit_onset_date'] == 1) ?: 'd-none'; ?>">
518 <div class="form-group">
519 <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>
520 <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'); ?>' />
521 </div>
522 </div>
523 <div class="col-sm <?php echo ($GLOBALS['gbl_visit_referral_source'] == 1) ?: 'd-none';?>">
524 <div class="form-group">
525 <label for="form_referral_source" class="text-right"><?php echo xlt('Referral Source'); ?>:</label>
526 <?php echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', ''); ?>
527 </div>
528 </div>
529 <div class="col-sm <?php echo ($GLOBALS['set_pos_code_encounter'] == 1) ?: 'd-none';?>">
530 <div class="form-group">
531 <label for='pos_code' class="text-right"><?php echo xlt('POS Code'); ?>:</label>
532 <select name="pos_code" id="pos_code" class='form-control'>
533 <?php
534 $pc = new POSRef();
535 foreach ($pc->get_pos_ref() as $pos) {
536 echo "<option value=\"" . attr($pos["code"]) . "\"";
537 if (
538 ($pos["code"] == ($result['pos_code'] ?? '') && $viewmode)
539 || ($pos["code"] == ($posCode ?? '') && !$viewmode)
541 echo " selected";
543 echo ">" . text($pos['code']) . ": " . xlt($pos['title']);
544 echo "</option>\n";
547 </select>
548 </div>
549 </div>
550 <div class="col-sm <?php echo ($GLOBALS['hide_billing_widget'] != 1) ?: 'd-none';?>">
551 <div class="form-group">
552 <label for='in_collection' class="text-right"><?php echo xlt('In Collection'); ?>:</label>
553 <select class='form-control' name='in_collection' id='in_collection'>
554 <option value="1" <?php echo (($result["in_collection"] ?? null) == 1) ? "selected" : ""; ?>><?php echo xlt('Yes'); ?></option>
555 <option value="0" <?php echo (($result["in_collection"] ?? null) == 0) ? "selected" : ""; ?>><?php echo xlt('No'); ?></option>
556 </select>
557 </div>
558 </div>
559 </div>
561 <div class="form-row align-items-center">
562 <div class="col-sm">
563 <div class="form-group">
564 <label for='provider_id' class="text-right"><?php echo xlt('Encounter Provider'); ?>:</label>
565 <select name='provider_id' id='provider_id' class='form-control' onChange="newUserSelected()">
566 <?php
567 if ($viewmode) {
568 $provider_id = $result['provider_id'];
570 $userService = new UserService();
571 $users = $userService->getActiveUsers();
572 foreach ($users as $activeUser) {
573 $p_id = (int)$activeUser['id'];
574 // Check for the case where an encounter is created by non-auth user
575 // but has permissions to create/edit encounter.
576 $flag_it = "";
577 if ($activeUser['authorized'] != 1) {
578 if ($p_id === (int)($result['provider_id'] ?? null)) {
579 $flag_it = " (" . xlt("Non Provider") . ")";
580 } else {
581 continue;
584 echo "<option value='" . attr($p_id) . "'";
585 if ((int)$provider_id === $p_id) {
586 echo "selected";
588 echo ">" . text($activeUser['lname']) . ', ' . text($activeUser['suffix']) . ', ' .
589 text($activeUser['valedictory']) . ', ' . text($activeUser['fname']) . ', ' .
590 text($activeUser['mname']) . $flag_it . "</option>\n";
593 </select>
594 </div>
595 </div>
596 <div class="col-sm <?php displayOption('enc_enable_referring_provider');?>">
597 <div class="form-group">
598 <label for='referring_provider_id' class="text-right"><?php echo xlt('Referring Provider'); ?>:</label>
599 <?php
600 if ($viewmode && !empty($result["referring_provider_id"])) {
601 $MBO->genReferringProviderSelect('referring_provider_id', '-- ' . xl("Please Select") . ' --', $result["referring_provider_id"]);
602 } else { // defalut to the patient's referring provider from Demographics->Choices
603 $MBO->genReferringProviderSelect('referring_provider_id', '-- ' . xl("Please Select") . ' --', getPatientData($pid, "ref_providerID")['ref_providerID']);
604 } ?>
605 </select>
606 </div>
607 </div>
608 <div class="col-sm <?php displayOption('enc_enable_facility'); ?>">
609 <div class="form-group">
610 <label for='facility_id_sel' class="text-right"><?php echo xlt('Facility'); ?>:</label>
611 <select name='facility_id_sel' id='facility_id_sel' class='form-control' <?php echo ($mode === "followup") ? 'disabled' : ''; ?> >
612 <?php
613 $fac = getFacilityList();
614 foreach ($fac as $f) : ?>
615 <option value="<?php echo attr($f['id']); ?>" <?php echo ($f['selected'] == true) ? 'selected' : '';?>><?php echo text($f['name']); ?></option>
616 <?php endforeach; ?>
617 </select>
618 </div>
619 </div>
620 <div class="col-sm <?php echo ($GLOBALS['hide_billing_widget'] != 1) ?: 'd-none'; ?>">
621 <div class="form-group">
622 <label for='billing_facility' class="text-right"><?php echo xlt('Billing Facility'); ?>:</label>
623 <?php
624 if (!empty($default_bill_fac_override)) {
625 $default_bill_fac = $default_bill_fac_override;
626 } elseif (!$viewmode && $mode !== "followup") {
627 if ($user_facility['billing_location'] == '1') {
628 $default_bill_fac = $user_facility['id'] ;
629 } else {
630 $tmp_be = $facilityService->getPrimaryBusinessEntity();
631 $tmp_bl = $facilityService->getPrimaryBillingLocation();
632 $tmp = !empty($tmp_be['id']) ? $tmp_be['id'] : (!empty($tmp_bl['id']) ? $tmp_bl['id'] : null);
633 $default_bill_fac = !empty($tmp) ? $tmp : $def_facility;
635 } else {
636 $default_bill_fac = isset($result['billing_facility']) ? $result['billing_facility'] : $def_facility;
638 billing_facility('billing_facility', $default_bill_fac);
640 </div>
641 </div>
642 </div>
643 <div class="form-row align-items-center">
644 <!-- Discharge Disposition -->
645 <div class="col-sm <?php displayOption('enc_enable_discharge_disposition'); ?>">
646 <div class="form-group">
647 <label for='facility_id' class="text-right"><?php echo xlt('Discharge Disposition'); ?>:</label>
648 <select name='discharge_disposition' id='discharge_disposition' class='form-control'>
649 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
650 <?php
651 $dischargeListDisposition = new ListService();
652 $dischargeDisposiitons = $dischargeListDisposition->getOptionsByListName('discharge-disposition') ?? [];
653 foreach ($dischargeDisposiitons as $dispositon) {
654 $selected = ($result['discharge_disposition'] ?? null) == $dispositon['option_id'] ? "selected='selected'" : "";
656 <option value="<?php echo attr($dispositon['option_id']); ?>" <?php echo $selected; ?> ><?php echo text($dispositon['title']); ?></option>
657 <?php } ?>
658 </select>
659 </div>
660 </div>
661 <div class="col-sm <?php echo ($GLOBALS['enable_group_therapy'] == 1) ?: 'd-none'; ?>">
662 <div class="form-group">
663 <label for="form_group" class="text-right"><?php echo xlt('Group name'); ?>:</label>
664 <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 />
665 <input type='hidden' name='form_gid' value='<?php echo $viewmode && in_array($result['pc_catid'], $therapyGroupCategories) ? attr($result['external_id']) : '' ?>' />
666 </div>
667 </div>
668 </div>
669 </div>
670 </fieldset>
672 <div class="form-row">
673 <div class="col-sm">
674 <fieldset>
675 <legend><?php echo xlt('Reason for Visit') ?></legend>
676 <div class="form-row mx-3 h-100">
677 <textarea name="reason" id="reason" class="form-control" cols="80" rows="4"><?php echo $viewmode ? text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?></textarea>
678 </div>
679 </fieldset>
680 </div>
681 <div class="col-sm <?php displayOption('enc_enable_issues');?>">
682 <?php
683 // Before we even check for auth, see if we will even display
684 // To see issues stuff user needs write access to all issue types.
685 $issuesauth = true;
686 foreach ($ISSUE_TYPES as $type => $dummy) {
687 if (!AclMain::aclCheckIssue($type, '', 'write')) {
688 $issuesauth = false;
689 break;
692 if ($issuesauth) {
694 <fieldset>
695 <legend>
696 <?php echo xlt('Link/Add Issues to This Visit') ?>
697 </legend>
698 <div id="visit-issues">
699 <div class="form-row px-3">
700 <div class="pb-1 col-sm">
701 <?php if (AclMain::aclCheckCore('patients', 'med', '', 'write')) { ?>
702 <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>
703 <?php } ?>
704 </div>
705 <select multiple name='issues[]' class='form-control' title='<?php echo xla('Hold down [Ctrl] for multiple selections or to unselect'); ?>' size='4'>
706 <?php
707 while ($irow = sqlFetchArray($ires)) {
708 $list_id = $irow['id'];
709 $tcode = $irow['type'];
710 if ($ISSUE_TYPES[$tcode]) {
711 $tcode = $ISSUE_TYPES[$tcode][2];
713 echo "<option value='" . attr($list_id) . "'";
714 if ($viewmode) {
715 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
716 "pid = ? AND encounter = ? AND list_id = ?", array($pid, $encounter, $list_id));
717 if ($perow['count']) {
718 echo " selected";
720 } else {
721 // For new encounters the invoker may pass an issue ID.
722 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) {
723 echo " selected";
726 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
727 text(substr($irow['title'], 0, 40)) . "</option>\n";
730 </select>
731 <p><i><?php echo xlt('To link this encounter/consult to an existing issue, click the '
732 . 'desired issue above to highlight it and then click [Save]. '
733 . 'Hold down [Ctrl] button to select multiple issues.'); ?></i></p>
734 </div>
735 </div>
736 </fieldset>
737 <?php
740 </div>
741 </div>
742 <?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 ?>
743 <div class="form-row">
744 <div class="col-sm-12 text-left position-override pl-3">
745 <div class="btn-group" role="group">
746 <?php $link_submit = ($viewmode || empty($_GET['autoloaded'])) ? '' : 'link_submit';
747 $cancel_clicked = ($viewmode) ? 'cancelClickedOld()' : 'cancelClickedNew()';?>
748 <button type="button" class="btn btn-primary btn-save" onclick="top.restoreSession(); saveClicked(undefined);"><?php echo xlt('Save'); ?></button>
749 <button type="button" class="btn btn-cancel <?php echo $link_submit;?>" onClick="return <?php echo $cancel_clicked;?>"><?php echo xlt('Cancel'); ?></button>
750 </div>
751 </div>
752 </div>
753 </form>
754 </div><!--End of container div-->
755 <?php $oemr_ui->oeBelowContainerDiv(); ?>
756 <script>
757 const fac_id_sel = document.getElementById("facility_id_sel");
758 fac_id_sel.addEventListener("change", () => {
759 let fac_id = document.getElementById("facility_id");
760 fac_id.value = fac_id_sel[fac_id_sel.selectedIndex].value;
761 getPOS();
764 <?php
765 if (!$viewmode) { ?>
766 function duplicateVisit(enc, datestr) {
767 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.") ?>)) {
768 // User pressed the cancel button, so re-direct to today's encounter
769 top.restoreSession();
770 parent.left_nav.setEncounter(datestr, enc, window.name);
771 parent.left_nav.loadFrame('enc2', window.name, 'patient_file/encounter/encounter_top.php?set_encounter=' + encodeURIComponent(enc));
772 return;
774 // otherwise just continue normally
776 <?php
777 // Search for an encounter from today
778 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
779 "FROM form_encounter AS fe, forms AS f WHERE " .
780 "fe.pid = ? " .
781 " AND fe.date >= ? " .
782 " AND fe.date <= ? " .
783 " AND " .
784 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
785 "ORDER BY fe.encounter DESC LIMIT 1", array($pid, date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')));
787 if (!empty($erow['encounter'])) {
788 // If there is an encounter from today then present the duplicate visit dialog
789 echo "duplicateVisit(" . js_escape($erow['encounter']) . ", " .
790 js_escape(oeFormatShortDate(substr($erow['date'], 0, 10))) . ");\n";
794 <?php
795 if ($GLOBALS['enable_group_therapy']) { ?>
796 /* hide / show group name input */
797 let groupCategories = <?php echo json_encode($therapyGroupCategories); ?>;
798 $('#pc_catid').on('change', function () {
799 if (groupCategories.indexOf($(this).val()) > -1) {
800 $('#therapy_group_name').show();
801 } else {
802 $('#therapy_group_name').hide();
806 function sel_group() {
807 top.restoreSession();
808 const url = '<?php echo $GLOBALS['webroot']?>/interface/main/calendar/find_group_popup.php';
809 dlgopen(url, '_blank', 500, 400, '', '', {
810 buttons: [
811 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
816 // This is for callback by the find-group popup.
817 function setgroup(gid, name) {
818 var f = document.forms[0];
819 f.form_group.value = name;
820 f.form_gid.value = gid;
823 <?php
824 if ($viewmode && in_array($result['pc_catid'], $therapyGroupCategories)) {?>
825 $('#therapy_group_name').show();
826 <?php
827 } ?>
828 <?php
829 } ?>
831 $(function () {
832 $('#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();
833 $('#onset-tooltip').attr({"title": <?php echo xlj('Hospital date needed for successful billing of hospital encounters'); ?>, "data-toggle": "tooltip", "data-placement": "bottom"}).tooltip();
836 </script>
838 <?php if (!empty($GLOBALS['text_templates_enabled'])) { ?>
839 <script src="<?php echo $GLOBALS['web_root'] ?>/library/js/CustomTemplateLoader.js"></script>
840 <?php } ?>
841 </body>
842 </html>