TN / search.js
rainbowhunt's picture
Upload 22 files
fb33344 verified
// Search functionality for the TN Medical Connect site
document.addEventListener('DOMContentLoaded', function() {
// Set up search forms
const searchForms = document.querySelectorAll('.search-form');
searchForms.forEach(form => {
form.addEventListener('submit', function(e) {
e.preventDefault();
const searchInput = this.querySelector('input[type="text"]');
const searchTerm = searchInput.value.trim();
if (searchTerm) {
// Get search category if available (podcasts, research, etc.)
const category = this.dataset.category || '';
const finalSearchTerm = category ? `${category} ${searchTerm}` : searchTerm;
// Show loading state
const resultsContainer = document.getElementById('search-results');
if (resultsContainer) {
resultsContainer.innerHTML = '<div class="text-center py-4"><i class="fas fa-spinner fa-spin text-primary text-2xl"></i><p class="mt-2 text-gray-600">Searching...</p></div>';
}
// In a real implementation, this would call a server-side API
// For this demo, we'll simulate results after a delay
setTimeout(() => {
simulateSearchResults(finalSearchTerm, resultsContainer);
}, 1000);
}
});
});
// Function to simulate search results (in a real app, this would call the server)
function simulateSearchResults(searchTerm, container) {
if (!container) return;
// Simulate different results based on search term
const termLower = searchTerm.toLowerCase();
if (termLower.includes('podcast') || termLower.includes('audio')) {
showPodcastResults(container);
} else if (termLower.includes('research') || termLower.includes('paper') || termLower.includes('study')) {
showResearchResults(container);
} else if (termLower.includes('ai') || termLower.includes('artificial intelligence')) {
showAIResults(container);
} else {
showGeneralResults(container);
}
}
// Simulate podcast results
function showPodcastResults(container) {
container.innerHTML = `
<h3 class="text-xl font-semibold text-gray-800 mb-4">Search Results</h3>
<div class="grid gap-4 md:grid-cols-2">
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Recent Advances in Cardiology</h4>
<p class="text-sm text-gray-600">A discussion with Dr. Ramesh about the latest treatments.</p>
<audio controls class="mt-2 w-full">
<source src="#" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Public Health Initiatives in Tamil Nadu</h4>
<p class="text-sm text-gray-600">How local communities are benefiting from new programs.</p>
<audio controls class="mt-2 w-full">
<source src="#" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
</div>
`;
}
// Simulate research results
function showResearchResults(container) {
container.innerHTML = `
<h3 class="text-xl font-semibold text-gray-800 mb-4">Research Results</h3>
<div class="space-y-4">
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Impact of Climate Change on Vector-borne Diseases in South India</h4>
<p class="text-sm text-gray-500">Journal of Tropical Medicine • March 2025</p>
<p class="text-sm text-gray-600 mt-1">This study examines the correlation between rising temperatures and the spread of dengue and malaria in Tamil Nadu.</p>
<a href="#" class="text-primary text-sm hover:underline mt-2 inline-block">Read Abstract</a>
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Efficacy of Traditional Medicines in Managing Type 2 Diabetes</h4>
<p class="text-sm text-gray-500">Indian Journal of Medical Research • January 2025</p>
<p class="text-sm text-gray-600 mt-1">A randomized controlled trial comparing traditional herbal preparations with standard pharmaceutical interventions.</p>
<a href="#" class="text-primary text-sm hover:underline mt-2 inline-block">Read Abstract</a>
</div>
</div>
`;
}
// Simulate AI results
function showAIResults(container) {
container.innerHTML = `
<h3 class="text-xl font-semibold text-gray-800 mb-4">AI in Healthcare Results</h3>
<div class="space-y-4">
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">AI-Powered Diagnostic Tools for Rural Healthcare</h4>
<p class="text-sm text-gray-600 mt-1">How machine learning is helping bridge the healthcare gap in remote areas of Tamil Nadu.</p>
<div class="flex justify-between items-center mt-2">
<span class="text-xs text-gray-500">Resource Type: Case Study</span>
<a href="#" class="text-primary text-sm hover:underline">View Details</a>
</div>
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Implementing AI Chatbots in Patient Triage</h4>
<p class="text-sm text-gray-600 mt-1">A guide for hospitals looking to adopt AI-powered patient screening systems.</p>
<div class="flex justify-between items-center mt-2">
<span class="text-xs text-gray-500">Resource Type: Implementation Guide</span>
<a href="#" class="text-primary text-sm hover:underline">View Details</a>
</div>
</div>
</div>
`;
}
// General mixed results
function showGeneralResults(container) {
container.innerHTML = `
<h3 class="text-xl font-semibold text-gray-800 mb-4">Search Results</h3>
<div class="space-y-4">
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Upcoming Medical Conferences in Chennai</h4>
<p class="text-sm text-gray-600">View the schedule of medical conferences happening in the next 6 months.</p>
<a href="#" class="text-primary text-sm hover:underline mt-2 inline-block">View Calendar</a>
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Grant Opportunities for Medical Researchers</h4>
<p class="text-sm text-gray-600">Current funding opportunities for research in various medical fields.</p>
<a href="#" class="text-primary text-sm hover:underline mt-2 inline-block">Browse Grants</a>
</div>
<div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
<h4 class="text-lg font-medium">Latest Podcast: Healthcare Challenges in 2025</h4>
<p class="text-sm text-gray-600">A discussion with leading experts about what to expect this year.</p>
<a href="#" class="text-primary text-sm hover:underline mt-2 inline-block">Listen Now</a>
</div>
</div>
`;
}
// Initialize any search fields with the search parameter if present in URL
const urlParams = new URLSearchParams(window.location.search);
const searchParam = urlParams.get('search');
if (searchParam) {
const searchInputs = document.querySelectorAll('.search-form input[type="text"]');
searchInputs.forEach(input => {
input.value = searchParam;
});
// Auto-submit the first search form if a search term is provided in URL
const firstForm = document.querySelector('.search-form');
if (firstForm) {
firstForm.dispatchEvent(new Event('submit'));
}
}
});