Http (#3926)
[openemr.git] / custom / chart_tracker.php
blob2d95463a3522103f18d612d6c4e75a5091b2bf2d
1 <?php
3 /**
4 * The Chart Tracker feature facilitates the old traditional paper charts updates.
5 * This feature requires a new list:
6 * <pre>
7 * INSERT INTO list_options VALUES ('lists','chartloc','Chart Storage Locations',51,0,0);
8 * </pre>
10 * @package OpenEMR
11 * @link http://www.open-emr.org
12 * @author Rod Roark <rod@sunsetsystems.com>
13 * @author Brady Miller <brady.g.miller@gmail.com>
14 * @author Roberto Vasquez <robertogagliotta@gmail.com>
15 * @Copyright (C) 2008-2012 Rod Roark <rod@sunsetsystems.com>
16 * @Copyright (C) 2011-2018 Brady Miller <brady.g.miller@gmail.com>
17 * @Copyright (C) 2017 Roberto Vasquez <robertogagliotta@gmail.com>
20 require_once("../interface/globals.php");
21 require_once("$srcdir/options.inc.php");
23 use OpenEMR\Common\Csrf\CsrfUtils;
24 use OpenEMR\Core\Header;
25 use OpenEMR\Entities\ChartTracker;
26 use OpenEMR\Services\ChartTrackerService;
27 use OpenEMR\Services\UserService;
29 $form_newid = isset($_POST['form_newid' ]) ? trim($_POST['form_newid' ]) : '';
30 $form_curpid = isset($_POST['form_curpid' ]) ? trim($_POST['form_curpid' ]) : '';
31 $form_curid = isset($_POST['form_curid' ]) ? trim($_POST['form_curid' ]) : '';
32 $form_newloc = isset($_POST['form_newloc' ]) ? trim($_POST['form_newloc' ]) : '';
33 $form_newuser = isset($_POST['form_newuser']) ? trim($_POST['form_newuser']) : '';
35 if ($form_newuser) {
36 $form_newloc = '';
37 } else {
38 $form_newuser = 0;
41 <html>
43 <head>
44 <?php Header::setupHeader(); ?>
45 <title><?php echo xlt('Chart Tracker'); ?></title>
47 <script>
49 function locationSelect() {
50 var f = document.forms[0];
51 var i = f.form_newloc.selectedIndex;
52 if (i > 0) {
53 f.form_newuser.selectedIndex = 0;
57 function userSelect() {
58 var f = document.forms[0];
59 var i = f.form_newuser.selectedIndex;
60 if (i > 0) {
61 f.form_newloc.selectedIndex = 0;
65 </script>
67 </head>
69 <body class="body_top">
70 <div class="container">
72 <div class="row">
73 <div class="col-12">
74 <h1><?php echo xlt('Chart Tracker'); ?></h1>
75 </div>
76 </div>
78 <form method='post' action='chart_tracker.php' class='form-horizontal' onsubmit='return top.restoreSession()'>
79 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
81 <?php
82 // This is the place for status messages.
84 if ($form_newloc || $form_newuser) {
85 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
86 CsrfUtils::csrfNotVerified();
89 $tracker = new ChartTracker();
90 $tracker->setPid($form_curpid);
91 $tracker->setWhen(new \DateTime(date('Y-m-d H:i:s')));
92 $tracker->setUserId($form_newuser);
93 $tracker->setLocation($form_newloc);
94 $chartTrackerService = new ChartTrackerService();
95 $chartTrackerService->trackPatientLocation($tracker);
96 echo "<div class='alert alert-success'>" . xlt('Save Successful for chart ID') . " " . "'" . text($form_curid) . "'.</div>";
99 $row = array();
101 if ($form_newid) {
102 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
103 CsrfUtils::csrfNotVerified();
106 // Find out where the chart is now.
107 $query = "SELECT pd.pid, pd.pubpid, pd.fname, pd.mname, pd.lname, " .
108 "pd.ss, pd.DOB, ct.ct_userid, ct.ct_location, ct.ct_when " .
109 "FROM patient_data AS pd " .
110 "LEFT OUTER JOIN chart_tracker AS ct ON ct.ct_pid = pd.pid " .
111 "WHERE pd.pubpid = ? " .
112 "ORDER BY pd.pid ASC, ct.ct_when DESC LIMIT 1";
113 $row = sqlQuery($query, array($form_newid));
114 if (empty($row)) {
115 echo "<div class='alert alert-danger'>" . xlt('Chart ID') . " " . "'" . text($form_newid) . "' " . xlt('not found') . "!</div>";
120 <?php
121 if (!empty($row)) {
122 $userService = new UserService();
123 $ct_userid = $row['ct_userid'];
124 $ct_location = $row['ct_location'];
125 $current_location = xlt('Unassigned');
126 if ($ct_userid) {
127 $user = $userService->getUser($ct_userid);
128 $current_location = text($user->getLname() . ", " . $user->getFname() . " " . $user->getMname() . " " . oeFormatDateTime($row['ct_when'], "global", true));
129 } elseif ($ct_location) {
130 $current_location = generate_display_field(array('data_type' => '1','list_id' => 'chartloc'), $ct_location);
134 <div class="row">
135 <div class="col-sm-6 jumbotron jumbotron-fluid p-3">
136 <div class="form-row">
137 <label for="form_pat_id" class='col-form-label col-sm-3'><?php echo xlt('Patient ID') . ":"; ?></label>
138 <div class='col-sm-9'>
139 <p class="form-control-static"><?php echo text($row['pid']) ?></p>
140 <input type='hidden' name='form_curpid' value='<?php echo attr($row['pid']); ?>' />
141 <input type='hidden' name='form_curid' value='<?php echo attr($row['pubpid']); ?>' />
142 </div>
143 </div>
144 <div class="form-row">
145 <label for="form_pat_id" class='col-form-label col-sm-3'><?php echo xlt('Name') . ":"; ?></label>
146 <div class='col-sm-9'>
147 <p class="form-control-static"><?php echo text($row['lname'] . ", " . $row['fname'] . " " . $row['mname']) ?></p>
148 </div>
149 </div>
150 <div class="form-row">
151 <label for="form_pat_id" class='col-form-label col-sm-3'><?php echo xlt('DOB') . ":"; ?></label>
152 <div class='col-sm-9'>
153 <p class="form-control-static"><?php echo text(oeFormatShortDate($row['DOB'])) ?></p>
154 </div>
155 </div>
156 <div class="form-row">
157 <label for="form_pat_id" class='col-form-label col-sm-3'><?php echo xlt('SSN') . ":"; ?></label>
158 <div class='col-sm-9'>
159 <p class="form-control-static"><?php echo text($row['ss']) ?></p>
160 </div>
161 </div>
162 <div class="form-row">
163 <label for="form_pat_id" class='col-form-label col-sm-3'><?php echo xlt('Current Location') . ":"; ?></label>
164 <div class='col-sm-9'>
165 <p class="form-control-static"><?php echo text($current_location) ?></p>
166 </div>
167 </div>
168 <div class="form-row">
169 <label for="form_curr_loc" class='col-form-label col-sm-3'><?php echo xlt('Check In To') . ":"; ?></label>
170 <div class='col-sm-9'>
171 <?php generate_form_field(array('data_type' => 1,'field_id' => 'newloc','list_id' => 'chartloc','empty_title' => ''), ''); ?>
172 </div>
173 </div>
174 <div class="form-row">
175 <label for="form_out_to" class='col-form-label col-sm-3'><?php echo xlt('Our Out To') . ":"; ?></label>
176 <div class='col-sm-9'>
177 <select name='form_newuser' class='form-control' onchange='userSelect()'>
178 <option value=''></option>
179 <?php
180 $users = $userService->getActiveUsers();
182 foreach ($users as $activeUser) {
183 echo " <option value='" . attr($activeUser->getId()) . "'";
184 echo ">" . text($activeUser->getLname()) . ', ' . text($activeUser->getFname()) . ' ' . text($activeUser->getMname()) .
185 "</option>\n";
188 </select>
189 </div>
190 </div>
191 <div class="form-row">
192 <div class="offset-sm-3 col-sm-9">
193 <button type='submit' class='btn btn-secondary btn-save' name='form_save'><?php echo xlt("Save"); ?></button>
194 </div>
195 </div>
196 </div>
199 <?php
202 <div class="col-sm-6 jumbotron jumbotron-fluid p-3">
203 <div class="form-row">
204 <label for='form_newid' class='col-form-label col-sm-3'><?php echo xlt('New Patient ID') . ":"; ?></label>
205 <div class='col-sm-9'>
206 <input type='text' name='form_newid' id='form_newid' class='form-control' title='<?php echo xla('Type or scan the patient identifier here'); ?>' />
207 </div>
208 </div>
209 <div class="form-row">
210 <div class='offset-sm-3 col-sm-9'>
211 <button type='submit' class='btn btn-secondary btn-search' name='form_lookup'><?php echo xlt("Look Up"); ?></button>
212 </div>
213 </div>
214 </div>
215 </div>
216 </form>
218 </div>
220 </body>
221 </html>