Potassium Correction Calculator
Relevant source files
The following files were used as context for generating this wiki page:The Potassium Correction Calculator is a feature within the MDcalc application designed to assist healthcare professionals in calculating the required dosage for correcting a patient's potassium levels. It provides dose calculations for both Asparkam and 7.5% potassium chloride (KCl) based on the patient's current potassium level and weight. The calculator aims to correct the potassium level to a fixed target of 4.5 mmol/L.
This calculator is one of several tools available in the application, which also includes an Electrolyte Correction Calculator, an Antibiotic Prophylaxis Calculator, and a Pediatric Dose Calculator. It is implemented as a standalone React component and is integrated into the main application page.
Sources: PROJECT_SUMMARY.md, src/calculators/PotassiumCorrectionCalculator.tsx:71-74, src/app/page.tsx:18-35
Architecture and Component Structure
The calculator is implemented as a functional React component, PotassiumCorrectionCalculator, located in src/calculators/PotassiumCorrectionCalculator.tsx. It utilizes React hooks for state management and is built using reusable presentational components.
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:10
State Management
The component manages its state using the useState hook for two primary pieces of data: user inputs and calculation results.
inputs: An object of typePotassiumCorrectionInputsthat stores the values entered by the user. It is initialized with default values.result: An object of typePotassiumCorrectionResultornull. It holds the calculated results and isnullbefore a calculation is performed or after a reset.
// src/calculators/PotassiumCorrectionCalculator.tsx:11-18
const [inputs, setInputs] = useState<PotassiumCorrectionInputs>({
currentPotassium: 3.0,
weight: 70,
useAsparkam: true,
});
const [result, setResult] = useState<PotassiumCorrectionResult | null>(null);
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:11-18
UI Components
The calculator's user interface is constructed from a set of reusable components found in the src/components/ directory.
| Component | File Path | Purpose |
|---|---|---|
Card | src/components/Card.tsx | Provides a container with a title and subtitle for the calculator. |
NumberInput | src/components/NumberInput.tsx | Used for capturing the patient's current potassium and weight. |
Checkbox | src/components/Checkbox.tsx | Allows the user to select whether to use Asparkam for the calculation. |
Button | src/components/Button.tsx | Used for the "Calculate" and "Reset" actions. |
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:3-7, src/calculators/PotassiumCorrectionCalculator.tsx:71-110
Data Flow and Logic
The following diagram illustrates the data flow from user input to the display of results within the PotassiumCorrectionCalculator component.
This diagram shows the user interaction and internal state updates within the calculator component.
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:20-69
Data Structures
The data models for the calculator's inputs and results are defined in src/types/index.ts.
PotassiumCorrectionInputs
This interface defines the shape of the user-provided data.
| Field | Type | Description |
|---|---|---|
currentPotassium | `number | null` |
weight | `number | null` |
useAsparkam | boolean | A flag to indicate if Asparkam should be considered in the calculation. |
Sources: src/types/index.ts:2-6
PotassiumCorrectionResult
This interface defines the structure of the calculation output.
| Field | Type | Description |
|---|---|---|
deficit | number | The total calculated potassium deficit in mmol. |
asparkamDose | number | The required dose of 10% Asparkam solution in ml. |
potassiumChlorideDose | number | The required dose of 7.5% KCl solution in ml. |
infusionRate | number | The recommended infusion rate in mmol/hour. |
duration | number | The estimated duration of the infusion in hours. |
Sources: src/types/index.ts:8-14
Calculation Logic
The core logic resides in the calculateCorrection function. It uses several formulas to determine the correction doses and rates.
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:20-50
Formulas
| Calculation | Formula |
|---|---|
| Potassium Deficit | (4.5 - currentPotassium) * 0.2 * weight |
| Asparkam Dose (ml) | (potassiumDeficit * 39.1) / 10.33 |
| KCl 7.5% Dose (ml) | (potassiumDeficit * 39.1) / 75 |
| Infusion Rate (mmol/hr) | min(20, potassiumDeficit) |
| Duration (hours) | potassiumDeficit / infusionRate |
The target potassium level is a fixed value of 4.5 mmol/L. The maximum infusion rate is capped at 20 mmol/hour for safety.
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:26-38, src/calculators/PotassiumCorrectionCalculator.tsx:90-92
Core Function
The calculateCorrection function orchestrates the entire calculation process.
// src/calculators/PotassiumCorrectionCalculator.tsx:20-50
const calculateCorrection = () => {
// Проверяем, что все необходимые поля заполнены
if (inputs.currentPotassium === null || inputs.weight === null) {
alert(t.pleaseFillAllFields);
return;
}
// Расчет дефицита калия до 4.5 ммоль/л (ммоль)
const potassiumDeficit = (4.5 - inputs.currentPotassium) * 0.2 * inputs.weight;
// Расчет дозы аспаркама 7.5% (мл) по формуле: дефицит * 39.1 / 10.33
const asparkamDose = (potassiumDeficit * 39.1) / 10.33;
// Расчет дозы KCl 7.5% (мл) по формуле: (дефицит * 39.1) / 75
const potassiumChlorideDose = (potassiumDeficit * 39.1) / 75;
// Скорость инфузии (максимум 20 ммоль/час для безопасности)
const maxInfusionRate = 20; // ммоль/час
const infusionRate = Math.min(maxInfusionRate, potassiumDeficit);
// Длительность инфузии
const duration = potassiumDeficit / infusionRate;
setResult({
deficit: Math.round(potassiumDeficit * 10) / 10,
asparkamDose: Math.round(asparkamDose * 10) / 10,
potassiumChlorideDose: Math.round(potassiumChlorideDose * 10) / 10,
infusionRate: Math.round(infusionRate * 10) / 10,
duration: Math.round(duration * 10) / 10,
});
};
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:20-50
Clinical Recommendations and Safety
After a successful calculation, the UI displays a set of clinical recommendations to ensure patient safety during potassium correction. These recommendations are hardcoded as internationalized strings.
The recommendations include:
- Maximum potassium infusion rate: 20 mmol/hour.
- Monitor potassium level every 2-4 hours.
- Stop infusion if potassium level > 5.5 mmol/L.
- ECG monitoring for severe hypokalemia.
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:142-148, src/i18n/translations.ts:200-203
Internationalization (i18n)
All user-facing text, including labels, buttons, results, and recommendations, is handled through an internationalization system. The component uses the useLanguage hook to get the translation function t. The text strings are defined in src/i18n/translations.ts for multiple languages (English, Russian, Ukrainian).
// src/calculators/PotassiumCorrectionCalculator.tsx:10
const { t } = useLanguage();
// Example usage
// src/calculators/PotassiumCorrectionCalculator.tsx:80
label={t.currentPotassiumLevel}
Sources: src/calculators/PotassiumCorrectionCalculator.tsx:10, src/i18n/translations.ts:15-18, 71-82, 198-203
Evolution to ElectrolyteCorrectionCalculator
It is worth noting that a more advanced ElectrolyteCorrectionCalculator exists in the codebase. This newer component also includes logic for potassium correction but as part of a broader system for managing multiple electrolytes (sodium, magnesium, calcium). The logic for potassium correction in ElectrolyteCorrectionCalculator is more detailed, including oral dose calculations and more extensive notes.
Sources: src/calculators/ElectrolyteCorrectionCalculator.tsx:96-140