📋 Simple EMR Dashboard
// conversions
tempF.addEventListener("input",()=>{const f=parseFloat(tempF.value);tempC.textContent=!isNaN(f)?`Temperature in Celsius: ${((f-32)*5/9).toFixed(1)} °C`:"";});
heightIn.addEventListener("input",()=>{const i=parseFloat(heightIn.value);heightCm.textContent=!isNaN(i)?`Height in cm: ${(i*2.54).toFixed(1)} cm`:"";});
weightLb.addEventListener("input",()=>{const w=parseFloat(weightLb.value);weightKg.textContent=!isNaN(w)?`Weight in kg: ${(w*0.453592).toFixed(1)} kg`:"";});
// save patient
emrForm.addEventListener("submit",e=>{
e.preventDefault();
const patient={name:name.value,age:age.value,sex:sex.value,heightIn:heightIn.value,weightLb:weightLb.value,
symptoms:symptoms.value,diagnosis:diagnosis.value,heartRate:heartRate.value,respRate:respRate.value,
systolic:systolic.value,diastolic:diastolic.value,tempF:tempF.value,spo2:spo2.value,notes:"",orders:[]};
let patients=JSON.parse(localStorage.getItem("patients"))||[];
patients.push(patient);localStorage.setItem("patients",JSON.stringify(patients));
status.textContent="✅ Record saved successfully!";emrForm.reset();tempC.textContent=heightCm.textContent=weightKg.textContent="";
});
function showHub(){formSection.style.display="none";chartSection.style.display="none";hubSection.style.display="block";
patientList.innerHTML="";const patients=JSON.parse(localStorage.getItem("patients"))||[];
patients.forEach((p,i)=>{const li=document.createElement("li");li.textContent=`${i+1}. ${p.name}, Age ${p.age}, Sex ${p.sex}`;
li.onclick=()=>openChart(i);patientList.appendChild(li);});
}
function showForm(){hubSection.style.display="none";chartSection.style.display="none";formSection.style.display="block";}
let currentIndex=null;
function openChart(i){hubSection.style.display="none";formSection.style.display="none";chartSection.style.display="block";
const patients=JSON.parse(localStorage.getItem("patients"))||[];const p=patients[i];currentIndex=i;
chartTitle.textContent=`Patient Chart: ${p.name}`;chartDetails.innerHTML=`Age: ${p.age}
Sex: ${p.sex}
Diagnosis: ${p.diagnosis}
Symptoms: ${p.symptoms}
`;
chartNotes.value=p.notes||"";orderList.innerHTML="";p.orders.forEach(o=>{const li=document.createElement("li");li.textContent=`${o.text} - ${o.info}`;orderList.appendChild(li);});
}
function saveNotes(){let patients=JSON.parse(localStorage.getItem("patients"))||[];patients[currentIndex].notes=chartNotes.value;
localStorage.setItem("patients",JSON.stringify(patients));alert("Notes saved!");}
orderForm.addEventListener("submit",e=>{
e.preventDefault();let patients=JSON.parse(localStorage.getItem("patients"))||[];
const order={text:orderText.value,info:orderInfo.value