Type Definitions
Relevant source files
The following files were used as context for generating this wiki page:The project leverages TypeScript to enforce strict data structures, ensuring type safety and data integrity for all medical calculations. Type definitions are crucial for standardizing the inputs and outputs of each calculator, managing application state, and supporting internationalization. While some complex types are defined locally within their respective calculator components, the standard practice is to define shared types in src/types/index.ts.
This document outlines the key data structures used across the application, including core application types and the specific data models for each medical calculator. The use of well-defined types is fundamental to the project's goal of providing accurate and reliable medical calculations.
Sources: CONTRIBUTING.md:3-16, src/calculators/BloodGasAnalysisCalculator.tsx:6-69
Core Application Types
These types are fundamental to the application's routing, state management, and internationalization features.
CalculatorType
This string literal union type is used in the main application component to manage which calculator is currently active and displayed to the user.
- File:
src/app/page.tsx
// src/app/page.tsx:11
type CalculatorType = 'home' | 'electrolyte' | 'antibiotic' | 'pediatric' | 'bloodGas' | 'infusionTherapy';
The state is managed in the Home component:
// src/app/page.tsx:14
const [activeCalculator, setActiveCalculator] = useState<CalculatorType>('home');
Sources: src/app/page.tsx:11-14
Internationalization Types
The internationalization (i18n) system uses types to ensure that all required translation strings are available for each supported language.
- File:
src/i18n/translations.ts
Language
A string literal union defining the supported language codes.
// src/i18n/translations.ts:1
export type Language = 'en' | 'ru' | 'uk';
Translations
An interface that defines the schema for the translation keys. Each key corresponds to a string in the UI.
// src/i18n/translations.ts:3-9
export interface Translations {
// Navigation
home: string;
potassium: string;
wounds: string;
children: string;
about: string;
// ... more keys
}
This structure is used to create a translations object that holds the text for all supported languages, ensuring consistency.
Sources: src/i18n/translations.ts:1-9
Calculator-Specific Types
Each calculator follows a standard pattern of using two primary interfaces: one for inputs (<CalculatorName>Inputs) and one for results (<CalculatorName>Result). This pattern is recommended for all new contributions.
Sources: CONTRIBUTING.md:3-16
Blood Gas Analysis Calculator Types
This calculator defines its data structures locally due to their complexity and specificity.
- File:
src/calculators/BloodGasAnalysisCalculator.tsx
BloodGasData (Inputs)
This interface defines the extensive set of input parameters required for a comprehensive blood gas analysis.
| Field | Type | Description |
|---|---|---|
ph | number | null | Blood pH level. |
pco2 | number | null | Partial pressure of carbon dioxide. |
hco3 | number | null | Bicarbonate level. |
pao2 | number | null | Partial pressure of oxygen. |
na | number | null | Sodium level. |
cl | number | null | Chloride level. |
k | number | null | Potassium level. |
sampleType | 'arterial' | 'venous' | Type of blood sample. |
albumin | number | null | Albumin level for corrected anion gap. |
includeK | boolean | Flag to include potassium in anion gap calculation. |
fio2 | number | null | Fraction of inspired oxygen. |
age | number | null | Patient's age. |
glucose | number | null | Glucose level for osmolar gap. |
bun | number | null | Blood Urea Nitrogen for osmolar gap. |
ethanol | number | null | Ethanol level for osmolar gap. |
urineNa | number | null | Urine sodium for urine anion gap. |
urineK | number | null | Urine potassium for urine anion gap. |
urineCl | number | null | Urine chloride for urine anion gap. |
hemoglobin | number | null | Hemoglobin for Base Excess calculation. |
oxygenSaturation | number | null | Oxygen saturation for Base Excess calculation. |
Sources: src/calculators/BloodGasAnalysisCalculator.tsx:7-29
BloodGasResult (Outputs)
This interface structures the calculated results, including interpretations, warnings, and treatment advice.
The following diagram illustrates the composition of the BloodGasResult interface.
This structure separates raw calculated values from derived interpretations and actionable advice, making the output highly organized and useful for clinical decision support.
Sources: src/calculators/BloodGasAnalysisCalculator.tsx:31-69
Pediatric Dose Calculator Types
The types for this calculator are defined in src/types/index.ts and imported into the component. Their structure can be inferred from their usage.
- File:
src/calculators/PediatricDoseCalculator.tsx
PediatricDoseInputs
This interface captures the necessary patient and medication details for pediatric dose calculation.
| Field | Type | Description |
|---|---|---|
age | number | null | Child's age in years. |
weight | number | null | Child's weight in kg. |
height | number | null | Child's height in cm (for BSA calculation). |
medication | string | Name of the medication. |
indication | string | Reason for administering the medication. |
route | 'oral' | 'iv' | 'im' | 'sc' | Route of administration. |
Sources: src/calculators/PediatricDoseCalculator.tsx:13-20
PediatricDoseResult
This interface structures the output, including safety checks, dose recommendations, and warnings.
| Field | Type | Description |
|---|---|---|
isSafe | boolean | Indicates if the dose is considered safe. |
isContraindicated | boolean | Indicates if the medication is contraindicated. |
contraindicationReason | string | Explanation if contraindicated. |
recommendedDose | number | The calculated single dose. |
doseUnit | string | The unit for the dose (e.g., 'mg'). |
frequency | string | How often the dose should be given. |
totalDailyDose | number | The total calculated dose for a 24-hour period. |
warnings | string[] | Array of important warnings. |
notes | string[] | Array of additional notes and context. |
bsa | number | undefined | Calculated Body Surface Area, if applicable. |
Sources: src/calculators/PediatricDoseCalculator.tsx:22-34, src/calculators/PediatricDoseCalculator.tsx:280-292
Infusion Therapy Calculator Types
Like the pediatric calculator, these types are imported, and their structure is inferred from the component's state and logic.
- File:
src/calculators/InfusionTherapyCalculator.tsx
InfusionTherapyInputs
This interface is highly detailed, capturing a wide range of patient parameters for a comprehensive infusion plan.
| Field | Type | Description |
|---|---|---|
weight | number | Patient's weight in kg. |
height | number | Patient's height in cm. |
age | number | Patient's age in years. |
gender | 'male' | 'female' | Patient's gender. |
serumSodium | number | Serum sodium level. |
hasDehydration | boolean | Clinical sign of dehydration. |
hasFever | boolean | Presence of fever. |
isPostoperative | boolean | Whether the patient is in a postoperative state. |
bloodPressure | { systolic: number, diastolic: number } | Systolic and diastolic blood pressure. |
... | ... | Many other clinical, lab, and surgical factors. |
Sources: src/calculators/InfusionTherapyCalculator.tsx:8-40
InfusionTherapyResult
The result object contains calculated fluid requirements and a structured plan for infusion and monitoring.
The diagram below shows the relationships within the InfusionTherapyResult type.
Type Contribution Guide
The CONTRIBUTING.md file provides a clear guide for adding new calculators, which starts with defining the necessary types.
Process for Adding New Types
When creating a new calculator, developers must first define its input and result interfaces in src/types/index.ts.
The following flowchart illustrates the development process for a new calculator, emphasizing the initial type definition step.
Example Type Definitions
The contribution guide provides a template for these interfaces.
// src/types/index.ts
export interface NewCalculatorInputs {
// Define input parameters
parameter1: number;
parameter2: string;
// ...
}
export interface NewCalculatorResult {
// Define calculation result
result1: number;
result2: string;
// ...
}
This standardized approach ensures that all calculators in the application are built with a consistent and predictable data structure.
Sources: CONTRIBUTING.md:5-16