gerd
11/8/2016 - 1:47 PM

provider_profile_pharmacy.js

jQuery.namespace('lexisnexis.component');
lexisnexis.component.ProviderProfilePharmacy = lexisnexis.component.Table
.extend({
	 data : {
		        summaryTableId : '#ln_summary_provider_list',
		        summaryContainer: "#ln_summary_patient_list_container",
                provProfilePharmacyTemplateID :'#provider_profile_pharmacy_totals_template',
                gridSearchID: '#ln_patient_grid_search',
                summaryViewName: "Summary View",
                baseSummaryUrl: "getProviderPharmacySummary",
                previousVal: '',
                providerId : '',
                providerRoleHiddenID: '#viewbyHiddenVal',
                defaultSortColumn_summary : "Total Rx Cost",
                defaultSortColumn_summary_second : "Patient Name",
                prevProviderId : '',
                fixedColumnCount : 1,
                gridAccessCount: 0,
                gridSearchCount: 0,
                manualsort : false,
                columnDefs : '',
                "isProviderCountCallMade" : false,
             
                delay : (function(){
        			  var timer = 0;
        			  return function(callback, ms){
        				  clearTimeout (timer);
        				  timer = setTimeout(callback, ms);
        			  };
        		})()
    			},
    		
    		ready: function(){ 
    			var cs=this;
                LN.getPage().registerEvent(EVENT_TYPES.UPDATE_SCREEN_PARAMETERS_SUCCESS,cs, cs.registerApplyButtonChange);
                $(".fa-eye").hide(); 
    		},
    		
    		registerApplyButtonChange : function(cs) {
    	        // Load Totals
    			cs.data.providerRole = $(cs.data.providerRoleHiddenID).val();
    	    	cs.populateTotalsGrid(true );
    	    	var currentView= cs.data.summaryViewName; 
    	    	cs.reloadTableViews(currentView) ;
    	    	cs.registerSearch();
    	    	LN.getPage().checkPCPProviderProfile();
    	    },
    	    
    		populateTotalsGrid: function(callAjax) {
    	    	var cs = this;
    	    	if(callAjax){ 
    	    		$.ajax({
    		    		beforeSend: function(){
    		    			LN.showAjaxIndicator("#ln_provider_profile_pharmacy_totals_table .table");
    		    			
    		    		},
    		        	url: "getProviderPharmacyTotals",
    		        	data: {'dataSetId':$('#ln_topmenu_dataset').attr("datasetkey"),
    		     		       'selDataSetRangeRiskColumnName':  $('#ln_topmenu_dataset_range_id').attr("riskColumnName"),
    		     		       'selDataSetRangeBegin':  $('#ln_topmenu_dataset_range_id').attr("beginDateKey"),
    						   'selDataSetRangeEnd':  $('#ln_topmenu_dataset_range_id').attr("endDateKey"),
    						   'providerRole':cs.data.providerRole
    						},
    		     		method: 'POST',
    		        	dataType: 'json',
    		        	success: function(data) {
    		        		cs.data.totalsData = data ;
    		        		//Clone the cs.data.totalsData Object and send to the render totals
    		        		cs.renderTotals(cs, $.extend({},cs.data.totalsData)) ;
    		        		
    		        	},
    		        	error: function(){      
    		        		var data={};
    		        		data.title=cs.data.groupBy;
    		  			  	var template = $(cs.data.provProfilePharmacyTemplateID).html();
    		  			  	var html = Mustache.to_html(template, data);
    		  			  	$("#ln_provider_profile_pharmacy_totals_table").html(html);
    		        		$("#ln_provider_profile_pharmacy_totals_table thead").html('');
    		        		$("#ln_provider_profile_pharmacy_totals_table tbody").html('<span style="color:red">Error: Data is currently unavailable.</span>');
    		        	},
    		        	complete: function(data){
    		        		LN.hideAjaxIndicator("#ln_provider_profile_pharmacy_totals_table .table");
    		        	
    		        	}
    		        });
    	    	}else{
    	    		//Clone the cs.data.totalsData Object and send to the render totals
    	    		cs.renderTotals(cs , $.extend({},cs.data.totalsData)) ; 
    	    	}
    	    },
    	    
    	    renderTotals: function (cs , data ) { 
    	    	    data.memberCount = numeral(data.memberCount).format('0,0');
    	    	    data.genericRate=cs.convertPercentageValue(data.genericRate);
    	    	    data.brandRate=cs.convertPercentageValue(data.brandRate);
    	    	    data.avgRxCost= formatUtil.formatNumber(parseInt(data.avgRxCost));
    	    	    data.actualRxCost= formatUtil.formatNumber(parseInt(data.actualRxCost));
    	    	    data.maintenanceRxCompliance = cs.convertPercentageValue(data.maintenanceRxCompliance);
    			    data.fromScreen = 'PH';
    			    var template =  $(cs.data.provProfilePharmacyTemplateID).html(); 
    			    var html = Mustache.to_html(template, data);
    			    $("#ln_provider_profile_pharmacy_totals_table").html(html); 
    			  
    			 
    	    } ,
    	    
    	    convertPercentageValue: function(percentValue , isTruncateZeros ){	
        		var newPercentageValue = parseFloat(percentValue) * 100;
        		if(isTruncateZeros){
        			newPercentageValue= newPercentageValue.toFixed(2).replace(/\.?0+$/, '');
        		}else{
        			newPercentageValue= newPercentageValue.toFixed(2);
        		}
        		return newPercentageValue ;
        	},
        	
    	    
    	    reloadTableViews: function(viewName){
    	    	var cs = this;
    	        cs.initializeSummaryTable();
    	     },
    	    
            initializeSummaryTable : function() {
                var cs = this;
                LN.debug("initializeSummaryTable called ");
                
                var prevColumnNamesArray=cs.getCurrentSummaryColumnNamesArray(cs.data.summaryTableId);

                $(cs.data.summaryContainer).show();
                $(cs.data.summaryTableId).dataTable().fnDestroy();
                cs.data.tableSummary = $(cs.data.summaryTableId)
	                .dataTable(
                        {
                        	"dom": 'R<"top"f>rt<"bottom"ilp><"clear">',
                        	scrollY: "300px",
                            scrollX: "true",
                            "scrollXInner": "100%",
                            scrollCollapse: true,
                            "bFilter" : false,
                            "bInfo": true,
                            "iTotalRecords" : "dataTableModel.iTotalRecords",
                            "iDisplayLength" : 100,
                            "processing" : false,
                            "serverSide" : true,
                            "searching": false,
                            "bLengthChange" : true,
                            "bResponsive" :false,
                            "ordering" : true, 
                            "paging": true,
                            "pagingType": "simple_numbers",
                            "colReorder": {
                                //Exclude first two columns from colreorder
                                "iFixedColumns": 1,
                                realtime: true
                            },
                            "bDeferRender" : true,
                            "ajax" : {
                                "cache": false,
                                "url" : cs.data.baseSummaryUrl,
                                "type" : "POST",
                                "dataType" : "json",
                                "data" : function ( d ) {
                                    LN.debug("data called");
                                    var columnNamesArray=cs.getCurrentSummaryColumnNamesArray(cs.data.summaryTableId);
                                    return $.extend( {}, d, {
                                    	 "columnNames":columnNamesArray.length>0?columnNamesArray:prevColumnNamesArray,
                                    	 "dataSetId":$('#ln_topmenu_dataset').attr('datasetkey'),
                                    	 'selDataSetRangeRiskColumnName':  $('#ln_topmenu_dataset_range_id').attr("riskColumnName"),
                                    	 'selDataSetRangeBegin':  $('#ln_topmenu_dataset_range_id').attr("beginDateKey"),
                                    	 'selDataSetRangeEnd':  $('#ln_topmenu_dataset_range_id').attr("endDateKey"),
                         				 'selBenchMark' : $('#ln_benchid').attr("data-key"),
                         				 'searchPatientName':cs.data.patientName
                                    	 
                                    } ); },
                                'beforeSend': function(xhr) {
                                    LN.debug("beforeSend");
                                    cs.data.prevPatientName = cs.data.patientName;
					                cs.data.defaultStartingRow = -1;                                    
                                    //LN.debug("id="+ cs.data.defaultStartingRow);
                                	$('.DTFC_LeftHeadWrapper').css('display','none');
                                	$('.DTFC_LeftBodyWrapper').css('display','none');
                                	xhr.setRequestHeader('X-TransactionID', LN.TRANSACTION_ID);
                                    cs.handleBeforeAjaxLoad(cs.data.summaryTableId);                                    
                                },
                                'complete' : function() {
                                    //LN.debug("complete");
 			                    	if(cs.data.gridSearchCount>0){
 			                    		cs.data.gridSearchCount--;
 			                    		 //LN.debug("complete cs.data.gridSearchCount--->"+cs.data.gridSearchCount);
 			                        } 
                                    cs.handleAfterAjaxLoad(cs.data.summaryTableId);
                                    $('.DTFC_LeftHeadWrapper').css('display','block');
                                	$('.DTFC_LeftBodyWrapper').css('display','block');
                                	cs.removeDblScrollbar();

                                	var patientGridDesc=$('#ln_patient_viewBydesc').text();
                                	$('#ln_patient_grid_col_13').css("display","");
                	        		$('#ln_patient_grid_col_14').css("display","");
                                    cs.data.tableSummary.fnAdjustColumnSizing(false);

                            
					                cs.data.defaultStartingRow = -1;
                                    //LN.debug("beforeSend prevPatientName---->" + cs.data.prevPatientName);
                                   // LN.debug("beforeSend PatientName---->" + cs.data.patientName);
 			                    	if(cs.data.gridSearchCount==0 && cs.data.prevPatientName!=cs.data.patientName){
 			                    		//LN.debug("calling keyup function");
 			                    		$(cs.data.searchFieldId).trigger('keyup');
 			                    	}
                                },
                                "dataFilter" : function(json,type){
                                	var obj = jQuery.parseJSON(json);
                                	cs.enableExport(obj);
                                	return json;
                                }
                            },
                            "order" : [
                                       [ cs.getPreferencesIndex(cs.data.defaultTablePreferences  ,cs.data.defaultSortColumn_summary),"desc" ],
                                       [ cs.getPreferencesIndex(cs.data.defaultTablePreferences  ,cs.data.defaultSortColumn_summary_second),"asc" ]
                                      ],                            
                              "columnDefs": [
												{ 
													"sClass":"ln-text-align-left ln-nowrap",
													"render" : function(data,type,row) {
													return '<a href="javascript:void(0);" class="patientProfileDetails" patientName="'+ row[0] +'" patientId="'+ row[12] +'-'+ row[14] +'" >'+ data + '</a>';
												},
													"width": "1%",
													"targets": ['Patient_Name']
												},
												{ 
													"sClass":"ln-text-align-left",
													"width": "30%",
													"targets": ['Primary_Condition']
												},
         									{
												"render" : function(data, type,	row) {
													return formatUtil.formatNumber(parseInt(data));
												},
												"width" : "1%",
												"targets" : [ 'Total_Rx_Cost' ]
											},
											{
												"render" : function(data, type,	row) {
													var percentage = cs.convertPercentageValue(data);
													return percentage + '%';
												},
												"width" : "1%",
												"targets" : [ 'Generic_Rate', 'Brand_Rate', 'Maint_Rx_Compliance' ]
											},
											{
												"width" : "1%",
												"targets" : [ 'Patient_ID' ]
											},
											{
												"sClass" : "ln-hide-column td_memberKey",
												"targets" : [ 'MemberKey' ]
											},
											{
												"sClass" : "ln-hide-column td_subClientID ln-display-none",
												"targets" : [ 'Subclient_CD' ]
											}
  	       								],
										"fnDrawCallback" : function(oSettings) {
											cs.addGotoPageComponentPPM("ln_summary_provider_list","patientTable_gotobtn","patientTable_gototxt","patientTable_gotoerror");
											var tableId = cs.data.summaryTableId;
											if (oSettings.aaSorting.length == 1) {
												tableId = 'table.DTFC_Cloned';
											}
					                    	cs.removeSecondarySortingHeaderColor(oSettings,tableId,0);
		                                
		                                    cs.removeDblScrollbar();
		                                    cs.getPatientProfileDetails();
		                                   
										},
										"fnInitComplete": function(oSettings, json) {
											cs.noDataCleanup(json.iTotalDisplayRecords);
											setTimeout(function(){
												$('.ln-tableheadertextextended a').on('click',function(e){
												e.preventDefault();
												return false;
											});        	         	    		
										},0);
                            }
                        }    	
                    );
					new $.fn.dataTable.FixedColumns( cs.data.tableSummary ,{
						leftColumns:cs.data.fixedColumnCount
					} );
            },			            
    	    
    	   
      	    /* added for patient profile screen  */
            getPatientProfileDetails : function(){ 
            	$('.patientProfileDetails').on('click', function(e){
    	            if($(this).attr('patientName')){
    	            	 var patientProfileName = $(this).attr('patientName');
    	            	 var patientId = $(this).attr('patientId');
    	            }
    	            e.preventDefault();
    	            
    	            var fromScreen = "PPPP";
    	            
                    if ( $("#ln_isProfileScreenFlag").val() === "true" ) 
                    {
                    	fromScreen = "PPPP";
                    }
    	            
    	            $.ajax({
    					url : LN.getContextPath()+'/updatePatientProfileDetails',
    					data : {
    						"patientName" : patientProfileName,
    						"fromScreen" : fromScreen,
    						"patientId" : patientId  
    					},
    					type : "POST",
    					success : function(data) {
    						location.href = LN.getContextPath()+'/patientprofile';
    					}
    				  });
    	    	});
    	    },
    	    
    	    clearGridSearchBox: function(cs){            	
    	    	cs.data.providerId = '';
    	    	$(cs.data.gridSearchID).parent().next(".error").remove();
                $(cs.data.gridSearchID).val("").attr('placeholder','2 characters minimum');
    	  	
    	    },
           
    	    
            registerSearch:function() {
    	    	var cs = this;
    	    	
    	    	$(cs.data.gridSearchID).on('keyup', function (e) {
    	    		var isValidSearch=true;
    	    		if (!isValidateSearch(e,cs.data.gridSearchID, true)) {
    	    			isValidSearch= false;
    	    			cs.data.previousVal = $(cs.data.gridSearchID).val();
    				}
    	    		
    	    		if($(cs.data.gridSearchID).val().length>1 || $(cs.data.gridSearchID).val().length == 0)	{
    					cs.data.patientName=this.value.toUpperCase();
    	         	cs.data.delay(function(){
    	         		if(isValidSearch && cs.data.gridSearchCount==0){
    	         			if( isValidTextLength(cs,$(cs.data.gridSearchID).val(),2)) {                     		
    	                 		cs.data.gridSearchCount++;
                                $(cs.data.summaryTableId).DataTable().ajax.reload(function(data){
                                	cs.noDataCleanup(data.iTotalDisplayRecords);
                                });
    	                		
    	                 	}
    	         		}                     	
    	 			 }, 1000 );
    	    		 }
    	         });
    	    }
        });