Openemr encounters twig kernel (#4644)
[openemr.git] / interface / forms / newpatient / common.php
blobc5cd0a52a1a0d2e3dc9a50671b5f9e84d1b378ea
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");
19 use OpenEMR\Common\Acl\AclExtended;
20 use OpenEMR\Common\Acl\AclMain;
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Core\Header;
23 use OpenEMR\Services\FacilityService;
24 use OpenEMR\Services\ListService;
25 use OpenEMR\Services\UserService;
26 use OpenEMR\OeUI\OemrUI;
28 $facilityService = new FacilityService();
30 if ($GLOBALS['enable_group_therapy']) {
31 require_once("$srcdir/group.inc");
34 $months = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
35 $days = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
36 "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
37 $thisyear = date("Y");
38 $years = array($thisyear - 1, $thisyear, $thisyear + 1, $thisyear + 2);
40 $mode = (!empty($_GET['mode'])) ? $_GET['mode'] : null;
42 // "followup" mode is relevant when enable follow up encounters global is enabled
43 // it allows the user to duplicate past encounter and connect between the two
44 // under this mode the facility and the visit category will be same as the origin and in readonly
45 if ($mode === "followup") {
46 $encounter = (!empty($_GET['enc'])) ? (int)$_GET['enc'] : null;
47 if (!is_null($encounter)) {
48 $viewmode = true;
49 $_REQUEST['id'] = $encounter;
53 if ($viewmode) {
54 $id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : '';
55 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
56 $encounter = $result['encounter'];
57 $encounter_followup_id = $result['parent_encounter_id'] ?? null;
58 if ($encounter_followup_id) {
59 $q = "SELECT fe.date as date, fe.encounter as encounter FROM form_encounter AS fe " .
60 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
61 "WHERE fe.id = ? AND f.deleted = 0 ";
62 $followup_enc = sqlQuery($q, array($encounter_followup_id));
63 $followup_date = date("m/d/Y", strtotime($followup_enc['date']));
64 $encounter_followup = $followup_enc['encounter'];
66 // @todo why is this here?
67 if ($mode === "followup") {
68 $followup_date = date("m/d/Y", strtotime($result['date']));
69 $encounter_followup = $result['encounter'];
70 $result['reason'] = '';
71 $result['date'] = date('Y-m-d H:i:s');
72 $encounterId = $result['id'];
75 if ($result['sensitivity'] && !AclMain::aclCheckCore('sensitivities', $result['sensitivity'])) {
76 echo "<body>\n<html>\n";
77 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
78 echo "</body>\n</html>\n";
79 exit();
83 // Sort comparison for sensitivities by their order attribute.
84 function sensitivity_compare($a, $b)
86 return ($a[2] < $b[2]) ? -1 : 1;
89 // get issues
90 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
91 "pid = ? AND enddate IS NULL " .
92 "ORDER BY type, begdate", array($pid));
94 <!DOCTYPE html>
95 <head>
96 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
97 <title><?php echo xlt('Patient Encounter'); ?></title>
100 <!-- validation library -->
101 <?php
102 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
103 $use_validate_js = 1;
104 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
106 <?php include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?>
107 <script>
108 const mypcc = '' + <?php echo js_escape($GLOBALS['phone_country_code']); ?>;
110 // Process click on issue title.
111 function newissue() {
112 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 700, 535, '', '', {
113 buttons: [
114 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
117 return false;
120 // callback from add_edit_issue.php:
121 function refreshIssue(issue, title) {
122 var s = document.forms[0]['issues[]'];
123 s.options[s.options.length] = new Option(title, issue, true, true);
126 <?php
127 //Gets validation rules from Page Validation list.
128 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
129 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
130 if (empty($collectthis)) {
131 $collectthis = "undefined";
132 } else {
133 $collectthis = json_sanitize($collectthis["new_encounter"]["rules"]);
136 let collectvalidation = <?php echo $collectthis; ?>;
137 $(function () {
138 window.saveClicked = function (event) {
139 const submit = submitme(1, event, 'new-encounter-form', collectvalidation);
140 if (submit) {
141 top.restoreSession();
142 $('#new-encounter-form').submit();
146 $(".enc_issue").on('click', function (e) {
147 e.preventDefault();
148 e.stopPropagation();
149 dlgopen('', '', 700, 650, '', '', {
150 allowResize: true,
151 allowDrag: true,
152 dialogId: '',
153 type: 'iframe',
154 url: $(this).attr('href')
158 $('.datepicker').datetimepicker({
159 <?php $datetimepicker_timepicker = false; ?>
160 <?php $datetimepicker_showseconds = false; ?>
161 <?php $datetimepicker_formatInput = true; ?>
162 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
163 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
167 const isPosEnabled = "" + <?php echo js_escape($GLOBALS['set_pos_code_encounter']); ?>;
169 function getPOS() {
170 if (!isPosEnabled) {
171 return false;
173 let facility = document.forms[0].facility_id.value;
174 $.ajax({
175 url: "./../../../library/ajax/facility_ajax_code.php",
176 method: "GET",
177 data: {
178 mode: "get_pos",
179 facility_id: facility,
180 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
182 }).done(function (fid) {
183 document.forms[0].pos_code.value = JSON.parse(fid);
184 }).fail(function (xhr) {
185 console.log('error', xhr);
189 function newUserSelected() {
190 let provider = document.getElementById('provider_id').value;
191 $.ajax({
192 url: "./../../../library/ajax/facility_ajax_code.php",
193 method: "GET",
194 data: {
195 mode: "get_user_data",
196 provider_id: provider,
197 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
199 }).done(function (data) {
200 let rtn = JSON.parse(data);
201 document.forms[0].facility_id.value = rtn[0];
202 if (isPosEnabled) {
203 document.forms[0].pos_code.value = rtn[1];
205 if (Number(rtn[2]) === 1) {
206 document.forms[0]['billing_facility'].value = rtn[0];
208 }).fail(function (xhr) {
209 console.log('error', xhr);
213 // Handler for Cancel clicked when creating a new encounter.
214 // Show demographics or encounters list depending on what frame we're in.
215 function cancelClickedNew() {
216 window.parent.left_nav.loadFrame('ens1', window.name, 'patient_file/history/encounters.php');
217 return false;
220 // Handler for cancel clicked when not creating a new encounter.
221 // Just reload the view mode.
222 function cancelClickedOld() {
223 location.href = '<?php echo "$rootdir/patient_file/encounter/forms.php"; ?>';
224 return false;
227 </script>
228 <style>
229 @media only screen and (max-width: 1024px) {
230 #visit-details [class*="col-"],
231 #visit-issues [class*="col-"] {
232 width: 100%;
233 text-align: <?php echo ($_SESSION['language_direction'] == 'rtl') ? 'right ' : 'left '?> !important;
236 </style>
237 <?php
238 if ($viewmode) {
239 $body_javascript = '';
240 $heading_caption = xl('Patient Encounter Form');
241 } else {
242 $body_javascript = 'onload="javascript:document.new_encounter.reason.focus();"';
243 $heading_caption = xl('New Encounter Form');
247 if ($GLOBALS['enable_help'] == 1) {
248 $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>';
249 } elseif ($GLOBALS['enable_help'] == 2) {
250 $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>';
251 } elseif ($GLOBALS['enable_help'] == 0) {
252 $help_icon = '';
255 <?php
256 $arrOeUiSettings = array(
257 'heading_title' => $heading_caption,
258 'include_patient_name' => true,// use only in appropriate pages
259 'expandable' => false,
260 'expandable_files' => array(""),//all file names need suffix _xpd
261 'action' => "",//conceal, reveal, search, reset, link or back
262 'action_title' => "",
263 'action_href' => "",//only for actions - reset, link or back
264 'show_help_icon' => true,
265 'help_file_name' => "common_help.php"
267 $oemr_ui = new OemrUI($arrOeUiSettings);
269 $provider_id = $userauthorized ? $_SESSION['authUserID'] : 0;
270 if (!$viewmode) {
271 $now = date('Y-m-d');
272 $encnow = date('Y-m-d 00:00:00');
273 $time = date("H:i:00");
274 $q = "SELECT pc_aid, pc_facility, pc_billing_location, pc_catid, pc_startTime" .
275 " FROM openemr_postcalendar_events WHERE pc_pid=? AND pc_eventDate=?" .
276 " ORDER BY pc_startTime ASC";
277 $q_events = sqlStatement($q, array($pid, $now));
278 while ($override = sqlFetchArray($q_events)) {
279 $q = "SELECT fe.encounter as encounter FROM form_encounter AS fe " .
280 "JOIN forms AS f ON f.form_id = fe.id AND f.encounter = fe.encounter " .
281 "WHERE fe.pid=? AND fe.date=? AND fe.provider_id=? AND f.deleted=0";
282 $q_enc = sqlQuery($q, array($pid, $encnow, $override['pc_aid']));
283 if (!empty($override) && is_array($override) && empty($q_enc['encounter'])) {
284 $provider_id = $override['pc_aid'];
285 $default_bill_fac_override = $override['pc_billing_location'];
286 $default_fac_override = $override['pc_facility'];
287 $default_catid_override = $override['pc_catid'];
292 </head>
293 <body <?php echo $body_javascript; ?>>
294 <div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?> mt-3">
295 <div class="row">
296 <div class="col-sm-12">
297 <!-- Required for the popup date selectors -->
298 <div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;"></div>
299 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
300 </div>
301 </div>
302 <form class="mt-3" id="new-encounter-form" method='post' action="<?php echo $rootdir ?>/forms/newpatient/save.php" name='new_encounter'>
303 <?php if ($viewmode && $mode !== "followup") { ?>
304 <input type='hidden' name='mode' value='update' />
305 <input type='hidden' name='id' value='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>' />
306 <?php } else { ?>
307 <input type='hidden' name='mode' value='new' />
308 <?php } ?>
309 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
311 <?php if ($mode === "followup") { ?>
312 <input type='hidden' name='parent_enc_id' value='<?php echo attr($encounterId); ?>' />
313 <?php } ?>
315 <fieldset>
316 <legend><?php echo xlt('Visit Details') ?>
317 <small>
318 <?php echo (!empty($encounter_followup)) ? (xlt("Follow up for") . ": " . text($encounter_followup) . " " . xlt("Dated") . ": " . text($followup_date)) : ''; ?>
319 </small>
320 </legend>
321 <div id="visit-details" class="px-5">
322 <div class="form-row align-items-center">
323 <div class="col-sm-2">
324 <label for="pc_catid" class="text-right"><?php echo xlt('Visit Category:'); ?></label>
325 </div>
326 <div class="col-sm">
327 <select name='pc_catid' id='pc_catid' class='form-control' <?php echo ($mode === "followup") ? 'disabled' : ''; ?>>
328 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
329 <?php
330 //Bring only patient and group categories
331 $visitSQL = "SELECT pc_catid, pc_catname, pc_cattype
332 FROM openemr_postcalendar_categories
333 WHERE pc_active = 1 and pc_cattype IN (0,3) and pc_constant_id != 'no_show' ORDER BY pc_seq";
335 $visitResult = sqlStatement($visitSQL);
336 $therapyGroupCategories = [];
338 while ($row = sqlFetchArray($visitResult)) {
339 $catId = $row['pc_catid'];
340 $name = $row['pc_catname'];
342 if ($row['pc_cattype'] == 3) {
343 $therapyGroupCategories[] = $catId;
346 if ($catId === "_blank") {
347 continue;
350 if ($row['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) {
351 continue;
354 // Fetch acl for category of given encounter. Only if has write auth for a category, then can create an encounter of that category.
355 $postCalendarCategoryACO = AclMain::fetchPostCalendarCategoryACO($catId);
356 if ($postCalendarCategoryACO) {
357 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
358 $authPostCalendarCategoryWrite = AclMain::aclCheckCore($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
359 } else { // if no aco is set for category
360 $authPostCalendarCategoryWrite = true;
363 //if no permission for category write, don't show in drop-down
364 if (!$authPostCalendarCategoryWrite) {
365 continue;
368 $optionStr = '<option value="%pc_catid%" %selected%>%pc_catname%</option>';
369 $optionStr = str_replace("%pc_catid%", attr($catId), $optionStr);
370 $optionStr = str_replace("%pc_catname%", text(xl_appt_category($name)), $optionStr);
371 if ($viewmode) {
372 $selected = ($result['pc_catid'] == $catId) ? " selected" : "";
373 } else {
374 $selected = ($GLOBALS['default_visit_category'] == $catId) ? " selected" : "";
377 $optionStr = str_replace("%selected%", $selected, $optionStr);
378 echo $optionStr;
381 </select>
382 <?php if ($mode === "followup") { ?>
383 <input name="pc_catid" value="<?php echo attr($result['pc_catid']); ?>" hidden />
384 <?php } ?>
385 </div>
386 <?php
387 $sensitivities = AclExtended::aclGetSensitivities();
388 if ($sensitivities && count($sensitivities)) {
389 usort($sensitivities, "sensitivity_compare");
391 <div class="col-sm-2">
392 <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>
393 </div>
394 <div class="col-sm">
395 <select name='form_sensitivity' id='form_sensitivity' class='form-control'>
396 <?php
397 foreach ($sensitivities as $value) {
398 // Omit sensitivities to which this user does not have access.
399 if (AclMain::aclCheckCore('sensitivities', $value[1])) {
400 echo " <option value='" . attr($value[1]) . "'";
401 if ($viewmode && $result['sensitivity'] == $value[1]) {
402 echo " selected";
405 echo ">" . xlt($value[3]) . "</option>\n";
408 echo " <option value=''";
409 if ($viewmode && !$result['sensitivity']) {
410 echo " selected";
412 echo ">" . xlt('None{{Sensitivity}}') . "</option>\n";
414 </select>
415 <?php } ?>
416 </div>
417 </div>
418 <div class="form-row align-items-center mt-2">
419 <div class="col-sm-2">
420 <label for='form_date' class="text-right"><?php echo xlt('Date of Service:'); ?></label>
421 </div>
422 <div class="col-sm">
423 <input type='text' class='form-control datepicker' name='form_date' id='form_date' <?php echo ($disabled ?? '') ?> value='<?php echo $viewmode ? attr(oeFormatShortDate(substr($result['date'], 0, 10))) : attr(oeFormatShortDate(date('Y-m-d'))); ?>' title='<?php echo xla('Date of service'); ?>' />
424 </div>
425 <div class="col-sm-2" <?php echo empty($GLOBALS['gbl_visit_onset_date']) ? "style='visibility:hidden;'" : ""; ?>>
426 <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>
427 </div>
428 <div class="col-sm" <?php echo empty($GLOBALS['gbl_visit_onset_date']) ? "style='visibility:hidden;'" : ""; ?>>
429 <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(oeFormatShortDate(substr($result['onset_date'], 0, 10))) : ''; ?>' title='<?php echo xla('Date of onset or hospitalization'); ?>' />
430 </div>
431 </div>
432 <div class="form-row align-items-center mt-2"
433 <?php
434 if (!$GLOBALS['gbl_visit_referral_source']) {
435 echo "style='display:none' ";
436 } ?>>
437 <div class="col-sm-2">
438 <label for="form_referral_source" class="text-right"><?php echo xlt('Referral Source'); ?>:</label>
439 </div>
440 <div class="col-sm">
441 <?php echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', ''); ?>
442 </div>
443 </div>
444 <?php if ($GLOBALS['enable_group_therapy']) { ?>
445 <div class="form-group mx-auto mt-2" id="therapy_group_name" style="display: none">
446 <div class="col-sm-2">
447 <label for="form_group" class="text-right"><?php echo xlt('Group name'); ?>:</label>
448 </div>
449 <div class="col-sm">
450 <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 />
451 <input type='hidden' name='form_gid' value='<?php echo $viewmode && in_array($result['pc_catid'], $therapyGroupCategories) ? attr($result['external_id']) : '' ?>' />
452 </div>
453 </div>
454 <?php } ?>
455 <div class="form-row align-items-center mt-2">
456 <div class="col-sm-2">
457 <label for='provider_id' class="text-right"><?php echo xlt('Encounter Provider'); ?>:</label>
458 </div>
459 <div class="col-sm">
460 <select name='provider_id' id='provider_id' class='form-control' onChange="newUserSelected()">
461 <?php
462 if ($viewmode) {
463 $provider_id = $result['provider_id'];
465 $userService = new UserService();
466 $users = $userService->getActiveUsers();
467 foreach ($users as $activeUser) {
468 $p_id = (int)$activeUser['id'];
469 // Check for the case where an encounter is created by non-auth user
470 // but has permissions to create/edit encounter.
471 $flag_it = "";
472 if ($activeUser['authorized'] != 1) {
473 if ($p_id === (int)($result['provider_id'] ?? null)) {
474 $flag_it = " (" . xlt("Non Provider") . ")";
475 } else {
476 continue;
479 echo "<option value='" . attr($p_id) . "'";
480 if ((int)$provider_id === $p_id) {
481 echo "selected";
483 echo ">" . text($activeUser['lname']) . ' ' .
484 text($activeUser['fname']) . ' ' . text($activeUser['mname']) . $flag_it . "</option>\n";
487 </select>
488 </div>
489 <div class="col-sm-2">
490 <label for='class' class="text-right"><?php echo xlt('Class'); ?>:</label>
491 </div>
492 <div class="col-sm">
493 <?php echo generate_select_list('class_code', '_ActEncounterCode', $viewmode ? $result['class_code'] : '', '', ''); ?>
494 </div>
495 </div>
496 <div class="form-row align-items-center mt-2">
497 <div class="col-sm-2">
498 <label for='facility_id' class="text-right"><?php echo xlt('Facility'); ?>:</label>
499 </div>
500 <div class="col-sm">
501 <select name='facility_id' id='facility_id' class='form-control' onChange="getPOS()" <?php echo ($mode === "followup") ? 'disabled' : ''; ?> >
502 <?php
503 if ($viewmode) {
504 $def_facility = $result['facility_id'];
505 } elseif (!empty($default_fac_override)) {
506 $def_facility = $default_fac_override;
507 } else {
508 $def_facility = ($facilityService->getFacilityForUser($_SESSION['authUserID'])['id'] ?? null);
510 $posCode = '';
511 $facilities = $facilityService->getAllServiceLocations();
512 foreach ($facilities as $iter) {
513 $selected_fac = '';
514 if ($def_facility === $iter['id']) {
515 $selected_fac = " selected";
516 if (!$viewmode) {
517 $posCode = $iter['pos_code'];
519 } ?>
520 <option value="<?php echo attr($iter['id']); ?>"<?php echo $selected_fac; ?>><?php echo text($iter['name']); ?></option>
521 <?php } ?>
522 </select>
523 </div>
524 <?php if ($mode === "followup") { ?>
525 <input type="hidden" name="facility_id" value="<?php echo attr($result['facility_id']); ?>" />
526 <?php } ?>
527 <div class="col-sm-2">
528 <label for='billing_facility' class="text-right"><?php echo xlt('Billing Facility'); ?>:</label>
529 </div>
530 <div id="ajaxdiv" class="col-sm">
531 <?php
532 if (!empty($default_bill_fac_override)) {
533 $default_bill_fac = $default_bill_fac_override;
534 } elseif (!$viewmode && $mode !== "followup") {
535 $tmp_be = $facilityService->getPrimaryBusinessEntity();
536 $tmp_bl = $facilityService->getPrimaryBillingLocation();
537 $tmp = !empty($tmp_be['id']) ? $tmp_be['id'] : (!empty($tmp_bl['id']) ? $tmp_bl['id'] : null);
538 $default_bill_fac = !empty($tmp) ? $tmp : $def_facility;
539 } else {
540 $default_bill_fac = isset($result['billing_facility']) ? $result['billing_facility'] : $def_facility;
542 billing_facility('billing_facility', $default_bill_fac);
544 </div>
545 </div>
546 <!-- Discharge Disposition -->
547 <div class="form-row align-items-center mt-2">
548 <div class="col-sm-2">
549 <label for='facility_id' class="text-right"><?php echo xlt('Discharge Disposition'); ?>:</label>
550 </div>
551 <div class="col-sm">
552 <select name='discharge_disposition' id='discharge_disposition' class='form-control'>
553 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
554 <?php
555 $dischargeListDisposition = new ListService();
556 $dischargeDisposiitons = $dischargeListDisposition->getOptionsByListName('discharge-disposition') ?? [];
557 foreach ($dischargeDisposiitons as $dispositon) {
558 $selected = $result['discharge_disposition'] == $dispositon['option_id'] ? "selected='selected'" : "";
560 <option value="<?php echo attr($dispositon['option_id']); ?>" <?php echo $selected; ?> ><?php echo text($dispositon['title']); ?></option>
561 <?php } ?>
562 </select>
563 </div>
564 <div class="col-sm-2"></div>
565 <div class="col-sm"></div>
566 </div>
567 <?php if ($GLOBALS['set_pos_code_encounter']) { ?>
568 <div class="form-row mt-2">
569 <div class="col-sm-2">
570 <label for='pos_code' class="text-right"><?php echo xlt('POS Code'); ?>:</label>
571 </div>
572 <div class="col-sm-8">
573 <select name="pos_code" id="pos_code" class='form-control'>
574 <?php
575 $pc = new POSRef();
576 foreach ($pc->get_pos_ref() as $pos) {
577 echo "<option value=\"" . attr($pos["code"]) . "\"";
578 if (($pos["code"] == $result['pos_code'] && $viewmode) || ($pos["code"] == $posCode && !$viewmode)) {
579 echo " selected";
581 echo ">" . text($pos['code']) . ": " . xlt($pos['title']);
582 echo "</option>\n";
585 </select>
586 </div>
587 </div>
588 <?php } ?>
589 </div>
590 </fieldset>
591 <fieldset>
592 <legend><?php echo xlt('Reason for Visit') ?></legend>
593 <div class="form-row mx-5">
594 <textarea name="reason" id="reason" class="form-control" cols="80" rows="4"><?php echo $viewmode ? text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?></textarea>
595 </div>
596 </fieldset>
597 <?php
598 // To see issues stuff user needs write access to all issue types.
599 $issuesauth = true;
600 foreach ($ISSUE_TYPES as $type => $dummy) {
601 if (!AclMain::aclCheckIssue($type, '', 'write')) {
602 $issuesauth = false;
603 break;
606 if ($issuesauth) {
608 <fieldset>
609 <legend><?php echo xlt('Link/Add Issues (Injuries/Medical/Allergy) to Current Visit') ?></legend>
610 <div id="visit-issues">
611 <div class="form-row px-5">
612 <div class="pb-1">
613 <div class="btn-group" role="group">
614 <?php if (AclMain::aclCheckCore('patients', 'med', '', 'write')) { ?>
615 <a href="../../patient_file/summary/add_edit_issue.php" class="btn btn-primary btn-add btn-sm enc_issue" onclick="top.restoreSession()"><?php echo xlt('Add Issue'); ?></a>
616 <?php } ?>
617 </div>
618 </div>
619 <select multiple name='issues[]' class='form-control' title='<?php echo xla('Hold down [Ctrl] for multiple selections or to unselect'); ?>' size='6'>
620 <?php
621 while ($irow = sqlFetchArray($ires)) {
622 $list_id = $irow['id'];
623 $tcode = $irow['type'];
624 if ($ISSUE_TYPES[$tcode]) {
625 $tcode = $ISSUE_TYPES[$tcode][2];
627 echo " <option value='" . attr($list_id) . "'";
628 if ($viewmode) {
629 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
630 "pid = ? AND encounter = ? AND list_id = ?", array($pid, $encounter, $list_id));
631 if ($perow['count']) {
632 echo " selected";
634 } else {
635 // For new encounters the invoker may pass an issue ID.
636 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) {
637 echo " selected";
640 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
641 text(substr($irow['title'], 0, 40)) . "</option>\n";
644 </select>
645 <p><i><?php echo xlt('To link this encounter/consult to an existing issue, click the '
646 . 'desired issue above to highlight it and then click [Save]. '
647 . 'Hold down [Ctrl] button to select multiple issues.'); ?></i></p>
648 </div>
649 </div>
650 </fieldset>
651 <?php
654 <?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 ?>
655 <div class="form-row">
656 <div class="col-sm-12 text-left position-override">
657 <div class="btn-group" role="group">
658 <button type="button" class="btn btn-primary btn-save" onclick="top.restoreSession(); saveClicked(undefined);"><?php echo xlt('Save'); ?></button>
659 <?php if ($viewmode || empty($_GET["autoloaded"])) { // not creating new encounter ?>
660 <button type="button" class="btn btn-secondary btn-cancel" onClick="return cancelClickedOld()"><?php echo xlt('Cancel'); ?></button>
661 <?php } else { // not $viewmode ?>
662 <button class="btn btn-secondary btn-cancel link_submit" onClick="return cancelClickedNew()"><?php echo xlt('Cancel'); ?></button>
663 <?php } // end not $viewmode ?>
664 </div>
665 </div>
666 </div>
667 </form>
668 </div><!--End of container div-->
669 <?php $oemr_ui->oeBelowContainerDiv(); ?>
670 <script>
671 <?php
672 if (!$viewmode) { ?>
673 function duplicateVisit(enc, datestr) {
674 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.") ?>)) {
675 // User pressed the cancel button, so re-direct to today's encounter
676 top.restoreSession();
677 parent.left_nav.setEncounter(datestr, enc, window.name);
678 parent.left_nav.loadFrame('enc2', window.name, 'patient_file/encounter/encounter_top.php?set_encounter=' + encodeURIComponent(enc));
679 return;
681 // otherwise just continue normally
683 <?php
684 // Search for an encounter from today
685 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
686 "FROM form_encounter AS fe, forms AS f WHERE " .
687 "fe.pid = ? " .
688 " AND fe.date >= ? " .
689 " AND fe.date <= ? " .
690 " AND " .
691 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
692 "ORDER BY fe.encounter DESC LIMIT 1", array($pid, date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')));
694 if (!empty($erow['encounter'])) {
695 // If there is an encounter from today then present the duplicate visit dialog
696 echo "duplicateVisit(" . js_escape($erow['encounter']) . ", " .
697 js_escape(oeFormatShortDate(substr($erow['date'], 0, 10))) . ");\n";
701 <?php
702 if ($GLOBALS['enable_group_therapy']) { ?>
703 /* hide / show group name input */
704 let groupCategories = <?php echo json_encode($therapyGroupCategories); ?>;
705 $('#pc_catid').on('change', function () {
706 if (groupCategories.indexOf($(this).val()) > -1) {
707 $('#therapy_group_name').show();
708 } else {
709 $('#therapy_group_name').hide();
713 function sel_group() {
714 top.restoreSession();
715 const url = '<?php echo $GLOBALS['webroot']?>/interface/main/calendar/find_group_popup.php';
716 dlgopen(url, '_blank', 500, 400, '', '', {
717 buttons: [
718 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
723 // This is for callback by the find-group popup.
724 function setgroup(gid, name) {
725 var f = document.forms[0];
726 f.form_group.value = name;
727 f.form_gid.value = gid;
730 <?php
731 if ($viewmode && in_array($result['pc_catid'], $therapyGroupCategories)) {?>
732 $('#therapy_group_name').show();
733 <?php
734 } ?>
735 <?php
736 } ?>
738 $(function () {
739 $('#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();
740 $('#onset-tooltip').attr({"title": <?php echo xlj('Hospital date needed for successful billing of hospital encounters'); ?>, "data-toggle": "tooltip", "data-placement": "bottom"}).tooltip();
743 </script>
745 <?php if (!empty($GLOBALS['text_templates_enabled'])) { ?>
746 <script src="<?php echo $GLOBALS['web_root'] ?>/library/js/CustomTemplateLoader.js"></script>
747 <?php } ?>
748 </body>
749 </html>