bug fix (#7559)
[openemr.git] / interface / patient_tracker / patient_tracker_status.php
blob95986df37302abc29da805748652611dff8c26d9
1 <?php
3 /**
4 * Patient Tracker Status Editor
6 * This allows entry and editing of current status for the patient from within patient tracker and updates the status on the calendar.
7 * Contains a drop down for the Room information driven by the list Patient Flow Board Rooms.
9 * @package OpenEMR
10 * @link http://www.open-emr.org
11 * @author Terry Hill <terry@lillysystems.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2015 Terry Hill <terry@lillysystems.com>
14 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 require_once("../globals.php");
19 require_once("$srcdir/options.inc.php");
20 require_once("$srcdir/forms.inc.php");
21 require_once("$srcdir/encounter_events.inc.php");
22 require_once("$srcdir/patient_tracker.inc.php");
24 use OpenEMR\Common\Csrf\CsrfUtils;
25 use OpenEMR\Core\Header;
27 if (!empty($_GET)) {
28 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
29 CsrfUtils::csrfNotVerified();
33 # Get the information for fields
34 $tracker_id = $_GET['tracker_id'];
35 $trow = sqlQuery("SELECT apptdate, appttime, patient_tracker_element.room AS lastroom, " .
36 "patient_tracker_element.status AS laststatus, eid, random_drug_test, encounter, pid " .
37 "FROM patient_tracker " .
38 "LEFT JOIN patient_tracker_element " .
39 "ON patient_tracker.id = patient_tracker_element.pt_tracker_id " .
40 "AND patient_tracker.lastseq = patient_tracker_element.seq " .
41 "WHERE patient_tracker.id =?", array($_GET['tracker_id']));
43 $tkpid = $trow['pid'];
44 $appttime = $trow['appttime'];
45 $apptdate = $trow['apptdate'];
46 $pceid = $trow['eid'];
47 $theroom = '';
50 <html>
51 <head>
52 <?php Header::setupHeader(['common','opener']); ?>
53 </head>
55 <?php
56 if (!empty($_POST['statustype'])) {
57 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
58 CsrfUtils::csrfNotVerified();
61 $status = $_POST['statustype'];
62 if (strlen($_POST['roomnum']) != 0) {
63 $theroom = $_POST['roomnum'];
66 # Manage tracker status. Also auto create encounter, if applicable.
67 if (!empty($tkpid)) {
68 // if an encounter is found it is returned to be carried forward with status changes.
69 // otherwise 0 which is table default.
70 $is_tracker = is_tracker_encounter_exist($apptdate, $appttime, $tkpid, $pceid);
71 if ($GLOBALS['auto_create_new_encounters'] && $apptdate == date('Y-m-d') && (is_checkin($status) == '1') && !$is_tracker) {
72 # Gather information for encounter fields
73 $genenc = sqlQuery("select pc_catid as category, pc_hometext as reason, pc_aid as provider, pc_facility as facility, pc_billing_location as billing_facility " .
74 "from openemr_postcalendar_events where pc_eid =? ", array($pceid));
75 $encounter = todaysEncounterCheck($tkpid, $apptdate, $genenc['reason'], $genenc['facility'], $genenc['billing_facility'], $genenc['provider'], $genenc['category'], false);
76 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
77 if (!empty($pceid)) {
78 manage_tracker_status($apptdate, $appttime, $pceid, $tkpid, $_SESSION["authUser"], $status, $theroom, $encounter);
80 } else {
81 # Capture the appt status and room number for patient tracker.
82 if (!empty($pceid)) {
83 manage_tracker_status($apptdate, $appttime, $pceid, $tkpid, $_SESSION["authUser"], $status, $theroom, $is_tracker);
88 echo "<body>\n<script>\n";
89 echo " window.opener.document.flb.submit();\n";
90 echo " dlgclose();\n";
91 echo "</script></body></html>\n";
92 exit();
95 #get the patient name for display
96 $row = sqlQuery("select fname, lname " .
97 "from patient_data where pid =? limit 1", array($tkpid));
100 <body>
101 <div class="container mt-3">
102 <div class="row">
103 <div class="col-12">
104 <h2><?php echo xlt('Change Status for') . " " . text($row['fname']) . " " . text($row['lname']); ?></h2>
105 </div>
106 </div>
107 <form id="form_note" method="post" action="patient_tracker_status.php?tracker_id=<?php echo attr_url($tracker_id) ?>&csrf_token_form=<?php echo attr_url(CsrfUtils::collectCsrfToken()); ?>" enctype="multipart/form-data" >
108 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
109 <div class="form-group">
110 <label for="statustype"><?php echo xlt('Status Type'); ?></label>
111 <?php echo generate_select_list('statustype', 'apptstat', $trow['laststatus'], xl('Status Type')); ?>
112 </div>
113 <div class="form-group">
114 <label for="roomnum"><?php echo xlt('Exam Room Number'); ?></label>
115 <?php echo generate_select_list('roomnum', 'patient_flow_board_rooms', $trow['lastroom'], xl('Exam Room Number')); ?>
116 </div>
117 <div class="position-override">
118 <div class="btn-group" role="group">
119 <button type="button" class='btn btn-primary btn-save btn-sm' onclick='document.getElementById("form_note").submit();'><?php echo xlt('Save')?></button>
120 <button type="button" class='btn btn-secondary btn-cancel btn-sm' onclick="dlgclose();" ><?php echo xlt('Cancel'); ?></button>
121 </div>
122 </div>
123 </form>
124 </div>
125 </body>
126 </html>