4 * This section handles ajax functions for insurance,patient and for encounters.
7 * @link https://www.open-emr.org
8 * @author Eldho Chacko <eldho@zhservices.com>
9 * @author Paul Simon K <paul@zhservices.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 use OpenEMR\Common\Csrf\CsrfUtils
;
21 $
("#type_code").keyup(function(e
){
22 if (e
.which
== 9 || e
.which
== 13)
23 {//tab key,enter key.Prevent ajax activity.
27 {//Both insurance or patient can come.The drop down value in 'type_name' decides which one to process.
28 ajaxFunction('non','Simple',document
.getElementById('type_code'));
32 $
("#patient_code").keyup(function(e
){
33 if (e
.which
== 9 || e
.which
== 13)
34 {//tab key,enter key.Prevent ajax activity.
39 ajaxFunction('patient','Submit',document
.getElementById('patient_code'));
43 $
("#form_pt_name").keyup(function(e
){
44 if (e
.which
== 9 || e
.which
== 13)
45 {//tab key,enter key.Prevent ajax activity.
50 ajaxFunction('patient','Simple',document
.getElementById('form_pt_name'));
54 $
("#encounter_no").keyup(function(e
){
55 if (e
.which
== 9 || e
.which
== 13)
56 {//tab key,enter key.Prevent ajax activity.
61 ajaxFunction('encounter');
65 function ajaxFunction(Source
,SubmitOrSimple
,SourceObject
) {
66 if(Source
=='encounter')
68 document
.getElementById('ajax_mode').value
='encounter';
70 else if(Source
=='patient')
72 if(SourceObject
.value
.length
<3)
74 document
.getElementById('ajax_mode').value
='set_patient';
76 //For the below two cases, same text box is used for both insurance and patient.
77 else if(document
.getElementById('type_name') && document
.getElementById('type_name').options
[document
.getElementById('type_name').selectedIndex
].value
=='patient')
79 if(document
.getElementById('type_code').value
.length
<3)
81 document
.getElementById('ajax_mode').value
='set_patient';
85 if(document
.getElementById('type_code').value
.length
<3)
87 document
.getElementById('ajax_mode').value
='set';
92 url
: "../../library/ajax/payment_ajax.php",
95 ajax_mode
: document
.getElementById('ajax_mode').value
,
96 patient_code
: Source
=='patient' ? SourceObject
.value
: '',
97 insurance_text_ajax
: document
.getElementById('type_code') ? document
.getElementById('type_code').value
: '',
98 encounter_patient_code
:Source
=='encounter' ? document
.getElementById('hidden_patient_code').value
: '',
99 submit_or_simple_type
:SubmitOrSimple
,
100 csrf_token_form
: <?php
echo js_escape(CsrfUtils
::collectCsrfToken()); ?
>
103 success
: function(thedata
){
104 if(Source
=='encounter')
110 ThedataArray
=thedata
.split('~`~`');
111 thedata
=ThedataArray
[1];
112 if(Source
=='patient')
114 if(ThedataArray
[0]!=SourceObject
.value
.length
)
116 return;//To deal with speedy typing.
121 if(ThedataArray
[0]!=document
.getElementById('type_code').value
.length
)
123 return;//To deal with speedy typing.
127 document
.getElementById('ajax_mode').value
='';
128 if(Source
=='encounter')
130 if(document
.getElementById('SelFacility'))
132 document
.getElementById('SelFacility').style
.display
='none';//In Internet explorer this drop down comes over the ajax listing.
134 $
("#ajax_div_encounter_error").empty();
135 $
("#ajax_div_encounter").empty();
136 $
("#ajax_div_encounter").html(thedata
);
137 $
("#ajax_div_encounter").show();
139 else if(Source
=='patient')
141 if(document
.getElementById('SelFacility'))
143 document
.getElementById('SelFacility').style
.display
='none';//In Internet explorer this drop down comes over the ajax listing.
145 $
("#ajax_div_patient_error").empty();
146 $
("#ajax_div_patient").empty();
147 $
("#ajax_div_insurance_error").empty();
148 $
("#ajax_div_insurance").empty();
149 $
("#ajax_div_patient").html(thedata
);
150 $
("#ajax_div_patient").show();
153 {//Patient or Insurance
154 $
("#ajax_div_patient_error").empty();
155 $
("#ajax_div_patient").empty();
156 $
("#ajax_div_insurance_error").empty();
157 $
("#ajax_div_insurance").empty();
158 $
("#ajax_div_insurance").html(thedata
);
159 $
("#ajax_div_insurance").show();
161 if(document
.getElementById('anchor_insurance_code_1'))
162 document
.getElementById('anchor_insurance_code_1').focus();
163 if(document
.getElementById('tr_insurance_1'))
164 document
.getElementById('tr_insurance_1').bgColor
='#94D6E7'//selected color
172 //==============================================================================================================================================
173 //Following functions are needed for other tasks related to ajax.
174 //Html retured from the ajax above, contains list of either insurance,patient or encounter.
175 //On click or 'enter key' press over any one item the listing vanishes and the clicked one gets listed in the parent page's text box.
176 //List of functions starts
177 //===========================================================
178 function PutTheValuesClick(Code
,Name
)
179 {//Used while -->CLICK<-- over list in the insurance/patient portion.
180 document
.getElementById('type_code').value
=Name
;
181 document
.getElementById('hidden_ajax_close_value').value
=Name
;
182 document
.getElementById('description').value
=Name
;
183 document
.getElementById('hidden_type_code').value
=Code
;
184 document
.getElementById('div_insurance_or_patient').innerHTML
=Code
;
185 document
.getElementById('ajax_div_insurance').style
.display
='none';
186 $
("#ajax_div_patient_error").empty();
187 $
("#ajax_div_patient").empty();
188 $
("#ajax_div_insurance_error").empty();
189 $
("#ajax_div_insurance").empty();
190 document
.getElementById('type_code').focus();
192 function PutTheValuesClickDistribute(Code
,Name
)
193 {//Used while -->CLICK<-- over list in the patient portion before the start of distribution of amount.
194 if(document
.getElementById('SelFacility'))
196 document
.getElementById('SelFacility').style
.display
='';//In Internet explorer this drop down comes over the ajax listing.
198 document
.getElementById('patient_code').value
=Name
;
199 document
.getElementById('hidden_ajax_patient_close_value').value
=Name
;
200 document
.getElementById('hidden_patient_code').value
=Code
;
201 document
.getElementById('patient_name').innerHTML
=Code
;
202 document
.getElementById('ajax_div_patient').style
.display
='none';
203 document
.getElementById('patient_name').focus();
204 document
.getElementById('mode').value
='search';
205 top
.restoreSession();
206 document
.forms
[0].submit();
208 function PutTheValuesClickPatient(Code
,Name
)//Non submission patient ajax.
210 document
.getElementById('form_pt_name').value
=Name
;
211 document
.getElementById('hidden_ajax_patient_close_value').value
=Name
;
212 document
.getElementById('hidden_patient_code').value
=Code
;
213 document
.getElementById('ajax_div_patient').style
.display
='none';
214 document
.getElementById('form_pt_code').innerHTML
=Code
;
215 document
.getElementById('form_pt_name').focus();
217 function PutTheValuesClickEncounter(Code
,Name
)
218 {//Used while -->CLICK<-- over list in the encounter portion.
219 if(document
.getElementById('SelFacility'))
221 document
.getElementById('SelFacility').style
.display
='';//In Internet explorer this drop down comes over the ajax listing.
223 document
.getElementById('encounter_no').value
=Code
;
224 document
.getElementById('hidden_ajax_encounter_close_value').value
=Code
;
225 document
.getElementById('hidden_encounter_no').value
=Code
;
226 document
.getElementById('encounter_date').innerHTML
=Name
;
227 document
.getElementById('ajax_div_encounter').style
.display
='none';
228 document
.getElementById('encounter_date').focus();
229 document
.getElementById('mode').value
='search_encounter';
230 top
.restoreSession();
231 document
.forms
[0].submit();
233 function PlaceValues(evt
,Code
,Name
)
234 {//Used while -->KEY PRESS<-- over list in the insurance/patient portion.
235 evt
= (evt
) ? evt
: window
.event
;
236 var charCode
= (evt
.which
) ? evt
.which
: evt
.keyCode
;
237 if (charCode
== 13)//enter key
238 {//Vanish the list and populate the parent text box
239 PutTheValuesClick(Code
,Name
);
240 PreventIt(evt
) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
242 else if(!((charCode
== 38) ||
(charCode
== 40)))
243 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
244 document
.getElementById('type_code').focus();
247 function PlaceValuesDistribute(evt
,Code
,Name
)
248 {//Used while -->KEY PRESS<-- over list in the patient portion before the start of distribution of amount.
249 evt
= (evt
) ? evt
: window
.event
;
250 var charCode
= (evt
.which
) ? evt
.which
: evt
.keyCode
;
251 if (charCode
== 13)//enter key
252 {//Vanish the list and populate the parent text box
253 PutTheValuesClickDistribute(Code
,Name
);
254 PreventIt(evt
) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
256 else if(!((charCode
== 38) ||
(charCode
== 40)))
257 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
258 document
.getElementById('patient_code').focus();
261 function PlaceValuesPatient(evt
,Code
,Name
)
263 evt
= (evt
) ? evt
: window
.event
;
264 var charCode
= (evt
.which
) ? evt
.which
: evt
.keyCode
;
265 if (charCode
== 13)//enter key
266 {//Vanish the list and populate the parent text box
267 PutTheValuesClickPatient(Code
,Name
);
268 PreventIt(evt
) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
270 else if(!((charCode
== 38) ||
(charCode
== 40)))
271 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
272 document
.getElementById('form_pt_name').focus();
275 function PlaceValuesEncounter(evt
,Code
,Name
)
276 {//Used while -->KEY PRESS<-- over list in the encounter portion.
277 evt
= (evt
) ? evt
: window
.event
;
278 var charCode
= (evt
.which
) ? evt
.which
: evt
.keyCode
;
279 if (charCode
== 13)//enter key
280 {//Vanish the list and populate the parent text box
281 PutTheValuesClickEncounter(Code
,Name
);
282 PreventIt(evt
) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
284 else if(!((charCode
== 38) ||
(charCode
== 40)))
285 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
286 document
.getElementById('encounter_no').focus();
289 function ProcessKeyForColoring(evt
,Location
)
290 {//Shows the navigation in the listing by change of colors and focus.Happens when down or up arrow is pressed.
291 evt
= (evt
) ? evt
: window
.event
;
292 var charCode
= (evt
.which
) ? evt
.which
: evt
.keyCode
;
293 if (charCode
== 38)//Up key press
296 if(document
.getElementById('tr_insurance_' +
(Location
)))
298 //restore color in below row
299 if((Location+
1)%2
==1)
301 document
.getElementById('tr_insurance_' +
(Location+
1)).bgColor
='#ddddff';
305 document
.getElementById('tr_insurance_' +
(Location+
1)).bgColor
='#ffdddd';
307 document
.getElementById('tr_insurance_' +
(Location
)).bgColor
='#94D6E7';
308 document
.getElementById('anchor_insurance_code_' +
(Location
)).focus();
311 else if (charCode
== 40)//Down key press
314 if(document
.getElementById('tr_insurance_' +
(Location
)))
316 //restore color in above row
317 if((Location
-1)%2
==1)
319 document
.getElementById('tr_insurance_' +
(Location
-1)).bgColor
='#ddddff';
323 document
.getElementById('tr_insurance_' +
(Location
-1)).bgColor
='#ffdddd';
325 document
.getElementById('tr_insurance_' +
(Location
)).bgColor
='#94D6E7';
326 document
.getElementById('anchor_insurance_code_' +
(Location
)).focus();
330 function HideTheAjaxDivs()
331 {//Starts working when clicking on the body.Hides the ajax and restores the codes back, as he may have changed it in the text box.
332 if(document
.getElementById('ajax_div_insurance'))
334 if(document
.getElementById('ajax_div_insurance').style
.display
!='none')
336 document
.getElementById('type_code').value
=document
.getElementById('hidden_ajax_close_value').value
;
337 $
("#ajax_div_patient_error").empty();
338 $
("#ajax_div_patient").empty();
339 $
("#ajax_div_insurance_error").empty();
340 $
("#ajax_div_insurance").empty();
341 $
("#ajax_div_insurance").hide();
344 if(document
.getElementById('ajax_div_patient'))
346 if(document
.getElementById('ajax_div_patient').style
.display
!='none')
348 if(document
.getElementById('SelFacility'))
350 document
.getElementById('SelFacility').style
.display
='';//In Internet explorer this drop down comes over the ajax listing.
352 if(document
.getElementById('patient_code'))
353 document
.getElementById('patient_code').value
=document
.getElementById('hidden_ajax_patient_close_value').value
;
354 else if(document
.getElementById('form_pt_name'))
355 document
.getElementById('form_pt_name').value
=document
.getElementById('hidden_ajax_patient_close_value').value
;
356 $
("#ajax_div_patient_error").empty();
357 $
("#ajax_div_patient").empty();
358 $
("#ajax_div_insurance_error").empty();
359 $
("#ajax_div_insurance").empty();
360 $
("#ajax_div_patient").hide();
363 if(document
.getElementById('ajax_div_encounter'))
365 if(document
.getElementById('ajax_div_encounter').style
.display
!='none')
367 if(document
.getElementById('SelFacility'))
369 document
.getElementById('SelFacility').style
.display
='';//In Internet explorer this drop down comes over the ajax listing.
371 document
.getElementById('encounter_no').value
=document
.getElementById('hidden_ajax_encounter_close_value').value
;
372 $
("#ajax_div_encounter_error").empty();
373 $
("#ajax_div_encounter").empty();
374 $
("#ajax_div_encounter").hide();
378 //===========================================================
379 //List of functions ends
380 //==============================================================================================================================================