3 * Common script for the encounter form (new and view) scripts.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
17 * @author Brady Miller <brady.g.miller@gmail.com>
18 * @link http://www.open-emr.org
21 require_once("$srcdir/options.inc.php");
22 require_once("$srcdir/acl.inc");
23 require_once("$srcdir/lists.inc");
25 $facilityService = new \services\
FacilityService();
27 if ($GLOBALS['enable_group_therapy']) {
28 require_once("$srcdir/group.inc");
31 $months = array("01","02","03","04","05","06","07","08","09","10","11","12");
32 $days = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14",
33 "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
34 $thisyear = date("Y");
35 $years = array($thisyear-1, $thisyear, $thisyear+
1, $thisyear+
2);
38 $id = (isset($_REQUEST['id'])) ?
$_REQUEST['id'] : '';
39 $result = sqlQuery("SELECT * FROM form_encounter WHERE id = ?", array($id));
40 $encounter = $result['encounter'];
41 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
42 echo "<body>\n<html>\n";
43 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
44 echo "</body>\n</html>\n";
49 // Sort comparison for sensitivities by their order attribute.
50 function sensitivity_compare($a, $b)
52 return ($a[2] < $b[2]) ?
-1 : 1;
56 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
57 "pid = ? AND enddate IS NULL " .
58 "ORDER BY type, begdate", array($pid));
60 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
63 <?php
html_header_show();?
>
64 <title
><?php
echo xlt('Patient Encounter'); ?
></title
>
66 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
67 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
69 <link rel
="stylesheet" type
="text/css" href
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.css" media
="screen" />
70 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
71 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
72 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"></script
>
73 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
74 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
75 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
77 <!-- validation library
-->
79 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
81 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?
>
83 <?php
include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?
>
84 <script language
="JavaScript">
86 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
88 // Process click on issue title.
90 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 800, 600);
94 // callback from add_edit_issue.php:
95 function refreshIssue(issue
, title
) {
96 var s
= document
.forms
[0]['issues[]'];
97 s
.options
[s
.options
.length
] = new Option(title
, issue
, true, true);
101 //Gets validation rules from Page Validation list.
102 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
103 $collectthis = collectValidationPageRules("/interface/forms/newpatient/common.php");
104 if (empty($collectthis)) {
105 $collectthis = "undefined";
107 $collectthis = $collectthis["new_encounter"]["rules"];
110 var collectvalidation
= <?php
echo($collectthis); ?
>;
111 $
(document
).ready(function(){
112 window
.saveClicked
= function(event
) {
113 var submit
= submitme(1, event
, 'new-encounter-form', collectvalidation
);
115 top
.restoreSession();
116 $
('#new-encounter-form').submit();
122 $
('.datepicker').datetimepicker({
123 <?php
$datetimepicker_timepicker = false; ?
>
124 <?php
$datetimepicker_showseconds = false; ?
>
125 <?php
$datetimepicker_formatInput = false; ?
>
126 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
127 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
132 var pid
=<?php
echo attr($pid);?
>;
133 var dte
=document
.getElementById('form_date').value
;
134 var facility
=document
.forms
[0].facility_id
.value
;
135 ajax_bill_loc(pid
,dte
,facility
);
138 // Handler for Cancel clicked when creating a new encounter.
139 // Show demographics or encounters list depending on what frame we're in.
140 function cancelClicked() {
141 if (window
.name
== 'RBot') {
142 parent
.left_nav
.loadFrame('ens1', window
.name
, 'patient_file/history/encounters.php');
145 parent
.left_nav
.loadFrame('dem1', window
.name
, 'patient_file/summary/demographics.php');
153 <?php
if ($viewmode) { ?
>
154 <body
class="body_top">
156 <body
class="body_top" onload
="javascript:document.new_encounter.reason.focus();">
159 <!-- Required
for the popup date selectors
-->
160 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
162 <form id
="new-encounter-form" method
='post' action
="<?php echo $rootdir ?>/forms/newpatient/save.php" name
='new_encounter'>
164 <div style
='float:left'>
165 <?php
if ($viewmode) { ?
>
166 <input type
=hidden name
='mode' value
='update'>
167 <input type
=hidden name
='id' value
='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>'>
168 <span
class=title
><?php
echo xlt('Patient Encounter Form'); ?
></span
>
170 <input type
='hidden' name
='mode' value
='new'>
171 <span
class='title'><?php
echo xlt('New Encounter Form'); ?
></span
>
176 <div style
= 'float:left; margin-left:8px;margin-top:-3px'>
177 <a href
="javascript:saveClicked(undefined);" class="css_button link_submit"><span
><?php
echo xlt('Save'); ?
></span
></a
>
178 <?php
if ($viewmode ||
!isset($_GET["autoloaded"]) ||
$_GET["autoloaded"] != "1") { ?
>
180 <div style
= 'float:left; margin-top:-3px'>
181 <a href
="<?php echo "$rootdir/patient_file
/encounter
/encounter_top
.php
"; ?>"
182 class="css_button link_submit" onClick
="top.restoreSession()"><span
><?php
echo xlt('Cancel'); ?
></span
></a
>
183 <?php
} else { // not $viewmode ?>
184 <a href
="" class="css_button link_submit" onClick
="return cancelClicked()">
185 <span
><?php
echo xlt('Cancel'); ?
></span
></a
>
186 <?php
} // end not $viewmode ?>
195 <td width
='33%' nowrap
class='bold'><?php
echo xlt('Consultation Brief Description'); ?
>:</td
>
196 <td width
='34%' rowspan
='2' align
='center' valign
='center' class='text'>
200 <td
class='bold' nowrap
><?php
echo xlt('Visit Category:'); ?
></td
>
202 <select name
='pc_catid' id
='pc_catid'>
203 <option value
='_blank'>-- <?php
echo xlt('Select One'); ?
> --</option
>
205 $visitSQL = "SELECT pc_catid, pc_catname, pc_cattype
206 FROM openemr_postcalendar_categories
207 WHERE pc_active = 1 ORDER BY pc_seq";
208 $visitResult = sqlStatement($visitSQL);
209 $therapyGroupCategories = [];
211 while ($row = sqlFetchArray($visitResult)) {
212 $catId = $row['pc_catid'];
213 $name = $row['pc_catname'];
215 if ($row['pc_cattype'] == 3) {
216 $therapyGroupCategories[] = $catId;
219 if (($catId < 9 && $catId != "5") ||
$catId === "_blank") {
223 if ($row['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) {
227 // Fetch acl for category of given encounter. Only if has write auth for a category, then can create an encounter of that category.
228 $postCalendarCategoryACO = fetchPostCalendarCategoryACO($catId);
229 if ($postCalendarCategoryACO) {
230 $postCalendarCategoryACO = explode('|', $postCalendarCategoryACO);
231 $authPostCalendarCategoryWrite = acl_check($postCalendarCategoryACO[0], $postCalendarCategoryACO[1], '', 'write');
232 } else { // if no aco is set for category
233 $authPostCalendarCategoryWrite = true;
236 //if no permission for category write, don't show in drop-down
237 if (!$authPostCalendarCategoryWrite) {
241 $optionStr = '<option value="%pc_catid%" %selected%>%pc_catname%</option>';
242 $optionStr = str_replace("%pc_catid%", attr($catId), $optionStr);
243 $optionStr = str_replace("%pc_catname%", text(xl_appt_category($name)), $optionStr);
245 $selected = ($result['pc_catid'] == $catId) ?
" selected" : "";
247 $selected = ($GLOBALS['default_visit_category'] == $catId) ?
" selected" : "";
250 $optionStr = str_replace("%selected%", $selected, $optionStr);
259 <td
class='bold' nowrap
><?php
echo xlt('Facility:'); ?
></td
>
261 <select name
='facility_id' onChange
="bill_loc()">
265 $def_facility = $result['facility_id'];
267 $dres = sqlStatement("select facility_id from users where username = ?", array($_SESSION['authUser']));
268 $drow = sqlFetchArray($dres);
269 $def_facility = $drow['facility_id'];
272 $facilities = $facilityService->getAllServiceLocations();
274 foreach ($facilities as $iter) {
276 <option value
="<?php echo attr($iter['id']); ?>" <?php
if ($def_facility == $iter['id']) {
278 }?
>><?php
echo text($iter['name']); ?
></option
>
287 <td
class='bold' nowrap
><?php
echo xlt('Billing Facility'); ?
>:</td
>
291 billing_facility('billing_facility', $result['billing_facility']);
296 <?php
if ($GLOBALS['set_pos_code_encounter']) { ?
>
298 <td
><span
class='bold' nowrap
><?php
echo xlt('POS Code'); ?
>: </span
></td
>
300 <select name
="pos_code">
305 foreach ($pc->get_pos_ref() as $pos) {
306 echo "<option value=\"" . attr($pos["code"]) . "\" ";
307 if ($pos["code"] == $result['pos_code']) {
311 echo ">" . text($pos['code']) . ": ". xlt($pos['title']);
322 $sensitivities = acl_get_sensitivities();
323 if ($sensitivities && count($sensitivities)) {
324 usort($sensitivities, "sensitivity_compare");
326 <td
class='bold' nowrap
><?php
echo xlt('Sensitivity:'); ?
></td
>
328 <select name
='form_sensitivity'>
330 foreach ($sensitivities as $value) {
331 // Omit sensitivities to which this user does not have access.
332 if (acl_check('sensitivities', $value[1])) {
333 echo " <option value='" . attr($value[1]) . "'";
334 if ($viewmode && $result['sensitivity'] == $value[1]) {
338 echo ">" . xlt($value[3]) . "</option>\n";
342 echo " <option value=''";
343 if ($viewmode && !$result['sensitivity']) {
347 echo ">" . xlt('None'). "</option>\n";
354 <td colspan
='2'><!-- sensitivities not used
--></td
>
360 <tr
<?php
if (!$GLOBALS['gbl_visit_referral_source']) {
361 echo " style='visibility:hidden;'";
363 <td
class='bold' nowrap
><?php
echo xlt('Referral Source'); ?
>:</td
>
366 echo generate_select_list('form_referral_source', 'refsource', $viewmode ?
$result['referral_source'] : '', '');
371 <?php
if ($GLOBALS['enable_group_therapy']) { ?
>
372 <!-- select group name
- showing just
if therapy group type is selected
-->
373 <tr id
="therapy_group_name" style
="display: none">
374 <td
class='bold' nowrap
><?php
echo xlt('Group name'); ?
>:</td
>
376 <input type
='text' size
='10' name
='form_group' id
="form_group" style
='width:100%;cursor:pointer;cursor:hand' placeholder
='<?php echo xla('Click to select
');?>' value
='<?php echo $viewmode && in_array($result['pc_catid
'], $therapyGroupCategories) ? attr(getGroup($result['external_id
'])['group_name
']) : ''; ?>' onclick
='sel_group()' title
='<?php echo xla('Click to select group
'); ?>' readonly
/>
377 <input type
='hidden' name
='form_gid' value
='<?php echo $viewmode && in_array($result['pc_catid
'], $therapyGroupCategories) ? attr($result['external_id
']) : '' ?>' />
383 <td
class='bold' nowrap
><?php
echo xlt('Date of Service:'); ?
></td
>
384 <td
class='text' nowrap
>
385 <input type
='text' size
='10' class='datepicker' name
='form_date' id
='form_date' <?php
echo $disabled ?
>
386 value
='<?php echo $viewmode ? substr($result['date
'], 0, 10) : date('Y
-m
-d
'); ?>'
387 title
='<?php echo xla('yyyy
-mm
-dd Date of service
'); ?>' />
391 <tr
<?php
if ($GLOBALS['ippf_specific']) {
392 echo " style='visibility:hidden;'";
394 <td
class='bold' nowrap
><?php
echo xlt('Onset/hosp. date:'); ?
></td
>
395 <td
class='text' nowrap
><!-- default is blank so that
while generating claim the date is blank
. -->
396 <input type
='text' size
='10' class='datepicker' name
='form_onset_date' id
='form_onset_date'
397 value
='<?php echo $viewmode && $result['onset_date
']!='0000-00-00 00:00:00' ? substr($result['onset_date
'], 0, 10) : ''; ?>'
398 title
='<?php echo xla('yyyy
-mm
-dd Date of onset
or hospitalization
'); ?>' />
402 <td
class='text' colspan
='2' style
='padding-top:1em'>
410 <td
class='bold' width
='33%' nowrap
>
413 // To see issues stuff user needs write access to all issue types.
415 foreach ($ISSUE_TYPES as $type => $dummy) {
416 if (!acl_check_issue($type, '', 'write')) {
424 <div style
='float:left'>
425 <?php
echo xlt('Issues (Injuries/Medical/Allergy)'); ?
>
427 <div style
='float:left;margin-left:8px;margin-top:-3px'>
428 <?php
if (acl_check('patients', 'med', '', 'write')) { ?
>
429 <a href
="../../patient_file/summary/add_edit_issue.php" class="css_button_small link_submit iframe"
430 onclick
="top.restoreSession()"><span
><?php
echo xlt('Add'); ?
></span
></a
>
439 <td
class='text' valign
='top'>
440 <textarea name
='reason' cols
='40' rows
='12' wrap
='virtual' style
='width:96%'
441 ><?php
echo $viewmode ?
text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?
></textarea
>
443 <td
class='text' valign
='top'>
445 <?php
if ($issuesauth) { ?
>
446 <select multiple name
='issues[]' size
='8' style
='width:100%'
447 title
='<?php echo xla('Hold down
[Ctrl
] for multiple selections
or to unselect
'); ?>'>
449 while ($irow = sqlFetchArray($ires)) {
450 $list_id = $irow['id'];
451 $tcode = $irow['type'];
452 if ($ISSUE_TYPES[$tcode]) {
453 $tcode = $ISSUE_TYPES[$tcode][2];
456 echo " <option value='" . attr($list_id) . "'";
458 $perow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
459 "pid = ? AND encounter = ? AND list_id = ?", array($pid,$encounter,$list_id));
460 if ($perow['count']) {
464 // For new encounters the invoker may pass an issue ID.
465 if (!empty($_REQUEST['issue']) && $_REQUEST['issue'] == $list_id) {
470 echo ">" . text($tcode) . ": " . text($irow['begdate']) . " " .
471 text(substr($irow['title'], 0, 40)) . "</option>\n";
475 <p
><i
><?php
echo xlt('To link this encounter/consult to an existing issue, click the '
476 . 'desired issue above to highlight it and then click [Save]. '
477 . 'Hold down [Ctrl] button to select multiple issues.'); ?
></i
></p
>
489 <script language
="javascript">
492 function duplicateVisit(enc
, datestr
) {
493 if (!confirm('<?php echo xls("A visit already exists for this patient today. Click Cancel to open it, or OK to proceed with creating a new one.") ?>')) {
494 // User pressed the cancel button, so re-direct to today's encounter
495 top
.restoreSession();
496 parent
.left_nav
.setEncounter(datestr
, enc
, window
.name
);
497 parent
.left_nav
.loadFrame('enc2', window
.name
, 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
500 // otherwise just continue normally
504 // Search for an encounter from today
505 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
506 "FROM form_encounter AS fe, forms AS f WHERE " .
508 " AND fe.date >= ? " .
509 " AND fe.date <= ? " .
511 "f.formdir = 'newpatient' AND f.form_id = fe.id AND f.deleted = 0 " .
512 "ORDER BY fe.encounter DESC LIMIT 1", array($pid,date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')));
514 if (!empty($erow['encounter'])) {
515 // If there is an encounter from today then present the duplicate visit dialog
516 echo "duplicateVisit('" . $erow['encounter'] . "', '" .
517 oeFormatShortDate(substr($erow['date'], 0, 10)) . "');\n";
522 <?php
if ($GLOBALS['enable_group_therapy']) { ?
>
523 /* hide / show group name input */
524 var groupCategories
= <?php
echo json_encode($therapyGroupCategories); ?
>;
525 $
('#pc_catid').on('change', function () {
526 if(groupCategories
.indexOf($
(this
).val()) > -1){
527 $
('#therapy_group_name').show();
529 $
('#therapy_group_name').hide();
533 function sel_group() {
534 top
.restoreSession();
535 var url
= '<?php echo $GLOBALS['webroot
']?>/interface/main/calendar/find_group_popup.php';
536 dlgopen(url
, '_blank', 500, 400);
538 // This is for callback by the find-group popup.
539 function setgroup(gid
, name
) {
540 var f
= document
.forms
[0];
541 f
.form_group
.value
= name
;
542 f
.form_gid
.value
= gid
;
545 <?php
if ($viewmode && in_array($result['pc_catid'], $therapyGroupCategories)) {?
>
546 $
('#therapy_group_name').show();