Skip to content

Latest commit

 

History

History
185 lines (161 loc) · 6.39 KB

File metadata and controls

185 lines (161 loc) · 6.39 KB
layout base
menu nav/home.html
permalink /make_post

Rate a Hospital

Hospital name UC San Diego Medical Center Rady Children's Hospital Scripps Memorial Hospital La Jolla Jacobs Medical Center
  <!-- Title -->
  <div>
    <label for="title" class="block text-sm font-medium text-gray-700">Rating out of 5</label>
    <input type="text" id="title" name="title" placeholder="Enter title" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:ring-red-500 focus:border-red-500">
  </div>

  <!-- Description -->
  <div>
    <label for="description" class="block text-sm font-medium text-gray-700">Description</label>
    <textarea id="description" name="description" placeholder="Describe your car post" rows="3" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:ring-red-500 focus:border-red-500"></textarea>
  </div>

  <!-- Submit Button -->
  <div class="text-center">
    <button id="submit-btn" class="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
      Submit
    </button>
  </div>
</div>

All Hospital Ratings

Loading ratings...

<script type="module"> let pythonURI; if (location.hostname === "localhost") { pythonURI = "https://medipulse.opencodingsociety.com/"; } else if (location.hostname === "127.0.0.1") { pythonURI = "https://medipulse.opencodingsociety.com/"; } else { pythonURI = "https://medipulse.opencodingsociety.com/"; } async function createPost(post) { const postOptions = { method: "POST", mode: "cors", cache: "default", credentials: "include", headers: { "Content-Type": "application/json", "X-Origin": "client", }, body: JSON.stringify({ title: post.title, description: post.description, car_type: post.car_type, image_base64_table: [] // required field in API }), }; const endpoint = pythonURI + "/api/carPost"; try { const response = await fetch(endpoint, postOptions); if (!response.ok) { throw new Error(`Failed to create post: ${response.status}`); } const result = await response.json(); return true; } catch (error) { console.error("Error creating post:", error.message); return false; } } const submitButton = document.getElementById('submit-btn'); async function submit() { const title = document.getElementById('title').value; const description = document.getElementById('description').value; const carType = document.getElementById('car_type').value; if (!title || !description || !carType) { alert('All fields are required'); return; } try { const created = await createPost({ title: title, description: description, car_type: carType }); if (created) { window.location.href = '{{site.baseurl}}/allPosts'; } else { alert('Failed to create post. Please try again.'); } } catch (error) { console.error('Error creating post:', error); alert('An error occurred while creating your post. Please try again.'); } } // Function to load and display hospital ratings async function loadHospitalRatings() { const endpoint = pythonURI + "/api/carPost"; // Use the carPost endpoint // Define fetchOptions if not already available const fetchOptions = { method: 'GET', mode: 'cors', cache: 'default', credentials: 'include', headers: { 'Content-Type': 'application/json', 'X-Origin': 'client' // Custom header }, }; try { const response = await fetch(endpoint, fetchOptions); if (!response.ok) { throw new Error(`Failed to fetch hospital ratings: ${response.status}`); } const ratings = await response.json(); const container = document.getElementById('hospital-ratings-container'); container.innerHTML = ''; // Clear loading message if (ratings.length === 0) { container.innerHTML = '

No ratings found.

'; return; } ratings.forEach(rating => { const ratingElement = document.createElement('div'); ratingElement.classList.add('p-4', 'border', 'rounded-md', 'shadow-sm'); ratingElement.innerHTML = `

${rating.hospital || rating.title}

Rating: ${rating.rating}/5

${rating.description}

Posted by ${rating.user ? rating.user.name : 'Unknown User'} on ${new Date(rating.date_posted).toLocaleDateString()}
`; container.appendChild(ratingElement); }); } catch (error) { console.error('Error loading hospital ratings:', error); const container = document.getElementById('hospital-ratings-container'); container.innerHTML = '

Error loading ratings.

'; } } submitButton.addEventListener('click', submit); // Load ratings when the page loads loadHospitalRatings(); </script>