1) Section-wise display of CCDA data
[openemr.git] / interface / modules / zend_modules / public / js / application / sendTo.js
blob5851bbb2071d2c92e7656bc61d9a35f4d6d98219
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                                                 var resultTranslated = js_xl("ajax error");
166                                                 alert(resultTranslated.msg);
167                                         }
168                                 });
169                         }
170                 }
171         });
172         
173         
174         //
175         $("#facility_fax_no").change(function(){
176                 if($("#facility_fax_no").val()){
177                         $("#fax_no_tr").show();
178                         $("#fax_no").attr('style','background:#ccc;');
179                         $("#fax_no").attr('readonly','readonly');
180                         $("#fax_no").val($("#facility_fax_no").val());
181                 } else {
182                         var resultTranslated = js_xl("No Fax Number Saved For The Selected Organization");
183                         alert(resultTranslated.msg);
184                 }
185                 return false;
186         });
187         
188         $(".showcomponentsForCCDA-div").click(function(){
189           $("#componentsForCCDA").slideToggle('slow');
190         });
191               
192         //check all for component 
193             $('#chkall_cmp1').click(function(event) {  
194                 if(this.checked) { 
195                   $("#chkall_cmp_div1").removeClass("selected_check");
196                   $('.chkbxcmp_click1').each(function() { 
197                     this.checked = true; 
198                     $(".selected_check").removeClass("selected_check");
199                   });
200                 }
201                 else {
202                   $("#chkall_cmp_div1").addClass("selected_check");
203                   $('.chkbxcmp_click1').each(function() { 
204                     this.checked = false;  
205                     $(".chkdivcmp1").addClass("selected_check");
206                   });         
207                 }
208               });
209               $(".chkbxcmp_click1").click(function(){
210                 chk_cmp_id = $(this).attr('id');
211                 if($(this).is(":checked")){
212                   $("#"+chk_cmp_id).removeClass("selected_check");
213                 }else{
214                   $("#"+chk_cmp_id).addClass("selected_check");
215                 }
216                 chkbx_click_len         = $(".chkbxcmp_click1").length;
217                 chkbx_click_checked_len = $(".chkbxcmp_click1:checked").length;
218                 if(chkbx_click_checked_len == chkbx_click_len){                  
219                 $("#chkall_cmp1").attr("checked",true);
220                 $("#chkall_cmp_div1").removeClass("selected_check");
221                 }else{
222                    $("#chkall_cmp1").attr("checked",false); 
223                    $("#chkall_cmp_div1").addClass("selected_check");
224                 }
225               });
227 function getComponents(val){
228         $.ajax({
229                 type: "POST",
230                 url     : APP_URL+"/application/sendto/ajax",
231                 dataType: "html",
232                 data: {
233                         ajax_mode : 'get_componets',
234                         form_id   : val
235                 },
236                 async: true,
237                 success: function(json){
238                         $(".ap-st-st-5").html("");
239                         $(".ap-st-st-4").attr("checked",false);
240                         
241                         checkBox                =       "";
242                         components      = JSON.parse(json);
243                         for(form_id in components){
244                                 check_count++;
245                                 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>";
246                         }
247                         checkBox+="<div class='clear'></div>";
248                         $(".ap-st-st-4").attr("checked",true);
249                         $(".ap-st-st-5").html(checkBox);
250                         
251                 }, 
252                 error:function(){
253                         var resultTranslated = js_xl("Something went wrong");
254                         alert(resultTranslated.msg);
255                 }
256         });
259 function send(){
260         var send_to = $('input:radio[name="send_to"]:checked').val();   
261         var cover_letter = 0;
262         if($("#include_coverletter").is(":checked")) cover_letter = 1;
263         $('.activity_indicator').css({
264             "display" :"block"
265             });
266   $("#downloadccda").val('');
267   $("#downloadccr").val('');
268   $("#downloadccd").val('');
269   var comp = '';
270     $(".check_component1").each(function(){
271                         if($(this).is(":checked")){
272                                 i++;
273                                 if(comp) comp +="|";
274                                 comp += $(this).val();
275                         }
276     });
277         if(send_to == "printer" || send_to == "fax"){
278                 formnames                       = "";
279                 formnames_title = "";
280                 var i = 0;
281                 $(".check_component").each(function(){
282                         if($(this).is(":checked")){
283                                 i++;
284                                 if(i>1) {
285                                         formnames +="***";
286                                         formnames_title +="***";
287                                 }
288                                 formnames                       += $(this).val();
289                                 formnames_title += $(this).attr("ref");
290                         }
291                 });
292                 if(send_to == "printer"){
293                         url      = "";
294                         url     += "covering_letter="+cover_letter+"&selected_cform="+$("#selected_cform").val();
295                         url     += "&formnames="+formnames+"&formnames_title="+formnames_title;
296                         window.open(WEB_ROOT+"/interface/patient_file/encounter/print_report.php?"+url,"Print",'width=1000,height=800,resizable=yes,scrollbars=yes');
297                         $('.ap-st-st-12').fadeToggle();
298                         $('.activity_indicator').css({"display" :"none"});
299                 }
300                 if(send_to == "fax"){
301                         $.ajax({
302                                 type: "POST",
303                                 url     : APP_URL+"/application/sendto/ajax",
304                                 dataType: "html",
305                                 data: {
306                                         ajax_mode : 'send_fax',
307                                         sendfax : 'send',
308                                         attentionto : $("#attention_to").val(),
309                                         selectedforms : formnames,
310                                         form_sel_title:formnames_title,
311                                         selected_cform : $("#selected_cform").val(),
312                                         covering_letter : $("#include_coverletter").val(),
313                                         visit_duration : $("#include_visitduration").val(),
314                                         fax_no : $('#fax_no').val()
315                                 },
316                                 async: true,
317                                 success: function(data){
318                     $('.activity_indicator').css({"display" :"none"});
319                                 }, 
320                                 error:function(){
321                                         var resultTranslated = js_xl("Fax sending failed");
322                                         alert(resultTranslated.msg);
323                                         $('.activity_indicator').css({"display" :"none"});
324                                 }
325                         });
326                 }
327         }
328         else if(send_to == "hie"){
329             var str = ''; var combination = '';
330             components = document.getElementsByName('ccda');
331             for(i=0 ; i<components.length ; i++){
332                 if(components[i].checked){
333                     if(str) str += '|';
334                     str += components[i].value;
335                 }
336             }
337             
338             if(document.getElementById('ccda_pid')){
339                 combination = document.getElementById('ccda_pid').value;
340             }
341             else{
342                 pid_encounter = document.getElementsByName('ccda_pid[]');
343                 for(i=0 ; i<pid_encounter.length ; i++){
344                     if(pid_encounter[i].checked){
345                         if(combination) combination += '|';
346                         combination += pid_encounter[i].value;
347                     }
348                 }
349             }
350             if(combination == ''){
351                 $('.ap-st-st-12').fadeToggle();
352                 $('.activity_indicator').css({"display" :"none"});
353                                 var resultTranslated = js_xl("Please select atleast one patient.");
354                 alert(resultTranslated.msg);
355                 return false;
356             }
357             
358             $.ajax({
359                 type: "POST",
360                 url : APP_URL+"/encounterccdadispatch/index?combination="+combination+"&sections="+str+"&send=1&recipient=hie&components="+comp,
361                 dataType: "html",
362                 data: {
363                 },
364                 success: function(thedata){                    
365                     $('.ap-st-st-12').fadeToggle();
366                     $('.activity_indicator').css({"display" :"none"});
367                                         var resultTranslated = js_xl('Successfully Sent');
368                     alert(resultTranslated.msg);
369                 },
370                 error: function(){                    
371                     $('.activity_indicator').css({"display" :"none"});
372                                         var resultTranslated = js_xl("Send To HIE failed");
373                     alert(resultTranslated.msg);
374                 }
375             });
376         }
377         
378         else if(send_to == "download"){
379                 $('.activity_indicator').css({"display" :"none"});
380                 obj = document.getElementsByName('download_format');
381                 count = 0;
382                 for(i=0 ; i<obj.length ; i++){
383                         if (obj[i].disabled == false && obj[i].checked == true) {
384                                 count++;
385                         }
386                 }
387                 if(count == 0){
388                         var resultTranslated = js_xl("Please select a format");
389                         alert(resultTranslated.msg);
390                         return false;
391                 }
392                 $('#hl7button').trigger('click');
393         }
394         else if(send_to == "emr_direct") {
395                 format      = $('input:radio[name="phimail_format"]:checked').val();
396                 combination = '';
397                 components  = '';
398                 if($("#ccda_pid").val()){
399                         combination = $("#ccda_pid").val();
400                 }
401                 else{
402                         pid_encounter = document.getElementsByName('ccda_pid[]');
403                         for(i=0 ; i<pid_encounter.length ; i++){
404                                 if(pid_encounter[i].checked){
405                                         if(combination) combination += '|';
406                                         combination += pid_encounter[i].value;
407                                 }
408                         }
409                 }
410                 if(combination == ''){
411                         $('.ap-st-st-12').fadeOut();
412                         $('.activity_indicator').css({"display" :"none"});
413                         var resultTranslated = js_xl("Please select atleast one patient.");
414                         alert(resultTranslated.msg);
415                         return false;
416                 }
417                 $(".chkbx_cmps").each(function(){
418                 if($(this).is(":checked")){
419                         i++;
420                                                         if(components) components +="|";
421                         components += $(this).val();
422                 }
423                 });
424                 recipients = $(".emr_to_phimail").val();
425                 var referral_reason = $("#referral_reason").val();
426                 if(recipients != '') {
427                         $.ajax({
428                         type: "POST",
429                         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,
430                         dataType: "html",
431                         data: {
432                         },
433                 });
434                 $.ajax({
435                         type: "POST",
436                         url : APP_URL+"/encountermanager/transmitCCD?combination="+combination+"&recipients="+recipients+"&xml_type="+format,
437                         dataType: "html",
438                         data: {
439                         },
440                         success: function(thedata){                    
441                                 $('.ap-st-st-12').fadeOut();
442                                 $('.activity_indicator').css({"display" :"none"});
443                                 var resultTranslated = js_xl(thedata);
444                                 alert(resultTranslated.msg);
445                         },
446                         error: function(){          
447                                 $('.ap-st-st-12').fadeOut();
448                                 $('.activity_indicator').css({"display" :"none"});
449                                 var resultTranslated = js_xl("Failed to send");
450                                 alert(resultTranslated.msg);
451                         }
452                 });    
453                 }
454                 else {
455                         $('.activity_indicator').css({"display" :"none"});
456                         var resultTranslated = js_xl("Please Specify Atleast One Direct Address");
457                         alert(resultTranslated.msg);
458                 }
459         }
460         else if(send_to == "download_all") {
461     var count = 0; 
462      if($('#ccda_pid').val()) {
463        pids = $('#ccda_pid').val();
464        pids = pids.split("_");
465        pid = pids[0];
466        count++;
467      }
468      else {
469        pids = document.getElementsByName('ccda_pid[]');   
470        for(i=0 ; i<pids.length ; i++){        
471          if(pids[i].checked){          
472            count++;        
473          }      
474        }
475      } 
476          
477     if(count == 0) {
478       $('.ap-st-st-12').fadeOut();
479       $('.activity_indicator').css({"display" :"none"});
480       var resultTranslated = js_xl("Please select atleast one patient.");
481       alert(resultTranslated.msg);
482       return false;
483     }
484     else {
485       var download_format = $('input:radio[name="downloadformat"]:checked').val();      
486       if(download_format == 'ccda') {
487         if($('#ccda_pid').val()) {
488           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccda="+pid+"&downloadccda=download_ccda&components="+comp);
489         }
490         else {
491           $('#components').val(comp);
492           $('#download_ccda').trigger("click"); 
493           $(".check_pid").prop("checked",false);
494         }
495       }
496       else if(download_format == 'ccr') {
497         if($('#ccda_pid').val()) {
498           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccr="+pid+"&downloadccr=download_ccr");
499         }
500         else {
501           $('#download_ccr').trigger("click"); 
502           $(".check_pid").prop("checked",false);
503         }   
504       }
505       else if(download_format == 'ccd') {
506         if($('#ccda_pid').val()) {
507           window.location.assign(WEB_ROOT+"/interface/modules/zend_modules/public/encountermanager/index?pid_ccd="+pid+"&downloadccd=download_ccd");
508         }
509         else {
510           $('#download_ccd').trigger("click"); 
511           $(".check_pid").prop("checked",false);
512         }   
513       }
514       //$(".check_pid").prop("checked",false);
515       $('.ap-st-st-12').fadeOut();
516       $('.activity_indicator').css({"display" :"none"});
517     }
518   }