Highway to PSR2
[openemr.git] / interface / forms / newGroupEncounter / common.php
blob49812189c56a4b2d29e6624f68dee30ba518f050
1 <?php
2 /**
3 * Common script for the encounter form (new and view) scripts.
5 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
6 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Amiel Elboim <amielel@matrix.co.il>
22 * @author Brady Miller <brady.g.miller@gmail.com>
23 * @link http://www.open-emr.org
26 require_once("$srcdir/options.inc.php");
27 require_once("$srcdir/group.inc");
28 require_once("$srcdir/classes/POSRef.class.php");
30 $facilityService = new \services\FacilityService();
32 $months = array("01","02","03","04","05","06","07","08","09","10","11","12");
33 $days = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14",
34 "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
35 $thisyear = date("Y");
36 $years = array($thisyear-1, $thisyear, $thisyear+1, $thisyear+2);
38 if ($viewmode) {
39 $id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : '';
40 $result = sqlQuery("SELECT * FROM form_groups_encounter WHERE id = ?", array($id));
41 $encounter = $result['encounter'];
42 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
43 echo "<body>\n<html>\n";
44 echo "<p>" . xlt('You are not authorized to see this encounter.') . "</p>\n";
45 echo "</body>\n</html>\n";
46 exit();
50 // Sort comparison for sensitivities by their order attribute.
51 function sensitivity_compare($a, $b)
53 return ($a[2] < $b[2]) ? -1 : 1;
56 /*// get issues
57 $ires = sqlStatement("SELECT id, type, title, begdate FROM lists WHERE " .
58 "pid = ? AND enddate IS NULL " .
59 "ORDER BY type, begdate", array($pid));
60 */?>
61 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
62 <html>
63 <head>
64 <?php html_header_show();?>
65 <title><?php echo xlt('Therapy Group Encounter'); ?></title>
67 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
68 <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" />
69 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
71 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
72 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
73 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
74 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"></script>
75 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
76 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
78 <!-- validation library -->
79 <?php
80 //Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation
81 $use_validate_js = 1;
82 require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
84 <?php include_once("{$GLOBALS['srcdir']}/ajax/facility_ajax_jav.inc.php"); ?>
85 <script language="JavaScript">
87 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
90 // Process click on issue title.
91 function newissue() {
92 dlgopen('../../patient_file/summary/add_edit_issue.php', '_blank', 800, 600);
93 return false;
96 // callback from add_edit_issue.php:
97 function refreshIssue(issue, title) {
98 var s = document.forms[0]['issues[]'];
99 s.options[s.options.length] = new Option(title, issue, true, true);
103 <?php
104 //Gets validation rules from Page Validation list.
105 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
106 $collectthis = collectValidationPageRules("/interface/forms/newGroupEncounter/common.php");
107 if (empty($collectthis)) {
108 $collectthis = "undefined";
109 } else {
110 $collectthis = $collectthis["new-encounter-form"]["rules"];
113 var collectvalidation = <?php echo($collectthis); ?>;
114 $(document).ready(function(){
115 window.saveClicked = function(event) {
116 var submit = submitme(1, event, 'new-encounter-form', collectvalidation);
117 if (submit) {
118 top.restoreSession();
119 $('#new-encounter-form').submit();
123 $('.datepicker').datetimepicker({
124 <?php $datetimepicker_timepicker = false; ?>
125 <?php $datetimepicker_showseconds = false; ?>
126 <?php $datetimepicker_formatInput = false; ?>
127 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
128 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
131 enable_big_modals();
134 function bill_loc(){
135 var pid=<?php echo attr($pid);?>;
136 var dte=document.getElementById('form_date').value;
137 var facility=document.forms[0].facility_id.value;
138 ajax_bill_loc(pid,dte,facility);
141 // Handler for Cancel clicked when creating a new encounter.
142 // Show demographics or encounters list depending on what frame we're in.
143 function cancelClicked() {
144 if (window.name == 'RBot') {
145 parent.left_nav.loadFrame('ens1', window.name, 'patient_file/history/encounters.php');
147 else {
148 parent.left_nav.loadFrame('dem1', window.name, 'patient_file/summary/demographics.php');
150 return false;
153 </script>
154 </head>
156 <?php if ($viewmode) { ?>
157 <body class="body_top">
158 <?php } else { ?>
159 <body class="body_top" onload="javascript:document.new_encounter.reason.focus();">
160 <?php } ?>
162 <!-- Required for the popup date selectors -->
163 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
165 <form id="new-encounter-form" method='post' action="<?php echo $rootdir ?>/forms/newGroupEncounter/save.php" name='new_encounter'>
167 <div style='float:left'>
168 <?php if ($viewmode) { ?>
169 <input type=hidden name='mode' value='update'>
170 <input type=hidden name='id' value='<?php echo (isset($_GET["id"])) ? attr($_GET["id"]) : '' ?>'>
171 <span class=title><?php echo xlt('Group Encounter Form'); ?></span>
172 <?php } else { ?>
173 <input type='hidden' name='mode' value='new'>
174 <span class='title'><?php echo xlt('New Group Encounter Form'); ?></span>
175 <?php } ?>
176 </div>
178 <div>
179 <div style = 'float:left; margin-left:8px;margin-top:-3px'>
180 <a href="javascript:saveClicked(undefined);" class="css_button link_submit"><span><?php echo xlt('Save'); ?></span></a>
181 <?php if ($viewmode || !isset($_GET["autoloaded"]) || $_GET["autoloaded"] != "1") { ?>
182 </div>
183 <div style = 'float:left; margin-top:-3px'>
184 <a href="<?php echo "$rootdir/patient_file/encounter/encounter_top.php"; ?>"
185 class="css_button link_submit" onClick="top.restoreSession()"><span><?php echo xlt('Cancel'); ?></span></a>
186 <?php } else { // not $viewmode ?>
187 <a href="" class="css_button link_submit" onClick="return cancelClicked()">
188 <span><?php echo xlt('Cancel'); ?></span></a>
189 <?php } // end not $viewmode ?>
190 </div>
191 </div>
193 <br> <br>
195 <table width='96%'>
197 <tr>
198 <td width='33%' nowrap class='bold'><?php echo xlt('Consultation Brief Description'); ?>:</td>
199 <td width='34%' rowspan='2' align='center' valign='center' class='text'>
200 <table>
202 <tr>
203 <td class='bold' nowrap><?php echo xlt('Visit Category'); ?>:</td>
204 <td class='text'>
205 <select name='pc_catid' id='pc_catid'>
206 <option value='_blank'>-- <?php echo xlt('Select One'); ?> --</option>
207 <?php
208 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_cattype " .
209 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq ");
210 while ($crow = sqlFetchArray($cres)) {
211 $catid = $crow['pc_catid'];
212 if ($crow['pc_cattype'] != 3) {
213 continue;
216 echo " <option value='" . attr($catid) . "'";
217 // mark therapy group's category as selected
218 if (!$viewmode && $crow['pc_cattype'] == 3) {
219 echo " selected";
222 if ($viewmode && $crow['pc_catid'] == $result['pc_catid']) {
223 echo " selected";
226 echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
229 </select>
230 </td>
231 </tr>
233 <tr>
234 <td class='bold' nowrap><?php echo xlt('Facility'); ?>:</td>
235 <td class='text'>
236 <select name='facility_id' onChange="bill_loc()">
237 <?php
239 if ($viewmode) {
240 $def_facility = $result['facility_id'];
241 } else {
242 $dres = sqlStatement("select facility_id from users where username = ?", array($_SESSION['authUser']));
243 $drow = sqlFetchArray($dres);
244 $def_facility = $drow['facility_id'];
247 $facilities = $facilityService->getAllServiceLocations();
248 if ($facilities) {
249 foreach ($facilities as $iter) {
251 <option value="<?php echo attr($iter['id']); ?>" <?php if ($def_facility == $iter['id']) {
252 echo "selected";
253 }?>><?php echo text($iter['name']); ?></option>
254 <?php
258 </select>
259 </td>
260 </tr>
261 <tr>
262 <td class='bold' nowrap><?php echo xlt('Billing Facility'); ?>:</td>
263 <td class='text'>
264 <div id="ajaxdiv">
265 <?php
266 billing_facility('billing_facility', $result['billing_facility']);
268 </div>
269 </td>
270 </tr>
271 <?php if ($GLOBALS['set_pos_code_encounter']) { ?>
272 <tr>
273 <td><span class='bold' nowrap><?php echo xlt('POS Code'); ?>: </span></td>
274 <td colspan="6">
275 <select name="pos_code">
276 <?php
278 $pc = new POSRef();
280 foreach ($pc->get_pos_ref() as $pos) {
281 echo "<option value=\"" . attr($pos["code"]) . "\" ";
282 if ($pos["code"] == $result['pos_code']) {
283 echo "selected";
286 echo ">" . text($pos['code']) . ": ". xlt($pos['title']);
287 echo "</option>\n";
291 </select>
292 </td>
293 </tr>
294 <?php } ?>
295 <tr>
296 <?php
297 $sensitivities = acl_get_sensitivities();
298 if ($sensitivities && count($sensitivities)) {
299 usort($sensitivities, "sensitivity_compare");
301 <td class='bold' nowrap><?php echo xlt('Sensitivity:'); ?></td>
302 <td class='text'>
303 <select name='form_sensitivity'>
304 <?php
305 foreach ($sensitivities as $value) {
306 // Omit sensitivities to which this user does not have access.
307 if (acl_check('sensitivities', $value[1])) {
308 echo " <option value='" . attr($value[1]) . "'";
309 if ($viewmode && $result['sensitivity'] == $value[1]) {
310 echo " selected";
313 echo ">" . xlt($value[3]) . "</option>\n";
317 echo " <option value=''";
318 if ($viewmode && !$result['sensitivity']) {
319 echo " selected";
322 echo ">" . xlt('None'). "</option>\n";
324 </select>
325 </td>
326 <?php
327 } else {
329 <td colspan='2'><!-- sensitivities not used --></td>
330 <?php
333 </tr>
335 <tr<?php if (!$GLOBALS['gbl_visit_referral_source']) {
336 echo " style='visibility:hidden;'";
337 } ?>>
338 <td class='bold' nowrap><?php echo xlt('Referral Source'); ?>:</td>
339 <td class='text'>
340 <?php
341 echo generate_select_list('form_referral_source', 'refsource', $viewmode ? $result['referral_source'] : '', '');
343 </td>
344 </tr>
346 <tr>
347 <td class='bold' nowrap><?php echo xlt('Date of Service'); ?>:</td>
348 <td class='text' nowrap>
349 <input type='text' size='10' class='datepicker' name='form_date' id='form_date' <?php echo $disabled ?>
350 value='<?php echo $viewmode ? substr($result['date'], 0, 10) : date('Y-m-d'); ?>'
351 title='<?php echo xla('yyyy-mm-dd Date of service'); ?>' />
352 </td>
353 </tr>
355 <tr<?php if ($GLOBALS['ippf_specific']) {
356 echo " style='visibility:hidden;'";
357 } ?>>
358 <td class='bold' nowrap><?php echo xlt('Additional Date:'); ?></td>
359 <td class='text' nowrap><!-- default is blank so that while generating claim the date is blank. -->
360 <input type='text' size='10' class='datepicker' name='form_onset_date' id='form_onset_date'
361 value='<?php echo $viewmode && $result['onset_date']!='0000-00-00 00:00:00' ? substr($result['onset_date'], 0, 10) : ''; ?>'
362 title='<?php echo xla('yyyy-mm-dd Date of onset or hospitalization'); ?>' />
363 </td>
364 </tr>
365 <tr>
366 <td class='text' colspan='2' style='padding-top:1em'>
367 </td>
368 </tr>
369 </table>
371 </td>
372 </tr>
374 <tr>
375 <td class='text' valign='top'>
376 <textarea name='reason' cols='40' rows='12' wrap='virtual' style='width:96%'
377 ><?php echo $viewmode ? text($result['reason']) : text($GLOBALS['default_chief_complaint']); ?></textarea>
378 </td>
379 </tr>
381 </table>
383 </form>
385 </body>
387 <script language="javascript">
388 <?php
389 if (!$viewmode) { ?>
390 function duplicateVisit(enc, datestr) {
391 if (!confirm('<?php echo xls("A visit already exists for this group today. Click Cancel to open it, or OK to proceed with creating a new one.") ?>')) {
392 // User pressed the cancel button, so re-direct to today's encounter
393 top.restoreSession();
394 parent.left_nav.setEncounter(datestr, enc, window.name);
395 parent.left_nav.loadFrame('enc2', window.name, 'patient_file/encounter/encounter_top.php?set_encounter=' + enc);
396 return;
398 // otherwise just continue normally
400 <?php
402 // Search for an encounter from today
403 $erow = sqlQuery("SELECT fe.encounter, fe.date " .
404 "FROM form_groups_encounter AS fe, forms AS f WHERE " .
405 "fe.group_id = ? " .
406 " AND fe.date >= ? " .
407 " AND fe.date <= ? " .
408 " AND " .
409 "f.formdir = 'newGroupEncounter' AND f.form_id = fe.id AND f.deleted = 0 " .
410 "ORDER BY fe.encounter DESC LIMIT 1", array($therapy_group,date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')));
412 if (!empty($erow['encounter'])) {
413 // If there is an encounter from today then present the duplicate visit dialog
414 echo "duplicateVisit('" . $erow['encounter'] . "', '" .
415 oeFormatShortDate(substr($erow['date'], 0, 10)) . "');\n";
419 </script>
423 </html>