gerd
11/8/2016 - 2:08 PM

LN_Component.js

/**
 * Base class for all component Javascript objects . All class should extend this object
 * @class  lexisnexis.component.Component
 */
jQuery.namespace( 'lexisnexis.component' );
//Base Component which all components should inherit from
lexisnexis.component.Component = lexisnexis.LNClass.extend({
  init: function(config){
    this._super(config);
    var cs = this;
    LN.registerComponent(cs);
  },
  /**
   * This line is executed once the page is loaded. Needs to be implemented by the
   * extending classes
   * @method ready
   */
   ready : function() {
   },
   updateLabel: function(inputId, labelId,labelValue) {
     var input=$("input[id='"+inputId+"']");
     var label=$("label[for='"+labelId+"']");
     $(input).live( "click",function() {
         $(label).html('');
     });
     $(input).focus( function() {
         $(label).html('');
     });
     $(input).focusout( function(event) {
       var srchValue=$(this).val();
       if(srchValue=='') {
         $(label).html(labelValue);
       }
       event.stopPropagation();
       });
      /** If input is not empty then dont show label **/
      if($(input).val() !='') {
         $(label).html('');
    }
  },
  updateInputLabel: function(inputId, inputValue) {
    var input=$("input[id='"+inputId+"']");
    $(input).click( function() {
      $(input).select();
    });
    $(input).focusout( function(event) {
      if($(input).val()==''){
        $(input).val(inputValue);
      }
      });
  },
  
  /**
   * Function for "Select and navigate to" Buttons
   * handles redirection with drilldown filters.
   */
  navigateTo: function(toPage, fromPage, groupByVal) {
      var cs=this;
      var samePageRedirect = false;
      var drillDownFilter = "";
      var drillDownFilterValue = "";
      var activeFilterSummary = "";
      var groupBy = "";
      var i = 0;
      for (;i<cs.data.selectedIDs.length;i++) {
          if ( i == 0) {
              drillDownFilterValue = cs.data.selectedIDs[i].value;
              if (cs.data.selectedIDs[i].specialty_text != '') {
                  drillDownFilterValue += ','+cs.data.selectedIDs[i].specialty_text;
              }
              activeFilterSummary = cs.data.selectedIDs[i].filter_val;
          } else {
              drillDownFilterValue = drillDownFilterValue + '|' + cs.data.selectedIDs[i].value;
              if (cs.data.selectedIDs[i].specialty_text != '') {
                  drillDownFilterValue += ','+cs.data.selectedIDs[i].specialty_text;
              }
              activeFilterSummary = activeFilterSummary + '|' + cs.data.selectedIDs[i].filter_val;
          }
      }
      
      switch(groupByVal){
		  case "Provider":
			  groupBy ="PR";
		  break;
		  case "Network":
			  groupBy ="NW";
		  break;
		  case "Specialty":
			  groupBy ="SP";
		  break;
		  case "Peer Group":
			  groupBy ="PG";
		  break;
		  case "Group":
			  groupBy ="GR";
		  break;  
		  case "ETG":
			  groupBy = "ETG";
		  break;
		  case "MPC":
			  groupBy = "MPC";
		  break;
	  }
      
      if (toPage == 'ln_apply_to_current_page') {
     	   toPage = fromPage;
           samePageRedirect = true;
           cs.data.selectedIDs = []; //Clear the selected Values
       }
      
      var drillDownFilter = fromPage +"_"+ toPage +"_"+ groupBy;
  
      drillDownFilters.updateDrillDownCriteriaRedirectUrl(drillDownFilter, drillDownFilterValue, activeFilterSummary, drillDownFilters, samePageRedirect);
},

/**
 * Function to redirect to patient profile details screen
 */
	goToPatientProfileDetails : function(patientName, patientId){
         var fromScreen = "PC";
		
        $.ajax({
			url : LN.getContextPath()+'/updatePatientProfileDetails',
			data : {
				"patientName" : patientName,
				"fromScreen" : fromScreen,
				"patientId" : patientId  
			},
			type : "POST",
			success : function(data) {
				location.href = LN.getContextPath()+'/patientprofile';
			}
		  });
	},

  /**
   * Funtion to the domain of the application
   */
  getDomain : function() {
    var pathArray = window.location.pathname.split('/');
    var domain = pathArray[1];
    return domain;
  },
  /**
   * method to check if the browser is Internet Explorer
   * @method isIE
   */
   isIE:function() {
        var rv = -1;
        var ua;
        var re; 
        if (navigator.appName === 'Microsoft Internet Explorer') {
          ua = navigator.userAgent;
          re= new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
          if (re.exec(ua) != null) {
            rv = parseFloat(RegExp.$1);
          }
        } else if (navigator.appName === 'Netscape') {
          ua = navigator.userAgent;
          re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
          if (re.exec(ua) != null) {
            rv = parseFloat(RegExp.$1);
          }
        }
        return rv === -1 ? false : true;
      },
      
      /**
		 * detect IE
		 * returns version of IE (10 to 12) or false, if browser is not Internet Explorer
	   */
		detectIE: function() {
		  var ua = window.navigator.userAgent;
		  var vNum = 0;
		  // test values
		  // IE 10
		  //ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
		  // IE 11
		  //ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
		  // IE 12 / Spartan
		  //ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
		  
		  var msie = ua.indexOf('MSIE ');
		  if (msie > 0) {
		    // IE 10 or older => return version number
		    return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
		  }
		  var trident = ua.indexOf('Trident/');
		  if (trident > 0) {
		    // IE 11 => return version number
		    var rv = ua.indexOf('rv:');
		    return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
		  }
		  var edge = ua.indexOf('Edge/');
		  if (edge > 0) {
		    // IE 12 => return version number
		    return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
		  }
			// other browser
		  return false;
		}, 
      
  /**
   * Function to get the domain with the path
   */
  getDomainPath : function() {
    var protocol = location.protocol;
    var host = location.host;
    var pathname = location.pathname;
    if (pathname[pathname.length - 1] === "/") {
        pathname = pathname.substring(0, (pathname.length - 1));
    }
    var match = RegExp('[?&]' + 'id' + '=([^&]*)').exec(
        window.location.search);
    var id = match
        && decodeURIComponent(match[1].replace(/\+/g, ' '));
    var url = protocol + '//' + host + pathname + '?id=' + id;
    return url;
  },
    
  /**
   * Function to udpate the prediction indicator on the each patients page
   */
  showPredictionIndicator : function(){
	    var relativeCost = $('#relativeCost').html();
	    if (relativeCost <= 50) {
	    $('#relativeCost').addClass('ln-legend-colorGreen'); // green
	    $('#relativeCost').css("color", "#fff");
	    }
	    if (relativeCost > 50 && relativeCost <= 70) {
	    $('#relativeCost').addClass('ln-legend-colorGreen');
	    $('#relativeCost').css("color", "#fff");
	    }
	    if (relativeCost > 70 && relativeCost <= 85) {
	    $('#relativeCost').addClass('ln-legend-colorYellow');; // yellow
	    $('#relativeCost').css("color", "#fff");
	    }
	    if (relativeCost > 85 && relativeCost <= 95) {
	    $('#relativeCost').addClass('ln-legend-colorRed'); // red
	    $('#relativeCost').css("color", "#fff");
	    }
	    if (relativeCost > 95 && relativeCost <= 100) {
	    $('#relativeCost').addClass('ln-legend-colorRed');
	    $('#relativeCost').css("color", "#fff");
	    }
	    var riskPercent = $('#forecastedRisk').html();
	    if (riskPercent <= 50) {
	    $('#riskPercent').addClass('ln-legend-colorGreen');// green
	    $('#riskPercent').css("color", "#fff");
	    }
	    if (riskPercent > 50 && riskPercent <= 70) {
	    $('#riskPercent').addClass('ln-legend-colorGreen');
	    $('#riskPercent').css("color", "#fff");
	    }
	    if (riskPercent > 70 && riskPercent <= 85) {
	    $('#riskPercent').addClass('ln-legend-colorYellow');;
	    $('#riskPercent').css("color", "#fff");
	    }
	    if (riskPercent > 85 && riskPercent <= 95) {
	    $('#riskPercent').addClass('ln-legend-colorRed');
	    $('#riskPercent').css("color", "#fff");
	    }
	    if (riskPercent > 95 && riskPercent <= 100) {
	    $('#riskPercent').addClass('ln-legend-colorRed');
	    $('#riskPercent').css("color", "#fff");
	    }
	    var IPEDPercent = $('#IPEDVisitRisk').html();
	    if (IPEDPercent <= 50) {
	    $('#IPEDVisitRisk').addClass('ln-legend-colorGreen');
	    $('#IPEDVisitRisk').css("color", "#fff");
	    }
	    if (IPEDPercent > 50 && IPEDPercent <= 70) {
	    $('#IPEDVisitRisk').addClass('ln-legend-colorGreen');
	    $('#IPEDVisitRisk').css("color", "#fff");
	    }
	    if (IPEDPercent > 70 && IPEDPercent <= 85) {
	    $('#IPEDVisitRisk').addClass('ln-legend-colorYellow');;
	    $('#IPEDVisitRisk').css("color", "#fff");
	    }
	    if (IPEDPercent > 85 && IPEDPercent <= 95) {
	    $('#IPEDVisitRisk').addClass('ln-legend-colorRed');
	    $('#IPEDVisitRisk').css("color", "#fff");
	    }
	    if (IPEDPercent > 95 && IPEDPercent <= 100) {
	    $('#IPEDVisitRisk').addClass('ln-legend-colorRed');
	    $('#IPEDVisitRisk').css("color", "#fff");
	    }
	    var CompliancePercent = $('#ComplianceRisk').html();
	    if (CompliancePercent == 0) {
	    $('#ComplianceRisk').addClass('ln-legend-colorGrey');
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    if (CompliancePercent > 1 && CompliancePercent <= 50) {
	    $('#ComplianceRisk').addClass('ln-legend-colorGreen');
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    if (CompliancePercent > 50 && CompliancePercent <= 70) {
	    $('#ComplianceRisk').addClass('ln-legend-colorGreen');
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    if (CompliancePercent > 70 && CompliancePercent <= 85) {
	    $('#ComplianceRisk').addClass('ln-legend-colorYellow');;
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    if (CompliancePercent > 85 && CompliancePercent <= 95) {
	    $('#ComplianceRisk').addClass('ln-legend-colorRed');
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    if (CompliancePercent > 95 && CompliancePercent <= 100) {
	    $('#ComplianceRisk').addClass('ln-legend-colorRed');
	    $('#ComplianceRisk').css("color", "#fff");
	    }
	    var motivationPercent = $('#motivationRisk').html();
	    if (motivationPercent == 0) {
	    $('#motivationRisk').addClass('ln-legend-colorGrey');
	    $('#motivationRisk').css("color", "#fff");
	    }
	    if (motivationPercent >= 1 && motivationPercent <= 5) {
	    $('#motivationRisk').addClass('ln-legend-colorGreen');
	    $('#motivationRisk').css("color", "#fff");
	    }
	    if (motivationPercent >= 6 && motivationPercent <= 15) {
	    $('#motivationRisk').addClass('ln-legend-colorGreen');
	    $('#motivationRisk').css("color", "#fff");
	    }
	    if (motivationPercent >= 16 && motivationPercent <= 30) {
	    $('#motivationRisk').addClass('ln-legend-colorYellow');;
	    $('#motivationRisk').css("color", "#fff");
	    }
	    if (motivationPercent > 30 && motivationPercent <= 50) {
	    $('#motivationRisk').addClass('ln-legend-colorGrey');
	    $('#motivationRisk').css("color", "#fff");
	    }
	    if (motivationPercent > 50 && motivationPercent <= 100) {
	    $('#motivationRisk').addClass('ln-legend-colorGrey');
	    $('#motivationRisk').css("color", "#fff");
	    }
	    var moversRiskPercent = $('#moversRisk').html();
	    if (moversRiskPercent <= 50) {
	    $('#moversRisk').addClass('ln-legend-colorGreen');
	    $('#moversRisk').css("color", "#fff");
	    }
	    if (moversRiskPercent > 50 && moversRiskPercent <= 70) {
	    $('#moversRisk').addClass('ln-legend-colorGreen');
	    $('#moversRisk').css("color", "#fff");
	    }
	    if (moversRiskPercent > 70 && moversRiskPercent <= 85) {
	    $('#moversRisk').addClass('ln-legend-colorYellow');;
	    $('#moversRisk').css("color", "#fff");
	    }
	    if (moversRiskPercent > 85 && moversRiskPercent <= 95) {
	    $('#moversRisk').addClass('ln-legend-colorRed');
	    $('#moversRisk').css("color", "#fff");
	    }
	    if (moversRiskPercent > 95 && moversRiskPercent <= 100) {
	    $('#moversRisk').addClass('ln-legend-colorRed');
	    $('#moversRisk').css("color", "#fff");
	    }
  },
  /**
   * Returns an array finding the intersecting elements from two arrays.
   */
  array_intersect: function() {
	  var i,shortest, nShortest, n, len, ret = [], obj={}, nOthers;
	  nOthers = arguments.length-1;
	  nShortest = arguments[0].length;
	  shortest = 0;
	  for (i=0; i<=nOthers; i++){
	    n = arguments[i].length;
	    if (n<nShortest) {
	      shortest = i;
	      nShortest = n;
	    }
	  }
	 
	  for (i=0; i<=nOthers; i++) {
	    n = (i===shortest)?0:(i||shortest); //Read the shortest array first. Read the first array instead of the shortest
	    len = arguments[n].length;
	    for (var j=0; j<len; j++) {
	        var elem = arguments[n][j];
	        if(obj[elem] === i-1) {
	          if(i === nOthers) {
	            ret.push(elem);
	            obj[elem]=0;
	          } else {
	            obj[elem]=i;
	          }
	        }else if (i===0) {
	          obj[elem]=0;
	        }
	    }
	  }
	  return ret;
	}, 
	
	/**
     * Identifies the index of the column based on the id
     * @method getColumnIndex
     */
    getColumnIndex : function(name) {
        name = name.replace(/[ /]/g, '_').replace(/"/g, '');
        return $(name).index();
    },
    /**
     * function to get the index based on header data-idval
     * e.g.
     * $("th[data-idval='Payer ID']").index()
     * @param name
     */
    getHeaderColumnIndex: function(name) {
    	return $("th[data-idval='"+name+"']").index();
    },
    
   /**
    * Function to trim long template names for display.
    * Takes 2 args: The element class or id to trim and the number of characters to trim at.
    */
   trimTemplateName: function(element, chars) {
   	 	element = element || "#";
   	 	chars = chars || "30";
	   	var tname = $(element).text();
	   	$(element).attr('title', tname);
	   	if (tname.length > 30) { 
	   		var shortname = tname.slice(0,chars-1); 
	          shortname  = shortname.concat("...");
	          $(element).text(shortname);
	   	}
   },
   
});