Pediatric Dose Calculator
Relevant source files
The following files were used as context for generating this wiki page:
The Pediatric Dose Calculator is a feature within the Medical Calculators application designed to compute pediatric drug dosages based on a child's age and weight. It provides a user-friendly interface for healthcare professionals to select a medication, input patient data, and receive a calculated dose, along with safety checks, contraindications, and important warnings. The calculator leverages a comprehensive internal database of 38 common pediatric medications.
This module is a key component of the application's clinical decision support tools, alongside the Electrolyte Correction Calculator and Wound Antibiotic Prophylaxis Calculator. It emphasizes safety by checking age and weight restrictions and providing clear, actionable results.
Sources: PROJECT_SUMMARY.md, src/calculators/PediatricDoseCalculator.tsx:370-373, PEDIATRIC_CALCULATOR.md
Architecture and Components
The Pediatric Dose Calculator is implemented as a single React component, PediatricDoseCalculator, which encapsulates all the logic for user input, calculation, and result display. It is integrated into the main application page and can be selected from the navigation menu.
Sources: src/app/page.tsx:7, 71-82, 303-317, src/calculators/PediatricDoseCalculator.tsx:11
Component Interaction
The following diagram illustrates how the PediatricDoseCalculator interacts with other parts of the application.
This diagram shows that page.tsx renders the PediatricDoseCalculator component. The calculator fetches medication data from pediatricMedicationsDatabase and UI text from translations.ts via the useLanguage hook, and it is built using reusable UI components like Card and NumberInput.
Sources: src/app/page.tsx:7, 315, src/calculators/PediatricDoseCalculator.tsx:4-13
State Management
The component manages its state using React's useState hook. The key state variables include:
inputs: An object of typePediatricDoseInputsthat stores all user-provided data (age, weight, medication, etc.).result: An object of typePediatricDoseResultthat holds the outcome of the calculation, ornullif no calculation has been performed.searchTerm,selectedCategory: Used for filtering the list of available medications.showAutocomplete,showMedicationsList: Boolean flags to control the visibility of UI elements like the medication search dropdown and the full medication list.
Sources: src/calculators/PediatricDoseCalculator.tsx:14-22
Data Model
The calculator relies on an internal data source, pediatricMedicationsDatabase, which is an array of medication objects. Each object contains detailed information required for dosing calculations and safety checks.
Sources: src/calculators/PediatricDoseCalculator.tsx:25, PEDIATRIC_CALCULATOR.md
Medication Data Structure
The structure for each medication in the database is outlined below.
| Field | Type | Description |
|---|---|---|
name | string | The name of the medication. |
category | string | The therapeutic category (e.g., "Analgesics/Antipyretics", "Antibiotics"). |
minAge | number | The minimum age in years for which the medication is indicated. |
minWeight | number | The minimum weight in kg for which the medication is indicated. |
dosingMethods | DosingMethod[] | An array of objects defining how to calculate the dose. |
warnings | string[] | A list of important warnings associated with the medication. |
Sources: src/calculators/PediatricDoseCalculator.tsx:81-84, 98-100, PEDIATRIC_CALCULATOR.md
Dosing Method Structure
The dosingMethods array contains objects specifying the calculation logic.
| Field | Type | Description |
|---|---|---|
type | 'weight' | 'age' | 'fixed' | 'bsa' | The basis for the calculation. |
minDose | number | The minimum dose value for the range. |
maxDose | number | The maximum dose value for the range. |
unit | string | The unit of measurement (e.g., 'mg/kg', 'mg'). |
frequency | string | The recommended frequency of administration (e.g., 'every 6 hours'). |
notes | string | Additional notes, often including route-specific dosing. |
Sources: src/calculators/PediatricDoseCalculator.tsx:103-105, 237-240
Calculation Logic
The core logic resides in the calculateDose function. It executes a series of steps to ensure a safe and accurate dose recommendation.
Sources: src/calculators/PediatricDoseCalculator.tsx:43-305
Data Flow
The following sequence diagram shows the flow of data from user input to the final result display.
This diagram illustrates the user interaction triggering the calculateDose function, which validates inputs, queries the medication database, performs safety checks, and finally calculates and displays the dose.
Sources: src/calculators/PediatricDoseCalculator.tsx:43-305
Calculation Flowchart
This flowchart details the internal logic of the calculateDose function.
This flowchart breaks down the calculateDose function, showing the validation, safety checks, branching logic for different dosing methods, and final result preparation.
Sources: src/calculators/PediatricDoseCalculator.tsx:43-305
Medication Database and Search
The calculator includes a database of 38 medications, which are displayed in an expandable and filterable list. This allows users to browse available drugs or quickly find a specific one.
Sources: PEDIATRIC_CALCULATOR.md, src/calculators/PediatricDoseCalculator.tsx:645-650
Key Features
- Autocomplete Search: As the user types in the medication input field, a dropdown list appears with matching medications from the database. The search matches against both the medication name and its category.
- Category Filtering: Users can filter the full medication list by category (e.g., "Antibiotics", "Analgesics").
- Click to Select: Clicking a medication name in the search results or the full list automatically populates the input field.
- Database Statistics: The UI displays the total number of medications and a count for each category.
- Special Highlighting: Specially requested or verified medications are highlighted in the list for emphasis.
Sources: src/calculators/PediatricDoseCalculator.tsx:441-475, 715-808, PEDIATRIC_CALCULATOR.md
Internationalization (i18n)
The calculator is designed to be multi-lingual. All user-facing strings are managed through a centralized translation system. The useLanguage hook provides a translation function t which retrieves the correct string for the currently selected language based on a key.
Sources: src/calculators/PediatricDoseCalculator.tsx:12, src/i18n/translations.ts
Relevant Translation Keys
The following table lists some of the i18n keys used in the Pediatric Dose Calculator.
| Key | English Value |
|---|---|
pediatricDoses | Pediatric Drug Doses |
pediatricDosesDesc | Calculation of pediatric drug doses considering age and weight. Safety check and contraindications. |
medicationName | Medication name |
childAge | Child age |
childWeight | Child weight |
selectMedication | Select medication |
recommendedDose | Recommended dose |
maxDose | Maximum dose |
contraindications | Contraindications |
contraindicatedForAge | Medication is contraindicated for children under |
medicationNotFound | Medication not found in database |
disclaimerText | This calculator is for informational purposes only... |
Sources: src/i18n/translations.ts:15, 104-124, 161-165
Conclusion
The Pediatric Dose Calculator is a robust and safety-oriented tool for healthcare professionals. It combines a well-structured medication database with a detailed calculation engine to provide reliable dosing recommendations. Key architectural features include component-based UI construction, local state management, a clear data flow for calculations, and built-in support for internationalization. The user interface is enhanced with search, filtering, and autocomplete capabilities to ensure ease of use.