UNPKG

emr-types

Version:

Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation

304 lines 9.74 kB
/** * Date/Time Utility Types for EMR Application * * Provides comprehensive date and time related types for scheduling, * appointments, medical records, and business logic. * * @package emr-types */ // ============================================================================ // TIME PERIOD TYPES // ============================================================================ /** * Time period types */ export var TimePeriod; (function (TimePeriod) { TimePeriod["MINUTE"] = "minute"; TimePeriod["HOUR"] = "hour"; TimePeriod["DAY"] = "day"; TimePeriod["WEEK"] = "week"; TimePeriod["MONTH"] = "month"; TimePeriod["QUARTER"] = "quarter"; TimePeriod["YEAR"] = "year"; TimePeriod["DECADE"] = "decade"; })(TimePeriod || (TimePeriod = {})); // ============================================================================ // SCHEDULING TYPES // ============================================================================ /** * Day of week */ export var DayOfWeek; (function (DayOfWeek) { DayOfWeek[DayOfWeek["SUNDAY"] = 0] = "SUNDAY"; DayOfWeek[DayOfWeek["MONDAY"] = 1] = "MONDAY"; DayOfWeek[DayOfWeek["TUESDAY"] = 2] = "TUESDAY"; DayOfWeek[DayOfWeek["WEDNESDAY"] = 3] = "WEDNESDAY"; DayOfWeek[DayOfWeek["THURSDAY"] = 4] = "THURSDAY"; DayOfWeek[DayOfWeek["FRIDAY"] = 5] = "FRIDAY"; DayOfWeek[DayOfWeek["SATURDAY"] = 6] = "SATURDAY"; })(DayOfWeek || (DayOfWeek = {})); /** * Month of year */ export var MonthOfYear; (function (MonthOfYear) { MonthOfYear[MonthOfYear["JANUARY"] = 0] = "JANUARY"; MonthOfYear[MonthOfYear["FEBRUARY"] = 1] = "FEBRUARY"; MonthOfYear[MonthOfYear["MARCH"] = 2] = "MARCH"; MonthOfYear[MonthOfYear["APRIL"] = 3] = "APRIL"; MonthOfYear[MonthOfYear["MAY"] = 4] = "MAY"; MonthOfYear[MonthOfYear["JUNE"] = 5] = "JUNE"; MonthOfYear[MonthOfYear["JULY"] = 6] = "JULY"; MonthOfYear[MonthOfYear["AUGUST"] = 7] = "AUGUST"; MonthOfYear[MonthOfYear["SEPTEMBER"] = 8] = "SEPTEMBER"; MonthOfYear[MonthOfYear["OCTOBER"] = 9] = "OCTOBER"; MonthOfYear[MonthOfYear["NOVEMBER"] = 10] = "NOVEMBER"; MonthOfYear[MonthOfYear["DECEMBER"] = 11] = "DECEMBER"; })(MonthOfYear || (MonthOfYear = {})); /** * Medication frequency types */ export var MedicationFrequency; (function (MedicationFrequency) { MedicationFrequency["DAILY"] = "daily"; MedicationFrequency["TWICE_DAILY"] = "twice_daily"; MedicationFrequency["THREE_TIMES_DAILY"] = "three_times_daily"; MedicationFrequency["FOUR_TIMES_DAILY"] = "four_times_daily"; MedicationFrequency["WEEKLY"] = "weekly"; MedicationFrequency["BIWEEKLY"] = "biweekly"; MedicationFrequency["MONTHLY"] = "monthly"; MedicationFrequency["AS_NEEDED"] = "as_needed"; MedicationFrequency["CUSTOM"] = "custom"; })(MedicationFrequency || (MedicationFrequency = {})); /** * Follow-up frequency types */ export var FollowUpFrequency; (function (FollowUpFrequency) { FollowUpFrequency["IMMEDIATE"] = "immediate"; FollowUpFrequency["ONE_WEEK"] = "one_week"; FollowUpFrequency["TWO_WEEKS"] = "two_weeks"; FollowUpFrequency["ONE_MONTH"] = "one_month"; FollowUpFrequency["THREE_MONTHS"] = "three_months"; FollowUpFrequency["SIX_MONTHS"] = "six_months"; FollowUpFrequency["ONE_YEAR"] = "one_year"; FollowUpFrequency["CUSTOM"] = "custom"; })(FollowUpFrequency || (FollowUpFrequency = {})); /** * Age group classification */ export var AgeGroup; (function (AgeGroup) { AgeGroup["INFANT"] = "infant"; AgeGroup["TODDLER"] = "toddler"; AgeGroup["CHILD"] = "child"; AgeGroup["TEEN"] = "teen"; AgeGroup["YOUNG_ADULT"] = "young_adult"; AgeGroup["ADULT"] = "adult"; AgeGroup["SENIOR"] = "senior"; AgeGroup["ELDERLY"] = "elderly"; // 80+ years })(AgeGroup || (AgeGroup = {})); /** * Pregnancy trimester */ export var PregnancyTrimester; (function (PregnancyTrimester) { PregnancyTrimester["FIRST"] = "first"; PregnancyTrimester["SECOND"] = "second"; PregnancyTrimester["THIRD"] = "third"; // 27-40 weeks })(PregnancyTrimester || (PregnancyTrimester = {})); // ============================================================================ // TYPE GUARDS // ============================================================================ /** * Type guard for ISO date string */ export function isISODateString(value) { if (typeof value !== 'string') return false; const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/; return isoDateRegex.test(value); } /** * Type guard for ISO datetime string */ export function isISODateTimeString(value) { if (typeof value !== 'string') return false; const isoDateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/; return isoDateTimeRegex.test(value); } /** * Type guard for date range */ export function isDateRange(value) { return (typeof value === 'object' && value !== null && 'start' in value && 'end' in value && value.start instanceof Date && value.end instanceof Date); } /** * Type guard for time range */ export function isTimeRange(value) { return (typeof value === 'object' && value !== null && 'start' in value && 'end' in value && value.start instanceof Date && value.end instanceof Date); } /** * Type guard for business hours */ export function isBusinessHours(value) { return (typeof value === 'object' && value !== null && 'start' in value && 'end' in value && 'daysOfWeek' in value && 'timezone' in value && typeof value.start === 'string' && typeof value.end === 'string' && Array.isArray(value.daysOfWeek) && typeof value.timezone === 'string'); } /** * Type guard for appointment time slot */ export function isAppointmentTimeSlot(value) { return (typeof value === 'object' && value !== null && 'start' in value && 'end' in value && 'duration' in value && 'isAvailable' in value && 'isBooked' in value && value.start instanceof Date && value.end instanceof Date && typeof value.duration === 'number' && typeof value.isAvailable === 'boolean' && typeof value.isBooked === 'boolean'); } // ============================================================================ // UTILITY FUNCTIONS // ============================================================================ /** * Convert date to ISO string */ export function toISODateString(date) { const isoString = date.toISOString(); return isoString.split('T')[0] || ''; } /** * Convert date to ISO datetime string */ export function toISODateTimeString(date) { return date.toISOString(); } /** * Parse ISO date string to Date */ export function parseISODateString(dateString) { return new Date(dateString + 'T00:00:00.000Z'); } /** * Parse ISO datetime string to Date */ export function parseISODateTimeString(dateTimeString) { return new Date(dateTimeString); } /** * Get current date as ISO string */ export function getCurrentISODateString() { return toISODateString(new Date()); } /** * Get current datetime as ISO string */ export function getCurrentISODateTimeString() { return toISODateTimeString(new Date()); } /** * Calculate age from birth date */ export function calculateAge(birthDate) { const now = new Date(); const diffTime = Math.abs(now.getTime() - birthDate.getTime()); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); const years = Math.floor(diffDays / 365.25); const months = Math.floor((diffDays % 365.25) / 30.44); const days = Math.floor(diffDays % 30.44); let ageGroup; if (years < 2) ageGroup = AgeGroup.INFANT; else if (years < 6) ageGroup = AgeGroup.TODDLER; else if (years < 13) ageGroup = AgeGroup.CHILD; else if (years < 18) ageGroup = AgeGroup.TEEN; else if (years < 26) ageGroup = AgeGroup.YOUNG_ADULT; else if (years < 65) ageGroup = AgeGroup.ADULT; else if (years < 80) ageGroup = AgeGroup.SENIOR; else ageGroup = AgeGroup.ELDERLY; return { years, months, days, totalDays: diffDays, totalMonths: Math.floor(diffDays / 30.44), isMinor: years < 18, ageGroup }; } /** * Calculate duration between two dates */ export function calculateDuration(start, end) { const diffTime = Math.abs(end.getTime() - start.getTime()); const totalMinutes = Math.floor(diffTime / (1000 * 60)); const totalHours = Math.floor(totalMinutes / 60); const totalDays = Math.floor(totalHours / 24); const hours = totalHours % 24; const minutes = totalMinutes % 60; const seconds = Math.floor((diffTime % (1000 * 60)) / 1000); const formatted = `${totalDays}d ${hours}h ${minutes}m ${seconds}s`; return { totalMinutes, totalHours, totalDays, hours, minutes, seconds, formatted }; } /** * Check if date is in business hours */ export function isInBusinessHours(date, businessHours) { const dayOfWeek = date.getDay(); const timeString = date.toTimeString().slice(0, 5); // HH:mm format return (businessHours.daysOfWeek.includes(dayOfWeek) && timeString >= businessHours.start && timeString <= businessHours.end); } /** * Check if date is a working day */ export function isWorkingDay(date, workingDays) { const dayOfWeek = date.getDay(); const workingDay = workingDays.find(wd => wd.dayOfWeek === dayOfWeek); return workingDay?.isWorkingDay ?? false; } //# sourceMappingURL=datetime.js.map