Script
Script
document.querySelectorAll('.card-container').forEach(cardContainer => {
cardContainer.addEventListener('click', () => {
const card = cardContainer.querySelector('.card');
if (activeCard === card) return;
if (activeCard) {
activeCard.classList.remove('flip');
}
card.classList.add('flip');
activeCard = card;
});
});
// Logout function
function logout() {
sessionStorage.removeItem('loggedIn');
window.location.href = 'index.html';
}
const newPatient = {
id: ++lastPatientId,
name: document.getElementById('name').value,
dob: document.getElementById('dob').value,
ssn: document.getElementById('ssn').value,
address: document.getElementById('address').value
};
if (patient) {
patient.name = document.getElementById('editName').value;
patient.dob = document.getElementById('editDob').value;
patient.address = document.getElementById('editAddress').value;
document.getElementById('editResponseMessage').textContent = "Patient
information updated successfully!";
editPatientForm.reset();
} else {
document.getElementById('editResponseMessage').textContent = "Patient
not found.";
}
});
}
if (patient) {
document.getElementById('editName').value = patient.name;
document.getElementById('editDob').value = patient.dob;
document.getElementById('editAddress').value = patient.address;
document.getElementById('editPatientDetails').style.display = 'block';
} else {
alert("Patient not found.");
}
}
// Delete patient
const deletePatientForm = document.getElementById('deletePatientForm');
if (deletePatientForm) {
deletePatientForm.addEventListener('submit', function (e) {
e.preventDefault();
const ssn = document.getElementById('deletePatientSsn').value;
const patientIndex = patients.findIndex(p => p.ssn === ssn);
patients.forEach(patient => {
const patientDiv = document.createElement('div');
patientDiv.textContent = `ID: ${patient.id}, Name: ${patient.name}, DOB: $
{patient.dob}, SSN: ${patient.ssn}, Address: ${patient.address}`;
patientListDiv.appendChild(patientDiv);
});
}
if (patient) {
document.getElementById('searchResult').textContent = `Patient found:
ID: ${patient.id}, Name: ${patient.name}`;
} else {
document.getElementById('searchResult').textContent = "Patient not
found.";
}
});
}