3 * Multi select patient.
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"])) {
25 $patients = rtrim($_GET['patients'], ";");
26 $patients = explode(';', $patients);
28 foreach ($patients as $patient) {
29 $result=getPatientData($patient, 'id, pid, lname, fname, mname, pubpid, ss, DOB, phone_home');
39 <?php Header
::setupHeader(['select2', 'opener']); ?
>
40 <title
><?php
echo xlt('Patient Finder'); ?
></title
>
46 background
-color
: #ddddff;
51 display
: inline
-block
;
54 width
: 90px
!important
;
57 width
: 120px
!important
;
62 display
: inline
-block
;
63 vertical
-align
: middle
;
66 display
: inline
-block
;
67 vertical
-align
: middle
;
73 #searchResultsHeader {
75 border
-collapse
: collapse
;
79 border
-collapse
: collapse
;
80 background
-color
: white
;
84 #searchResults .remove-patient {
90 border
-bottom
: 1px solid
#eee;
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
>
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
>
110 <div
class="buttons-box">
111 <div
class="inline-box">
112 <button id
="add-to-list"><?php
echo xlt('Add to list'); ?
></button
>
114 <div
class="inline-box">
115 <button id
="send-patients" onclick
="selPatients()"><?php
echo xlt('OK'); ?
></button
>
121 <table id
="results-table" class="table table-condensed">
122 <thead id
="searchResultsHeader" class="head">
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
>
132 <tbody id
="searchResults">
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>' .
155 <?php
if (isset($_GET['patients'])) { ?
>
156 var patientsList
= <?php
echo json_encode($results); ?
>;
158 var patientsList
= [];
159 $
('#results-table').hide();
162 //Initial select2 library for auto completing using ajax
163 $
('#by-id, #by-name').select2({
165 beforeSend
: top
.restoreSession
,
166 url
: 'multi_patients_finder_ajax.php',
167 data
:function (params
) {
170 type
: $
(this
).attr('id'),
171 csrf_token_form
: "<?php echo attr(collectCsrfToken()); ?>"
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();
184 url
: 'multi_patients_finder_ajax.php',
186 type
:'patient-by-id',
187 search
:$
('#by-id').val(),
188 csrf_token_form
: "<?php echo attr(collectCsrfToken()); ?>"
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();
204 url
: 'multi_patients_finder_ajax.php',
206 type
:'patient-by-id',
207 search
:$
('#by-name').val(),
208 csrf_token_form
: "<?php echo attr(collectCsrfToken()); ?>"
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
) {
224 if($
('#by-name').val() == '')return;
226 if(patientsList
.length
=== 0){
227 $
('#results-table').show();
230 // return if patient already exist in the list
232 $
.each(patientsList
, function (key
, patient
) {
233 if (patient
.pid
== currentResult
.pid
) exist
= true;
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>' +
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.'); ?>");
269 opener
.setMultiPatients(patientsList
);