fixes for #1467 #1479 #1462 #1489
[openemr.git] / custom / chart_tracker.php
blobb9fd6cbd63b4e79fd35ec83ff1168e4256758914
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()'>
82 <?php
83 // This is the place for status messages.
85 if ($form_newloc || $form_newuser) {
86 $tracker = new ChartTracker();
87 $tracker->setPid($form_curpid);
88 $tracker->setWhen(new \DateTime(date('Y-m-d H:i:s')));
89 $tracker->setUserId($form_newuser);
90 $tracker->setLocation($form_newloc);
91 $chartTrackerService = new ChartTrackerService();
92 $chartTrackerService->trackPatientLocation($tracker);
93 echo "<div class='alert alert-success'>" . xlt('Save Successful for chart ID') . " " . "'" . text($form_curid) . "'.</div>";
96 $row = array();
98 if ($form_newid) {
99 // Find out where the chart is now.
100 $query = "SELECT pd.pid, pd.pubpid, pd.fname, pd.mname, pd.lname, " .
101 "pd.ss, pd.DOB, ct.ct_userid, ct.ct_location, ct.ct_when " .
102 "FROM patient_data AS pd " .
103 "LEFT OUTER JOIN chart_tracker AS ct ON ct.ct_pid = pd.pid " .
104 "WHERE pd.pubpid = ? " .
105 "ORDER BY pd.pid ASC, ct.ct_when DESC LIMIT 1";
106 $row = sqlQuery($query, array($form_newid));
107 if (empty($row)) {
108 echo "<div class='alert alert-danger'>" . xlt('Chart ID') . " " . "'" . text($form_newid) . "' " . xlt('not found') . "!</div>";
113 <?php
114 if (!empty($row)) {
115 $userService = new UserService();
116 $ct_userid = $row['ct_userid'];
117 $ct_location = $row['ct_location'];
118 $current_location = xlt('Unassigned');
119 if ($ct_userid) {
120 $user = $userService->getUser($ct_userid);
121 $current_location = text($user->getLname() . ", " . $user->getFname() . " " . $user->getMname() . " " . oeFormatDateTime($row['ct_when'], "global", true));
122 } else if ($ct_location) {
123 $current_location = generate_display_field(array('data_type'=>'1','list_id'=>'chartloc'), $ct_location);
127 <div class="row">
128 <div class="col-sm-6 well">
129 <div class="form-group">
130 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Patient ID') . ":"; ?></label>
131 <div class='col-sm-9'>
132 <p class="form-control-static"><?php echo text($row['pid']) ?></p>
133 <input type='hidden' name='form_curpid' value='<?php echo attr($row['pid']); ?>' />
134 <input type='hidden' name='form_curid' value='<?php echo attr($row['pubpid']); ?>' />
135 </div>
136 </div>
137 <div class="form-group">
138 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Name') . ":"; ?></label>
139 <div class='col-sm-9'>
140 <p class="form-control-static"><?php echo text($row['lname'] . ", " . $row['fname'] . " " . $row['mname']) ?></p>
141 </div>
142 </div>
143 <div class="form-group">
144 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('DOB') . ":"; ?></label>
145 <div class='col-sm-9'>
146 <p class="form-control-static"><?php echo text(oeFormatShortDate($row['DOB'])) ?></p>
147 </div>
148 </div>
149 <div class="form-group">
150 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('SSN') . ":"; ?></label>
151 <div class='col-sm-9'>
152 <p class="form-control-static"><?php echo text($row['ss']) ?></p>
153 </div>
154 </div>
155 <div class="form-group">
156 <label for="form_pat_id" class='control-label col-sm-3'><?php echo xlt('Current Location') . ":"; ?></label>
157 <div class='col-sm-9'>
158 <p class="form-control-static"><?php echo text($current_location) ?></p>
159 </div>
160 </div>
161 <div class="form-group">
162 <label for="form_curr_loc" class='control-label col-sm-3'><?php echo xlt('Check In To') . ":"; ?></label>
163 <div class='col-sm-9'>
164 <?php generate_form_field(array('data_type'=>1,'field_id'=>'newloc','list_id'=>'chartloc','empty_title'=>''), ''); ?>
165 </div>
166 </div>
167 <div class="form-group">
168 <label for="form_out_to" class='control-label col-sm-3'><?php echo xlt('Our Out To') . ":"; ?></label>
169 <div class='col-sm-9'>
170 <select name='form_newuser' class='form-control' onchange='userSelect()'>
171 <option value=''></option>
172 <?php
173 $users = $userService->getActiveUsers();
175 foreach ($users as $activeUser) {
176 echo " <option value='" . attr($activeUser->getId()) . "'";
177 echo ">" . text($activeUser->getLname()) . ', ' . text($activeUser->getFname()) . ' ' . text($activeUser->getMname()) .
178 "</option>\n";
181 </select>
182 </div>
183 </div>
184 <div class="form-group">
185 <div class="col-sm-offset-3 col-sm-9">
186 <button type='submit' class='btn btn-default btn-save' name='form_save'><?php echo xlt("Save"); ?></button>
187 </div>
188 </div>
189 </div>
192 <?php
195 <div class="row">
196 <div class="col-sm-6 well">
197 <div class="form-group">
198 <label for='form_newid' class='control-label col-sm-3'><?php echo xlt('New Patient ID') . ":"; ?></label>
199 <div class='col-sm-9'>
200 <input type='text' name='form_newid' id='form_newid' class='form-control' title='<?php echo xla('Type or scan the patient identifier here'); ?>'>
201 </div>
202 </div>
203 <div class="form-group">
204 <div class='col-sm-offset-3 col-sm-9'>
205 <button type='submit' class='btn btn-default btn-search' name='form_lookup'><?php echo xlt("Look Up"); ?></button>
206 </div>
207 </div>
208 </div>
209 </form>
211 </div>
213 </body>
214 </html>