/** * 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_v7'; export const PROJECT_REPOSITORY_URL = 'https://git.11001001.org/cbaoth/med-plan-assistant'; export const APP_VERSION = versionInfo.version; export const BUILD_INFO = versionInfo; // 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 { weightBasedVd: { enabled: boolean; bodyWeight: string }; // kg foodEffect: { enabled: boolean; tmaxDelay: string }; // hours urinePh: { enabled: boolean; phTendency: string }; // 5.5-8.0 range fOral: string; // bioavailability fraction steadyStateDays: string; // days of medication history to simulate } 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 } 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; showTherapeuticRange?: boolean; steadyStateDaysEnabled?: boolean; stickyChart: boolean; } 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.9' // changed from 1.5, better reflects ~1h Tmax }, advanced: { weightBasedVd: { enabled: false, bodyWeight: '70' }, // kg, adult average foodEffect: { enabled: false, tmaxDelay: '1.0' }, // hours delay urinePh: { enabled: false, phTendency: '6.0' }, // pH scale (5.5-8.0) 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: '20' }, { id: 'dose-2', time: '12:30', ldx: '10' }, { id: 'dose-3', time: '17:30', ldx: '10' }, { id: 'dose-4', time: '22:00', ldx: '7.5' }, ] } ], steadyStateConfig: { daysOnMedication: '7' }, // kept for backwards compatibility, now sourced from pkParams.advanced therapeuticRange: { min: '5', max: '25' }, // widened from 10.5-11.5 to general adult range doseIncrement: '2.5', uiSettings: { showDayTimeOnXAxis: '24h', showTemplateDay: true, chartView: 'damph', yAxisMin: '', yAxisMax: '', simulationDays: '5', displayedDays: '2', showTherapeuticRange: true, steadyStateDaysEnabled: true, stickyChart: false, } });