Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / main / finder / multi_patients_finder.php
blobc5336bb157550eaa3e90b92dcf3b3a727c18d48c
1 <?php
2 /**
3 * Multi select patient.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Amiel Elboim <amielel@matrix.co.il>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2017 Amiel Elboim <amielel@matrix.co.il
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once('../../globals.php');
15 require_once("$srcdir/patient.inc");
17 use OpenEMR\Core\Header;
19 // for editing selected patients
20 if (isset($_GET['patients'])) {
21 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
22 csrfNotVerified();
25 $patients = rtrim($_GET['patients'], ";");
26 $patients = explode(';', $patients);
27 $results = array();
28 foreach ($patients as $patient) {
29 $result=getPatientData($patient, 'id, pid, lname, fname, mname, pubpid, ss, DOB, phone_home');
30 $results[] = $result;
36 <!DOCTYPE html>
37 <html>
38 <head>
39 <?php Header::setupHeader(['select2', 'opener']); ?>
40 <title><?php echo xlt('Patient Finder'); ?></title>
42 <style>
43 #searchCriteria {
44 text-align: center;
45 width: 100%;
46 background-color: #ddddff;
47 font-weight: bold;
48 padding: 7px;
50 .select-box{
51 display: inline-block;
53 #by-id{
54 width: 90px !important;
56 #by-name{
57 width: 120px !important;
59 .buttons-box{
60 margin-left: 10px;
61 margin-right: 10px;
62 display: inline-block;
63 vertical-align: middle;
65 .inline-box{
66 display: inline-block;
67 vertical-align: middle;
69 .remove-patient{
70 color: red;
71 pointer-events: auto;
73 #searchResultsHeader {
74 width: 100%;
75 border-collapse: collapse;
77 #searchResults {
78 width: 100%;
79 border-collapse: collapse;
80 background-color: white;
81 overflow: auto;
84 #searchResults .remove-patient {
85 cursor: hand;
86 cursor: pointer;
88 #searchResults td {
89 /*font-size: 0.7em;*/
90 border-bottom: 1px solid #eee;
92 </style>
94 </head>
96 <body class="body_top">
97 <div class="container-responsive">
98 <div id="searchCriteria">
99 <form class="form-inline">
100 <div class="select-box">
101 <label><?php echo xlt('Patient name') .':'; ?></label>
102 <select id="by-name" class="input-sm">
103 <option value=""><?php echo xlt('Enter name'); ?></option>
104 </select>
105 <label><?php echo xlt('Patient ID'); ?></label>
106 <select id="by-id" class="input-sm">
107 <option value=""><?php echo xlt('Enter ID'); ?></option>
108 </select>
109 </div>
110 <div class="buttons-box">
111 <div class="inline-box">
112 <button id="add-to-list"><?php echo xlt('Add to list'); ?></button>
113 </div>
114 <div class="inline-box">
115 <button id="send-patients" onclick="selPatients()"><?php echo xlt('OK'); ?></button>
116 </div>
117 </div>
118 </form>
119 </div>
121 <table id="results-table" class="table table-condensed">
122 <thead id="searchResultsHeader" class="head">
123 <tr>
124 <th class="srName"><?php echo xlt('Name'); ?></th>
125 <th class="srPhone"><?php echo xlt('Phone'); ?></th>
126 <th class="srSS"><?php echo xlt('SS'); ?></th>
127 <th class="srDOB"><?php echo xlt('DOB'); ?></th>
128 <th class="srID"><?php echo xlt('ID'); ?></th>
129 <th></th>
130 </tr>
131 </thead>
132 <tbody id="searchResults">
133 <?php
134 if (isset($_GET['patients'])) {
135 foreach ($results as $index => $result) {
136 echo '<tr id="row' . attr($result['pid']) . '">' .
137 '<td>' . text($result['lname']) . ', ' . text($result['fname']) . '</td>' .
138 '<td>' . text($result['phone_home']) . '</td>' .
139 '<td>' . text($result['ss']) . '</td>' .
140 '<td>' . text(oeFormatShortDate($result['DOB'])) . '</td>' .
141 '<td>' . text($result['pubpid']) . '</td>' .
142 '<td><i class="fa fa-remove remove-patient" onclick="removePatient(' . attr(addslashes($result['pid'])) . ')"></i></td>' .
143 '<tr>';
145 } ?>
146 </tbody>
147 </table>
149 </div>
151 <script>
153 var currentResult;
155 <?php if (isset($_GET['patients'])) { ?>
156 var patientsList = <?php echo json_encode($results); ?>;
157 <?php } else { ?>
158 var patientsList = [];
159 $('#results-table').hide();
160 <?php } ?>
162 //Initial select2 library for auto completing using ajax
163 $('#by-id, #by-name').select2({
164 ajax: {
165 beforeSend: top.restoreSession,
166 url: 'multi_patients_finder_ajax.php',
167 data:function (params) {
168 var query = {
169 search: params.term,
170 type: $(this).attr('id'),
171 csrf_token_form: "<?php echo attr(collectCsrfToken()); ?>"
173 return query;
175 dataType: 'json',
177 <?php require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?>
180 //get all the data of selected patient
181 $('#by-id').on('change', function () {
182 top.restoreSession();
183 $.ajax({
184 url: 'multi_patients_finder_ajax.php',
185 data:{
186 type:'patient-by-id',
187 search:$('#by-id').val(),
188 csrf_token_form: "<?php echo attr(collectCsrfToken()); ?>"
190 dataType: 'json'
191 }).done(function(data){
192 currentResult=data.results;
193 //change patient name to selected patient
194 $('#by-name').val(null);
195 var newOption = "<option value='" +currentResult.pid+ "' selected>"+currentResult.lname + ', ' + currentResult.fname+"</option>";
196 $('#by-name').append(newOption);
200 //get all the data of selected patient
201 $('#by-name').on('change', function () {
202 top.restoreSession();
203 $.ajax({
204 url: 'multi_patients_finder_ajax.php',
205 data:{
206 type:'patient-by-id',
207 search:$('#by-name').val(),
208 csrf_token_form: "<?php echo attr(collectCsrfToken()); ?>"
210 dataType: 'json'
211 }).done(function(data){
212 currentResult=data.results;
213 //change patient pubpid to selected patient
214 $('#by-id').val(null);
215 var newOption = "<option value='" +currentResult.pid+ "' selected>"+ currentResult.pubpid +"</option>";
216 $('#by-id').append(newOption);
220 //add new patient to list
221 $('#add-to-list').on('click', function (e) {
222 e.preventDefault();
224 if($('#by-name').val() == '')return;
226 if(patientsList.length === 0){
227 $('#results-table').show();
230 // return if patient already exist in the list
231 var exist
232 $.each(patientsList, function (key, patient) {
233 if (patient.pid == currentResult.pid) exist = true;
235 if(exist)return;
238 // add to array
239 patientsList.push(currentResult);
241 $('#searchResults').append('<tr id="row'+currentResult.pid +'">' +
242 '<td>'+ currentResult.lname + ', ' + currentResult.fname + '</td>' +
243 '<td>' + currentResult.phone_home + '</td>' +
244 '<td>' + currentResult.ss + '</td>' +
245 '<td>' + currentResult.DOB + '</td>' +
246 '<td>' + currentResult.pubpid + '</td>' +
247 '<td><i class="fa fa-remove remove-patient" onclick="removePatient('+currentResult.pid+')"></i></td>' +
248 '<tr>');
252 // remove patient from list
253 function removePatient(pid) {
255 $.each(patientsList, function (index, patient) {
256 if (typeof patient !== 'undefined' && patient.pid == pid) {
257 patientsList.splice(index,1);
261 $('#row'+pid).remove();
264 //send array of patients to function 'setMultiPatients' of the opener
265 function selPatients() {
266 if (opener.closed || ! opener.setMultiPatients)
267 alert("<?php echo xls('The destination form was closed; I cannot act on your selection.'); ?>");
268 else
269 opener.setMultiPatients(patientsList);
270 dlgclose();
271 return false;
275 </script>
277 </body>