function calculateInfusionRate() {
var volumeToInfuse = parseFloat(document.getElementById("volumeToInfuse").value);
var infusionTimeHours = parseFloat(document.getElementById("infusionTimeHours").value);
var infusionTimeMinutes = parseFloat(document.getElementById("infusionTimeMinutes").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(volumeToInfuse) || isNaN(infusionTimeHours) || isNaN(infusionTimeMinutes)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (volumeToInfuse <= 0 || infusionTimeHours < 0 || infusionTimeMinutes < 0) {
resultDiv.innerHTML = "Volume must be positive, and time values cannot be negative.";
return;
}
var totalMinutes = (infusionTimeHours * 60) + infusionTimeMinutes;
if (totalMinutes <= 0) {
resultDiv.innerHTML = "Total infusion time must be greater than zero.";
return;
}
var infusionRateMLPerHour = (volumeToInfuse / totalMinutes) * 60;
var infusionRateMLPerMinute = volumeToInfuse / totalMinutes;
resultDiv.innerHTML = `
Infusion Rate Calculation
Total Volume to Infuse:
${volumeToInfuse.toFixed(2)} mL
Total Infusion Time:
${infusionTimeHours} hours and ${infusionTimeMinutes} minutes (${totalMinutes.toFixed(0)} minutes)
Calculated Infusion Rate:
${infusionRateMLPerHour.toFixed(2)} mL/hour
Calculated Infusion Rate:
${infusionRateMLPerMinute.toFixed(2)} mL/minute
This calculation is for informational purposes only. Always verify with your healthcare provider or pharmacist.
`;
}
.calculator-container {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
background-color: #fff;
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-description {
color: #555;
font-size: 0.9em;
text-align: center;
margin-bottom: 25px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
color: #444;
font-weight: bold;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
.calculator-button {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #eee;
border-radius: 4px;
background-color: #f9f9f9;
}
.calculator-result h3 {
color: #007bff;
margin-top: 0;
text-align: center;
margin-bottom: 15px;
}
.calculator-result p {
margin-bottom: 8px;
font-size: 0.95em;
color: #333;
}
.calculator-result strong {
color: #007bff;
}
.calculator-result .disclaimer {
font-size: 0.8em;
color: #777;
text-align: center;
margin-top: 15px;
}
.calculator-result .error {
color: #dc3545;
font-weight: bold;
}