PageSourceSearch

https://www.hss.edu/scripts/os-api.js

js hss.edu collected 2026-09-24 08:43:07 UTC 125,076 bytes, 3,260 lines download raw bytes

1//import moment from 'moment';
2console.log("momment installed-" + moment().format('MMMM Do YYYY, h:mm:ss a'));
3
4/// Get Availability Data
5export async function getAvailabilityData() {
6
7  console.log("getAvailabilydta() fired")
8  var insValue = localStorage.getItem("insname");
9  var searchTypeValue = localStorage.getItem("searchType");
10
11  let requestOptions = {
12    method: 'GET',
13    headers: {
14      'x-api-key': 'OqrTIBKNOXajKIrSueK0313MOoKgkTUJ3c7wgJa3'
15      //'x-api-key': 'sD3wv7GBJ79xl0EUgAQec2mkp3QV7ngfv8FzxQXj'
16    },
17    redirect: 'follow'
18  };
19
20  fetch("https://os.hss.edu/availability", requestOptions)
21  //fetch("https://09uj9r5x0m.execute-api.us-east-1.amazonaws.com/prod/availability", requestOptions)
22    .then(response => response.json())
23    .then(data => {
24      //console.log(data)
25      let filteredData = Object.values(data).filter(item => item.nameLastFirst !== 'AAA UOC Midtown MD');
26
27// Step 2: Further filter based on searchTypeValue conditionally
28filteredData = filteredData.filter(appointment => {
29        return appointment.appointmentId === '11700000136';
30});
31
32// Step 3: Map data by ID and combine availability values
33const mapById = filteredData.reduce((acc, { id, availability }) => {
34    acc[id] = {
35        id,
36        availability: (acc[id] ? acc[id].availability + "," : "") + availability
37    };
38    return acc;
39}, {});
40
41      const resultArray = Object.values(mapById);
42//in-person all
43
44//var afterdate = moment().add(90, 'days').format('M/D');
45var selectedInsuranceOption = localStorage.getItem("insname");
46
47function NYPall() {
48  $('#search-results .element-item').each(function(){
49    if ($(this).hasClass("yesoscondition")) {  
50    if ($(this).attr('data-externalLink') !== '') {
51      console.log($(this).attr('data-breadcrumb') + "-nyp-doc-found")
52      $(this).addClass('inperson-available')
53      $(this).addClass('date-show')
54      $(this).addClass("inperson-show");
55
56      $(this).addClass("book-me");
57      $(this).removeClass("call-me");
58                  //add inperson dates to os BTN
59      if (insValue !== 'unselect') {
60         const inpersonWrapperDiv2 = $(this).find('.inperson-date-wrapper');
61         inpersonWrapperDiv2.empty().append("For appointment availability, continue to book online with this specialist.");
62      }
63      var afterdate = moment().add(100, 'days').format('MMM D, YYYY');
64      $(this).attr('datetime', afterdate);  
65      $(this).find('.inperson-date-wrapper').show();
66      $(this).find('.loc-date-wrapper').hide();
67      $(this).find('.viewalltime').hide();
68      $(this).find('.btn-primary').show();
69      $(this).find('.btn-primary-filtered').remove();
70    }
71  }
72  });  
73} 
74NYPall()
75
76function inpersonall() { 
77      const isShowAllSelected = $('#location-filter').val() === '';
78      resultArray.forEach((result) => {
79        $('#search-results .element-item').each(function(){
80          const $el = $(this);
81
82      const matchesCommon = 
83        $el.attr('dataosdefault') === '' &&
84        ($el.attr('data-oic') === '' || $el.attr('data-oic') === 'yes') &&
85        $el.attr('data-providerid') == result.id &&
86        $el.attr('data-breadcrumb') !== 'AAA UOC Telehealth' &&
87        $el.hasClass('inperson') &&
88        $el.hasClass('yesoscondition') &&
89        !$el.hasClass('hasCall') &&
90        !$el.hasClass("out-of-network-call");
91
92
93      const condition1 = matchesCommon && $el.attr('data-forclearfilter') !== 'call-me';
94      const condition2 = matchesCommon && !$el.hasClass('call-me');
95
96      if ((isShowAllSelected && condition1) || (!isShowAllSelected && condition2)) {
97            if ((result.id !=='11700123') && (result.availability !== '') && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {
98             $(this).removeClass("no-dates-available");
99             $(this).addClass('inperson-available')
100             $(this).addClass('date-show')
101             $(this).addClass("inperson-show");
102
103             $(this).addClass("book-me");
104             $(this).removeClass("call-me");
105             var urlParams = new URLSearchParams(window.location.search);
106             //if (searchTypeValue === 'FAD') {
107              if (urlParams.get('searchtype') === 'fad') {
108             $(this).find('.viewalltime').show(); 
109             $(this).find('.viewalltime').attr("data-ip-show","yes")
110             }
111             let availabledates =  JSON.stringify(result.availability);
112             availabledates = availabledates.replace(/['"]+/g, '');
113            //remove first comma from string
114
115             availabledates = availabledates.replace(/^,/, '');
116             availabledates = availabledates.replace(/^,/,'');
117            //remove last commna from string 
118
119             availabledates = availabledates.replace(/,\s*$/, "");
120            //remove one extra comma when there is only one date per each location
121
122             availabledates = availabledates.replace(',,', ',');
123              //remove starting and ending comma from variable in javascript
124             availabledates = availabledates.replace(/^,|,$/g,'');
125            //order dates by the latest
126             let availabledatessort = availabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
127            //find the first date
128             let firstdate = availabledatessort.split(",")[0]
129            //add first date to the datetime attribute
130             //firstdateattr = [moment(firstdate).format('MMM D, YYYY')]; 
131             let firstdateattr = [];  // Declare the variable first
132
133             if (typeof firstdate !== "undefined") {
134             firstdateattr = [moment(firstdate).format('MMM D, YYYY')];
135             } else {
136             console.error("firstdate is undefined or null");
137             }
138             $(this).attr('datetime', firstdateattr);
139              //switch to mm/dd format for os btn 
140             
141             //firstdateforosbtn = [moment(firstdate).format('MMM D')];
142             let firstdateforosbtn = [];  // Declare first
143
144             if (typeof firstdate !== "undefined" && firstdate !== null) {
145                 firstdateforosbtn = [moment(firstdate).format('MMM D')];
146             } else {
147                 console.error("firstdate is undefined or null");
148             }
149
150            //find 1st and 2nd dates and combime into one
151            let seconddateforosbtn = ""; // Declare globally to avoid ReferenceError
152
153            const countdates = [...availabledates].filter(l => l === ',').length;
154            if (countdates == 0) {
155                seconddateforosbtn = ""; 
156            } else {   
157                let seconddate = availabledatessort.split(",")[1]; // Get second date safely
158                if (typeof seconddate !== "undefined" && seconddate !== null) {
159                    seconddateforosbtn = [moment(seconddate).format('MMM D')];
160                } else {
161                    console.error("seconddate is undefined or null");
162                }
163            }
164             let inpersonalldates = firstdateforosbtn + ", " + seconddateforosbtn
165      
166             //remove last commna from string 
167             inpersonalldates = inpersonalldates.replace(/,\s*$/, "");    
168             //console.log( inpersonalldates) 
169            //add inperson dates to os BTN
170            if (insValue !== 'unselect') {
171            const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
172            const inPersonDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
173            inpersonWrapperDiv.empty().append(inPersonDates);
174            }
175
176            $(this).find('.inperson-date-wrapper').show();
177            $(this).find('.loc-date-wrapper').hide();
178            //profilebtn.attr('href', profileBtnBook);
179
180      }
181
182    } else if (($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
183     //$(this).find('.multi-os-checkbox').hide(); 
184    }
185    
186    const localFilter = localStorage.getItem('location-filter_filter');
187    if ((isShowAllSelected) && (localFilter !== null && localFilter === '')) {
188      $(this).find('.availability').text('Next available appointments:');
189      $(this).find('.btn-primary').show();
190      $(this).find('.btn-primary-filtered').remove();
191    }
192    
193
194 });   
195
196});
197    
198}
199//end in-person all
200
201//if (insValue !== 'Medicare' || insValue !== 'Aetna_Medicare_PPO' || insValue !== 'EmblemHealth_Medicare' || insValue !== 'Oxford_Medicare' || insValue !== 'UHC_Medicare_HMO' | insValue !== 'UHC_Medicare_PPO') { 
202if (insValue.indexOf("Medicare") == -1) {  
203console.log("fire inpersonall api")   
204inpersonall();
205}
206
207//fire inpersonallapit when it's pt search because PTs don't have medicare VT
208if (searchTypeValue === 'PT' && (insValue.indexOf("Medicare") >= 0)) {   
209//console.log("fire inpersonall api - pt medicare")  
210inpersonall();
211}
212
213
214
215//defaultall start
216
217//var afterdate= moment().add(90, 'days').format('M/D');
218
219function defaultall() {
220data.forEach((result) => {
221$('#search-results .element-item').each(function(){
222if (($(this).attr('dataosdefault') == 'yes') && ( ($(this).attr('data-oic') ==='') || ($(this).attr('data-oic') ==='yes') ) && ($(this).attr('data-providerid') == result.id) && ($(this).hasClass("inperson")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me"))  ) {  
223  //alert("yes");
224  var defaultlocationvalue = $(this).attr('dataosdefault');
225  var docname = $(this).attr('data-breadcrumb');
226
227  if ((result.id !=='11700123') && (result.availability !== '') && (result.appointmentId !== '1170000218') && (result.locationName !== 'VIRTUAL') && (result.nameLastFirst === docname) && (result.availability != null) && (result.availability.length > 0) && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {  
228  
229   $(this).addClass('inperson-available')
230   let availabledates =  JSON.stringify(result.availability);
231   availabledates = availabledates.replace(/['"]+/g, '');
232   availabledates=  availabledates.replace('[', '');
233   availabledates=  availabledates.replace(']', '');
234   //remove last commna from string 
235   availabledates = availabledates.replace(/,\s*$/, "");
236   
237   //remove first comma from string
238   availabledates = availabledates.replace(/^,/, '');
239   availabledates = availabledates.replace(/^,/,'');
240
241   //remove one extra comma when there is only one date per each location
242   availabledates = availabledates.replace(',,', ',');
243   //console.log (result.id + availabledates); 
244
245   //console.log(availabledates)
246   
247   //order dates by the latest
248   let availabledatessort = availabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
249   //availabledatessort = availabledatessort + ",";
250   //console.log (availabledatessort); 
251
252   //find the first date
253   let firstdate = availabledatessort.split(",")[0]
254   //add first date to the datetime attribute
255   //if ((firstdate !== ' ') || (firstdate !== null) || (firstdate.length > 0)) {
256   firstdateattr = [moment(firstdate).format('MMM D, YYYY')];
257   $(this).attr('datetime', firstdateattr);
258   //}
259   
260   //switch to mm/dd format for os btn 
261   firstdateforosbtn = [moment(firstdate).format('MMM D')];
262   //console.log((availabledatessort.split(",").length - 1));
263   //find 1st and 2nd dates and combime into one
264
265   const countdates = [...availabledates].filter(l => l === ',').length;
266   if (countdates == 0) {
267   seconddateforosbtn = ""; 
268   } else {   
269   let seconddate = availabledatessort.split(",")[1]
270   seconddateforosbtn = [moment(seconddate).format('MMM D')]; 
271   } 
272   let inpersonalldates = firstdateforosbtn + ", " + seconddateforosbtn
273   //remove last commna from string 
274   inpersonalldates = inpersonalldates.replace(/,\s*$/, "");    
275
276   //$(this).addClass("inperson-show");    
277
278    //add inperson dates to os BTN
279const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
280const inPersonDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
281inpersonWrapperDiv.empty().append(inPersonDates);
282
283$(this).find('.inperson-date-wrapper').show();
284$(this).find('.loc-date-wrapper').hide();
285
286   } 
287
288} else if (($(this).attr('dataosdefault') == 'yes') && ($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
289   //$(this).find('.multi-os-checkbox').hide(); 
290
291}
292});   
293
294});
295
296}
297
298// end defaultall
299if (insValue.indexOf("Medicare") == -1) { 
300console.log("fire defaultall api")   
301defaultall()
302}
303
304
305//AAA uoc midtown MD
306var itemValue = localStorage.getItem("insname");
307
308if (insValue.indexOf("Medicare") >= 0)  { 
309var dataoic = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
310var  dataoicmc = Object.values(dataoic).filter(appointment => appointment.appointmentId === '1170000218') 
311} else {  
312var dataoic = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
313var dataoicmc = Object.values(dataoic).filter(appointment => appointment.appointmentId === '11700000136')
314}
315//var dataoicall = Object.values(dataoicmc).filter(department => department.locationName === 'HSS Ortho Injury Care' | department.locationName === 'HSS Midtown')
316//var dataoicall = Object.values(dataoicmc).filter(department => department.locationName === 'HSS Ortho Injury Care')
317var dataoicall = Object.values(dataoicmc).filter(department => department.departmentId === '501029002')
318var mapByIdoic = dataoicall.reduce((acc, { id, availability, nameLastFirst }) => {  
319acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
320return acc;
321}, {})
322
323const resultArrayoic = Object.values(mapByIdoic);
324
325
326//OIC all
327function oicall() {
328  resultArrayoic.forEach((result) => {
329  
330  $('#search-results .element-item').each(function(){
331  
332  if (($(this).attr('dataosdefault') === '') && ($(this).attr('data-breadcrumb') == 'AAA UOC Midtown MD') && ($(this).hasClass("inpers
332on")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me")) ) { 
333  console.log("fire oicall")          
334  if ((result.id !=='11700123') && (result.availability !== '') && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {
335  console.log("oicall-matched") 
336     $(this).addClass('inperson-available')
337     $(this).addClass('date-show')
338     $(this).addClass("inperson-show");   
339     //$(this).addClass("UpperEastSide");   
340     //$(this).addClass("UpperEastSide-show");   
341     $(this).addClass("Midtown-show");   
342     $(this).addClass("Midtown-show-show");
343     $(this).addClass("MCall-show");
344     $(this).addClass("NYCall-show");
345  
346      $(this).addClass("book-me");
347      $(this).removeClass("call-me");
348  
349     //let availabledates2 =  JSON.stringify(result.availability);
350     let availabledates =  JSON.stringify(result.availability);
351     availabledates = availabledates.replace(/['"]+/g, '');
352     
353     //remove first comma from string
354     availabledates = availabledates.replace(/^,/, '');
355     availabledates = availabledates.replace(/^,/,'');
356  
357     //remove last commna from string 
358     availabledates = availabledates.replace(/,\s*$/, "");
359     
360     //remove one extra comma when there is only one date per each location
361     availabledates = availabledates.replace(',,', ',');
362  
363     //remove starting and ending comma from variable in javascript
364     availabledates = availabledates.replace(/^,|,$/g,'');
365  
366     //remove duplicate dates from array
367     availabledates = Array.from(new Set(availabledates.split(','))).toString();
368  
369        //order dates by the latest
370   let availabledatessort = availabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
371   console.log ("OICALL:"+ result.id + "--" + availabledatessort); 
372   //find the first date
373   let firstdate = availabledatessort.split(",")[0]
374   //add first date to the datetime attribute
375   let firstdateattr = [moment(firstdate).format('MMM D, YYYY')];
376          var itemValue = localStorage.getItem("insname");
377         if (insValue.indexOf("Medicare") >= 0) { 
378         $(this).attr('mcdatetime', firstdateattr);
379         $(this).attr('locdatetime', firstdateattr);   
380         } else {
381         $(this).attr('datetime', firstdateattr);
382         $(this).attr('locdatetime', firstdateattr);
383         }
384   
385   //switch to mm/dd format for os btn 
386   let firstdateforosbtn = [moment(firstdate).format('MMM D')];
387   //console.log((availabledatessort.split(",").length - 1));
388   //find 1st and 2nd dates and combime into one
389
390   // Count the number of commas in availabledates
391const countdates = (availabledates.match(/,/g) || []).length;
392
393// Declare seconddateforosbtn outside the block
394let seconddateforosbtn = "";
395
396if (countdates > 0) {   
397    let seconddate = availabledatessort.split(",")[1];
398    seconddateforosbtn = moment(seconddate).format('MMM D'); 
399}
400
401// Concatenate dates and remove the last comma if needed
402let inpersonalldates = `${firstdateforosbtn}${seconddateforosbtn ? ', ' + seconddateforosbtn : ''}`;
403
404console.log(inpersonalldates);
405     
406     //$(this).addClass("inperson-show");
407  
408      //add inperson dates to os BTN
409  
410  const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
411  const inpersonDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
412  inpersonWrapperDiv.empty().append(inpersonDates);
413  
414  const locationWrapperDiv = $(this).find('.loc-date-wrapper');
415  const locationDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
416  locationWrapperDiv.empty().append(locationDates);
417  $(this).find('.loc-date-wrapper').hide();
418  
419  
420  
421  } else {
422          $(this).attr('data-inpersonts', 'skip');
423          $(this).find('.EndScreenModalBtn').attr('data-inpersonts', 'skip');
424          
425          $(this).addClass("call-me");
426          $(this).removeClass("book-me");
427  
428          var doctorPhone = $(this).attr('data-phone');
429  var doctorPhoneNumber = doctorPhone.split('.').join("");
430  var profilebtn = $(this).find('.btn-outline-primary');
431  var profileUrl = profilebtn.attr('href');
432  var modifiedUrl = profileUrl + '?osbtn=no';
433  profilebtn.attr('href', modifiedUrl);
434  
435  $(this).find('.inperson-date-wrapper').hide();
436  $(this).find('.loc-date-wrapper').hide();
437  
438  $(this).removeClass("dates-available");
439  $(this).addClass("no-dates-available");
440  
441  $(this).find('.availability').text('Call for availability & booking')
442  $(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
443  
444  } 
445  
446  } else if (($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
447     //$(this).find('.multi-os-checkbox').hide(); 
448  }
449  });   
450  //});
451  
452  });
453    
454  }
455// END OIC
456
457oicall() 
458
459//AAA uoc midtown PA
460var itemValue = localStorage.getItem("insname");
461
462if (insValue.indexOf("Medicare") >= 0)  { 
463var dataoicpa = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
464var  dataoicmcpa = Object.values(dataoicpa).filter(appointment => appointment.appointmentId === '1170000218') 
465} else {  
466var dataoicpa = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
467var dataoicmcpa = Object.values(dataoicpa).filter(appointment => appointment.appointmentId === '11700000136')
468}
469var dataoicallpa = Object.values(dataoicmcpa).filter(department => department.locationName === 'HSS Ortho Injury Care' | department.locationName === 'HSS Midtown')
470//var dataoicall = Object.values(dataoicmc).filter(department => department.locationName === 'HSS Ortho Injury Care')
471//var dataoicall = Object.values(dataoicmc).filter(department => department.departmentId === '501029002')
472var mapByIdoicpa = dataoicallpa.reduce((acc, { id, availability, nameLastFirst }) => {  
473acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
474return acc;
475}, {})
476
477const resultArrayoicpa = Object.values(mapByIdoicpa);
478
479
480//OIC all
481
482function oicallpa() {
483resultArrayoicpa.forEach((result) => {
484
485$('#search-results .element-item').each(function(){
486
487if (($(this).attr('dataosdefault') === '') && ($(this).attr('data-breadcrumb') == result.nameLastFirst) && ($(this).attr('data-oic') ==='yes') && ($(this).hasClass("inpers
487on")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me")) ) { 
488console.log("fire oicall")          
489if ((result.id !=='11700123') && (result.availability !== '') && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {
490console.log("oicall-matched") 
491   $(this).addClass('inperson-available')
492   $(this).addClass('date-show')
493   $(this).addClass("inperson-show");   
494   //$(this).addClass("UpperEastSide");   
495   //$(this).addClass("UpperEastSide-show");   
496   $(this).addClass("Midtown-show");   
497   $(this).addClass("Midtown-show-show");
498   $(this).addClass("MCall-show");
499   $(this).addClass("NYCall-show");
500
501    $(this).addClass("book-me");
502    $(this).removeClass("call-me");
503
504   //let availabledates2 =  JSON.stringify(result.availability);
505   let availabledates =  JSON.stringify(result.availability);
506   availabledates = availabledates.replace(/['"]+/g, '');
507   
508   //remove first comma from string
509   availabledates = availabledates.replace(/^,/, '');
510   availabledates = availabledates.replace(/^,/,'');
511
512   //remove last commna from string 
513   availabledates = availabledates.replace(/,\s*$/, "");
514   
515   //remove one extra comma when there is only one date per each location
516   availabledates = availabledates.replace(',,', ',');
517
518   //remove starting and ending comma from variable in javascript
519   availabledates = availabledates.replace(/^,|,$/g,'');
520
521   //remove duplicate dates from array
522   availabledates = Array.from(new Set(availabledates.split(','))).toString();
523
524   //order dates by the latest
525   let availabledatessort = availabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
526   console.log ("OICALL:"+ result.id + "--" + availabledatessort); 
527   //find the first date
528   let firstdate = availabledatessort.split(",")[0]
529   //add first date to the datetime attribute
530   let firstdateattr = [moment(firstdate).format('MMM D, YYYY')];
531          var itemValue = localStorage.getItem("insname");
532         if (insValue.indexOf("Medicare") >= 0) { 
533         $(this).attr('mcdatetime', firstdateattr);
534         $(this).attr('locdatetime', firstdateattr);   
535         } else {
536         $(this).attr('datetime', firstdateattr);
537         $(this).attr('locdatetime', firstdateattr);
538         }
539   
540   //switch to mm/dd format for os btn 
541   let firstdateforosbtn = [moment(firstdate).format('MMM D')];
542   //console.log((availabledatessort.split(",").length - 1));
543   //find 1st and 2nd dates and combime into one
544
545   // Count the number of commas in availabledates
546const countdates = (availabledates.match(/,/g) || []).length;
547
548// Declare seconddateforosbtn outside the block
549let seconddateforosbtn = "";
550
551if (countdates > 0) {   
552    let seconddate = availabledatessort.split(",")[1];
553    seconddateforosbtn = moment(seconddate).format('MMM D'); 
554}
555
556// Concatenate dates and remove the last comma if needed
557let inpersonalldates = `${firstdateforosbtn}${seconddateforosbtn ? ', ' + seconddateforosbtn : ''}`;
558
559console.log(inpersonalldates);
560   
561   //$(this).addClass("inperson-show");
562
563    //add inperson dates to os BTN
564
565const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
566const inpersonDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
567inpersonWrapperDiv.empty().append(inpersonDates);
568
569const locationWrapperDiv = $(this).find('.loc-date-wrapper');
570const locationDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
571locationWrapperDiv.empty().append(locationDates);
572$(this).find('.loc-date-wrapper').hide();
573
574
575
576} else {
577        $(this).attr('data-inpersonts', 'skip');
578        $(this).find('.EndScreenModalBtn').attr('data-inpersonts', 'skip');
579        
580        $(this).addClass("call-me");
581        $(this).removeClass("book-me");
582
583        var doctorPhone = $(this).attr('data-phone');
584var doctorPhoneNumber = doctorPhone.split('.').join("");
585var profilebtn = $(this).find('.btn-outline-primary');
586var profileUrl = profilebtn.attr('href');
587var modifiedUrl = profileUrl + '?osbtn=no';
588profilebtn.attr('href', modifiedUrl);
589
590$(this).find('.inperson-date-wrapper').hide();
591$(this).find('.loc-date-wrapper').hide();
592
593$(this).removeClass("dates-available");
594$(this).addClass("no-dates-available");
595
596$(this).find('.availability').text('Call for availability & booking')
597$(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
598
599} 
600
601} else if (($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
602   //$(this).find('.multi-os-checkbox').hide(); 
603}
604});   
605//});
606
607});
608  
609}
610// END OIC
611
612oicallpa() 
613
614
615//AAA uoc midtown PT
616var itemValue = localStorage.getItem("insname");
617
618if (insValue.indexOf("Medicare") >= 0)  { 
619var dataoicpt = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
620var  dataoicmcpt = Object.values(dataoicpt).filter(appointment => appointment.appointmentId === '1170000218') 
621} else {  
622var dataoicpt = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
623var dataoicmcpt = Object.values(dataoicpt).filter(appointment => appointment.appointmentId === '11700000136')
624}
625var dataoicallpt = Object.values(dataoicmc).filter(department => department.departmentId === '101033008')
626var mapByIdoicpt = dataoicallpt.reduce((acc, { id, availability, nameLastFirst }) => {  
627acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
628return acc;
629}, {})
630
631const resultArrayoicpt = Object.values(mapByIdoicpt);
632
633function oicallpt() {
634resultArrayoicpt.forEach((result) => {
635
636$('#search-results .element-item').each(function(){
637
638if (($(this).attr('dataosdefault') === '') && ($(this).attr('data-breadcrumb') == 'AAA UOC Midtown PT') && ($(this).attr('data-oic') ==='yes') && ($(this).hasClass("inpers
638on")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me")) ) { 
639console.log("fire oicall pt")          
640if ((result.id !=='11700123') && (result.availability !== '') && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {
641console.log("oicall-matched") 
642   $(this).addClass('inperson-available')
643   $(this).addClass('date-show')
644   $(this).addClass("inperson-show");   
645   //$(this).addClass("UpperEastSide");   
646   //$(this).addClass("UpperEastSide-show");   
647   $(this).addClass("Midtown-show");   
648   $(this).addClass("Midtown-show-show");
649   $(this).addClass("MCall-show");
650   $(this).addClass("NYCall-show");
651
652    $(this).addClass("book-me");
653    $(this).removeClass("call-me");
654
655   //let availabledates2 =  JSON.stringify(result.availability);
656   let availabledates =  JSON.stringify(result.availability);
657   availabledates = availabledates.replace(/['"]+/g, '');
658   
659   //remove first comma from string
660   availabledates = availabledates.replace(/^,/, '');
661   availabledates = availabledates.replace(/^,/,'');
662
663   //remove last commna from string 
664   availabledates = availabledates.replace(/,\s*$/, "");
665   
666   //remove one extra comma when there is only one date per each location
667   availabledates = availabledates.replace(',,', ',');
668
669   //remove starting and ending comma from variable in javascript
670   availabledates = availabledates.replace(/^,|,$/g,'');
671
672   //remove duplicate dates from array
673   availabledates = Array.from(new Set(availabledates.split(','))).toString();
674
675   //order dates by the latest
676   let availabledatessort = availabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
677   console.log ("OICALL:"+ result.id + "--" + availabledatessort); 
678   //find the first date
679   let firstdate = availabledatessort.split(",")[0]
680   //add first date to the datetime attribute
681   let firstdateattr = [moment(firstdate).format('MMM D, YYYY')];
682          var itemValue = localStorage.getItem("insname");
683         if (insValue.indexOf("Medicare") >= 0) { 
684         $(this).attr('mcdatetime', firstdateattr);
685         $(this).attr('locdatetime', firstdateattr);   
686         } else {
687         $(this).attr('datetime', firstdateattr);
688         $(this).attr('locdatetime', firstdateattr);
689         }
690   
691   //switch to mm/dd format for os btn 
692   let firstdateforosbtn = [moment(firstdate).format('MMM D')];
693   //console.log((availabledatessort.split(",").length - 1));
694   //find 1st and 2nd dates and combime into one
695
696   // Count the number of commas in availabledates
697const countdates = (availabledates.match(/,/g) || []).length;
698
699// Declare seconddateforosbtn outside the block
700let seconddateforosbtn = "";
701
702if (countdates > 0) {   
703    let seconddate = availabledatessort.split(",")[1];
704    seconddateforosbtn = moment(seconddate).format('MMM D'); 
705}
706
707// Concatenate dates and remove the last comma if needed
708let inpersonalldates = `${firstdateforosbtn}${seconddateforosbtn ? ', ' + seconddateforosbtn : ''}`;
709
710console.log(inpersonalldates);
711   
712   //$(this).addClass("inperson-show");
713
714    //add inperson dates to os BTN
715
716const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
717const inpersonDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
718inpersonWrapperDiv.empty().append(inpersonDates);
719
720const locationWrapperDiv = $(this).find('.loc-date-wrapper');
721const locationDates = 'In-person: <strong>' +inpersonalldates + '</strong>';
722locationWrapperDiv.empty().append(locationDates);
723$(this).find('.loc-date-wrapper').hide();
724
725
726
727} else {
728        $(this).attr('data-inpersonts', 'skip');
729        $(this).find('.EndScreenModalBtn').attr('data-inpersonts', 'skip');
730        
731        $(this).addClass("call-me");
732        $(this).removeClass("book-me");
733
734        var doctorPhone = $(this).attr('data-phone');
735var doctorPhoneNumber = doctorPhone.split('.').join("");
736var profilebtn = $(this).find('.btn-outline-primary');
737var profileUrl = profilebtn.attr('href');
738var modifiedUrl = profileUrl + '?osbtn=no';
739profilebtn.attr('href', modifiedUrl);
740
741$(this).find('.inperson-date-wrapper').hide();
742$(this).find('.loc-date-wrapper').hide();
743
744$(this).removeClass("dates-available");
745$(this).addClass("no-dates-available");
746
747$(this).find('.availability').text('Call for availability & booking')
748$(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
749
750} 
751
752} else if (($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
753   //$(this).find('.multi-os-checkbox').hide(); 
754}
755});   
756//});
757
758});
759  
760}
761// END OIC
762
763oicallpt() 
764
765function uoctelehealth() {
766//function vcall() {
767data.forEach((result) => {  
768
769$('#search-results .element-item').each(function(){
770
771  if (result.availability === '') { 
772   //if there is no availability for both in-person or vc
773   $(this).addClass("call-me");
774   $(this).removeClass("book-me");
775   $(this).addClass("no-dates-available");
776   $(this).removeClass('date-show')
777   $(this).removeClass("inperson");
778  }  
779
780  if (($(this).attr('data-providerid') == result.id) && ($(this).hasClass("Visb")) && ($(this).hasClass("yesoscondition"))  ) {  
781
782//vc                
783//if ((result.availability !== '') && (result.id !== '11700123') && (result.locationName ==='VIRTUAL') && (result.appointmentId ==='11700000132') && (result.availability != null) && (result.availability.length > 0)) {
784if ((result.id ==='11700123') && (result.availability !== '') && (result.departmentId ==='VIRTUAL') && (result.appointmentId !=='11700000132') && (result.availability != null) && (result.availability.length > 0)) {
785
786   let vcavailabledates =  JSON.stringify(result.availability);
787   vcavailabledates= vcavailabledates.replace(/['"]+/g, '');
788   vcavailabledates= vcavailabledates.replace('[', '');
789   vcavailabledates= vcavailabledates.replace(']', '');
790   //remove last commna from string 
791   vcavailabledates = vcavailabledates.replace(/,\s*$/, "");
792   //console.log(vcavailabledates); 
793
794   //find the first date
795   let vcfirstdate = vcavailabledates.split(",")[0]
796   //add first date to the datetime attribute
797   let vcfirstdateattr = [moment(vcfirstdate).format('MMM D, YYYY')];
798   $(this).attr('vcdatetime', vcfirstdateattr);
799   
800   //switch to mm/dd format for os btn 
801   let vcfirstdateforosbtn = [moment(vcfirstdate).format('MMM D')];
802   //console.log((availabledatessort.split(",").length - 1));
803   //find 1st and 2nd dates and combine into one
804
805   const vccountdates = [...vcavailabledates].filter(l => l === ',').length;
806   if (vccountdates == 0) {
807   vcseconddateforosbtn = ""; 
808   } else {   
809   let vcseconddate = vcavailabledates.split(",")[1]
810   vcseconddateforosbtn = [moment(vcseconddate).format('MMM D')]; 
811   } 
812   let vcalldates = vcfirstdateforosbtn + ", " + vcseconddateforosbtn
813   //remove last commna from string 
814   vcalldates = vcalldates.replace(/,\s*$/, "");    
815
816   $(this).addClass("vis-b-show");    
817   $(this).removeClass("no-dates-available");
818   $(this).addClass("vc-dates-available");
819
820   $(this).addClass("MCall-show");
821
822   //add vc dates to os BTN
823
824const vcWrapperDiv = $(this).find('.vc-date-wrapper');
825const vcDates = 'Virtual: <strong>' +vcalldates + '</strong>';
826vcWrapperDiv.empty().append(vcDates);
827
828
829   if ( (!$(this).hasClass('inperson-available')) && (!$(this).hasClass('OS_off_Call_on')) )  {
830   $(this).attr('datetime', vcfirstdateattr);
831   $(this).attr('locdatetime',vcfirstdateattr);
832    }
833
834    if ($(this).hasClass('OS_off_Call_on'))  {
835      $(this).removeClass('vis-b-show');
836      $(this).removeClass('dates-available');
837      $(this).addClass('no-dates-available');
838
839      $(this).attr('vcdatetime','2104-03-05');
840       var i = 1;
841       var newID= moment().add(30000, 'days').format('YYYY-MM-DD');
842        $(this).attr('vcdatetime',newID);
843       $(this).val(i);
844    }
845  
846}
847
848}
849});
850
851});
852
853}
854
855uoctelehealth() 
856
857
858//medicare all
859//filter to extract virtual 
860const datamc = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
861//const datamc2 = Object.values(datamc).filter(department => department.locationName !== 'HSS Ortho Injury Care')
862//const datamc3 = Object.values(datamc2).filter(appointment => appointment.appointmentId === '333')
863const datamc3 = Object.values(datamc).filter(appointment => appointment.appointmentId === '1170000218')
864//const datanoempty = Object.values(data2).filter(availability2 => availability2.availability !== '')
865const mapByIdmc = datamc3.reduce((acc, { id, availability }) => {  
866acc[id] = { id, availability: (acc[id] ? acc[id].availability + ",": "") + `${availability}`}
867return acc;
868}, {})
869//mapById  = mapById.replace(/^,/, '');
870const resultArraymc = Object.values(mapByIdmc);
871
872//medicare all
873
874//var afterdate= moment().add(90, 'days').format('M/D');
875
876function medicareall() {       
877 resultArraymc.forEach((result) => {
878
879  $('#search-results .element-item').each(function(){
880
881  if (($(this).attr('dataosdefault') === '') && ( ($(this).attr('data-oic') ==='') || ($(this).attr('data-oic') ==='yes') ) && ($(this).attr('data-providerid') == result.id) && !($(this).hasClass("out-of-network-call")) && !$(this).hasClass("hasCall") && ($(this).hasClass("inpers
881on")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') &&  ($(this).hasClass("yesoscondition")) && ($(this).attr('data-forclearfilter') !== 'call-me') ) { 
882
883if ((result.id !=='11700123') && (result.availability !== '')  && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {
884
885     $(this).addClass('inperson-available')
886     $(this).addClass("MCall-show");
887     $(this).addClass('date-show');
888     $(this).addClass("book-me");
889        $(this).removeClass("call-me");
890
891     let mcavailabledates2 =  JSON.stringify(result.availability);
892     let mcavailabledates =  JSON.stringify(result.availability);
893     mcavailabledates = mcavailabledates.replace(/['"]+/g, '');
894     //remove last commna from string 
895     mcavailabledates = mcavailabledates.replace(/,\s*$/, "");
896     
897     //remove first comma from string
898     mcavailabledates = mcavailabledates.replace(/^,/, '');
899     mcavailabledates = mcavailabledates.replace(/^,/,'');
900
901     //remove one extra comma when there is only one date per each location
902     mcavailabledates = mcavailabledates.replace(',,', ',');
903          //remove starting and ending comma from variable in javascript
904     mcavailabledates = mcavailabledates.replace(/^,|,$/g,'');
905     console.log (result.id + '-' + mcavailabledates); 
906
907     //console.log(availabledates2)
908     
909     //order dates by the latest
910     let mcavailabledatessort = mcavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
911     //availabledatessort = availabledatessort + ",";
912     //console.log (availabledatessort); 
913
914     //find the first date
915     let mcfirstdate = mcavailabledatessort.split(",")[0]
916     //add first date to the datetime attribute
917     //if ((firstdate !== ' ') || (firstdate !== null) || (firstdate.length > 0)) {
918     let mcfirstdateattr = [moment(mcfirstdate).format('MMM D, YYYY')];
919     $(this).attr('mcdatetime', mcfirstdateattr);
920     //}
921     
922     //switch to mm/dd format for os btn 
923     let mcfirstdateforosbtn = [moment(mcfirstdate).format('MMM D')];
924     //console.log((availabledatessort.split(",").length - 1));
925     //find 1st and 2nd dates and combime into one
926     
927     let mcseconddateforosbtn = ""; 
928
929     const mccountdates = [...mcavailabledates].filter(l => l === ',').length;
930     if (mccountdates == 0) {
931     mcseconddateforosbtn = ""; 
932     } else {   
933     let mcseconddate = mcavailabledatessort.split(",")[1]
934     mcseconddateforosbtn = [moment(mcseconddate).format('MMM D')]; 
935     } 
936     let mcinpersonalldates = mcfirstdateforosbtn + ", " + mcseconddateforosbtn
937     //remove last commna from string 
938     mcinpersonalldates = mcinpersonalldates.replace(/,\s*$/, "");    
939
940
941      
942      //add inperson dates to os BTN
943
944const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
945const inPersonDates = 'In-person: <strong>' +mcinpersonalldates + '</strong>';
946inpersonWrapperDiv.empty().append(inPersonDates);
947
948$(this).find('.inperson-date-wrapper').show();
949$(this).find('.loc-date-wrapper').hide();
950$(this).find('.availability').text('Next available appointments:');
951$(this).find('.btn-primary').show();
952$(this).find('.btn-primary-filtered').remove();
953
954} 
955
956} else if (($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
957   //$(this).find('.multi-os-checkbox').hide(); 
958}
959
960  });   
961 
962 });
963
964$('#search-results .element-item').each(function(){
965  if ( $(this).hasClass("MCall-show") && !$(this).hasClass("hasCall") ) {
966
967           $(this).removeClass('call-me')  
968           $(this).addClass('book-me') 
969           $(this).find('.inperson-date-wrapper').show();
970          $(this).find('.loc-date-wrapper').hide();
971
972           $(this).removeClass("no-dates-available");
973           $(this).addClass("dates-available");
974           $(this).addClass("inperson"); 
975  } else {  
976          $(this).removeClass('book-me')  
977          $(this).addClass('call-me') 
978
979          var doctorPhone = $(this).attr('data-phone');
980var doctorPhoneNumber = doctorPhone.split('.').join("");
981var profilebtn = $(this).find('.btn-outline-primary');
982var profileUrl = profilebtn.attr('href');
983var modifiedUrl = profileUrl + '?osbtn=no';
984profilebtn.attr('href', modifiedUrl);
985
986$(this).find('.inperson-date-wrapper').hide();
987$(this).find('.loc-date-wrapper').hide();
988
989$(this).removeClass("dates-available");
990$(this).addClass("no-dates-available");
991
992$(this).find('.availability').text('Call for availability & booking')
993$(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
994
995  }
996
997if ( !$(this).hasClass("MCall-show") && $(this).hasClass("vis-b-show") && !$(this).hasClass("hasCall") ) {
998$(this).removeClass('call-me')  
999$(this).addClass('book-me') 
1000$(this).find('.inperson-date-wrapper').hide();
1001$(this).attr('mcdatetime', '2103-12-12');
1002}  
1003
1004
1005});
1006
1007    var $grid = $('.grid');
1008    $grid.isotope({
1009    itemSelector: '.element-item',
1010    filter: function() {
1011      return !$(this).hasClass('hide-me');
1012    },
1013    layoutMode: 'fitRows',
1014    fitRows: {
1015      gutter: 0
1016    },
1017    transitionDuration: 0,
1018    getSortData: {
1019      priority: function(element) {
1020      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1021      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1022        priority = 0;
1023      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1024        priority = 1;
1025      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1026        priority = 2;
1027      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1028        priority = 3;
1029      }
1030      return priority;
1031    },
1032      bymcDate: function ($elem3) {
1033            return Date.parse($($elem3).attr('mcdatetime'));
1034      },
1035      providerName: '[data-breadcrumb]'
1036    },
1037    sortAscending: true,
1038    sortBy: ['priority', 'bymcDate', 'providerName'] 
1039  });
1040  
1041  $grid.isotope('updateSortData').isotope();
1042
1043}
1044
1045if (insValue.indexOf("Medicare") >= 0) { 
1046console.log("fire medicare api")   
1047medicareall()
1048}
1049
1050//medicare all end
1051
1052//medicare default - This api is for docs who have multi profiles such as dr.McElheny. Multi profile doc needs to show os for specific location only in the result instead of showing 'inpersonall' api which combines all locations. 
1053//var afterdate= moment().add(90, 'days').format('M/D');
1054function medicaredefault() {
1055data.forEach((result) => {
1056
1057$('#search-results .element-item').each(function(){
1058
1059if (($(this).attr('dataosdefault') == 'yes') && ( ($(this).attr('data-oic') ==='') || ($(this).attr('data-oic') ==='yes') ) && ($(this).attr('data-providerid') == result.id) && ($(this).hasClass("inpers
1059on")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && !$(this).hasClass("hasCall") && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me")) ) {  
1060  //alert("yes");
1061  var defaultlocationvalue = $(this).attr('dataosdefault');
1062  var docname = $(this).attr('data-breadcrumb');
1063
1064  if ((result.id !=='11700123') && (result.availability !== '') && (result.appointmentId === '1170000218') && (result.locationName !== 'VIRTUAL') && (result.nameLastFirst === docname) && (result.availability != null) && (result.availability.length > 0) && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {   
1065     $(this).addClass('inperson-available')
1066     $(this).addClass("MCall-show");
1067     $(this).addClass('date-show');
1068   let mcavailabledates =  JSON.stringify(result.availability);
1069   mcavailabledates = mcavailabledates.replace(/['"]+/g, '');
1070   mcavailabledates=  mcavailabledates.replace('[', '');
1071   mcavailabledates=  mcavailabledates.replace(']', '');
1072   //remove last commna from string 
1073   mcavailabledates = mcavailabledates.replace(/,\s*$/, "");
1074   
1075   //remove first comma from string
1076   mcavailabledates = mcavailabledates.replace(/^,/, '');
1077   mcavailabledates = mcavailabledates.replace(/^,/,'');
1078
1079   //remove one extra comma when there is only one date per each location
1080   mcavailabledates = mcavailabledates.replace(',,', ',');
1081   //console.log (result.id + availabledates); 
1082
1083   //console.log(availabledates)
1084   
1085   //order dates by the latest
1086   let mcavailabledatessort = mcavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
1087   //availabledatessort = availabledatessort + ",";
1088   //console.log (availabledatessort); 
1089
1090   //find the first date
1091   let mcfirstdate = mcavailabledatessort.split(",")[0]
1092   //add first date to the datetime attribute
1093   //if ((firstdate !== ' ') || (firstdate !== null) || (firstdate.length > 0)) {
1094   mcfirstdateattr = [moment(mcfirstdate).format('MMM D, YYYY')];
1095   $(this).attr('mcdatetime', mcfirstdateattr);
1096   //}
1097   
1098   //switch to mm/dd format for os btn 
1099   mcfirstdateforosbtn = [moment(mcfirstdate).format('MMM D')];
1100   //console.log((availabledatessort.split(",").length - 1));
1101   //find 1st and 2nd dates and combime into one
1102
1103   const mccountdates = [...mcavailabledates].filter(l => l === ',').length;
1104   if (mccountdates == 0) {
1105   mcseconddateforosbtn = ""; 
1106   } else {   
1107   let mcseconddate = mcavailabledatessort.split(",")[1]
1108   mcseconddateforosbtn = [moment(mcseconddate).format('MMM D')]; 
1109   } 
1110   let mcinpersonalldates = mcfirstdateforosbtn + ", " + mcseconddateforosbtn
1111   //remove last commna from string 
1112   mcinpersonalldates = mcinpersonalldates.replace(/,\s*$/, "");    
1113
1114     //add inperson dates to os BTN
1115
1116const inpersonWrapperDiv = $(this).find('.inperson-date-wrapper');
1117const inPersonDates = 'In-person: <strong>' +mcinpersonalldates + '</strong>';
1118inpersonWrapperDiv.empty().append(inPersonDates);
1119
1120$(this).find('.inperson-date-wrapper').show();
1121$(this).find('.loc-date-wrapper').hide();
1122      
1123   } else if ((result.id !=='11700123') && (result.availability === '') && (result.appointmentId === '1170000218') && (result.locationName !== 'VIRTUAL') && (result.nameLastFirst === docname) && (result.availability != null) && (result.availability.length > 0) && (result.availability !== ',,') && (result.availability !== ',,,') && (result.availability !== ',,,,')) {   
1124               $(this).attr('data-inpersonts', 'skip');
1125               $(this).find('.EndScreenModalBtn').attr('data-inpersonts', 'skip');
1126
1127               var doctorPhone = $(this).attr('data-phone');
1128var doctorPhoneNumber = doctorPhone.split('.').join("");
1129var profilebtn = $(this).find('.btn-outline-primary');
1130var profileUrl = profilebtn.attr('href');
1131var modifiedUrl = profileUrl + '?osbtn=no';
1132profilebtn.attr('href', modifiedUrl);
1133
1134$(this).find('.inperson-date-wrapper').hide();
1135$(this).find('.loc-date-wrapper').hide();
1136
1137$(this).removeClass("dates-available");
1138$(this).addClass("no-dates-available");
1139
1140$(this).find('.availability').text('Call for availability & booking')
1141$(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
1142
1143  } 
1144
1145} else if (($(this).attr('dataosdefault') == 'yes') && ($(this).attr('data-providerid')) == result.id && (!$(this).hasClass("yesoscondition"))) {  
1146   //$(this).find('.multi-os-checkbox').hide(); 
1147
1148}
1149});   
1150});
1151
1152    var $grid = $('.grid');
1153    $grid.isotope({
1154    itemSelector: '.element-item',
1155    filter: function() {
1156      return !$(this).hasClass('hide-me');
1157    },
1158    layoutMode: 'fitRows',
1159    fitRows: {
1160      gutter: 0
1161    },
1162    transitionDuration: 0,
1163    getSortData: {
1164      priority: function(element) {
1165      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1166      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1167        priority = 0;
1168      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1169        priority = 1;
1170      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1171        priority = 2;
1172      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1173        priority = 3;
1174      }
1175      return priority;
1176    },
1177      bymcDate: function ($elem3) {
1178            return Date.parse($($elem3).attr('mcdatetime'));
1179      },
1180      providerName: '[data-breadcrumb]'
1181    },
1182    sortAscending: true,
1183    sortBy: ['priority', 'bymcDate', 'providerName'] 
1184  });
1185  
1186  $grid.isotope('updateSortData').isotope();
1187
1188}
1189
1190if (insValue.indexOf("Medicare") >= 0) { 
1191console.log("fire medicaredefault api")   
1192medicaredefault()
1193}
1194//medicare-default end
1195
1196
1197
1198function vcall() {
1199data.forEach((result) => {  
1200
1201$('#search-results .element-item').each(function(){
1202
1203  if (result.availability === '') { 
1204   //if there is no availability for both in-person or vc
1205
1206   $(this).addClass("call-me");
1207   $(this).removeClass("book-me");
1208   $(this).addClass("no-dates-available");
1209   $(this).removeClass('date-show')
1210   $(this).removeClass("inperson");
1211   $(this).attr("data-os", "");
1212  }  
1213
1214  if (($(this).attr('data-providerid') == result.id) && ($(this).hasClass("Visb")) && ($(this).attr('data-breadcrumb') !== 'AAA UOC Telehealth') && ($(this).hasClass("yesoscondition")) && (!$(this).hasClass("call-me")) ) {  
1215
1216//vc                
1217if ((result.availability !== '') && (result.departmentId ==='VIRTUAL') && (result.appointmentId !=='11700000131') && (result.availability != null) && (result.availability.length > 0)) {
1218
1219   let vcavailabledates =  JSON.stringify(result.availability);
1220   vcavailabledates= vcavailabledates.replace(/['"]+/g, '');
1221   vcavailabledates= vcavailabledates.replace('[', '');
1222   vcavailabledates= vcavailabledates.replace(']', '');
1223   //remove last commna from string 
1224   vcavailabledates = vcavailabledates.replace(/,\s*$/, "");
1225   console.log("vc-" + vcavailabledates); 
1226
1227   //find the first date
1228   let vcfirstdate = vcavailabledates.split(",")[0]
1229   //add first date to the datetime attribute
1230   let vcfirstdateattr = [moment(vcfirstdate).format('MMM D, YYYY')];
1231   $(this).attr('vcdatetime', vcfirstdateattr);
1232   
1233   //switch to mm/dd format for os btn 
1234   let vcfirstdateforosbtn = [moment(vcfirstdate).format('MMM D')];
1235   //console.log((availabledatessort.split(",").length - 1));
1236   //find 1st and 2nd dates and combine into one
1237
1238// Count the number of commas in vcavailabledates correctly
1239const vccountdates = (vcavailabledates.match(/,/g) || []).length;
1240
1241// Extract the first date
1242vcfirstdate = vcavailabledates.split(",")[0];
1243vcfirstdateforosbtn = moment(vcfirstdate).format('MMM D');
1244
1245// Declare vcseconddateforosbtn before the conditional block
1246let vcseconddateforosbtn = "";
1247
1248if (vccountdates > 0) {   
1249    let vcseconddate = vcavailabledates.split(",")[1];
1250    vcseconddateforosbtn = moment(vcseconddate).format('MMM D');
1251}
1252
1253// Concatenate dates and remove the last comma if needed
1254let vcalldates = `${vcfirstdateforosbtn}${vcseconddateforosbtn ? ', ' + vcseconddateforosbtn : ''}`;
1255
1256console.log(vcalldates); // Check the output
1257
1258   $(this).addClass("vis-b-show");    
1259   $(this).removeClass("no-dates-available");
1260   $(this).addClass("vc-dates-available");
1261
1262   //add vc dates to os BTN
1263
1264const vcWrapperDiv = $(this).find('.vc-date-wrapper');
1265const vcDates = 'Virtual: <strong>' +vcalldates + '</strong>';
1266vcWrapperDiv.empty().append(vcDates);
1267
1268
1269   if ( (!$(this).hasClass('inperson-available')) && (!$(this).hasClass('OS_off_Call_on')) )  {
1270   $(this).attr('datetime', '2103-12-12');
1271    }
1272
1273    if ($(this).hasClass('OS_off_Call_on'))  {
1274      $(this).removeClass('vis-b-show');
1275      $(this).removeClass('dates-available');
1276      $(this).addClass('no-dates-available');
1277
1278      $(this).attr('vcdatetime','2104-03-05');
1279       var i = 1;
1280       var newID= moment().add(30000, 'days').format('YYYY-MM-DD');
1281        $(this).attr('vcdatetime',newID);
1282       $(this).val(i);
1283    }
1284  
1285}
1286
1287}
1288});
1289
1290});
1291//alert("call vcall function"); 
1292}
1293
1294//vcall() 
1295
1296
1297// Generate list of state licensures from XML
1298function VCStateLicensure() {
1299var selectSL = document.getElementById("selectStateLicensure");
1300var checkboxSL = document.getElementById("hidden-sl-checkboxes");
1301var virtualcareOpt = document.getElementById("virtualcareOpt");
1302var states = {};
1303$('.element-item:visible').each(function() {
1304  if ( ($(this).attr('data-statelicensure')) != "" && ($(this).hasClass('TelehealthYes')) ) {
1305    states[$(this).attr('data-statelicensure')] = true;
1306  }
1307});
1308var result = new Array();
1309for(var i in states) {
1310    result.push(i);
1311}
1312var newresult = result.join();
1313var unique = newresult.split(',');
1314var slSort = Array.from(new Set(unique));
1315var sl = slSort.sort();
1316
1317selectSL.innerHTML = '<option value=".TelehealthYes" disabled selected hidden>Please select a state</option>';
1318
1319
1320for (var i = 0; i < sl.length; i++) {
1321        var opt = sl[i];
1322        if (opt.trim() !== "") {
1323            var el = document.createElement("option");
1324            el.textContent = opt;
1325            //el.value = "." + (opt.replace(/\s+/g, '')) + ".vis-b-show";
1326            el.value = ".TelehealthYes";
1327            el.setAttribute('data-vcstate', opt)
1328            selectSL.appendChild(el);
1329        }
1330    }
1331
1332
1333 if (selectSL.options.length <= 1) {
1334        //selectSL.disabled = true;
1335        virtualcareOpt.disabled = true
1336    } else {
1337        //selectSL.disabled = false;
1338        virtualcareOpt.disabled = false
1339    }
1340
1341
1342
1343
1344}
1345
1346setTimeout(VCStateLicensure, 200)
1347
1348// if card has a 'book-me' class but there are no dates then switch to call
1349function switchProfileCard() {
1350  var locations = ['AAA UOC Stamford', 'AAA UOC Westchester', 'AAA UOC Uniondale', 'AAA UOC Midtown', 'AAA UOC Telehealth'];
1351  var insname = localStorage.getItem('insname');
1352
1353  $('#search-results .element-item').each(function() {
1354    var $this = $(this);
1355    
1356     if (insValue.indexOf("Medicare") >= 0) { 
1357      var datetime = $this.attr('mcdatetime'); 
1358    } else {
1359      var datetime = $this.attr('datetime'); 
1360    }
1361    
1362    var breadcrumb = $this.attr('data-breadcrumb');
1363
1364    if ( $this.hasClass('book-me') && $this.attr('data-externalLink') === '' && (!datetime || datetime.trim() === '') && !$this.hasClass('vc-dates-available') ) {
1365      var doctorDataPhone = $this.attr('data-phone');
1366      var doctorPhone = $this.attr('data-phone').split('.').join('');
1367      var profilebtn = $this.find('.btn-outline-primary');
1368      var profileUrl = profilebtn.attr('href');
1369      var modifiedUrl = profileUrl + '?osbtn=no';
1370
1371      $this.removeClass('book-me').addClass('call-me');
1372      $this.find('.btn-outline-primary').attr('href', modifiedUrl);
1373      $this.find('.inperson-date-wrapper, .loc-date-wrapper').hide();
1374      $this.removeClass('dates-available').addClass('no-dates-available');
1375      $this.find('.availability').text('Call for availability & booking');
1376      $this.find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1' + doctorPhone + '">Call ' + doctorDataPhone + '</a>');
1377    }
1378
1379    if (insname && ['Aetna_Medicare_PPO', 'Medicaid', 'Cigna', 'MultiPlan_PHCS'].includes(insname) && locations.includes(breadcrumb)) {
1380      $this.removeClass('book-me call-me').addClass('hide-me');
1381    }
1382
1383
1384
1385          if (insname === 'Medicaid' && !breadcrumb.includes('Clinic')) {
1386          $this.removeClass('book-me call-me').addClass('hide-me');
1387        }
1388    
1389
1390    //if ((locations.includes(breadcrumb) || breadcrumb === 'AAA Ortho Injury Care') && $this.hasClass('call-me')) {
1391      //$this.removeClass('call-me').addClass('hide-me');
1392    //}
1393
1394    var classesToAdd = [];
1395
1396    if ($this.hasClass('book-me')) {
1397        classesToAdd.push('book-me');
1398    }
1399    
1400    if ($this.hasClass('hide-me')) {
1401        classesToAdd.push('hide-me');
1402    }
1403    
1404    if ($this.hasClass('call-me')) {
1405        classesToAdd.push('call-me');
1406    }
1407
1408    if (classesToAdd.length > 0) {
1409        $this.attr('data-forclearfilter', classesToAdd.join(' '));
1410    } else {
1411        $this.attr('data-forclearfilter', 'none');
1412    }
1413
1414  });
1415}
1416
1417
1418switchProfileCard() 
1419
1420//setTimeout(function() {
1421  //initializeIsotope(revealGrid);
1422//}, 100);
1423
1424//function revealGrid() {
1425 // hideLoadingScreen();
1426//}
1427
1428
1429function revealGrid() {
1430 var filterCounter = document.getElementById("filter-count");
1431  var loader = document.getElementById("loader");
1432  var container = document.getElementById('grid-wrapper');
1433  var searchHeadingBox = document.getElementById('search_content_heading_box')
1434  container.style.visibility = 'visible';
1435 loader.style.display = "none";
1436  filterCounter.style.display = "block";
1437  searchHeadingBox.style.display = "block";
1438  }
1439
1440  initializeIsotope(revealGrid); // only call when you're really ready
1441
1442
1443function initializeIsotope(callback) {
1444
1445  var selectedInsuranceOption = localStorage.getItem("insname");
1446  var selectedCondition = localStorage.getItem("condition-linksource");
1447  var searchType = localStorage.getItem('searchType'); 
1448  var $grid = $('.grid');
1449  
1450  function preselectPanelOptions() {
1451  // Get the selected value from the #panel_rx_selector dropdown
1452  var selectedPanelValue = $('#panel_rx_selector').val();
1453  // Preselect matching option in the #panel-pt-filter dropdown
1454  $('#panel-pt-filter option').each(function() {
1455   var optionValue = $(this).val();
1456   if (optionValue === selectedPanelValue) {
1457     $(this).prop('selected', true).change();
1458     $('#panel-pt-filter').addClass('selected-filter-option');
1459   }
1460  });
1461  console.log('preselect pt panel')
1462  }
1463  
1464  if (searchType === 'PT') {
1465  setTimeout(preselectPanelOptions, 200);
1466  } else if (searchType === 'MD') {
1467  $('#panel-pt-filter option:selected').prop('selected', false);
1468  $('#panel-pt-filter').removeClass('selected-filter-option');
1469  }
1470  
1471  function countVisibleElements() {
1472  const elements = document.getElementsByClassName('element-item');
1473  let visibleElementCount = 0;
1474  
1475  for (let i = 0; i < elements.length; i++) {
1476   const element = elements[i];
1477  
1478   // Skip elements with the class name '.hide-me'
1479   if (element.classList.contains('hide-me')) {
1480     continue;
1481   }
1482  
1483   if (element.offsetWidth > 0 && element.offsetHeight > 0) {
1484     visibleElementCount++;
1485   }
1486  }
1487  return visibleElementCount;
1488  console.log('elements counted')
1489  }
1490  
1491  const insName = localStorage.getItem("insname");
1492  if (insName && insName !== 'unselect') {    
1493  $grid.find('.element-item').each(function() {
1494   var insuranceAttribute = $(this).attr('data-insurance');
1495   var insuranceValues = insuranceAttribute.split(",");
1496   var $shadowDesktop = $(this).find('.shadow-desktop');
1497   var mcoptoutvalue = $(this).attr('data-mcoptout');
1498  
1499   $shadowDesktop.find('.insurance-in-network, .insurance-out-of-network').remove();
1500   $shadowDesktop.removeClass('in-network-provider');
1501   $shadowDesktop.removeClass('out-of-network-provider');
1502  
1503   if (insuranceValues.includes(selectedInsuranceOption)) {
1504     $(this).addClass('innetwork');
1505     $shadowDesktop.append('<div class="insurance-in-network">In network</div>');
1506     $shadowDesktop.addClass('in-network-provider');
1507   } else {
1508     $(this).addClass('outofnetwork');
1509     //add opt-out rule
1510     if ((selectedInsuranceOption.indexOf("Medicare") >= 0) && ((mcoptoutvalue == "Opt Out"))) {
1511     $shadowDesktop.append('<div class="insurance-out-of-network">Not Accepting</div>');
1512     $shadowDesktop.addClass('out-of-network-provider');
1513     $(this).addClass('hide-me')
1514     $(this).removeClass('book-me')
1515     $(this).removeClass('call-me')
1516     } else {  
1517     $shadowDesktop.append('<div class="insurance-out-of-network">Out of network</div>');
1518     $shadowDesktop.addClass('out-of-network-provider');
1519     }
1520   }
1521  });
1522  } else {
1523   $grid.find('.element-item').each(function() {
1524   $(this).addClass('innetwork');
1525   });
1526  }
1527  
1528  if (insName && insName !== 'unselect') {  
1529   $grid.isotope({
1530   itemSelector: '.element-item',
1531   filter: function() {
1532     return !$(this).hasClass('hide-me');
1533   },
1534   layoutMode: 'fitRows',
1535   fitRows: {
1536     gutter: 0
1537   },
1538   transitionDuration: 0,
1539     getSortData: {
1540   priority: function(element) {
1541     var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1542     if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1543       priority = 0;
1544     } else if (($(element).hasClass('outofnetwork')) && (!$(element).hasClass('out-of-network-call')) && ($(element).hasClass('book-me'))) {
1545       priority = 1;
1546     } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1547       priority = 2;
1548     } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1549       priority = 3;
1550     } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('optout-me'))) {
1551       priority = 4;  
1552     }
1553     return priority;
1554   },
1555   byDate: function ($elem1) {
1556           //if (selectedInsuranceOption === 'Medicare' || selectedInsuranceOption === 'Aetna_Medicare_PPO' || selectedInsuranceOption === 'EmblemHealth_Medicare' || selectedInsuranceOption === 'Oxford_Medicare' || selectedInsuranceOption === 'UHC_Medicare_HMO' || selectedInsuranceOption === 'UHC_Medicare_PPO') {
1557           if (selectedInsuranceOption.indexOf("Medicare") >= 0) {
1558               return Date.parse($($elem1).attr('mcdatetime'));
1559           } else {
1560               return Date.parse($($elem1).attr('datetime'));
1561           }
1562       },
1563   byvcDate: function ($elem2) {
1564     return Date.parse($($elem2).attr('vcdatetime'));
1565   },
1566  
1567   providerName: '[data-breadcrumb]'
1568  },
1569  sortAscending: true,
1570  sortBy: ['priority', 'byDate', 'byvcDate', 'providerName']
1571  });
1572  } else {
1573  $grid.isotope({
1574   itemSelector: '.element-item',
1575   filter: function() {
1576     return !$(this).hasClass('hide-me');
1577   },
1578   layoutMode: 'fitRows',
1579   fitRows: {
1580     gutter: 0
1581   },
1582   transitionDuration: 0,
1583     getSortData: {
1584   priority: function(element) {
1585     var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1586     if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1587       priority = 0;
1588     } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1589       priority = 1;
1590     } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1591       priority = 2;
1592     } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1593       priority = 3;
1594     } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('optout-me'))) {
1595       priority = 4;  
1596     }
1597     return priority;
1598   },
1599   providerName: '[data-breadcrumb]'
1600  },
1601  sortAscending: true,
1602  sortBy: ['priority', 'providerName']
1603  });
1604  }
1605  
1606  // Update the filter count display
1607  var selectedInsuranceLabelOption = localStorage.getItem("insnamelabel");
1608  var insuranceText = (selectedInsuranceLabelOption && selectedInsuranceLabelOption !== "unselect") 
1609  ? " and <strong>'" + selectedInsuranceLabelOption + "'</strong>" 
1610  : "";
1611
1612  $('#filter-count').html("Showing <strong>" + countVisibleElements() + "</strong> specialists for <strong>'" + selectedCondition + "'</strong>" + insuranceText);
1613  
1614  $grid.on('arrangeComplete', function() {
1615   //if (searchType !== 'FAD') {
1616   //clearSFSelections()
1617   //}
1618  });
1619  $grid.isotope('updateSortData').isotope();
1620  
1621  console.log('iso init complete')
1622  callback();
1623  }
1624
1625 //fire virtual care screening modal
1626$('.vis-checkbox-opt').on('change', function() {
1627      if(this.checked) {
1628        $('#VCScreeningModal').modal('show');
1629        $('#compareSection').removeClass('d-lg-block');
1630        $('#compareSection').hide();
1631      } else {
1632        $('.vis-checkbox').prop( "checked", false );  
1633        $('#VCScreeningModal').modal('hide');
1634        $('.inperson-date-wrapper').hide();
1635        $('.vc-date-wrapper').hide();
1636        $('#compareSection').addClass('d-lg-block');
1637        $('#compareSection').show();
1638        $('.vis-checkbox').prop( "checked", false ).change();  
1639      }
1640});
1641
1642//fire vc again when user checks the checkboxes
1643
1644$('.vis-checkbox, .vis-checkbox-opt').on('change', function() {
1645    console.log("vis-checkbox checked")
1646    applyFilters();
1647    updateVCFilterCount();
1648});
1649
1650function applyFilters() {
1651    var selectedStateVal = $('#selectStateLicensure option:selected').val();
1652    var selectedSL = $('#selectStateLicensure option:selected').attr('data-vcstate');
1653    var selectedInsuranceOption = localStorage.getItem("insname");
1654    var isChecked = $('.vis-checkbox').is(':checked');
1655    var $grid = $('.grid');
1656
1657    if (isChecked) {
1658        $('#select').prop('selectedIndex', 0);
1659
1660        $('.vc-date-wrapper').show();
1661        $('.inperson-date-wrapper').hide();
1662        $('.loc-date-wrapper').hide();
1663        $(this).attr("data-sl", selectedStateVal)
1664        $('#VCScreeningModal').attr('data-vcstateselected', selectedStateVal)
1665        $('#VCScreeningModal').modal('hide');
1666
1667        var locationFilterValue = $('#location-filter').val();
1668        var languageFilterValue = $('#language-filter').val();
1669        var specialtyFilterValue = $('#specialty-filter').val();
1670        //var panelFilterValue = $('#panel-md-filter, #panel-pt-filter').val();
1671        var genderFilterValue = $('#gender-filter').val();
1672
1673        $grid.data('isotope').filteredItems = [];
1674        var filterString = locationFilterValue + languageFilterValue + specialtyFilterValue + genderFilterValue;
1675        var defaultFilter = (!$(this).hasClass('hide-me') && $(this).is(filterString));
1676
1677        $('#search-results .element-item').each(function() {
1678            var stateLicensure = $(this).data('statelicensure');
1679            if (stateLicensure) {
1680                var stateLicensureArray = stateLicensure.split(',');
1681                if ($(this).hasClass('vc-dates-available') && !$(this).hasClass('hide-me') && stateLicensureArray.includes(selectedSL.trim())) {
1682                    $(this).addClass('stv');
1683                }
1684            }
1685
1686            var doctorPhone = $(this).attr('data-phone');
1687            var doctorPhoneNumber = doctorPhone.split('.').join("");
1688            $(this).find('.inperson-date-wrapper').hide();
1689            $(this).find('.loc-date-wrapper').hide();
1690            $(this).find('.specialist-primary-button').hide();
1691            $(this).find('.specialist-schedules').hide();
1692
1693            //$(this).removeClass("dates-available");
1694            //$(this).addClass("no-dates-available");
1695            // Create the new call-btn div
1696            // Create the new call div
1697
1698            $(this).find('.specialist-primary-button2, .specialist-schedules2').remove();
1699
1700
1701            if ($(this).find('.specialist-primary-button2').length === 0) {
1702
1703            const newCallMessageDiv = $('<div class="col-12 specialist-schedules2"></div>').html(
1704              '<div class="call-btn-wrapper call-message"><div class="col-12 specialist-schedules-header"><div class="calendar-icon"></div><div class="availability">Call for availability &amp; booking</div></div></div>'
1705              );
1706            const newCallDiv = $('<div class="col-12 specialist-primary-button2"></div>').html(
1707           '<a class="btn btn-primary w-100 mt-1" href="tel:+1' + doctorPhoneNumber + '">Call ' + doctorPhone + '</a>'
1708           );
1709
1710           // Find where to insert
1711          const profileButtonDiv = $(this).find('.specialist-profile-button');
1712
1713          // Insert before the profile button div
1714         if (profileButtonDiv.length) { 
1715         newCallDiv.insertBefore(profileButtonDiv);
1716         newCallMessageDiv.insertBefore(newCallDiv);
1717         } else {
1718         console.warn('No .specialist-profile-button found in this element-item');
1719         }
1720
1721         }
1722         
1723            //$(this).find('.availability').text('Call for availability & booking')
1724            //$(this).find('.specialist-primary-button').html('<a class="btn btn-primary w-100 mt-1" href="tel:+1'+ doctorPhoneNumber +'">Call '+ doctorPhone +'</a>')
1725            
1726        });
1727        localStorage.setItem("vcstate", selectedSL);
1728        //vcall();
1729        uoctelehealth()
1730
1731        $grid.isotope({
1732            itemSelector: '.element-item',
1733        filter: function() {
1734        var stateLicensure = $(this).data('statelicensure');
1735
1736        if (stateLicensure) {
1737            var stateLicensureArray = stateLicensure.split(',');
1738
1739            return (
1740                //$(this).hasClass('vc-dates-available') &&
1741                $(this).hasClass('TelehealthYes') &&
1742                !$(this).hasClass('hide-me') &&
1743                stateLicensureArray.includes(selectedSL.trim()) && 
1744                ($(this).is(filterString) || defaultFilter)
1745            );
1746        }
1747
1748            return false; 
1749        },
1750            layoutMode: 'fitRows',
1751            fitRows: {
1752                gutter: 0
1753            },
1754            transitionDuration: 0,
1755            getSortData: {
1756                priority: function(element) {
1757                    var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1758                    if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1759                        priority = 0;
1760                    } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1761                        priority = 1;
1762                    } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1763                        priority = 2;
1764                    } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1765                        priority = 3;
1766                    }
1767                    return priority;
1768                },
1769                byvcDate: function(element) {
1770                    return Date.parse($(element).attr('vcdatetime'));
1771                },
1772                providerName: '[data-breadcrumb]'
1773            },
1774            sortAscending: true,
1775            sortBy: ['priority', 'byvcDate', 'providerName']
1776        });
1777
1778    } else {
1779        //inpersonall()
1780        var selectedLocation = $('#location-filter').val();
1781
1782        if (selectedLocation && selectedLocation !== $('#location-filter option:first').val()) {
1783          $('.loc-date-wrapper').show();
1784        } else {
1785          $('.inperson-date-wrapper').show();
1786        }
1787        $('.vc-date-wrapper').hide();
1788
1789        $(this).attr("data-sl", "");
1790        $('#VCScreeningModal').attr('data-vcstateselected', '');
1791
1792        $('#search-results .element-item').each(function() {
1793            if ($(this).hasClass('vc-dates-available')) {
1794                $(this).removeClass('stv');
1795            }
1796
1797            if (($(this).hasClass('date-show')) || ($(this).hasClass('book-me'))) {
1798              $(this).find('.specialist-primary-button2').hide();
1799              $(this).find('.specialist-schedules2').hide();
1800              $(this).find('.specialist-primary-button').show();
1801              $(this).find('.specialist-schedules').show();
1802            }  
1803        });
1804
1805        localStorage.setItem("vcstate", "");
1806
1807        var itemValue = localStorage.getItem("insname");
1808
1809        if (insValue.indexOf("Medicare") >= 0) { 
1810            medicareall();
1811            //vcall();
1812            uoctelehealth()
1813        } else {
1814            inpersonall();
1815            //vcall();
1816            uoctelehealth()
1817        }
1818
1819
1820var $grid = $('.grid');
1821
1822if (insValue.indexOf("Medicare") >= 0) { 
1823    $grid.isotope({
1824        itemSelector: '.element-item',
1825        filter: ':visible',
1826        layoutMode: 'fitRows',
1827        fitRows: {
1828            gutter: 0
1829        },
1830        transitionDuration: 0,
1831        getSortData: {
1832            priority: function(element) {
1833                var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1834                if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1835                    priority = 0;
1836                } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1837                    priority = 1;
1838                } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1839                    priority = 2;
1840                } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1841                    priority = 3;
1842                }
1843                return priority;
1844            },
1845            bymcDate: function ($elem3) {
1846                return Date.parse($($elem3).attr('mcdatetime'));
1847            },
1848            providerName: '[data-breadcrumb]'
1849        },
1850        sortAscending: true,
1851        sortBy: ['priority', 'bymcDate', 'providerName']
1852    });
1853
1854    $grid.isotope('updateSortData').isotope();
1855} else {
1856    $grid.isotope({
1857        itemSelector: '.element-item',
1858        filter: ':visible',
1859        layoutMode: 'fitRows',
1860        fitRows: {
1861            gutter: 0
1862        },
1863        transitionDuration: 0,
1864        getSortData: {
1865            priority: function(element) {
1866                var priority = 4; // Default priority for items without 'book-me' or 'call-me'
1867                if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
1868                    priority = 0;
1869                } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
1870                    priority = 1;
1871                } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
1872                    priority = 2;
1873                } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
1874                    priority = 3;
1875                }
1876                return priority;
1877            },
1878            byDate: function ($elem1) {
1879                return Date.parse($($elem1).attr('datetime'));
1880            },
1881            byvcDate: function ($elem2) {
1882                return Date.parse($($elem2).attr('vcdatetime'));
1883            },
1884            providerName: '[data-breadcrumb]'
1885        },
1886        sortAscending: true,
1887        sortBy: ['priority', 'byDate', 'byvcDate', 'providerName']
1888    });
1889
1890    $grid.isotope('updateSortData').isotope();
1891}
1892
1893    }
1894}
1895
1896function updateVCFilterCount() {
1897  var visibleElementCount = countVisibleElements();
1898  var selectedCondition = localStorage.getItem("condition-linksource");
1899  var selectedInsuranceOption = localStorage.getItem("insnamelabel");
1900  var selectedSL = localStorage.getItem("vcstate");
1901  var isChecked = $('.vis-checkbox').is(':checked');
1902  var insuranceText = (selectedInsuranceOption && selectedInsuranceOption !== "unselect") 
1903  ? " and <strong>'" + selectedInsuranceOption + "'</strong>" 
1904  : "";
1905
1906  if (isChecked) {
1907    $('#filter-count').html("Showing <strong>" + visibleElementCount + "</strong> virtual care specialists for <strong>'" + selectedCondition +  "'</strong>" + insuranceText + "licensed in <strong>'" + selectedSL + "'</strong>");
1908  } else {
1909    $('#filter-count').html("Showing <strong>" + countVisibleElements() + "</strong> specialists for <strong>'" + selectedCondition + "'</strong>" + insuranceText);
1910  }
1911}
1912
1913function countVisibleElements() {
1914    const elements = document.getElementsByClassName('element-item');
1915    let visibleElementCount = 0;
1916
1917    for (let i = 0; i < elements.length; i++) {
1918        const element = elements[i];
1919
1920        if (element.classList.contains('hide-me')) {
1921            continue;
1922        }
1923
1924        if (element.offsetWidth > 0 && element.offsetHeight > 0) {
1925            visibleElementCount++;
1926        }
1927    }
1928
1929    return visibleElementCount;
1930}
1931
1932
1933// End VC checkbox
1934
1935$('#VCScreeningModal').on('hidden.bs.modal', function() {
1936        $('#compareSection').show();
1937        if ($(this).attr('data-vcstateselected') == "") {
1938        $('.vis-checkbox-opt').prop( "checked", false );  
1939        }
1940});
1941$('#VCScreeningModal [data-dismiss="modal"]').click(function() {
1942        $('#compareSection').show();
1943        if ($(this).attr('data-vcstateselected') == "") {
1944        $('.vis-checkbox-opt').prop( "checked", false );  
1945        }
1946});
1947
1948 $('#selectStateLicensure').change(function() {
1949    if ($(this)[0].selectedIndex != 0) {
1950      var selectedState = $('#selectStateLicensure option:selected').text();
1951      var selectedStateVal = $('#selectStateLicensure option:selected').val();
1952        $('#sl-filter-btn label').removeClass('btn-is-disabled');
1953        $('#sl-filter-btn label .selectedState').text("licensed in " + selectedState);
1954    } 
1955});
1956
1957//for NYC all
1958var itemValue = localStorage.getItem("insname");
1959if (insValue.indexOf("Medicare") >= 0) { 
1960     
1961var data3 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
1962var data3mc = Object.values(data3).filter(appointment => appointment.appointmentId === '1170000218')
1963} else {     
1964var data3 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
1965var data3mc = Object.values(data3).filter(appointment => appointment.appointmentId === '11700000136' | appointment.appointmentId === '404')
1966}
1967var datanycall = Object.values(data3mc).filter(department => department.locationName === '75th Street Campus' | department.locationName === 'HSS Main' | department.locationName === 'HSS Midtown' | department.locationName === 'Sports Medicine Institute West Side' | department.locationName === 'HSS Hudson Yards' | department.locationName === 'HSS Brooklyn' | department.locationName === 'HSS Queens')
1968var mapByIdnycall = datanycall.reduce((acc, { id, availability, nameLastFirst }) => {  
1969acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
1970return acc;
1971}, {})
1972
1973const resultArraynycall = Object.values(mapByIdnycall);
1974
1975//nyc all filter start
1976function nycall() {
1977  //$('.vis-checkbox-opt').prop( "checked", false );
1978 //( ".vis-checkbox" ).prop( "checked", false );
1979 
1980  //re-assign dummy dates for all doc except for alchemar docs
1981  var i = 1;
1982  var elementItem = $('#search-results .element-item')
1983
1984  var locationname = $('#location-filter option:selected').attr("data-locname");
1985  var locationvalue = $('#location-filter option:selected').attr("id");
1986  locationvalue= locationvalue.replace('.', '');
1987
1988  elementItem.each(function(){
1989  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
1990  if ($(this).attr('locdatetime') == "") {  
1991  $(this).attr('locdatetime',newID);
1992  $(this).val(i);
1993  $(this).removeClass(locationvalue + "-show")
1994  }
1995  });
1996
1997 resultArraynycall.forEach((result) => { 
1998
1999 //console.log (locdata);  
2000elementItem.each(function(){
2001
2002 if (($(this).attr('data-breadcrumb') == result.nameLastFirst) && ($(this).hasClass("inpers
2002on")) && ($(this).hasClass("yesoscondition")) && ($(this).attr('data-forclearfilter') !== 'call-me') ) {  
2003
2004 if ((result.availability !== '')  && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability > ',,') && (result.availability > ',,,')) { 
2005
2006    $(this).addClass("NYCall-show");
2007    $(this).addClass('inperson-available')
2008             $(this).addClass('date-show')
2009             $(this).addClass("inperson-show");
2010
2011             $(this).addClass("book-me");
2012             $(this).removeClass("call-me");
2013             $(this).removeClass("no-dates-available");
2014
2015             var profilebtn = $(this).find('.btn-outline-primary');
2016var currentprofilebtnHref = profilebtn.attr('href');
2017var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2018var profileBtnCall = profileBtnBook + '?osbtn=no';
2019
2020$(this).find('.availability').text('Next available appointments:');
2021$(this).find('.btn-primary').show();
2022$(this).find('.btn-primary-filtered').remove();
2023profilebtn.attr('href', profileBtnBook);
2024
2025
2026   let locavailabledates =  JSON.stringify(result.availability);
2027   locavailabledates = locavailabledates.replace(/['"]+/g, '');
2028   
2029   //remove first comma from string
2030   locavailabledates = locavailabledates.replace(/^,/, '');
2031   locavailabledates = locavailabledates.replace(/^,/,'');
2032
2033   //remove last commna from string 
2034   locavailabledates = locavailabledates.replace(/,\s*$/, "");
2035   
2036   //remove one extra comma when there is only one date per each location
2037   locavailabledates = locavailabledates.replace(',,', ',');
2038   
2039   //remove starting and ending comma from variable in javascript
2040  locavailabledates = locavailabledates.replace(/^,|,$/g,'');
2041   //console.log (result.id + result.nameLastFirst + "-" + locavailabledates); 
2042
2043   //order dates by the latest
2044   let locavailabledatessort = locavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
2045   //availabledatessort = availabledatessort + ",";
2046   //console.log (availabledatessort); 
2047
2048   //find the first date
2049   let locfirstdate = locavailabledatessort.split(",")[0]
2050   //add first date to the datetime attribute
2051   let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2052   $(this).attr('locdatetime', locfirstdateattr);
2053   
2054   //switch to mm/dd format for os btn 
2055   let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2056   //console.log((availabledatessort.split(",").length - 1));
2057  // Find 1st and 2nd dates and combine into one
2058const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2059
2060let locseconddateforosbtn = ""; // Declare the variable before use
2061
2062if (loccountdates === 0) {
2063  locseconddateforosbtn = "";
2064} else {   
2065  let locseconddate = locavailabledatessort.split(",")[1];
2066  locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2067}
2068
2069let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2070
2071// Remove trailing comma, if any
2072localldates = localldates.replace(/,\s*$/, "");   
2073
2074    //add inperson dates to os BTN
2075
2076const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2077const locationDates = 'In-person: <strong>' +localldates+ '</strong>';
2078locationWrapperDiv.empty().append(locationDates);
2079
2080    //show each lodation dates when filter locaitons
2081    var checkbox = $('.vis-checkbox');
2082
2083    $('.inperson-date-wrapper').hide();
2084
2085    if (!checkbox.prop('checked')) {
2086        $('.vc-date-wrapper').hide();
2087    } else {
2088      $('.vc-date-wrapper').show();
2089    }
2090
2091     if ($(this).hasClass("NYCall-show")) {
2092      if (!checkbox.prop('checked')) {
2093        $(this).find('.loc-date-wrapper').show(); 
2094      }
2095    }
2096
2097} 
2098}
2099
2100if ((!$(this).hasClass("NYCall-show")) && ($(this).hasClass("vis-b-show"))) { 
2101//console.log ("yes change locdate") 
2102$(this).attr('locdatetime', '2103-12-12');
2103}  
2104
2105});
2106});
2107
2108oicall()
2109switchLocationProfileCard() 
2110
2111   var $grid = $('.grid');
2112   $grid.isotope({
2113    itemSelector: '.element-item',
2114    filter: function() {
2115      return !$(this).is(':hidden') && $(this).hasClass('nycall') && !$(this).hasClass('hide-me');
2116    },
2117    layoutMode: 'fitRows',
2118    fitRows: {
2119      gutter: 0
2120    },
2121    transitionDuration: 0,
2122      getSortData: {
2123    priority: function(element) {
2124      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
2125      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
2126        priority = 0;
2127      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
2128        priority = 1;
2129      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
2130        priority = 2;
2131      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
2132        priority = 3;
2133      }
2134      return priority;
2135    },
2136    bylocDate: function ($elem1) {
2137          return Date.parse($($elem1).attr('locdatetime'));
2138      },
2139    byvcDate: function ($elem2) {
2140      return Date.parse($($elem2).attr('vcdatetime'));
2141    },
2142    providerName: '[data-breadcrumb]'
2143  },
2144  sortAscending: true,
2145  sortBy: ['priority', 'bylocDate', 'byvcDate', 'providerName']
2146  });
2147  
2148  $grid.isotope('updateSortData').isotope();
2149
2150}
2151//nyc all filter end   
2152
2153//for CT all
2154//const data4 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2155var itemValue = localStorage.getItem("insname");
2156if (insValue.indexOf("Medicare") >= 0) { 
2157//console.log("medicare")       
2158var data4 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2159var data4mc = Object.values(data4).filter(appointment => appointment.appointmentId === '1170000218')
2160} else { 
2161//console.log("no medicare")      
2162var data4 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2163var data4mc = Object.values(data4).filter(appointment => appointment.appointmentId === '11700000136' | appointment.appointmentId === '404')
2164}
2165var datactall = Object.values(data4mc).filter(department => department.locationName === 'HSS Stamford' | department.locationName === 'HSS Hamden' | department.locationName === 'HSS Wilton' | department.locationName === 'HSS Westport')
2166var mapByIdctall = datactall.reduce((acc, { id, availability, nameLastFirst }) => {  
2167acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
2168return acc;
2169}, {})
2170
2171const resultArrayctall = Object.values(mapByIdctall);
2172
2173//CT all filter start
2174function ctall() {    
2175
2176  //$('.vis-checkbox-opt').prop( "checked", false );
2177  //$( ".vis-checkbox" ).prop( "checked", false ); 
2178
2179  //re-assign dummy dates for all doc
2180  var i = 1;
2181  var elementItem = $('#search-results .element-item')
2182
2183  var locationname = $('#location-filter option:selected').attr("data-locname");
2184  var locationvalue = $('#location-filter option:selected').attr("id");
2185  locationvalue= locationvalue.replace('.', '');
2186  
2187  elementItem.each(function(){
2188  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
2189  if ($(this).attr('locdatetime') == "") {  
2190  $(this).attr('locdatetime',newID);
2191  $(this).val(i);
2192  }
2193  $(this).removeClass(locationvalue + "-show")
2194  });
2195
2196resultArrayctall.forEach((result) => {   
2197 elementItem.each(function(){
2198
2199 if (($(this).attr('data-providerid') == result.id) && ( ($(this).attr('data-oic') ==='') || ($(this).attr('data-oic') ==='yes') ) && ($(this).attr('data-breadcrumb') == result.nameLastFirst) && ($(this).hasClass("inpers
2199on")) && ($(this).hasClass("yesoscondition")) && ($(this).attr('data-forclearfilter') !== 'call-me')) {  
2200
2201 if ((result.availability !== '')  && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability > ',,') && (result.availability > ',,,')) {
2202
2203  $(this).addClass("CTall-show");
2204  $(this).addClass('inperson-available')
2205             $(this).addClass('date-show')
2206             $(this).addClass("inperson-show");
2207
2208             $(this).addClass("book-me");
2209             $(this).removeClass("call-me");
2210             $(this).removeClass("no-dates-available");
2211
2212             var profilebtn = $(this).find('.btn-outline-primary');
2213var currentprofilebtnHref = profilebtn.attr('href');
2214var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2215var profileBtnCall = profileBtnBook + '?osbtn=no';
2216
2217$(this).find('.availability').text('Next available appointments:');
2218$(this).find('.btn-primary').show();
2219$(this).find('.btn-primary-filtered').remove();
2220profilebtn.attr('href', profileBtnBook);
2221
2222
2223   // add 'wc-show' for display os button for wc
2224
2225   let locavailabledates =  JSON.stringify(result.availability);
2226   locavailabledates = locavailabledates.replace(/['"]+/g, '');
2227  
2228   //remove first comma from string
2229   locavailabledates = locavailabledates.replace(/^,/, '');
2230   locavailabledates = locavailabledates.replace(/^,/,'');
2231
2232   //remove last commna from string 
2233   locavailabledates = locavailabledates.replace(/,\s*$/, "");
2234   
2235   //remove one extra comma when there is only one date per each location
2236   locavailabledates = locavailabledates.replace(',,', ',');
2237             //remove starting and ending comma from variable in javascript
2238  locavailabledates = locavailabledates.replace(/^,|,$/g,'');
2239   //console.log (result.id + availabledates); 
2240
2241   //order dates by the latest
2242   let locavailabledatessort = locavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
2243   //availabledatessort = availabledatessort + ",";
2244   //console.log (availabledatessort); 
2245
2246
2247   //find the first date
2248   let locfirstdate = locavailabledatessort.split(",")[0]
2249   //add first date to the datetime attribute
2250   let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2251   $(this).attr('locdatetime', locfirstdateattr);
2252   
2253   //switch to mm/dd format for os btn 
2254   let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2255   //console.log((availabledatessort.split(",").length - 1));
2256   //find 1st and 2nd dates and combine into one
2257
2258 // Find 1st and 2nd dates and combine into one
2259const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2260
2261let locseconddateforosbtn = ""; // Declare the variable before use
2262
2263if (loccountdates === 0) {
2264  locseconddateforosbtn = "";
2265} else {   
2266  let locseconddate = locavailabledatessort.split(",")[1];
2267  locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2268}
2269
2270let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2271
2272// Remove trailing comma, if any
2273localldates = localldates.replace(/,\s*$/, "");
2274
2275 
2276    //add inperson dates to os BTN
2277
2278const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2279const locationDates = 'In-person: <strong>' +localldates + '</strong>';
2280locationWrapperDiv.empty().append(locationDates);
2281
2282
2283    //show each lodation dates when filter locaitons
2284    var checkbox = $('.vis-checkbox');
2285
2286    $('.inperson-date-wrapper').hide();
2287
2288    if (!checkbox.prop('checked')) {
2289        $('.vc-date-wrapper').hide();
2290    } else {
2291      $('.vc-date-wrapper').show();
2292    }
2293
2294     if ($(this).hasClass("CTall-show")) {
2295      if (!checkbox.prop('checked')) {
2296        $(this).find('.loc-date-wrapper').show(); 
2297      }
2298    }
2299 
2300} 
2301}
2302
2303if ((!$(this).hasClass("CTCall-show")) && ($(this).hasClass("vis-b-show"))) { 
2304//console.log ("yes change locdate") 
2305$(this).attr('locdatetime', '2103-12-12');
2306}  
2307
2308});
2309}); 
2310
2311oicall()
2312switchLocationProfileCard() 
2313
2314  var $grid = $('.grid');
2315  $grid.isotope({
2316    itemSelector: '.element-item',
2317    filter: function() {
2318      return !$(this).is(':hidden') && $(this).hasClass('ctall') && !$(this).hasClass('hide-me');
2319    },
2320    layoutMode: 'fitRows',
2321    fitRows: {
2322      gutter: 0
2323    },
2324    transitionDuration: 0,
2325      getSortData: {
2326    priority: function(element) {
2327      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
2328      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
2329        priority = 0;
2330      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
2331        priority = 1;
2332      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
2333        priority = 2;
2334      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
2335        priority = 3;
2336      }
2337      return priority;
2338    },
2339    bylocDate: function ($elem1) {
2340          return Date.parse($($elem1).attr('locdatetime'));
2341      },
2342    byvcDate: function ($elem2) {
2343      return Date.parse($($elem2).attr('vcdatetime'));
2344    },
2345    providerName: '[data-breadcrumb]'
2346  },
2347  sortAscending: true,
2348  sortBy: ['priority', 'bylocDate', 'byvcDate', 'providerName']
2349});
2350  
2351  $grid.isotope('updateSortData').isotope();
2352    
2353}
2354//CT all filter end   
2355
2356//for FL all
2357var itemValue = localStorage.getItem("insname");
2358if (insValue.indexOf("Medicare") >= 0) { 
2359//console.log("medicare")       
2360var data5 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2361var data5mc = Object.values(data5).filter(appointment => appointment.appointmentId === '1170000218')
2362} else { 
2363//console.log("no medicare")      
2364var data5 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2365var data5mc = Object.values(data5).filter(appointment => appointment.appointmentId === '11700000136' | appointment.appointmentId === '404')
2366}
2367
2368
2369var dataflall = Object.values(data5mc).filter(department => department.locationName === 'HSS Florida - Wellington' | department.locationName === 'HSS Florida' | department.locationName === 'HSS Florida - Jupiter')
2370var mapByIdflall = dataflall.reduce((acc, { id, availability, nameLastFirst }) => {  
2371acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
2372return acc;
2373}, {})
2374
2375const resultArrayflall = Object.values(mapByIdflall);
2376
2377//FL all filter start
2378
2379function flall() {     
2380  //$('.vis-checkbox-opt').prop( "checked", false );
2381  //$( ".vis-checkbox" ).prop( "checked", false ); 
2382 
2383  //re-assign dummy dates for all doc
2384  var i = 1;
2385  var elementItem = $('#search-results .element-item')
2386
2387  var locationname = $('#location-filter option:selected').attr("data-locname");
2388  var locationvalue = $('#location-filter option:selected').attr("id");
2389  locationvalue= locationvalue.replace('.', '');
2390  
2391  elementItem.each(function(){
2392  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
2393  if ($(this).attr('locdatetime') == "") {  
2394  $(this).attr('locdatetime',newID);
2395  $(this).val(i);
2396  }
2397  $(this).removeClass(locationvalue + "-show")
2398  });
2399
2400
2401//console.log (locationvalue); 
2402
2403 resultArrayflall.forEach((result) => {   
2404 elementItem.each(function(){
2405
2406 if (($(this).attr('data-providerid') == result.id) && ($(this).attr('data-oic') ==='') && ($(this).attr('data-breadcrumb') == result.nameLastFirst) && ($(this).hasClass("inpers
2406on")) && ($(this).hasClass("yesoscondition")) && ($(this).attr('data-forclearfilter') !== 'call-me')) {  
2407
2408 if ((result.availability !== '')  && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability > ',,') && (result.availability > ',,,')) {
2409   // add 'wc-show' for display os button for wc
2410   $(this).addClass("FLall-show");
2411   $(this).addClass('inperson-available')
2412             $(this).addClass('date-show')
2413             $(this).addClass("inperson-show");
2414
2415             $(this).addClass("book-me");
2416             $(this).removeClass("call-me");
2417             $(this).removeClass("no-dates-available");
2418
2419var profilebtn = $(this).find('.btn-outline-primary');
2420var currentprofilebtnHref = profilebtn.attr('href');
2421var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2422var profileBtnCall = profileBtnBook + '?osbtn=no';
2423
2424$(this).find('.availability').text('Next available appointments:');
2425$(this).find('.btn-primary').show();
2426$(this).find('.btn-primary-filtered').remove();
2427profilebtn.attr('href', profileBtnBook);
2428
2429
2430   let locavailabledates =  JSON.stringify(result.availability);
2431   locavailabledates = locavailabledates.replace(/['"]+/g, '');
2432   
2433       //remove first comma from string
2434   locavailabledates = locavailabledates.replace(/^,/, '');
2435   locavailabledates = locavailabledates.replace(/^,/,'');
2436
2437   //remove last commna from string 
2438   locavailabledates = locavailabledates.replace(/,\s*$/, "");
2439   
2440   //remove one extra comma when there is only one date per each location
2441   locavailabledates = locavailabledates.replace(',,', ',');
2442             //remove starting and ending comma from variable in javascript
2443  locavailabledates = locavailabledates.replace(/^,|,$/g,'');
2444   //console.log (result.id + availabledates); 
2445
2446   //order dates by the latest
2447   let locavailabledatessort = locavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
2448   //availabledatessort = availabledatessort + ",";
2449   //console.log (availabledatessort); 
2450
2451
2452   //find the first date
2453   let locfirstdate = locavailabledatessort.split(",")[0]
2454   //add first date to the datetime attribute
2455   let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2456   $(this).attr('locdatetime', locfirstdateattr);
2457   
2458   //switch to mm/dd format for os btn 
2459   let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2460   //console.log((availabledatessort.split(",").length - 1));
2461   //find 1st and 2nd dates and combine into one
2462
2463   const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2464
2465   let locseconddateforosbtn = ""; // Declare the variable before use
2466   
2467   if (loccountdates === 0) {
2468     locseconddateforosbtn = "";
2469   } else {   
2470     let locseconddate = locavailabledatessort.split(",")[1];
2471     locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2472   }
2473   
2474   let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2475   
2476   // Remove trailing comma, if any
2477   localldates = localldates.replace(/,\s*$/, ""); 
2478
2479  
2480    //add inperson dates to os BTN
2481
2482const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2483const locationDates = 'In-person: <strong>' +localldates + '</strong>';
2484locationWrapperDiv.empty().append(locationDates);
2485
2486
2487    //show each lodation dates when filter locaitons
2488    var checkbox = $('.vis-checkbox');
2489
2490    $('.inperson-date-wrapper').hide();
2491
2492    if (!checkbox.prop('checked')) {
2493        $('.vc-date-wrapper').hide();
2494    } else {
2495      $('.vc-date-wrapper').show();
2496    }
2497
2498     if ($(this).hasClass("FLall-show")) {
2499      if (!checkbox.prop('checked')) {
2500        $(this).find('.loc-date-wrapper').show(); 
2501      }
2502    }
2503
2504  }
2505  }
2506  if ((!$(this).hasClass("FLall-show")) && ($(this).hasClass("vis-b-show"))) { 
2507//console.log ("yes change locdate") 
2508$(this).attr('locdatetime', '2103-12-12');
2509}  
2510
2511  });
2512  }); 
2513
2514oicall()
2515switchLocationProfileCard() 
2516
2517var $grid = $('.grid');
2518$grid.isotope({
2519    itemSelector: '.element-item',
2520    filter: function() {
2521      return !$(this).is(':hidden') && $(this).hasClass('flall') && !$(this).hasClass('hide-me');
2522    },
2523    layoutMode: 'fitRows',
2524    fitRows: {
2525      gutter: 0
2526    },
2527    transitionDuration: 0,
2528      getSortData: {
2529    priority: function(element) {
2530      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
2531      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
2532        priority = 0;
2533      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
2534        priority = 1;
2535      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
2536        priority = 2;
2537      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
2538        priority = 3;
2539      }
2540      return priority;
2541    },
2542    bylocDate: function ($elem1) {
2543          return Date.parse($($elem1).attr('locdatetime'));
2544      },
2545    byvcDate: function ($elem2) {
2546      return Date.parse($($elem2).attr('vcdatetime'));
2547    },
2548    providerName: '[data-breadcrumb]'
2549  },
2550  sortAscending: true,
2551  sortBy: ['priority', 'bylocDate', 'byvcDate', 'providerName']
2552});
2553  
2554  $grid.isotope('updateSortData').isotope();
2555
2556}
2557//FL all filter end 
2558
2559
2560//for NJ all
2561//const data6 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2562var itemValue = localStorage.getItem("insname");
2563if (insValue.indexOf("Medicare") >= 0) { 
2564//console.log("medicare")       
2565var data6 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2566var data6mc = Object.values(data6).filter(appointment => appointment.appointmentId === '1170000218')
2567} else { 
2568//console.log("no medicare")      
2569var data6 = Object.values(data).filter(department => department.departmentId !== 'VIRTUAL')
2570var data6mc = Object.values(data6).filter(appointment => appointment.appointmentId === '11700000136' | appointment.appointmentId === '404')
2571}
2572
2573var datanjall = Object.values(data6mc).filter(department => department.locationName === 'HSS Paramus' | department.locationName === 'HSS Saddle River')
2574var mapByIdnjall = datanjall.reduce((acc, { id, availability, nameLastFirst }) => {  
2575acc[nameLastFirst] = { id, nameLastFirst, availability: (acc[nameLastFirst] ? acc[nameLastFirst].availability + ",": "") + `${availability}`}
2576return acc;
2577}, {})
2578
2579const resultArraynjall = Object.values(mapByIdnjall);
2580
2581 function njall() {     
2582  //$('.vis-checkbox-opt').prop( "checked", false );
2583  //$( ".vis-checkbox" ).prop( "checked", false ); 
2584
2585  var i = 1;
2586  var elementItem = $('#search-results .element-item')
2587
2588  var locationname = $('#location-filter option:selected').attr("data-locname");
2589  var locationvalue = $('#location-filter option:selected').attr("id");
2590  locationvalue= locationvalue.replace('.', '');
2591  
2592  elementItem.each(function(){
2593  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
2594  if ($(this).attr('locdatetime') == "") {  
2595  $(this).attr('locdatetime',newID);
2596  $(this).val(i);
2597  }
2598  $(this).removeClass(locationvalue + "-show")
2599  });
2600
2601 resultArraynjall.forEach((result) => { 
2602 $('#search-results .element-item').each(function(){
2603
2604 if (($(this).attr('data-providerid') == result.id) && ($(this).attr('data-oic') ==='') && ($(this).attr('data-breadcrumb') == result.nameLastFirst) && ($(this).hasClass("inpers
2604on")) && ($(this).hasClass("yesoscondition")) && ($(this).attr('data-forclearfilter') !== 'call-me') ) {  
2605
2606 if ((result.availability !== '') && (result.availability != null) && (result.availability.length > 0) && (result.availability > ',') && (result.availability > ',,') && (result.availability > ',,,')) {
2607
2608  $(this).addClass("NJall-show");
2609  $(this).addClass('inperson-available')
2610             $(this).addClass('date-show')
2611             $(this).addClass("inperson-show");
2612
2613             $(this).addClass("book-me");
2614             $(this).removeClass("call-me");
2615             $(this).removeClass("no-dates-available");
2616
2617             var profilebtn = $(this).find('.btn-outline-primary');
2618var currentprofilebtnHref = profilebtn.attr('href');
2619var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2620var profileBtnCall = profileBtnBook + '?osbtn=no';
2621
2622$(this).find('.availability').text('Next available appointments:');
2623$(this).find('.btn-primary').show();
2624$(this).find('.btn-primary-filtered').remove();
2625profilebtn.attr('href', profileBtnBook);
2626
2627
2628   // add 'wc-show' for display os button for wc
2629
2630   let locavailabledates =  JSON.stringify(result.availability);
2631   locavailabledates = locavailabledates.replace(/['"]+/g, '');
2632   
2633  //remove first comma from string
2634   locavailabledates = locavailabledates.replace(/^,/, '');
2635   locavailabledates = locavailabledates.replace(/^,/,'');
2636
2637   //remove last commna from string 
2638   locavailabledates = locavailabledates.replace(/,\s*$/, "");
2639   
2640   //remove one extra comma when there is only one date per each location
2641   locavailabledates = locavailabledates.replace(',,', ',');
2642             //remove starting and ending comma from variable in javascript
2643  locavailabledates = locavailabledates.replace(/^,|,$/g,'');
2644   //console.log (result.id + availabledates); 
2645
2646   //order dates by the latest
2647   let locavailabledatessort = locavailabledates.split(",").sort((a,b)=>new Date(a) - new Date(b)).join(",");
2648   //availabledatessort = availabledatessort + ",";
2649   //console.log (availabledatessort); 
2650
2651   //find the first date
2652   let locfirstdate = locavailabledatessort.split(",")[0]
2653   //add first date to the datetime attribute
2654   let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2655   $(this).attr('locdatetime', locfirstdateattr);
2656   
2657   //switch to mm/dd format for os btn 
2658   let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2659
2660   //switch to mm/dd format for os btn 
2661   const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2662
2663   let locseconddateforosbtn = ""; // Declare the variable before use
2664   
2665   if (loccountdates === 0) {
2666     locseconddateforosbtn = "";
2667   } else {   
2668     let locseconddate = locavailabledatessort.split(",")[1];
2669     locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2670   }
2671   
2672   let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2673   
2674   // Remove trailing comma, if any
2675   localldates = localldates.replace(/,\s*$/, "");  
2676
2677   //$(this).addClass("vis-b-show");    
2678
2679    //add inperson dates to os BTN
2680
2681   const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2682const locationDates = 'In-person: <strong>' +localldates+ '</strong>';
2683locationWrapperDiv.empty().append(locationDates);
2684 
2685
2686   //show each lodation dates when filter locaitons
2687    var checkbox = $('.vis-checkbox');
2688
2689    $('.inperson-date-wrapper').hide();
2690
2691    if (!checkbox.prop('checked')) {
2692        $('.vc-date-wrapper').hide();
2693    } else {
2694      $('.vc-date-wrapper').show();
2695    }
2696
2697     if ($(this).hasClass("NJall-show")) {
2698      if (!checkbox.prop('checked')) {
2699        $(this).find('.loc-date-wrapper').show(); 
2700      }
2701    }
2702
2703  }
2704  }
2705
2706    if ((!$(this).hasClass("NJall-show")) && ($(this).hasClass("vis-b-show"))) { 
2707//console.log ("yes change locdate") 
2708$(this).attr('locdatetime', '2103-12-12');
2709}  
2710
2711  });
2712  }); 
2713
2714
2715oicall()
2716switchLocationProfileCard() 
2717
2718
2719var $grid = $('.grid');
2720$grid.isotope({
2721    itemSelector: '.element-item',
2722    filter: function() {
2723      return !$(this).is(':hidden') && $(this).hasClass('njall') && !$(this).hasClass('hide-me');
2724    },
2725    layoutMode: 'fitRows',
2726    fitRows: {
2727      gutter: 0
2728    },
2729    transitionDuration: 0,
2730      getSortData: {
2731    priority: function(element) {
2732      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
2733      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
2734        priority = 0;
2735      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
2736        priority = 1;
2737      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
2738        priority = 2;
2739      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
2740        priority = 3;
2741      }
2742      return priority;
2743    },
2744    bylocDate: function ($elem1) {
2745          return Date.parse($($elem1).attr('locdatetime'));
2746      },
2747    byvcDate: function ($elem2) {
2748      return Date.parse($($elem2).attr('vcdatetime'));
2749    },
2750    providerName: '[data-breadcrumb]'
2751  },
2752  sortAscending: true,
2753  sortBy: ['priority', 'bylocDate', 'byvcDate', 'providerName']
2754});
2755  
2756  $grid.isotope('updateSortData').isotope();
2757
2758}
2759//NJ all filter end 
2760
2761
2762//location
2763function locationall() {
2764//$('.vis-checkbox-opt').prop( "checked", false );
2765//$( ".vis-checkbox" ).prop( "checked", false );
2766
2767 //re-assign dummy dates for all doc
2768  var i = 1;
2769  var elementItem = $('#search-results .element-item');
2770
2771  var locationname = $('#location-filter option:selected').attr("data-locname");
2772  var locationvalue = $('#location-filter option:selected').attr("id");
2773  locationvalue= locationvalue.replace('.', '');
2774  
2775  elementItem.each(function(){
2776  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
2777  $(this).attr('locdatetime',newID);
2778  $(this).val(i);
2779  $(this).removeClass(locationvalue + "-show")
2780  
2781  //show aaa uoc 
2782  var $this = $(this);
2783  var breadcrumb = $this.attr('data-breadcrumb');
2784  if (insValue.indexOf("Medicare") == -1) {  
2785  if (breadcrumb && breadcrumb.includes('AAA UOC')) {
2786    //console.log('Found:', breadcrumb);
2787    $(this).find('.availability').text('Next available appointments:');
2788    $(this).removeClass('hide-me');
2789  }
2790  }
2791  });
2792  
2793
2794data.forEach((result) => {   
2795
2796 elementItem.each(function(){
2797
2798  $(this).removeClass("no-dates-available");
2799  $(this).removeClass("dates-available");
2800
2801 if (($(this).attr('data-providerid') == result.id) && ($(this).attr('data-forclearfilter') !== 'call-me') && ( ($(this).attr('data-oic') ==='') || ($(this).attr('data-oic') ==='yes') ) && ($(this).hasClass("inpers
2801on")) && ($(this).hasClass("yesoscondition")) && !($(this).hasClass("out-of-network-call")) && ($(this).hasClass(locationvalue)) ) { 
2802
2803//var insValue = localStorage.getItem("insname");
2804//var searchTypeValue = localStorage.getItem("searchType");
2805
2806console.log("searchtype:" + searchTypeValue + "/insvalue:" + insValue)
2807if (insValue.indexOf("Medicare") >= 0) {   
2808
2809    //medicare insurance for location start
2810 if ((result.availability !== '') && (result.appointmentId === '1170000218') && (result.locationName === locationname) && (result.availability != null) && (result.availability.length > 0)) {
2811
2812    $(this).addClass(locationvalue + "-show");
2813let locavailabledates =  JSON.stringify(result.availability);
2814locavailabledates= locavailabledates.replace(/['"]+/g, '');
2815locavailabledates= locavailabledates.replace('[', '');
2816locavailabledates= locavailabledates.replace(']', '');
2817   
2818//remove first comma from string
2819locavailabledates = locavailabledates.replace(/^,/, '');
2820locavailabledates = locavailabledates.replace(/^,/,'');
2821
2822//remove last commna from string 
2823locavailabledates = locavailabledates.replace(/,\s*$/, "");
2824
2825//find the first date
2826let locfirstdate = locavailabledates.split(",")[0]
2827   
2828//add first date to the datetime attribute
2829let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2830$(this).attr('locdatetime', locfirstdateattr);
2831   
2832//switch to mm/dd format for os btn 
2833let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2834
2835const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2836
2837let locseconddateforosbtn = ""; // Declare the variable before use
2838
2839if (loccountdates === 0) {
2840  locseconddateforosbtn = "";
2841} else {   
2842  let locseconddate = locavailabledates.split(",")[1];
2843  locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2844}
2845
2846let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2847
2848// Remove trailing comma, if any
2849localldates = localldates.replace(/,\s*$/, "");  
2850
2851//add inperson dates to os BTN
2852
2853const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2854const locationDates = 'In-person: <strong>' +localldates+ '</strong>';
2855locationWrapperDiv.empty().append(locationDates);
2856
2857var profilebtn = $(this).find('.btn-outline-primary');
2858var currentprofilebtnHref = profilebtn.attr('href');
2859var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2860var profileBtnCall = profileBtnBook + '?osbtn=no';
2861console.log ("locationall-medicare")
2862$(this).addClass('book-me');
2863$(this).addClass('inperson-available')
2864$(this).addClass('date-show')
2865$(this).addClass("inperson-show");
2866$(this).removeClass("call-me");
2867$(this).removeClass("no-dates-available");
2868$(this).find('.availability').text('Next available appointments:');
2869$(this).find('.btn-primary').show();
2870$(this).find('.btn-primary-filtered').remove();
2871profilebtn.attr('href', profileBtnBook);
2872
2873//show each lodation dates when filter locaitons
2874$('.vc-date-wrapper').hide();   
2875
2876var checkbox = $('.vis-checkbox');
2877
2878    $('.inperson-date-wrapper').hide();
2879
2880    if (!checkbox.prop('checked')) {
2881        $('.vc-date-wrapper').hide();
2882    } else {
2883      $('.vc-date-wrapper').show();
2884    }
2885
2886     if ($(this).hasClass(locationvalue + "-show")) {
2887      if (!checkbox.prop('checked')) {
2888        $(this).find('.loc-date-wrapper').show(); 
2889      }
2890    }
2891
2892
2893} 
2894
2895//medicare end
2896
2897    } else {
2898
2899      //commercial insurance  
2900 if ((result.availability !== '') && (result.appointmentId !== '1170000218') && ((result.appointmentId === '11700000136') || (result.appointmentId === '404')) &&  (result.locationName === locationname)   && (result.availability != null) && (result.availability.length > 0)) {
2901
2902    $(this).addClass(locationvalue + "-show");
2903
2904
2905let locavailabledates =  JSON.stringify(result.availability);
2906locavailabledates= locavailabledates.replace(/['"]+/g, '');
2907locavailabledates= locavailabledates.replace('[', '');
2908locavailabledates= locavailabledates.replace(']', '');
2909   
2910//remove first comma from string
2911locavailabledates = locavailabledates.replace(/^,/, '');
2912locavailabledates = locavailabledates.replace(/^,/,'');
2913
2914//remove last commna from string 
2915locavailabledates = locavailabledates.replace(/,\s*$/, "");
2916
2917//find the first date
2918let locfirstdate = locavailabledates.split(",")[0]
2919   
2920//add first date to the datetime attribute
2921let locfirstdateattr = [moment(locfirstdate).format('MMM D, YYYY')];
2922$(this).attr('locdatetime', locfirstdateattr);
2923   
2924//switch to mm/dd format for os btn 
2925let locfirstdateforosbtn = [moment(locfirstdate).format('MMM D')];
2926
2927const loccountdates = [...locavailabledates].filter(l => l === ',').length;
2928
2929let locseconddateforosbtn = ""; // Declare the variable before use
2930
2931if (loccountdates === 0) {
2932  locseconddateforosbtn = "";
2933} else {   
2934  let locseconddate = locavailabledates.split(",")[1];
2935  locseconddateforosbtn = [moment(locseconddate).format('MMM D')]; 
2936}
2937
2938let localldates = locfirstdateforosbtn + ", " + locseconddateforosbtn;
2939
2940// Remove trailing comma, if any
2941localldates = localldates.replace(/,\s*$/, "");   
2942
2943//add inperson dates to os BTN
2944
2945const locationWrapperDiv = $(this).find('.loc-date-wrapper');
2946const locationDates = 'In-person: <strong>' +localldates+ '</strong>';
2947locationWrapperDiv.empty().append(locationDates);
2948
2949var profilebtn = $(this).find('.btn-outline-primary');
2950var currentprofilebtnHref = profilebtn.attr('href');
2951var profileBtnBook = currentprofilebtnHref.replace('?osbtn=no', '');
2952var profileBtnCall = profileBtnBook + '?osbtn=no';
2953console.log ("locationall-commercial")
2954$(this).addClass('book-me');
2955$(this).addClass('inperson-available')
2956$(this).addClass('date-show')
2957$(this).addClass("inperson-show");
2958$(this).removeClass("call-me");
2959$(this).removeClass("no-dates-available");
2960$(this).find('.availability').text('Next available appointments:');
2961$(this).find('.availability').show();
2962$(this).find('.btn-primary').show();
2963$(this).find('.btn-primary-filtered').remove();
2964profilebtn.attr('href', profileBtnBook);
2965
2966//show each lodation dates when filter locaitons
2967$('.vc-date-wrapper').hide();   
2968
2969var checkbox = $('.vis-checkbox');
2970
2971    $('.inperson-date-wrapper').hide();
2972
2973    if (!checkbox.prop('checked')) {
2974        $('.vc-date-wrapper').hide();
2975    } else {
2976      $('.vc-date-wrapper').show();
2977    }
2978
2979     if ($(this).hasClass(locationvalue + "-show")) {
2980      if (!checkbox.prop('checked')) {
2981        $(this).find('.loc-date-wrapper').show(); 
2982      }
2983    }
2984
2985}
2986//commercial insurance end  
2987
2988}
2989
2990} 
2991});
2992});
2993
2994oicall()
2995oicallpa()
2996oicallpt()
2997switchLocationProfileCard() 
2998
2999   var $grid = $('.grid');
3000   $grid.isotope({
3001    itemSelector: '.element-item',
3002    filter: function() {
3003      return !$(this).is(':hidden') && $(this).hasClass(locationvalue) && !$(this).hasClass('hide-me');
3004    },
3005    layoutMode: 'fitRows',
3006    fitRows: {
3007      gutter: 0
3008    },
3009    transitionDuration: 0,
3010      getSortData: {
3011    priority: function(element) {
3012      var priority = 4; // Default priority for items without 'book-me' or 'call-me'
3013      if (($(element).hasClass('innetwork')) && ($(element).hasClass('book-me'))) {
3014        priority = 0;
3015      } else if (($(element).hasClass('innetwork')) && ($(element).hasClass('call-me'))) {
3016        priority = 1;
3017      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('book-me'))) {
3018        priority = 2;
3019      } else if (($(element).hasClass('outofnetwork')) && ($(element).hasClass('call-me'))) {
3020        priority = 3;
3021      }
3022      return priority;
3023    },
3024    bylocDate: function ($elem1) {
3025          return Date.parse($($elem1).attr('locdatetime'));
3026      },
3027    byvcDate: function ($elem2) {
3028      return Date.parse($($elem2).attr('vcdatetime'));
3029    },
3030    providerName: '[data-breadcrumb]'
3031  },
3032  sortAscending: true,
3033  sortBy: ['priority', 'bylocDate', 'byvcDate', 'providerName']
3034  });
3035  
3036  $grid.isotope('updateSortData').isotope();
3037
3038
3039
3040}
3041//location end 
3042
3043
3044function switchLocationProfileCard() {
3045
3046  var i = 1;
3047  var newID= moment().add(30000+i, 'days').format('YYYY-MM-DD');
3048  var dummylocdate = newID
3049
3050  $('#search-results .element-item').each(function() {
3051    var $this = $(this);
3052    
3053    var locdatetime = $this.attr('locdatetime');
3054    var breadcrumb = $this.attr('data-breadcrumb');
3055
3056    var dataoic = $this.attr('data-oic')
3057
3058    if ($this.hasClass('book-me') && ((!locdatetime || locdatetime.trim() === '') || locdatetime === dummylocdate) && !$this.hasClass('vc-dates-available') ) {
3059     
3060      var doctorPhone = $(this).attr('data-phone');
3061      var doctorPhoneNumber = doctorPhone.split('.').join("");
3062      var doctorPhoneHref = 'tel:+'+ doctorPhoneNumber;
3063      var doctorPhoneText = 'Call '+ doctorPhone;
3064      
3065      var profilebtn = $this.find('.btn-outline-primary');
3066      var profileUrl = profilebtn.attr('href');
3067      var modifiedUrl = profileUrl + '?osbtn=no';
3068
3069      $this.removeClass('book-me').addClass('call-me');
3070      $this.find('.btn-outline-primary').attr('href', modifiedUrl);
3071      $this.find('.inperson-date-wrapper, .loc-date-wrapper').hide();
3072      $this.removeClass('dates-available').addClass('no-dates-available');
3073      $this.find('.btn-primary').hide();
3074
3075       var newCallBtn = $('<a>', {
3076        'class': 'btn btn-primary-filtered w-100 mt-1',
3077        'href': doctorPhoneHref,
3078        'text': doctorPhoneText
3079      });
3080
3081      $this.find('.availability').text('Call for availability & booking');
3082      
3083      //$(this).find('.availability').hide();
3084      $this.find('.specialist-primary-button').append(newCallBtn);
3085    }
3086
3087    if ($this.hasClass('book-me') && dataoic === 'yes' && locdatetime !== dummylocdate && locdatetime !== null && locdatetime.trim() !== '') {
3088        $this.find('.loc-date-wrapper').show();
3089        $this.find('.inperson-date-wrapper').hide();
3090    }
3091
3092    if (breadcrumb === 'AAA UOC Telehealth') {
3093      $this.find('.vc-date-wrapper').show();
3094    }
3095
3096  });
3097}
3098function hideUOCAAASwitch () {
3099  var i = 1;
3100  var elementItem = $('#search-results .element-item');
3101
3102  elementItem.each(function(){
3103  //show aaa uoc 
3104  var $this = $(this);
3105  var breadcrumb = $this.attr('data-breadcrumb');
3106
3107  if (breadcrumb && breadcrumb.includes('AAA UOC')) {
3108    //console.log('hide uoc Found:', breadcrumb);
3109    $(this).find('.availability').text('Next available appointments:');
3110    $(this).addClass('hide-me');
3111  }
3112  });
3113}
3114
3115function showUOCAAASwitch() {
3116var i = 1;
3117var elementItem = $('#search-results .element-item');
3118
3119elementItem.each(function(){  
3120//show aaa uoc 
3121var $this = $(this);
3122var breadcrumb = $this.attr('data-breadcrumb');
3123if (insValue.indexOf("Medicare") == -1) {  
3124if (breadcrumb && breadcrumb.includes('AAA UOC')) {
3125  console.log('AAAUOC Found:', breadcrumb);
3126  $(this).find('.availability').text('Next available appointments:');
3127  $(this).removeClass('hide-me');
3128}
3129}
3130});
3131}
3132
3133function locationAPISwitch() {
3134  console.log("locationAPISwitch() fired");
3135  const locationFilter = document.getElementById('location-filter');
3136
3137  if (!locationFilter) {
3138    console.log("location filter not found");
3139    return;
3140  }
3141
3142  let debounceTimer;
3143  locationFilter.addEventListener('change', function () {
3144    showUOCAAASwitch()
3145    clearTimeout(debounceTimer);
3146    debounceTimer = setTimeout(handleLocationChange, 100); // Debounce to improve performance
3147  });
3148
3149  function handleLocationChange() {
3150    console.log("location-filter change");
3151    const LocationFilterValue = localStorage.getItem('location-filter_filter') || '';
3152    const selectedOption = locationFilter.value;
3153    const locationValue = selectedOption.substring(1);
3154
3155    // If LocationFilterValue is empty or Show All option selected
3156    if (!LocationFilterValue.trim() || !selectedOption.trim()) {
3157      //hideUOCAAASwitch();
3158      hideUOCAAASwitchAndUpdate(); 
3159
3160      if (insValue.indexOf("Medicare") >= 0) {
3161        medicareall();
3162      } else {
3163        inpersonall();
3164      }
3165
3166      initGrid(''); // Pass empty to show all visible items and sort by byDate
3167      return;
3168    } 
3169
3170    // Call specific location functions
3171    switch (selectedOption) {
3172      case '.nycall':
3173        nycall();
3174        console.log("nycall() function called");
3175        break;
3176      case '.njall':
3177        njall();
3178        console.log("njall() function called");
3179        break;
3180      case '.ctall':
3181        ctall();
3182        console.log("ctall() function called");
3183        break;
3184      case '.flall':
3185        flall();
3186        console.log("flall() function called");
3187        break;
3188      default:
3189        if (insValue !== 'unselect') {
3190          locationall();
3191          console.log("locationall() function called");
3192        }
3193    }
3194
3195    // Always call these
3196    uoctelehealth();
3197    NYPall();
3198
3199    // Initialize or re-sort the grid
3200    initGrid(locationValue);
3201  }
3202
3203  function initGrid(locationValue) {
3204    const $grid = $('.grid');
3205    const isShowingAll = !locationValue;
3206
3207    $grid.isotope({
3208      itemSelector: '.element-item',
3209      filter: function () {
3210        if (isShowingAll) {
3211          return !$(this).is(':hidden') && !$(this).hasClass('hide-me');
3212        }
3213        return !$(this).is(':hidden') &&
3214               $(this).hasClass(locationValue) &&
3215               !$(this).hasClass('hide-me');
3216      },
3217      layoutMode: 'fitRows',
3218      fitRows: { gutter: 0 },
3219      transitionDuration: 0,
3220      getSortData: {
3221        priority: function (element) {
3222          const $el = $(element);
3223          if ($el.hasClass('innetwork') && $el.hasClass('book-me')) return 0;
3224          if ($el.hasClass('innetwork') && $el.hasClass('call-me')) return 1;
3225          if ($el.hasClass('outofnetwork') && $el.hasClass('book-me')) return 2;
3226          if ($el.hasClass('outofnetwork') && $el.hasClass('call-me')) return 3;
3227          return 4;
3228        },
3229        byDate: el => Date.parse($(el).attr('datetime') || ''),
3230        bylocDate: el => Date.parse($(el).attr('locdatetime') || ''),
3231        byvcDate: el => Date.parse($(el).attr('vcdatetime') || ''),
3232        providerName: '[data-breadcrumb]'
3233      },
3234      sortAscending: true,
3235      sortBy: isShowingAll
3236        ? ['priority', 'byDate', 'byvcDate', 'providerName']
3237        : ['priority', 'bylocDate', 'byvcDate', 'providerName']
3238    });
3239
3240    $grid.isotope('updateSortData').isotope();
3241  }
3242  function hideUOCAAASwitchAndUpdate() {
3243    //alert("update")
3244    hideUOCAAASwitch();
3245
3246    const $grid = $('.grid');
3247    $grid.isotope('updateSortData').isotope();
3248  }
3249}
3250
3251locationAPISwitch();
3252
3253
3254
3255})
3256.catch(error => {
3257  // Handle any errors here
3258  console.error("Error fetching Availability API:", error);
3259});
3260}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.