mirror of
https://github.com/gauvainboiche/ketapk.git
synced 2026-09-02 03:03:11 +02:00
65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
import { CalculatorEngine } from '../../pkCore.js';
|
|
|
|
export function initCalculatorUI() {
|
|
const modal = document.getElementById('modalCalc');
|
|
const btnOpen = document.getElementById('btnOpenCalc');
|
|
const btnClose = document.getElementById('btnCloseCalc');
|
|
|
|
if (!modal || !btnOpen || !btnClose) return;
|
|
|
|
// 1. Ouverture de la modale & synchronisation avec le formulaire principal
|
|
btnOpen.addEventListener('click', () => {
|
|
const mainWeight = document.getElementById('inputWeight')?.value || 70;
|
|
const mainConc = document.getElementById('inputConc')?.value || 5;
|
|
|
|
document.getElementById('calcWeight').value = mainWeight;
|
|
document.getElementById('calcConc').value = mainConc;
|
|
|
|
modal.classList.remove('hidden');
|
|
});
|
|
|
|
// 2. Fermeture via le bouton X
|
|
btnClose.addEventListener('click', () => {
|
|
modal.classList.add('hidden');
|
|
});
|
|
|
|
// 3. Fermeture au clic sur le fond sombre
|
|
modal.addEventListener('click', (e) => {
|
|
if (e.target === modal) {
|
|
modal.classList.add('hidden');
|
|
}
|
|
});
|
|
|
|
// 4. Logique de conversion en temps réel
|
|
const calcWeightInput = document.getElementById('calcWeight');
|
|
const mgInput = document.getElementById('calcMg');
|
|
const mgKgInput = document.getElementById('calcMgKg');
|
|
const mgKgHInput = document.getElementById('calcMgKgH');
|
|
const ugKgMinInput = document.getElementById('calcUgKgMin');
|
|
|
|
const getWeight = () => parseFloat(calcWeightInput.value) || 70;
|
|
|
|
// Bolus : mg -> mg/kg
|
|
mgInput.addEventListener('input', () => {
|
|
const mg = parseFloat(mgInput.value);
|
|
mgKgInput.value = isNaN(mg) ? '' : (mg / getWeight()).toFixed(2);
|
|
});
|
|
|
|
// Bolus : mg/kg -> mg
|
|
mgKgInput.addEventListener('input', () => {
|
|
const mgKg = parseFloat(mgKgInput.value);
|
|
mgInput.value = isNaN(mgKg) ? '' : (mgKg * getWeight()).toFixed(1);
|
|
});
|
|
|
|
// Perfusion : mg/kg/h -> µg/kg/min
|
|
mgKgHInput.addEventListener('input', () => {
|
|
const mgKgH = parseFloat(mgKgHInput.value);
|
|
ugKgMinInput.value = isNaN(mgKgH) ? '' : CalculatorEngine.mgKgHToMicrogKgMin(mgKgH).toFixed(1);
|
|
});
|
|
|
|
// Perfusion : µg/kg/min -> mg/kg/h
|
|
ugKgMinInput.addEventListener('input', () => {
|
|
const ug = parseFloat(ugKgMinInput.value);
|
|
mgKgHInput.value = isNaN(ug) ? '' : CalculatorEngine.microgKgMinToMgKgH(ug).toFixed(2);
|
|
});
|
|
} |