translation fixes to prepare for a translation spreadsheet update
[openemr.git] / interface / modules / zend_modules / public / js / application / sendTo.js
blobfba8ee06eb92d6b7f86bb256eb06e911735e5c70
1 /* +-----------------------------------------------------------------------------+
2 *    OpenEMR - Open Source Electronic Medical Record
3 *    Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
5 *    This program is free software: you can redistribute it and/or modify
6 *    it under the terms of the GNU Affero General Public License as
7 *    published by the Free Software Foundation, either version 3 of the
8 *    License, or (at your option) any later version.
10 *    This program is distributed in the hope that it will be useful,
11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *    GNU Affero General Public License for more details.
15 *    You should have received a copy of the GNU Affero General Public License
16 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *    @author  BASIL PT <basil@zhservices.com>
18 *    @author  FASALU RAHMAN K.M <fasalu@zhservices.com>
19 *    @author  Riju K P <rijukp@zhservices.com>
20 * +------------------------------------------------------------------------------+
23 // Hide Menu if clicked outside
24 $(document).mouseup(function (e){
25         var container = $(".ap-st-st-12");
26         var buttons             = $(".send-to");
27         if(!container.is(e.target) && container.has(e.target).length === 0 && !buttons.is(e.target) )
28         {
29                 $(".ap-st-st-12").css("display","none");
30         }
33          
34 var check_count = 0;
35 (function ($) {
37     window.addRule = function (selector, styles, sheet) {
39         styles = (function (styles) {
40             if (typeof styles === "string") return styles;
41             var clone = "";
42             for (var prop in styles) {
43                 if (styles.hasOwnProperty(prop)) {
44                     var val = styles[prop];
45                     prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase(); // convert to dash-case
46                     clone += prop + ":" + (prop === "content" ? '"' + val + '"' : val) + "; ";
47                 }
48             }
49             return clone;
50         }(styles));
51         sheet = sheet || document.styleSheets[document.styleSheets.length - 1];
53         if (sheet.insertRule) sheet.insertRule(selector + " {" + styles + "}", sheet.cssRules.length);
54         else if (sheet.addRule) sheet.addRule(selector, styles);
56         return this;
58     };
60     if ($) $.fn.addRule = function (styles, sheet) {
61         addRule(this.selector, styles, sheet);
62         return this;
63     };
65 }(this.jQuery || this.Zepto));
67 $(document).ready(function(){
68               
69           /* show hide on click  */
70                 $('.send-to').click(function(){
71                         //var pos  = $(this).position();
72                         //$('.ap-st-st-12').fadeToggle().css({
73                         //      "left" : (pos.left)+"px",
74                         //      "top"  : (pos.top+35)+"px"
75                         //});
76                         $('.se_in_15').fadeOut();
77                         var cleintwidth = $(window).width();
78                         var pos = $(this).position();
79                         var sendLeft = $('.ap-st-st-12').width()+pos.left;
80                         
81                         if(sendLeft > cleintwidth){
82                             var sendCss = {
83                                 right : ((cleintwidth-pos.left)-74)+"px",
84                                 top : (pos.top+35)+"px"
85                                 
86                             }
87                             $('.ap-st-st-12:after').addRule({ left :"98%" });
88                             $('.ap-st-st-12:before').addRule({ left :"98%" });
89                         }
90                         else {
91                             var sendCss = { left : (pos.left+5)+"px", top : (pos.top+35)+"px" }
92                         }
93                         $('.ap-st-st-12').fadeToggle().css(sendCss);
94                 });
95         
96         $(".ap-st-st-4").click(function(){
97                 if($(this).is(":checked")){
98                         $(".check_component").attr("checked",true);
99                         $(".selected_check").removeClass("selected_check");
100                 }else{
101                         $(".check_component").removeAttr("checked");
102                         $(".option_wrap").addClass("selected_check");
103                 }
104                 
105         });
106         
107         $(".ap-st-st-5").on("click",".check_component",function(){
108                 checkedCount = $('[name="componentcheckbox[]"]:checked').length;
109                 if(check_count == checkedCount) $(".ap-st-st-4").attr("checked",true);
110                 else $(".ap-st-st-4").attr("checked",false);
111                 $(this).parent().toggleClass("selected_check");
112         });
113         
114         // Toggle Fax Section 
115         $('[name="send_to"]').click(function(){
116                 if($(this).attr("id") == "send_to_fax") {
117                         $(".ap-st-st-8").show();
118                         $(".display_block").removeClass("display_block");
119                         $("#combination_form_div").addClass("display_block");
120                 }
121                 else if($(this).attr("id") == "send_to_printer"){
122                         $(".ap-st-st-8").hide();
123                         $(".display_block").removeClass("display_block");
124                         $("#combination_form_div").addClass("display_block");
125                 }
126                 else if($(this).attr("id") == "send_to_hie"){
127                         $(".display_block").removeClass("display_block");
128                         $("#hie_div").addClass("display_block");
129                 }
130                 else if($(this).attr("id") == "send_to_emrdirect"){
131                         $(".display_block").removeClass("display_block");
132                         $("#emrDirect_div").addClass("display_block");
133                 }
134                 else if($(this).attr("id") == "download_all"){
135                         $(".display_block").removeClass("display_block");
136                         $("#download_all_div").addClass("display_block");
137                 }
138         });
139         
140         //
141         $("#fax_reciever").change(function(){
142                 if($("#fax_reciever").val() != ''){
143                         if($(this).val() == 'other'){
144                                 $("#fax_no").attr('style','');
145                                 $("#fax_no").attr('readonly',false);
146                                 $("#fax_no").val('');
147                                 $("#facility_tr").hide();
148                                 $("#fax_no_tr").show();
149                         }else{
150                                 $("#fax_no_tr").hide();
151                                 $("#facility_tr").show();
152                                 $.ajax({
153                                         type: "POST",
154                                         url : APP_URL+"/application/sendto/ajax",
155                                         dataType: "html",
156                                         data: {
157                                                 ajax_mode : 'fax_details',
158                                                 req_list : $("#fax_reciever").val(),
159                                         },
160                                         success: function(thedata){
161                                                 $("#facility_fax_no").html(thedata);
162                                                 
163                                         },
164                                         error:function(){
165                                                 alert("ajax error");
166                                         }
167                                 });
168                         }
169                 }
170         });
171         
172         
173         //
174         $("#facility_fax_no").change(function(){
175                 if($("#facility_fax_no").val()){
176                         $("#fax_no_tr").show();
177                         $("#fax_no").attr('style','background:#ccc;');
178                         $("#fax_no").attr('readonly','readonly');
179                         $("#fax_no").val($("#facility_fax_no").val());
180                 } else {
181                         var resultTranslated = js_xl("No Fax Number Saved For The Selected Organization");
182                         alert(resultTranslated.msg);
183                 }
184                 return false;
185         });
186         
187         $(".showcomponentsForCCDA-div").click(function(){
188           $("#componentsForCCDA").slideToggle('slow');
189         });
190               
191         //check all for component 
192             $('#chkall_cmp1').click(function(event) {  
193                 if(this.checked) { 
194                   $("#chkall_cmp_div1").removeClass("selected_check");
195                   $('.chkbxcmp_click1').each(function() { 
196                     this.checked = true; 
197                     $(".selected_check").removeClass("selected_check");
198                   });
199                 }
200                 else {
201                   $("#chkall_cmp_div1").addClass("selected_check");
202                   $('.chkbxcmp_click1').each(function() { 
203                     this.checked = false;  
204                     $(".chkdivcmp1").addClass("selected_check");
205                   });         
206                 }
207               });
208               $(".chkbxcmp_click1").click(function(){
209                 chk_cmp_id = $(this).attr('id');
210                 if($(this).is(":checked")){
211                   $("#"+chk_cmp_id).removeClass("selected_check");
212                 }else{
213                   $("#"+chk_cmp_id).addClass("selected_check");
214                 }
215                 chkbx_click_len         = $(".chkbxcmp_click1").length;
216                 chkbx_click_checked_len = $(".chkbxcmp_click1:checked").length;
217                 if(chkbx_click_checked_len == chkbx_click_len){                  
218                 $("#chkall_cmp1").attr("checked",true);
219                 $("#chkall_cmp_div1").removeClass("selected_check");
220                 }else{
221                    $("#chkall_cmp1").attr("checked",false); 
222                    $("#chkall_cmp_div1").addClass("selected_check");
223                 }
224               });
226 function getComponents(val){
227         $.ajax({
228                 type: "POST",
229                 url     : APP_URL+"/application/sendto/ajax",
230                 dataType: "html",
231                 data: {
232                         ajax_mode : 'get_componets',
233                         form_id   : val
234                 },
235                 async: true,
236                 success: function(json){
237                         $(".ap-st-st-5").html("");
238                         $(".ap-st-st-4").attr("checked",false);
239                         
240                         checkBox                =       "";
241                         components      = JSON.parse(json);
242                         for(form_id in components){
243                                 check_count++;
244                                 checkBox += "<div class='option_wrap'><input checked name='componentcheckbox[]' class='check_component' type='checkbox' value='"+form_id+"' ref='"+components[form_id]+"' >&nbsp;&nbsp;"+components[form_id]+"</div>";
245                         }
246                         checkBox+="<div class='clear'></div>";
247                         $(".ap-st-st-4").attr("checked",true);
248                         $(".ap-st-st-5").html(checkBox);
249                         
250                 }, 
251                 error:function(){
252                         var resultTranslated = js_xl("Something went wrong");
253                         alert(resultTranslated.msg);
254                 }
255         });
258 function send(){
259         var send_to = $('input:radio[name="send_to"]:checked').val();   
260         var cover_letter = 0;
261         if($("#include_coverletter").is(":checked")) cover_letter = 1;
262         $('.activity_indicator').css({
263             "display" :"block"
264             });
265   $("#downloadccda").val('');
266   $("#downloadccr").val('');
267   $("#downloadccd").val('');
268   var comp = '';
269     $(".check_component1").each(function(){
270                         if($(this).is(":checked")){
271                                 i++;
272                                 if(comp) comp +="|";
273                                 comp += $(this).val();
274                         }
275     });
276         if(send_to == "printer" || send_to == "fax"){
277                 formnames                       = "";
278                 formnames_title = "";
279                 var i = 0;
280                 $(".check_component").each(function(){
281                         if($(this).is(":checked")){
282                                 i++;
283                                 if(i>1) {
284                                         formnames +="***";
285                                         formnames_title +="***";
286                                 }
287                                 formnames                       += $(this).val();
288                                 formnames_title += $(this).attr("ref");
289                         }
290                 });
291                 if(send_to == "printer"){
292                         url      = "";
293                         url     += "covering_letter="+cover_letter+"&selected_cform="+$("#selected_cform").val();
294                         url     += "&formnames="+formnames+"&formnames_title="+formnames_title;
295                         window.open(WEB_ROOT+"/interface/patient_file/encounter/print_report.php?"+url,"Print",'width=1000,height=800,resizable=yes,scrollbars=yes');
296                         $('.ap-st-st-12').fadeToggle();
297                         $('.activity_indicator').css({"display" :"none"});
298                 }
299                 if(send_to == "fax"){
300                         $.ajax({
301                                 type: "POST",
302                                 url     : APP_URL+"/application/sendto/ajax",
303                                 dataType: "html",
304                                 data: {
305                                         ajax_mode : 'send_fax',
306                                         sendfax : 'send',
307                                         attentionto : $("#attention_to").val(),
308                                         selectedforms : formnames,
309                                         form_sel_title:formnames_title,
310                                         selected_cform : $("#selected_cform").val(),
311                                         covering_letter : $("#include_coverletter").val(),
312                                         visit_duration : $("#include_visitduration").val(),
313                                         fax_no : $('#fax_no').val()
314                                 },
315                                 async: true,
316                                 success: function(data){
317                     $('.activity_indicator').css({"display" :"none"});
318                                 }, 
319                                 error:function(){
320                                         var resultTranslated = js_xl("Fax sending failed");
321                                         alert(resultTranslated.msg);
322                                         $('.activity_indicator').css({"display" :"none"});
323                                 }
324                         });
325                 }
326         }
327         else if(send_to == "hie"){
328             var str = ''; var combination = '';
329             components = document.getElementsByName('ccda');
330             for(i=0 ; i<components.length ; i++){
331                 if(components[i].checked){
332                     if(str) str += '|';
333                     str += components[i].value;
334                 }
335             }
336             
337             if(document.getElementById('ccda_pid')){
338                 combination = document.getElementById('ccda_pid').value;
339             }
340             else{
341                 pid_encounter = document.getElementsByName('ccda_pid[]');
342                 for(i=0 ; i<pid_encounter.length ; i++){
343                     if(pid_encounter[i].checked){
344                         if(combination) combination += '|';
345                         combination += pid_encounter[i].value;
346                     }
347                 }
348             }
349             if(combination == ''){
350                 $('.ap-st-st-12').fadeToggle();
351                 $('.activity_indicator').css({"display" :"none"});
352                                 var resultTranslated = js_xl("Please select at least one patient.");
353                 alert(resultTranslated.msg);
354                 return false;
355             }
356             
357             $.ajax({
358                 type: "POST",
359                 url : APP_URL+"/encounterccdadispatch/index?combination="+combination+"&sections="+str+"&send=1&recipient=hie&components="+comp,
360                 dataType: "html",
361                 data: {
362                 },
363                 success: function(thedata){                    
364                     $('.ap-st-st-12').fadeToggle();
365                     $('.activity_indicator').css({"display" :"none"});
366                                         var resultTranslated = js_xl('Successfully Sent');
367                     alert(resultTranslated.msg);
368                 },
369                 error: function(){                    
370                     $('.activity_indicator').css({"display" :"none"});
371                                         var resultTranslated = js_xl("Send To HIE failed");
372                     alert(resultTranslated.msg);
373                 }
374             });
375         }
376         
377         else if(send_to == "download"){
378                 $('.activity_indicator').css({"display" :"none"});
379                 obj = document.getElementsByName('download_format');
380                 count = 0;
381                 for(i=0 ; i<obj.length ; i++){
382                         if (obj[i].disabled == false && obj[i].checked == true) {
383                                 count++;
384                         }
385                 }
386                 if(count == 0){
387                         var resultTranslated = js_xl("Please select a format");
388                         alert(resultTranslated.msg);
389                         return false;
390                 }
391                 $('#hl7button').trigger('click');
392         }
393         else if(send_to == "emr_direct") {
394                 format      = $('input:radio[name="phimail_format"]:checked').val();
395                 combination = '';
396                 components  = '';
397                 if($("#ccda_pid").val()){
398                         combination = $("#ccda_pid").val();
399                 }
400                 else{
401                         pid_encounter = document.getElementsByName('ccda_pid[]');
402                         for(i=0 ; i<pid_encounter.length ; i++){
403                                 if(pid_encounter[i].checked){
404                                         if(combination) combination += '|';
405                                         combination += pid_encounter[i].value;
406                                 }
407                         }
408                 }
409                 if(combination == ''){
410                         $('.ap-st-st-12').fadeOut();
411                         $('.activity_indicator').css({"display" :"none"});
412                         var resultTranslated = js_xl("Please select at least one patient.");
413                         alert(resultTranslated.msg);
414                         return false;
415                 }
416                 $(".chkbx_cmps").each(function(){
417                 if($(this).is(":checked")){
418                         i++;
419                                                         if(components) components +="|";
420                         components += $(this).val();
421                 }
422                 });
423                 recipients = $(".emr_to_phimail").val();
424                 var referral_reason = $("#referral_reason").val();
425                 if(recipients != '') {
426                         $.ajax({
427                         type: "POST",
428                         url : APP_URL+"/encounterccdadispatch/index?combination="+combination+"&sections="+components+"&view=1&emr_transfer=1&recipient=emr_direct&param="+recipients+"&referral_reason="+referral_reason+"&components="+comp,
429                         dataType: "html",
430                         data: {
431                         },
432                 });
433                 $.ajax({
434                         type: "POST",
435                         url : APP_URL+"/encountermanager/transmitCCD?combination="+combination+"&recipients="+recipients+"&xml_type="+format,
436                         dataType: "html",
437                         data: {
438                         },
439                         success: function(thedata){                    
440                                 $('.ap-st-st-12').fadeOut();
441                                 $('.activity_indicator').css({"display" :"none"});
442                                 var resultTranslated = js_xl(thedata);
443                                 alert(resultTranslated.msg);
444                         },
445                         error: function(){          
446                                 $('.ap-st-st-12').fadeOut();
447                                 $('.activity_indicator').css({"display" :"none"});
448                                 var resultTranslated = js_xl("Failed to send");
449                                 alert(resultTranslated.msg);
450                         }
451                 });    
452                 }
453                 else {
454                         $('.activity_indicator').css({"display" :"none"});
455                         var resultTranslated = js_xl("Please Specify at least One Direct Address");
456                         alert(resultTranslated.msg);
457                 }
458         }
459         else if(send_to == "download_all") {
460     var count = 0; 
461      if($('#ccda_pid').val()) {
462        pids = $('#ccda_pid').val();
463        pids = pids.split("_");
464        pid = pids[0];
465        count++;
466      }
467      else {
468        pids = document.getElementsByName('ccda_pid[]');   
469        for(i=0 ; i<pids.length ; i++){        
470          if(pids[i].checked){          
471            count++;        
472          }      
473        }
474      } 
475          
476     if(count == 0) {
477       $('.ap-st-st-12').fadeOut();
478       $('.activity_indicator').css({"display" :"none"});
479       var resultTranslated = js_xl("Please select at least one patient.");
480       alert(resultTranslated.msg);
481       return false;
482     }
483     else {
484       var download_format = $('input:radio[name="downloadformat"]:checked').val();      
485       if(download_format == 'ccda') {
486         if($('#ccda_pid').val()) {
487           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccda="+pid+"&downloadccda=download_ccda&components="+comp);
488         }
489         else {
490           $('#components').val(comp);
491           $('#download_ccda').trigger("click"); 
492           $(".check_pid").prop("checked",false);
493         }
494       }
495       else if(download_format == 'ccr') {
496         if($('#ccda_pid').val()) {
497           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccr="+pid+"&downloadccr=download_ccr");
498         }
499         else {
500           $('#download_ccr').trigger("click"); 
501           $(".check_pid").prop("checked",false);
502         }   
503       }
504       else if(download_format == 'ccd') {
505         if($('#ccda_pid').val()) {
506           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccd="+pid+"&downloadccd=download_ccd");
507         }
508         else {
509           $('#download_ccd').trigger("click"); 
510           $(".check_pid").prop("checked",false);
511         }   
512       }
513       //$(".check_pid").prop("checked",false);
514       $('.ap-st-st-12').fadeOut();
515       $('.activity_indicator').css({"display" :"none"});
516     }
517   }