/**
* This object will handle all the Create template functionalities
*
* @class lexisnexis.component.CreateTemplate
*/
lexisnexis.component.CreateTemplateGeneral = lexisnexis.component.Table
.extend({
data : {
peerGroupsTableId : "#ln_peerGroupsTable",
searchFieldId : '#peerGroupTableSearch',
lastcheckedbox: '0',
peerGroupSpecialty:'ALL_SPECIALTIES',
updateActiveFilterSummaryForPeerGroup:'updateActiveFiltersForPeerGroup',
comparisonPeerGroupKeyId:'#comparisonPeerGroupKeyId',
comparisonPeerGroupName:'',
SET_VIEWBY_METHOD : "setReferralPatternsViewBy",
benchmarkId : '#ln_clientBenchMarks',
clientProductId : '#ln_clientProduct',
clientSpecialtyId : '#ln_clientSpecialty',
manualSort : false,
delay : (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})()
},
ready : function() {
var cs = this;
cs.initPeerGroupTable();
cs.peerGroupCheckboxes();
cs.registerSearch();
cs.registerMeasuresRadioButton();
cs.onChangeComparisonPeergroupSpecialties();
// disable form post when enter key is pressed
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
//console.dir(cs)
cs.populateClientBenchmarks();
cs.populateClientProducts();
},
onChangeOfBenchmarkValues : function(){
var cs = this;
$(cs.data.benchmarkId ).on('change', function() {
cs.updateBenchmarkModel();
});
$(cs.data.clientProductId ).on('change', function() {
cs.updateBenchmarkModel();
});
$(cs.data.clientSpecialtyId ).on('change', function() {
cs.updateBenchmarkModel();
});
},
updateBenchmarkModel : function(){
var cs = this;
var selBenchMark = $("#ln_clientBenchMarks option:selected").val();
if(selBenchMark=='Client Total Population' ||selBenchMark=='Client East' || selBenchMark=='Client Midwest' ||
selBenchMark=='Client West' || selBenchMark== 'Client South'){
$(cs.data.clientProductId).prop("disabled",false);
$(cs.data.clientSpecialtyId).prop("disabled",false);
}else {
$(cs.data.clientProductId).val("0");
$(cs.data.clientProductId).prop("disabled",true);
$(cs.data.clientSpecialtyId).val("0");
$(cs.data.clientSpecialtyId).prop("disabled",true);
}
var selBenchMark = $("#ln_clientBenchMarks option:selected").html();
var selClientProduct = $("#ln_clientProduct option:selected").html();
var selClientSpecialty = $("#ln_clientSpecialty option:selected").html();
$('#ln_benchMarkModel').val(selBenchMark);
$('#ln_clientProductModel').val(selClientProduct);
$('#ln_clientSpecialtyModel').val(selClientSpecialty);
if($('#ln_clientProduct').is(':disabled') ){
selClientProduct = "0";
}
if($('#ln_clientSpecialty').is(':disabled') ){
selClientSpecialty = "0";
}
var selClientProduct_value = $("#ln_clientProduct option:selected").val();
var selClientSpecialty_value = $("#ln_clientSpecialty option:selected").val();
cs.updateBenchmarkValues(selBenchMark,selClientProduct_value,selClientSpecialty_value);
},
updateBenchmarkValues : function(selBenchMark,selClientProduct,selClientSpecialty){
var cs=this;
$.ajax({
'url' : LN.getContextPath() + '/updateBenchmarkData',
'dataType' : 'json',
'method' : 'POST',
'data' : {
'selBenchMark' : selBenchMark,
'selClientProduct' : selClientProduct,
'selClientSpecialty' : selClientSpecialty
},
'beforeSend' : function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN.getPage().getTransactionID());
},
'success' : function(data, textStatus, jqXHR) {
},
'complete': function(data, textStatus, jqXHR) {
//cs.rightNavSuccessEvent();
//createTemplateJs.updateActiveFilterSummary();
createTemplateJs.updatePatientCountAjax("getProviderCountForTemplate");
}
});
},
populateClientBenchmarks : function(){
var cs=this;
$.ajax({
cache : false,
'url' : LN.getContextPath() + '/getClientBenchmarks',
'dataType' : 'json',
'method' : 'post',
'data' : {
'selBenchMark' : $('#ln_benchid').attr("data-key"),
"selDataSet":$('#ln_topmenu_dataset').attr('datasetkey'),
'selDataSetRangeBegin': $('#ln_topmenu_dataset_range_id').attr("beginDateKey"),
'selDataSetRangeEnd': $('#ln_topmenu_dataset_range_id').attr("endDateKey"),
'selDataSetRangeRiskColumnName': $('#ln_topmenu_dataset_range_id').attr("riskColumnName")
},
'success' : function(data, textStatus, jqXHR) {
var object = JSON.stringify(data.clientProductSpecialtyDetailsList);
$.each($.parseJSON(object), function(idx, obj) {
var benchmarkName = obj.benchmarkName;
var newOption = "<option value='"+benchmarkName+"'>"+benchmarkName+"</option>";
$("#ln_clientBenchMarks").append(newOption);
});
},
'beforeSend' : function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN.getPage().getTransactionID());
cs.data.isInAjaxCall = true;
},
'complete' : function() {
var benchMarkModel = $('#ln_benchMarkModel').val();
$("#ln_clientBenchMarks option").filter(function() {
return $(this).text() == benchMarkModel;
}).prop('selected', true);
cs.populateClientProductSpcialty();
cs.onChangeOfBenchmarkValues();
},
'error' : function(jqXHR, textStatus, errorThrown) {
//LN.debug('Error Called');
cs.data.isInAjaxCall = false;
}
});
},
populateClientProducts : function(){
var cs=this;
$.ajax({
cache : false,
'url' : LN.getContextPath() + '/getClientProducts',
'dataType' : 'json',
'method' : 'post',
'data' : {
'selBenchMark' : $('#ln_benchid').attr("data-key"),
"selDataSet":$('#ln_topmenu_dataset').attr('datasetkey'),
'selDataSetRangeBegin': $('#ln_topmenu_dataset_range_id').attr("beginDateKey"),
'selDataSetRangeEnd': $('#ln_topmenu_dataset_range_id').attr("endDateKey"),
'selDataSetRangeRiskColumnName': $('#ln_topmenu_dataset_range_id').attr("riskColumnName")
},
'success' : function(data, textStatus, jqXHR) {
var object = JSON.stringify(data.clientProductSpecialtyDetailsList);
$("#ln_clientProduct").empty();
var div_data = "<option value='0'>All Products</option>";
$(div_data).appendTo('#ln_clientProduct');
$.each($.parseJSON(object), function(idx, obj) {
var newOption = "<option value='"+obj.product+"'>"+obj.productDesc+"</option>";
$("#ln_clientProduct").append(newOption);
});
},
'beforeSend' : function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN.getPage().getTransactionID());
cs.data.isInAjaxCall = true;
},
'complete' : function() {
var clientProductModel = $('#ln_clientProductModel').val();
$("#ln_clientProduct option").filter(function() {
return $(this).val() == clientProductModel;
}).prop('selected', true);
var selBenchMark = $('#ln_benchMarkModel').val();
if(selBenchMark=='Client Total Population' ||selBenchMark=='Client East' || selBenchMark=='Client Midwest' ||
selBenchMark=='Client West' || selBenchMark== 'Client South'){
$(cs.data.clientProductId).prop("disabled",false);
}else {
$(cs.data.clientProductId).prop("disabled",true);
}
},
'error' : function(jqXHR, textStatus, errorThrown) {
//LN.debug('Error Called');
cs.data.isInAjaxCall = false;
}
});
},
populateClientProductSpcialty : function(){
var cs=this;
$.ajax({
cache : false,
'url' : LN.getContextPath() + '/getClientSpecialty',
'dataType' : 'json',
'method' : 'post',
'data' : {
'selBenchMark' : $('#ln_benchid').attr("data-key"),
"selDataSet":$('#ln_topmenu_dataset').attr('datasetkey'),
'selDataSetRangeBegin': $('#ln_topmenu_dataset_range_id').attr("beginDateKey"),
'selDataSetRangeEnd': $('#ln_topmenu_dataset_range_id').attr("endDateKey"),
'selDataSetRangeRiskColumnName': $('#ln_topmenu_dataset_range_id').attr("riskColumnName")
},
'success' : function(data, textStatus, jqXHR) {
var object = JSON.stringify(data.clientProductSpecialtyDetailsList);
$("#ln_clientSpecialty").empty();
var div_data = "<option value='0'>All Specialties</option>";
$(div_data).appendTo('#ln_clientSpecialty');
$.each($.parseJSON(object), function(idx, obj) {
var newOption = "<option value='"+obj.specialty+"'>"+obj.specialtyDesc+"</option>";
$("#ln_clientSpecialty").append(newOption);
});
},
'beforeSend' : function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN.getPage().getTransactionID());
cs.data.isInAjaxCall = true;
},
'complete' : function() {
var clientSpecialtyModel = $('#ln_clientSpecialtyModel').val();
$("#ln_clientSpecialty option").filter(function() {
return $(this).val() == clientSpecialtyModel;
}).prop('selected', true);
var selBenchMark = $('#ln_benchMarkModel').val();
if(selBenchMark=='Client Total Population' ||selBenchMark=='Client East' || selBenchMark=='Client Midwest' ||
selBenchMark=='Client West' || selBenchMark== 'Client South'){
$(cs.data.clientSpecialtyId).prop("disabled",false);
}else {
$(cs.data.clientSpecialtyId).prop("disabled",true);
}
},
'error' : function(jqXHR, textStatus, errorThrown) {
//LN.debug('Error Called');
cs.data.isInAjaxCall = false;
}
});
},
resetReferralPatternsViewBy : function()
{
var cs=this;
var selectedText = "All";
var jsonString = JSON.stringify({'viewByChoice': selectedText});
$.ajax({
cache : false,
'url' : cs.data.SET_VIEWBY_METHOD,
'dataType' : 'json',
'method' : 'post',
'data' : {"jsonData": jsonString},
'success' : function(data, textStatus, jqXHR) {
try {
//LN.debug("Success on sending viewBy selection");
} catch (err) {
// growl the error
LN.debug("Error in sending viewBy selection: "
+ err);
}
},
'beforeSend' : function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN
.getPage().getTransactionID());
cs.data.isInAjaxCall = true;
},
'complete' : function() {
},
'error' : function(jqXHR, textStatus, errorThrown) {
//LN.debug('Error Called');
cs.data.isInAjaxCall = false;
}
});
// End Dynamic update
},
registerMeasuresRadioButton : function() {
var cs = this;
$("#createTemplate_providerRole_episode").on('click',function(event) {
cs.resetReferralPatternsViewBy();
});
},
// make check boxes behave like radio buttons
peerGroupCheckboxes : function () {
var cs = this;
$('#ln_peerGroupsTable').on('change',"input.as_radio",function(event) {
$('input.as_radio').not(this).prop('checked', false);
cs.data.lastcheckedbox = this.id;
//alert(cs.data.lastcheckedbox);
cs.getComparisonPeergroupName(event);
if(!this.checked){
cs.data.lastcheckedbox = '';
cs.data.comparisonPeerGroupName='';
$(cs.data.comparisonPeerGroupKeyId).val("");
}else{
$(cs.data.comparisonPeerGroupKeyId).val(this.id);
}
$.ajax({
'url': cs.data.updateActiveFilterSummaryForPeerGroup,
'contentType': 'application/json',
'dataType': 'text',
'method': 'post',
'beforeSend': function(xhr) {
xhr.setRequestHeader('X-TransactionID', LN.TRANSACTION_ID);
},
'data': JSON.stringify({
'peerGroupKey': cs.data.lastcheckedbox,
'comparisonPeerGroupName':cs.data.comparisonPeerGroupName
}),
'success': function(data, textStatus, jqXHR) {
},
'complete': function(jqXHR, textStatus) {
createTemplateJs.updateActiveFilterSummary();
}
});
// see fnDrawCallback for clearing the previous checkboxs on other pages
});
},
getComparisonPeergroupName: function(event){
var cs=this;
var isHeader = event.currentTarget.getAttribute("isHeader") ;
var keyColumn = "";//Don't change this value here
LN.debug("getComparisonPeergroupName ..isHeader " + isHeader ) ;
if ( ! isHeader ) {
var currentTr = $(event.target).closest('tr');
cs.data.comparisonPeerGroupName = $(currentTr).find('td').eq(1).text() ;
}
},
initPeerGroupTable : function() {
var cs = this;
cs.data.searchPeerGroup='';
$(cs.data.peerGroupsTableId).dataTable().fnDestroy();
var peerGroupTable = $(cs.data.peerGroupsTableId).DataTable({
"dom": '<"top"f>rt<"bottom"ilp><"clear">',
"info": true,
"bFilter" : true,
"bLengthChange": true,
"iTotalRecords" : "dataTableModel.iTotalRecords",
"iDisplayLength":100,
"scrollY": "240px",
"ordering" : true,
"serverSide" : true,
"paging": true,
"pagingType": "simple_numbers",
"bAutoWidth" : false,
"searching": false,
"bResponsive" :false,
"order": [[ 1, "asc" ]],
"ajax" : {
"cache": false,
"url" :"ppmGetComparisonPeerGroups",
"type" : "POST",
"dataType" : "json",
"data" : function ( d ) {
LN.debug("data called");
return $.extend( {}, d, {
"columnNames":cs.getCurrentSummaryColumnNamesArray(cs.data.peerGroupsTableId),
"dataSetId":$('#ln_topmenu_dataset').attr('datasetkey'),
"searchText":cs.data.searchPeerGroup,
"peerGroupSpecialty":cs.data.peerGroupSpecialty,
"manualSort" : cs.data.manualSort
} ); },
"dataFilter" : function(json,type){
var obj = jQuery.parseJSON(json);
return json;
}
},
"columnDefs": [
{ //checkbox col
"render" : function(data, type, row) {
// NOTE: when converting this to dynamic data, unique id's are required for check box functionality
var selectedPeerGroupId = $(cs.data.comparisonPeerGroupKeyId).val();
if(data==selectedPeerGroupId){
return '<input id="' +data+ '" class="control-label as_radio" type="checkbox" name="peergroup" value="' +data+ '" checked>';
}else{
return '<input id="' +data+ '" class="control-label as_radio" type="checkbox" name="peergroup" value="' +data+ '">';
}
},
orderable: false,
width: '1%',
"targets" : [ 0 ]
}
],
"fnDrawCallback" : function(oSettings) {
// add goto box
cs.addGotoPageComponentPPM("ln_peerGroupsTable","peerGroupsTable_gotobtn","peerGroupsTable_gototxt","peerGroupsTable_gotoerror");
},
"fnPreDrawCallback" : function(oSettings) {
if (oSettings.aaSorting[0] && oSettings.aaSorting[0][0] !== 1 ) {
cs.data.manualSort = true;
}
return true;
},
"fnRowCallback": function( nRow, aData) {
var currentInputObj=$('td:eq(0) input', nRow);
if( $(cs.data.comparisonPeerGroupKeyId).val() && $(cs.data.comparisonPeerGroupKeyId).val()!=currentInputObj.val()){
currentInputObj.prop('checked',false);
}
}
});
},// end intitPeerGroupTable
onChangeComparisonPeergroupSpecialties : function() {
var cs = this;
$("#ln_sel_specialty li").on('click', function() {
$("#ln_sel_specialty_desc").text($(this).text());
var removeText = this.id;
removeText = removeText.replace("LN_CPG_", '');
cs.data.peerGroupSpecialty=removeText;
$(cs.data.searchFieldId).val("");
$(cs.data.searchFieldId).focus();
$("#ln_sel_specialty_desc").focus();// change focus to bring back the place holder text IR#1192
cs.initPeerGroupTable();
});
},
registerSearch:function(){
var cs=this;
var isValidChar=false;
var searchFlag=false;
$(cs.data.searchFieldId).on('keyup',function (e) {
cs.data.searchPeerGroup=this.value.toUpperCase();
cs.data.delay(function(){
if($(cs.data.searchFieldId).val().length>=3){
isValidChar=true;
}else if($(cs.data.searchFieldId).val().length===0){
isValidChar=false;
}
if(isValidChar && $(cs.data.searchFieldId).val().length<3){
cs.data.searchPeerGroup="";
searchFlag=true;
}else{
searchFlag=false;
}
if($(cs.data.searchFieldId).val().length>=3 || $(cs.data.searchFieldId).val().length==0 || searchFlag) {
$(cs.data.peerGroupsTableId).DataTable().ajax.reload();
}
}, 1000 );
});
}
});