2 * interface/modules/zend_modules/public/js/autosuggest/autosuggest.js
5 * @link https://www.open-emr.org
6 * @author Remesh Babu S <remesh@zhservices.com>
7 * @copyright Copyright (c) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
8 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 * @param {type} evt Event
19 * @returns {undefined}
21 function PreventIt(evt) {
22 evt = (evt) ? evt : window.event;
23 var charCode = (evt.which) ? evt.which : evt.keyCode;
24 if (charCode == 38 || charCode == 40) {
25 if (evt.preventDefault) evt.preventDefault();
26 if (evt.stopPropagation) evt.stopPropagation();
33 * @param {string} inputString keyword
34 * @param {string} searchType Patient, CPT, Diagnosis etc.
35 * @param {int} searchEleNo more then one search box
36 * @param {string} searchMode Single / Multiple
37 * @returns {undefined}
39 function lookup(inputString, searchType, searchEleNo, searchMode) {
40 if(inputString.length == 0) {
41 $('#suggestions' + searchEleNo).hide();
43 if (searchEleNo == '') {
46 if (searchEleNo != '' || searchEleNo > 0) {
47 $('#inputString' + searchEleNo).keyup(function() {
50 $('#inputString' + searchEleNo).keydown(function() {
53 var inputString = $('#inputString' + searchEleNo).val();
54 var inputStringCheck = $('#inputString' + searchEleNo).val();
56 $('#inputString').keyup(function() {
59 $('#inputString').keydown(function() {
62 var inputString = $('#inputString').val();
63 var inputStringCheck = $('#inputString').val();
68 var page = $('#page').val();
70 var path = window.location;
71 var arr = path.toString().split("public");
72 var count = arr[1].split("/").length-1;
74 for(var i = 0; i < count; i++){
77 /* eslint-disable-next-line no-unused-labels */
79 $.post(newPath + "public/application/index/search", {
80 queryString : inputString,
84 searchType : searchType,
85 searchEleNo : searchEleNo,
86 searchMode : searchMode,
88 /* eslint-disable-next-line no-unused-labels */
91 if (searchEleNo > 0) {
92 var inputStringValue = $('#inputString' + searchEleNo).val();
94 var inputStringValue = $('#inputString').val();
96 if (inputStringCheck == inputStringValue) {
97 if (searchEleNo > 0) {
98 $('#suggestions' + searchEleNo).show();
99 $('#autoSuggestionsList' + searchEleNo).html(data);
101 $('#suggestions').show();
102 $('#autoSuggestionsList').html(data);
105 if(document.getElementById('list_' + searchEleNo + '_1')) {
106 $('#list_' + searchEleNo + '_1').focus();
107 $('#list_' + searchEleNo + '_1').css("background-color","#659CD8");
118 * @param {type} evt Event
119 * @param {type} row Line No.
120 * @param {type} id ID for arrow key scroll
121 * @param {type} no Search Element no
122 * @returns {undefined}
124 function move(evt, row, id, no) {
125 evt = (evt) ? evt : window.event;
126 var charCode = (evt.which) ? evt.which : evt.keyCode;
127 if (charCode == 38 || charCode == 40) {
128 evt.stopPropagation();
129 evt.preventDefault();
131 if (charCode == 38) {
133 if(document.getElementById(id + '_' + (row))) {
134 if((row + 1)%2 == 1) {
135 $('#' + id + '_' + (row + 1)).css("background-color", "#fff");
137 $('#' + id + '_' + (row + 1)).css("background-color", "#fff");
139 $('#' + id + '_' + (row)).css("background-color","#659CD8");
140 document.getElementById(id + '_' + (row)).focus();
142 } else if (charCode == 40) {
144 if(document.getElementById(id + '_' + (row))) {
145 if((row - 1)%2 == 1) {
146 $('#' + id + '_' + (row - 1)).css("background-color", "#fff");
148 $('#' + id + '_' + (row - 1)).css("background-color", "#fff");
150 $('#' + id + '_' + (row)).css("background-color","#659CD8");
151 document.getElementById(id + '_' + (row)).focus();
153 } else if (charCode == 13) {
155 $('#fill' + id + '_' + (row)).trigger('click');
157 $('#fill' + id + '_' + (row)).trigger('click');
159 } else if (charCode == 27) {
161 $('#closeme' + no).trigger('click');
163 $('#closeme').trigger('click');
168 document.getElementById('inputString' + no).focus();
170 $('#inputString').focus();
177 * @param {type} params
180 * @returns {undefined}
182 function nextPage(params, id, no, mode) {
183 $('#page').val(params);
184 if (no != '' || no > 0) {
185 lookup($('#inputString' + no).val(), id, no, mode);
187 lookup($('#inputString').val(), id, no, mode);
191 function previousPage(params, id, no, mode) {
192 $('#page').val(params);
193 if (no != '' || no > 0) {
194 lookup($('#inputString' + no).val(), id, no);
196 lookup($('#inputString').val(), id, no, mode);
202 * Fill the selected value in the input box
204 * @param {string} thisValue Name to be Filled in the box
205 * @param {string} id Search Type 'Patient, CPT, Diagnosis etc.'
206 * @param {int} no search Element No more then one search box
207 * @param {string} mode Search Mode Single / Multiple
208 * @returns {undefined}
210 function fill(thisValue, id, no, mode) {
211 //Multiple search entry is in case of feesheet.
212 /*var multiplesearch = false;
213 if(document.getElementById('multiplesearch')){
214 multiplesearch = document.getElementById('multiplesearch').checked ;
216 $('#form_date').prop('disabled', true);
217 $('#form_to_date').prop('disabled', true);
218 $('.validatebox-text').prop('disabled', true);
219 var arr = thisValue.split("|");
220 if (mode == 'single') {
221 if (no == '' || no == 0) {
222 setTimeout("$('#suggestions').hide();", 100);
223 $('#inputString').val(arr[0]);
224 $('#string_id').val(arr[1]);
225 //$('#string_id').attr('type', 'text');
226 $('#string_id').get(0).type = 'text';
228 setTimeout("$('#suggestions" + no + "').hide();", 100);
229 $('#inputString' + no).val(arr[0]);
230 $('#string_id' + no).val(arr[1]);
231 //$('#string_id').attr('type', 'text');
232 $('#string_id' + no).get(0).type = 'text';
235 if (mode == 'multiple') {
236 if (no == '' || no == 0) {
237 //$('#inputString').val(arr[0]);
238 $('#inputString').val('').focus();
239 if ($('#string_value').val().length > 0) {
240 $('#string_value').val($('#string_value').val() + ';' + arr[0]);
242 $('#string_value').val(arr[0]);
244 if ($("#string_id").val().length > 0) {
245 $('#string_id').val($('#string_id').val() + ';' + arr[1]);
247 $("#string_id").val(arr[1]);
250 var close_id = 'close|' + arr[0] + '|' + arr[1] + '|' + no;
251 var stringValue = '<div id="'+ arr[1] + '" class="selected_item">'
253 + '<span class="close" id="' + close_id + '">×</span></div>';
254 $('#selected_search').append(stringValue);
255 //$("#target").append('<div style="border:1px solid red">' + arr[0] + '</div>');
256 setTimeout("$('#suggestions').hide();", 100);
258 $('#inputString' + no).val('').focus();
259 if ($('#string_value' + no).val().length > 0) {
260 $('#string_value' + no).val($('#string_value' + no).val() + ';' + arr[0]);
262 $('#string_value' + no).val(arr[0]);
264 if ($("#string_id" + no).val().length > 0) {
265 $('#string_id' + no).val($('#string_id' + no).val() + ';' + arr[1]);
267 $("#string_id" + no).val(arr[1]);
270 var close_id = 'close|' + arr[0] + '|' + arr[1] + '|' + no;
271 var stringValue = '<div id="'+ arr[1] + '" class="selected_item">'
273 + '<span class="close" id="' + close_id + '">×</span></div>';
274 $('#selected_search' + no).append(stringValue);
275 //$("#target").append('<div style="border:1px solid red">' + arr[0] + '</div>');
276 setTimeout("$('#suggestions" + no + "').hide();", 100);
284 * Remove Selected Item
287 $(document).on('click', '.close', function(e){
288 var id = $(this).attr("id");
289 var arrId = id.split('|');
291 // Remove from hidden string values
293 var stringValue = $("#string_value" + no).val();
295 var stringValue = $("#string_value").val();
297 var arr = stringValue.split(';');
299 for (var i = 0; i < arr.length; i++) {
300 if (arr[i] != arrId[1]) {
301 str = str + arr[i] + ';';
304 str = str.slice(0, -1);
306 $("#string_value" + no).val(str);
308 $("#string_value").val(str);
313 var stringId = $("#string_id" + no).val();
315 var stringId = $("#string_id").val();
317 var arr = stringId.split(';');
319 for (var i = 0; i < arr.length; i++) {
320 if (arr[i] != arrId[2]) {
321 str = str + arr[i] + ';';
324 str = str.slice(0, -1);
326 $("#string_id" + no).val(str);
328 $("#string_id").val(str);
330 $(this).parent().remove();
336 $(document).on('change click keyup', '.lookup', function(e){
337 var targetId = e.target.id;
338 var arr = targetId.split('inputString');
339 var classname =e.target.classList[1];
340 //$('#' + targetId).val("");
341 if (e.type == 'change' || (e.type == 'keyup' && e.keyCode == 8)) {
343 if (classname != 'multiple') { //do not reset values if mode is multiple
344 $('#string_value' + arr[1]).val("");
345 $('#string_id' + arr[1]).val("");
348 $('#string_value').val("");
349 $('#string_id').val("");
350 $('#form_date').prop('disabled', false);
351 $('#form_to_date').prop('disabled', false);
352 $('.validatebox-text').prop('disabled', false);
355 if (e.type == 'click') {
356 if ($(e.target).closest('.suggestions').length === 0) {
357 $('.suggestions').hide();
363 /*$(document).on('click', function(e){
364 if ($(e.target).closest('.suggestions').length === 0) {
365 $('.suggestions').hide();
367 if(this != $(".suggestions")[0]) {
368 $(".suggestions").hide();
370 var a = $(".suggestions");
375 * Close Auto suggest List
378 $(document).mouseup(function(e){
379 var a = $('.panel_content_wrapper');
383 // Hide Pop-up Mneu on Click outside
384 function bodyClick(container,e){
385 if(!container.is(e.target) && container.has(e.target).length === 0){
386 $(container).css("display","none");