`, '') : ``; /* Get the tracking pixels wrapper element */ const wrapper = document.querySelector('#pixels-wrapper'); /* If the wrapper element already exists, append to it. If not, create it with the pixels inside */ if (wrapper) { wrapper.insertAdjacentHTML('beforeend', pixels); } else { document.body.insertAdjacentHTML('beforeend', `
No providers found as this location
' : ''}${this.state.results.error.message}
`; return; }; /* Update state now that an initial search has been completed */ this.state.filters.init = false; /* Grabs the total number of results */ const count = this.state.filters.LocationsOnly ? this.state.results.locations.length : this.state.results["@odata.count"]; /* Calculate how many pages we need for the number of results returned. */ this.state.filters.pages = Math.ceil(count / post.top); /* Add badges for the applied filters */ const filtersElem = document.getElementById("filter-buttons"); filtersElem.innerHTML = ""; const filtersSorted = this.state.results.info.filters.sort((a,b) => a.text ? -1 : 1); const filtersBadged = []; for (let filter of search.state.results.info.filters) { let filterButton = document.createElement("span"); filterButton.classList.add("filter-button"); filterButton.innerHTML = `✖ ${filter.value}`; const { facets } = filter; /* if the text for a search is returned... */ if (filter.text) { filterButton.setAttribute('data-text', filter.text); for (let facet of facets) { try { const facetFilter = this.state.filters[facet.name]; if (facetFilter) { facetFilter[facet.value] = {...facetFilter[facet.value], text: filter.text, auto: filter.auto == true}; filtersBadged.push(`${facet.name}${facet.value}`); } } catch (e) { throw(e); } } /* otherwise... */ } else { if (filter.value == 1) { continue; }; /* everything else should have a length of 1 but let's check to be safe. If the value has already had a badge created, break out of this current loop iteration. */ if (facets.length === 1 && filtersBadged.includes(`${facets[0].name}${facets[0].value}`)) { continue; /* If a badge doesn't already exist, we'll add it to the badged array and keep on in this interation */ } else { filtersBadged.push(`${facets[0].name}${facets[0].value}`); } }; filterButton.setAttribute('data-facets', JSON.stringify(filter.facets)); filterButton.addEventListener('click', e => { const { target } = e; const { dataset } = target; if (dataset.text) { let theRegEx = new RegExp(dataset.text, "gi"); window.sessionStorage.setItem('previousQuery', this.state.query); this.state.query = this.state.query.replaceAll(/ +/gi, " ").replaceAll(theRegEx, "").replaceAll(/ +/gi, " ").trim(); document.getElementById("query").value = this.state.query; }; const facets = JSON.parse(dataset.facets); for (let facet of facets) { const { name, value } = facet; const state = this.state.filters[name]; if (state) { if (typeof state === 'string') { this.state.filters[name] = false; } else if (typeof state === 'object') { state[value].active = false; } } if (name == "InsuranceAccepted") { let lsInsurance = localStorage.getItem('omniSearchInsurance') || false; if (lsInsurance) { lsInsurance = lsInsurance.split(',').filter(ins => { ins != value }); lsInsurance.length ? localStorage.setItem('omniSearchInsurance', lsInsurance.join(',')) : localStorage.removeItem('omniSearchInsurance'); } } } this.handleSubmit(); }); filtersElem.appendChild(filterButton); } /* If we're sending a page that is greater than results paginated, reset to page one and redo the search. */ if (results.providersCount > 0 && results.providers.length === 0) { this.state.filters.page = 1; return this.handleSubmit(); } else if (this.state.filters.pages === 0) { this.state.filters.page = 1; }; /* Determine if we have results or not and display appropriate text. */ let resultsHtml = ""; if (this.state.description) { resultsHtml += `${this.state.description}
`; this.state.description = false; }; if (count == 0) { this.resultsEl.innerHTML = "No results"; return; } /* else { resultsHtml += `Displaying results ${( post.top * (this.state.filters.page - 1) + 1 ).toLocaleString()} - ${( post.top * (this.state.filters.page - 1) + this.state.results.providers.length ).toLocaleString()} of ${count.toLocaleString()}
`; }; */ else { resultsHtml += `
${count.toLocaleString()} results
`; } /* We'll use this to detmine if we show the map or not */ let withLocations = 0; /* If LocationsOnly is set, render the locations for the current page */ if (LocationsOnly){ resultsHtml += this.renderLocations(results.locations); } else { /* For each results on the current page, create a card and append it to our results container */ results.providers.forEach((result) => { const { ImageUrl, ImageSourceUrl, ImageWidth, ImageHeight, Name, PrimarySpecialties, ProviderTitle, Addresses, PracticeGroup, LocationNames, LocationName, Rating, virtual, distance, Npi, id, clinicVisits, NewClinicVisit, NewVideoVisit, GeocodedCoordinate, LocationId, RatingCount, Degrees, Phones, ProfileUrl, AcceptingNewPatients, VirtualCare, SjhScheduleProviderNum, allowsOpenSchedule, allowsDirectSchedule, acceptingNewPatients, AppointmentRequestUrl, DaysUntilNextAppt, DaysUntilFollowUpAppt, Tier, ProviderOrganization } = result; const width = (150 / ImageHeight) * ImageWidth; const badges = result.badges ? Object.values(result.badges) : []; const supportsOdhp = (acceptingNewPatients == 1 && allowsOpenSchedule == 1) || allowsDirectSchedule == 1; const onlineBooking = supportsOdhp || SjhScheduleProviderNum ? true : false; let hasTimeslots = false; let slotsType = ""; let AcceptingClinicVisits = AcceptingNewPatients == 1 ? `${descr}
${rating} ${offersVirtual} ${AcceptingClinicVisits} ${isTest && Tier ? `${curr}
`, '') + 'No appointments available for online booking within the next 30 days.
View more appointment options here