180 lines
5.6 KiB
TypeScript
180 lines
5.6 KiB
TypeScript
/**
|
|
* Application Constants and Type Definitions
|
|
*
|
|
* Defines TypeScript interfaces for application state, pharmacokinetic parameters,
|
|
* and default values. Central configuration for localStorage keys and conversion factors.
|
|
*
|
|
* @author Andreas Weyer
|
|
* @license MIT
|
|
*/
|
|
|
|
import packageJson from '../../package.json';
|
|
// Direct import of version.json - Vite handles this natively with import assertions
|
|
// This file is generated by prebuild script with git info
|
|
// @ts-ignore
|
|
import versionJsonDefault from '../version.json' assert { type: 'json' };
|
|
|
|
// Use the imported version.json, or fall back to -dev version
|
|
const versionInfo = versionJsonDefault && Object.keys(versionJsonDefault).length > 0 && versionJsonDefault.version && !versionJsonDefault.version.includes('unknown')
|
|
? versionJsonDefault
|
|
: {
|
|
version: `${packageJson.version}-dev`,
|
|
semver: packageJson.version,
|
|
commit: 'unknown',
|
|
branch: 'unknown',
|
|
buildDate: new Date().toISOString(),
|
|
gitDate: 'unknown',
|
|
};
|
|
|
|
export const LOCAL_STORAGE_KEY = 'medPlanAssistantState_v9'; // Incremented for urinePh mode structure change
|
|
export const PROJECT_REPOSITORY_URL = 'https://git.11001001.org/cbaoth/med-plan-assistant';
|
|
export const APP_VERSION = versionInfo.version;
|
|
export const BUILD_INFO = versionInfo;
|
|
|
|
// UI Configuration
|
|
export const MAX_DOSES_PER_DAY = 6; // Maximum number of doses allowed per day
|
|
|
|
// Pharmacokinetic Constants (from research literature)
|
|
// MW ratio: 135.21 (d-amphetamine) / 455.60 (LDX dimesylate) = 0.29677
|
|
export const LDX_TO_DAMPH_SALT_FACTOR = 0.29677;
|
|
// Oral bioavailability for LDX (FDA label, 96.4%)
|
|
export const DEFAULT_F_ORAL = 0.96;
|
|
|
|
// Type definitions
|
|
export interface AdvancedSettings {
|
|
standardVd: { preset: 'adult' | 'child' | 'custom' | 'weight-based'; customValue: string; bodyWeight: string }; // Volume of distribution (L)
|
|
foodEffect: { enabled: boolean; tmaxDelay: string }; // hours
|
|
urinePh: { mode: 'normal' | 'acidic' | 'alkaline' }; // pH effect on elimination
|
|
fOral: string; // bioavailability fraction
|
|
steadyStateDays: string; // days of medication history to simulate
|
|
// Age-specific pharmacokinetics (Research Section 5.2)
|
|
// Children (6-12y) have faster elimination: t½ ~9h vs adult ~11h
|
|
ageGroup?: {
|
|
preset: 'child' | 'adult' | 'custom';
|
|
};
|
|
// Renal function effects (Research Section 8.2, FDA label 8.6)
|
|
// Severe impairment extends half-life by ~50% (11h → 16.5h)
|
|
renalFunction?: {
|
|
enabled: boolean;
|
|
severity: 'normal' | 'mild' | 'severe';
|
|
};
|
|
}
|
|
|
|
export interface PkParams {
|
|
damph: { halfLife: string };
|
|
ldx: { halfLife: string; absorptionHalfLife: string }; // renamed from absorptionRate
|
|
advanced: AdvancedSettings;
|
|
}
|
|
|
|
export interface DayDose {
|
|
id: string;
|
|
time: string;
|
|
ldx: string;
|
|
damph?: string; // Optional, kept for backwards compatibility but not used in UI
|
|
isFed?: boolean; // Optional: indicates if dose is taken with food (delays absorption ~1h)
|
|
}
|
|
|
|
export interface DayGroup {
|
|
id: string;
|
|
isTemplate: boolean;
|
|
doses: DayDose[];
|
|
}
|
|
|
|
export interface SteadyStateConfig {
|
|
daysOnMedication: string;
|
|
}
|
|
|
|
export interface TherapeuticRange {
|
|
min: string;
|
|
max: string;
|
|
}
|
|
|
|
export interface UiSettings {
|
|
showDayTimeOnXAxis: 'continuous' | '24h' | '12h';
|
|
showTemplateDay: boolean;
|
|
chartView: 'ldx' | 'damph' | 'both';
|
|
yAxisMin: string;
|
|
yAxisMax: string;
|
|
simulationDays: string;
|
|
displayedDays: string;
|
|
showDayReferenceLines?: boolean;
|
|
showIntakeTimeLines?: boolean;
|
|
showTherapeuticRange?: boolean;
|
|
steadyStateDaysEnabled?: boolean;
|
|
stickyChart: boolean;
|
|
theme?: 'light' | 'dark' | 'system';
|
|
}
|
|
|
|
export interface AppState {
|
|
pkParams: PkParams;
|
|
days: DayGroup[];
|
|
steadyStateConfig: SteadyStateConfig;
|
|
therapeuticRange: TherapeuticRange;
|
|
doseIncrement: string;
|
|
uiSettings: UiSettings;
|
|
}
|
|
|
|
// Legacy interfaces for backwards compatibility (will be removed later)
|
|
export interface Dose {
|
|
time: string;
|
|
dose: string;
|
|
label: string;
|
|
}
|
|
|
|
export interface Deviation extends Dose {
|
|
dayOffset?: number;
|
|
isAdditional: boolean;
|
|
}
|
|
|
|
export interface ConcentrationPoint {
|
|
timeHours: number;
|
|
ldx: number;
|
|
damph: number;
|
|
}
|
|
|
|
// Default application state
|
|
export const getDefaultState = (): AppState => ({
|
|
pkParams: {
|
|
damph: { halfLife: '11' },
|
|
ldx: {
|
|
halfLife: '0.8',
|
|
absorptionHalfLife: '0.7' // Updated from 0.9 for better ~1h Tmax of prodrug
|
|
},
|
|
advanced: {
|
|
standardVd: { preset: 'adult', customValue: '377', bodyWeight: '70' }, // Adult: 377L (Roberts 2015), Child: ~150-200L, Weight-based: ~5.4 L/kg
|
|
foodEffect: { enabled: false, tmaxDelay: '1.0' }, // hours delay
|
|
urinePh: { mode: 'normal' }, // 'normal' (6-7.5), 'acidic' (<6), 'alkaline' (>7.5)
|
|
fOral: String(DEFAULT_F_ORAL), // 0.96 bioavailability
|
|
steadyStateDays: '7' // days of prior medication history
|
|
}
|
|
},
|
|
days: [
|
|
{
|
|
id: 'day-template',
|
|
isTemplate: true,
|
|
doses: [
|
|
{ id: 'dose-1', time: '06:30', ldx: '25' },
|
|
{ id: 'dose-2', time: '14:30', ldx: '15' },
|
|
{ id: 'dose-4', time: '22:15', ldx: '15' },
|
|
]
|
|
}
|
|
],
|
|
steadyStateConfig: { daysOnMedication: '7' }, // kept for backwards compatibility, now sourced from pkParams.advanced
|
|
therapeuticRange: { min: '', max: '' }, // users should personalize based on their response
|
|
doseIncrement: '2.5',
|
|
uiSettings: {
|
|
showDayTimeOnXAxis: '24h',
|
|
showTemplateDay: true,
|
|
chartView: 'both',
|
|
yAxisMin: '',
|
|
yAxisMax: '',
|
|
simulationDays: '5',
|
|
displayedDays: '2',
|
|
showTherapeuticRange: false,
|
|
showIntakeTimeLines: false,
|
|
steadyStateDaysEnabled: true,
|
|
stickyChart: false,
|
|
theme: 'system',
|
|
}
|
|
});
|