bug fix march continued (#1921)
[openemr.git] / custom / chart_tracker.php
blobb0186e7de961387162100ed8bcd17168919cb24c
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\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 language="JavaScript">
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-xs-12">
74 <div class="page-header">
75 <h1><?php echo xlt('Chart Tracker'); ?></h1>
76 </div>
77 </div>
78 </div>
80 <form method='post' action='chart_tracker.php' class='form-horizontal' onsubmit='return top.restoreSession()'>
81 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
83 <?php
84 // This is the place for status messages.
86 if ($form_newloc || $form_newuser) {
87 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
88 csrfNotVerified();
91 $tracker = new ChartTracker();
92 $tracker->setPid($form_curpid);
93 $tracker->setWhen(new \DateTime(date('Y-m-d H:i:s')));
94 $tracker->setUserId($form_newuser);
95 $tracker->setLocation($form_newloc);
96 $chartTrackerService = new ChartTrackerService();
97 $chartTrackerService->trackPatientLocation($tracker);
98 echo "<div class='alert alert-success'>" . xlt('Save Successful for chart ID') . " " . "'" . text($form_curid) . "'.</div>";
101 $row = array();
103 if ($form_newid) {
104 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
105 csrfNotVerified();
108 // Find out where the chart is now.
109 $query = "SELECT pd.pid, pd.pubpid, pd.fname, pd.mname, pd.lname, " .
110 "pd.ss, pd.DOB, ct.ct_userid, ct.ct_location, ct.ct_when " .
111 "FROM patient_data AS pd " .
112 "LEFT OUTER JOIN chart_tracker AS ct ON ct.ct_pid = pd.pid " .
113 "WHERE pd.pubpid = ? " .
114 "ORDER BY pd.pid ASC, ct.ct_when DESC LIMIT 1";
115 $row = sqlQuery($query, array($form_newid));
116 if (empty($row)) {
117 echo "<div class='alert alert-danger'>" . xlt('Chart ID') . " " . "'" . text($form_newid) . "' " . xlt('not found') . "!</div>";
122 <?php
123 if (!empty($row)) {
124 $userService = new UserService();
125 $ct_userid = $row['ct_userid'];
126 $ct_location = $row['ct_location'];
127 $current_location = xlt('Unassigned');
128 if ($ct_userid) {
129 $user = $userService->getUser($ct_userid);
130 $current_location = text($user->getLname() . ", " . $user->getFname() . " " . $user->getMname() . " " . oeFormatDateTime($row['ct_when'], "global", true));
131 } else if ($ct_location) {
132 $current_location = generate_display_field(array('data_type'=>'1','list_id'=>'chartloc'), $ct_location);
136 <div class="row">
137 <div class="col-sm-6 well">
138 <div class="form-group">
139 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Patient ID') . ":"; ?></label>
140 <div class='col-sm-9'>
141 <p class="form-control-static"><?php echo text($row['pid']) ?></p>
142 <input type='hidden' name='form_curpid' value='<?php echo attr($row['pid']); ?>' />
143 <input type='hidden' name='form_curid' value='<?php echo attr($row['pubpid']); ?>' />
144 </div>
145 </div>
146 <div class="form-group">
147 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Name') . ":"; ?></label>
148 <div class='col-sm-9'>
149 <p class="form-control-static"><?php echo text($row['lname'] . ", " . $row['fname'] . " " . $row['mname']) ?></p>
150 </div>
151 </div>
152 <div class="form-group">
153 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('DOB') . ":"; ?></label>
154 <div class='col-sm-9'>
155 <p class="form-control-static"><?php echo text(oeFormatShortDate($row['DOB'])) ?></p>
156 </div>
157 </div>
158 <div class="form-group">
159 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('SSN') . ":"; ?></label>
160 <div class='col-sm-9'>
161 <p class="form-control-static"><?php echo text($row['ss']) ?></p>
162 </div>
163 </div>
164 <div class="form-group">
165 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Current Location') . ":"; ?></label>
166 <div class='col-sm-9'>
167 <p class="form-control-static"><?php echo text($current_location) ?></p>
168 </div>
169 </div>
170 <div class="form-group">
171 <label for="form_curr_loc" class='control-label col-sm-3'><?php echo xlt('Check In To') . ":"; ?></label>
172 <div class='col-sm-9'>
173 <?php generate_form_field(array('data_type'=>1,'field_id'=>'newloc','list_id'=>'chartloc','empty_title'=>''), ''); ?>
174 </div>
175 </div>
176 <div class="form-group">
177 <label for="form_out_to" class='control-label col-sm-3'><?php echo xlt('Our Out To') . ":"; ?></label>
178 <div class='col-sm-9'>
179 <select name='form_newuser' class='form-control' onchange='userSelect()'>
180 <option value=''></option>
181 <?php
182 $users = $userService->getActiveUsers();
184 foreach ($users as $activeUser) {
185 echo " <option value='" . attr($activeUser->getId()) . "'";
186 echo ">" . text($activeUser->getLname()) . ', ' . text($activeUser->getFname()) . ' ' . text($activeUser->getMname()) .
187 "</option>\n";
190 </select>
191 </div>
192 </div>
193 <div class="form-group">
194 <div class="col-sm-offset-3 col-sm-9">
195 <button type='submit' class='btn btn-default btn-save' name='form_save'><?php echo xlt("Save"); ?></button>
196 </div>
197 </div>
198 </div>
201 <?php
204 <div class="row">
205 <div class="col-sm-6 well">
206 <div class="form-group">
207 <label for='form_newid' class='control-label col-sm-3'><?php echo xlt('New Patient ID') . ":"; ?></label>
208 <div class='col-sm-9'>
209 <input type='text' name='form_newid' id='form_newid' class='form-control' title='<?php echo xla('Type or scan the patient identifier here'); ?>'>
210 </div>
211 </div>
212 <div class="form-group">
213 <div class='col-sm-offset-3 col-sm-9'>
214 <button type='submit' class='btn btn-default btn-search' name='form_lookup'><?php echo xlt("Look Up"); ?></button>
215 </div>
216 </div>
217 </div>
218 </form>
220 </div>
222 </body>
223 </html>