Aquí tienes un prototipo de web‑app en HTML/CSS/JavaScript que te permite:
- Calcular dosis de fármacos (mg, volumen y tasa de infusión)
- Calcular la velocidad de usuario (km/h y m/s)
- Trabajar con concentraciones
Puedes clonar este código, alojarlo en tu máquina o servidor, y modificarlo según tus necesidades.
Estructura de archivos
code
drug‐speed‐calculator/
├── index.html
├── style.css
└── script.js
1. index.html
html
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Calculadora Médica & Velocidad</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>🧪 Calculadora de Fármacos & 🏃 Velocidad</h1>
<!-- Sección 1: Dosis de fármacos -->
<section class="card">
<h2>📦 Dosis de Fármacos</h2>
<div class="form-group">
<label>Peso (kg):</label>
<input type="number" id="peso" placeholder="ej. 70" />
</div>
<div class="form-group">
<label>Dosis deseada (mg / kg):</label>
<input type="number" id="dosisPerKg" placeholder="ej. 2" />
</div>
<div class="form-group">
<label>Concentración (mg / mL):</label>
<input type="number" id="concentracion" placeholder="ej. 5" />
</div>
<div class="form-group">
<label>Tiempo de infusión (min) <small>(opcional)</small> :</label>
<input type="number" id="tiempoInfusion" placeholder="ej. 30" />
</div>
<button onclick="calculaFarmaco()">Calcular</button>
<div class="result" id="resultadoFarmaco"></div>
</section>
<!-- Sección 2: Velocidad de usuario -->
<section class="card">
<h2>📏 Velocidad de Usuario</h2>
<div class="form-group">
<label>Distancia (km):</label>
<input type="number" id="distancia" placeholder="ej. 5" step="0.01" />
</div>
<div class="form-group">
<label>Tiempo (min):</label>
<input type="number" id="tiempo" placeholder="ej. 30" />
</div>
<button onclick="calculaVelocidad()">Calcular</button>
<div class="result" id="resultadoVelocidad"></div>
</section>
</div>
<script src="script.js"></script>
</body>
</html>
2. style.css
css
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: #f4f7fa;
margin: 0; padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
}
h1 {
text-align: center;
margin-bottom: 1rem;
}
.card {
background: #fff;
border-radius: 8px;
padding: 1rem 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.form-group {
margin-bottom: .8rem;
}
.form-group label {
display: block;
margin-bottom: .3rem;
}
.form-group input {
width: 100%;
padding: .5rem;
border-radius: 4px;
border: 1px solid #ccc;
}
button {
background: #007bff;
color: #fff;
padding: .6rem 1.2rem;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
.result {
margin-top: 1rem;
padding: .8rem;
background: #e9f7ef;
border: 1px solid #c3e6cb;
border-radius: 4px;
}
3. script.js
javascript
function calculaFarmaco() {
const peso = parseFloat(document.getElementById('peso').value) || 0;
const dosisPerKg = parseFloat(document.getElementById('dosisPerKg').value) || 0;
const conc = parseFloat(document.getElementById('concentracion').value) || 0;
const tInf = parseFloat(document.getElementById('tiempoInfusion').value) || 0;
const resDiv = document.getElementById('resultadoFarmaco');
if(peso <= 0 || dosisPerKg <= 0 || conc <= 0) {
resDiv.innerHTML = '<span style="color:red;">Por favor verifica los valores de peso, dosis y concentración.</span>';
return;
}
// Cálculos
const dosisTotal_mg = peso * dosisPerKg;
const volumen_mL = dosisTotal_mg / conc;
let texto = `
<ul>
<li>Dosis total: <b>${dosisTotal_mg.toFixed(2)} mg</b></li>
<li>Volumen a administrar: <b>${volumen_mL.toFixed(2)} mL</b></li>
</ul>
`;
if(tInf > 0) {
// tasa en mL/h
const tasa_ml_h = volumen_mL / (tInf / 60);
texto += `<p>Tasa de infusión: <b>${tasa_ml_h.toFixed(2)} mL/h</b> (en ${tInf} min)</p>`;
}
resDiv.innerHTML = texto;
}
function calculaVelocidad() {
const distKm = parseFloat(document.getElementById('distancia').value) || 0;
const tMin = parseFloat(document.getElementById('tiempo').value) || 0;
const resDiv = document.getElementById('resultadoVelocidad');
if(distKm <= 0 || tMin <= 0) {
resDiv.innerHTML = '<span style="color:red;">Ingresa distancia y tiempo válidos.</span>';
return;
}
const horas = tMin / 60;
const vel_kmh = distKm / horas;
const vel_ms = (distKm * 1000) / (tMin * 60);
resDiv.innerHTML = `
<ul>
<li>Velocidad: <b>${vel_kmh.toFixed(2)} km/h</b></li>
<li>Velocidad: <b>${vel_ms.toFixed(2)} m/s</b></li>
</ul>
`;
}
Cómo probarlo
- Descarga o copia los 3 archivos en una carpeta.
- Abre
index.html en tu navegador.
- Rellena los campos y haz clic en Calcular.
Puedes extender esta base para:
- Agregar validaciones más complejas.
- Incluir más fórmulas (e.g. aclaramiento renal, dosis pediátricas, etc.).
- Integrar frameworks (React, Vue, Angular) o convertirlo en app móvil con Ionic/React Native.
¡Espero que te sirva como punto de partida! 🚀