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