ts-time-utils 3.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -6
- package/dist/calculate.d.ts +25 -0
- package/dist/calculate.d.ts.map +1 -1
- package/dist/calculate.js +125 -0
- package/dist/calendar.d.ts +45 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +68 -0
- package/dist/calendars.d.ts +156 -0
- package/dist/calendars.d.ts.map +1 -0
- package/dist/calendars.js +348 -0
- package/dist/compare.d.ts +27 -0
- package/dist/compare.d.ts.map +1 -1
- package/dist/compare.js +46 -0
- package/dist/esm/calculate.d.ts +25 -0
- package/dist/esm/calculate.d.ts.map +1 -1
- package/dist/esm/calculate.js +125 -0
- package/dist/esm/calendar.d.ts +45 -0
- package/dist/esm/calendar.d.ts.map +1 -1
- package/dist/esm/calendar.js +68 -0
- package/dist/esm/calendars.d.ts +156 -0
- package/dist/esm/calendars.d.ts.map +1 -0
- package/dist/esm/calendars.js +348 -0
- package/dist/esm/compare.d.ts +27 -0
- package/dist/esm/compare.d.ts.map +1 -1
- package/dist/esm/compare.js +46 -0
- package/dist/esm/finance.d.ts +236 -0
- package/dist/esm/finance.d.ts.map +1 -0
- package/dist/esm/finance.js +495 -0
- package/dist/esm/healthcare.d.ts +260 -0
- package/dist/esm/healthcare.d.ts.map +1 -0
- package/dist/esm/healthcare.js +447 -0
- package/dist/esm/holidays.d.ts +11 -1
- package/dist/esm/holidays.d.ts.map +1 -1
- package/dist/esm/holidays.js +220 -1
- package/dist/esm/index.d.ts +19 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +23 -9
- package/dist/esm/iterate.d.ts +55 -0
- package/dist/esm/iterate.d.ts.map +1 -1
- package/dist/esm/iterate.js +86 -0
- package/dist/esm/locale.d.ts +53 -0
- package/dist/esm/locale.d.ts.map +1 -1
- package/dist/esm/locale.js +141 -0
- package/dist/esm/precision.d.ts +225 -0
- package/dist/esm/precision.d.ts.map +1 -0
- package/dist/esm/precision.js +491 -0
- package/dist/esm/scheduling.d.ts +206 -0
- package/dist/esm/scheduling.d.ts.map +1 -0
- package/dist/esm/scheduling.js +329 -0
- package/dist/esm/temporal.d.ts +237 -0
- package/dist/esm/temporal.d.ts.map +1 -0
- package/dist/esm/temporal.js +660 -0
- package/dist/esm/validate.d.ts +30 -0
- package/dist/esm/validate.d.ts.map +1 -1
- package/dist/esm/validate.js +48 -0
- package/dist/finance.d.ts +236 -0
- package/dist/finance.d.ts.map +1 -0
- package/dist/finance.js +495 -0
- package/dist/healthcare.d.ts +260 -0
- package/dist/healthcare.d.ts.map +1 -0
- package/dist/healthcare.js +447 -0
- package/dist/holidays.d.ts +11 -1
- package/dist/holidays.d.ts.map +1 -1
- package/dist/holidays.js +220 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -9
- package/dist/iterate.d.ts +55 -0
- package/dist/iterate.d.ts.map +1 -1
- package/dist/iterate.js +86 -0
- package/dist/locale.d.ts +53 -0
- package/dist/locale.d.ts.map +1 -1
- package/dist/locale.js +141 -0
- package/dist/precision.d.ts +225 -0
- package/dist/precision.d.ts.map +1 -0
- package/dist/precision.js +491 -0
- package/dist/scheduling.d.ts +206 -0
- package/dist/scheduling.d.ts.map +1 -0
- package/dist/scheduling.js +329 -0
- package/dist/temporal.d.ts +237 -0
- package/dist/temporal.d.ts.map +1 -0
- package/dist/temporal.js +660 -0
- package/dist/validate.d.ts +30 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +48 -0
- package/package.json +31 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Healthcare utilities for medical scheduling and compliance timing
|
|
3
|
+
* Provides medication schedules, shift patterns, on-call rotations, and compliance windows
|
|
4
|
+
*/
|
|
5
|
+
import type { DateInput, DateRange } from './types.js';
|
|
6
|
+
import { Duration } from './duration.js';
|
|
7
|
+
/**
|
|
8
|
+
* Standard medical abbreviations for medication frequency
|
|
9
|
+
*/
|
|
10
|
+
export type MedicationFrequency = 'QD' | 'BID' | 'TID' | 'QID' | 'q4h' | 'q6h' | 'q8h' | 'q12h' | 'PRN';
|
|
11
|
+
/**
|
|
12
|
+
* Shift duration patterns
|
|
13
|
+
*/
|
|
14
|
+
export type ShiftPattern = '8hr' | '12hr' | '24hr';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for shift scheduling
|
|
17
|
+
*/
|
|
18
|
+
export interface ShiftConfig {
|
|
19
|
+
pattern: ShiftPattern;
|
|
20
|
+
startTime: {
|
|
21
|
+
hour: number;
|
|
22
|
+
minute: number;
|
|
23
|
+
};
|
|
24
|
+
rotation?: 'fixed' | 'rotating';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for medication timing
|
|
28
|
+
*/
|
|
29
|
+
export interface MedicationConfig {
|
|
30
|
+
wakeTime?: string;
|
|
31
|
+
sleepTime?: string;
|
|
32
|
+
withMeals?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* On-call slot assignment
|
|
36
|
+
*/
|
|
37
|
+
export interface OnCallSlot {
|
|
38
|
+
staff: string;
|
|
39
|
+
start: Date;
|
|
40
|
+
end: Date;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Number of doses per day for each frequency
|
|
44
|
+
*/
|
|
45
|
+
export declare const MEDICATION_FREQUENCIES: Record<MedicationFrequency, number | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Hours per shift pattern
|
|
48
|
+
*/
|
|
49
|
+
export declare const SHIFT_DURATIONS: Record<ShiftPattern, number>;
|
|
50
|
+
/**
|
|
51
|
+
* Default medication timing config
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_MEDICATION_CONFIG: Required<MedicationConfig>;
|
|
54
|
+
/**
|
|
55
|
+
* Get medication administration times for a given date and frequency
|
|
56
|
+
*
|
|
57
|
+
* @param date - The date to get medication times for
|
|
58
|
+
* @param frequency - Medical frequency abbreviation (QD, BID, TID, etc.)
|
|
59
|
+
* @param config - Optional configuration for wake/sleep times
|
|
60
|
+
* @returns Array of Date objects for each dose, empty array for PRN
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const times = getMedicationTimes(new Date('2024-01-15'), 'BID');
|
|
65
|
+
* // Returns [7:00 AM, 7:00 PM] (twice daily)
|
|
66
|
+
*
|
|
67
|
+
* const customTimes = getMedicationTimes(new Date('2024-01-15'), 'TID', {
|
|
68
|
+
* wakeTime: '06:00',
|
|
69
|
+
* sleepTime: '21:00'
|
|
70
|
+
* });
|
|
71
|
+
* // Returns [6:00 AM, 1:30 PM, 9:00 PM] (three times daily)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function getMedicationTimes(date: DateInput, frequency: MedicationFrequency, config?: MedicationConfig): Date[];
|
|
75
|
+
/**
|
|
76
|
+
* Get the next medication time after a given date/time
|
|
77
|
+
*
|
|
78
|
+
* @param after - The date/time to find the next medication time after
|
|
79
|
+
* @param frequency - Medical frequency abbreviation
|
|
80
|
+
* @param config - Optional configuration
|
|
81
|
+
* @returns Next medication Date, or null for PRN
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const next = getNextMedicationTime(new Date('2024-01-15T10:00:00'), 'BID');
|
|
86
|
+
* // Returns 7:00 PM on same day (next BID dose after 10 AM)
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function getNextMedicationTime(after: DateInput, frequency: MedicationFrequency, config?: MedicationConfig): Date | null;
|
|
90
|
+
/**
|
|
91
|
+
* Parse a medication frequency string to MedicationFrequency type
|
|
92
|
+
*
|
|
93
|
+
* @param freq - String to parse (case-insensitive)
|
|
94
|
+
* @returns MedicationFrequency or null if invalid
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* parseMedicationFrequency('bid'); // 'BID'
|
|
99
|
+
* parseMedicationFrequency('q8h'); // 'q8h'
|
|
100
|
+
* parseMedicationFrequency('invalid'); // null
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseMedicationFrequency(freq: string): MedicationFrequency | null;
|
|
104
|
+
/**
|
|
105
|
+
* Generate shift schedule for a date range
|
|
106
|
+
*
|
|
107
|
+
* @param start - Start of range
|
|
108
|
+
* @param end - End of range
|
|
109
|
+
* @param config - Shift configuration
|
|
110
|
+
* @returns Array of DateRange objects representing shifts
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const shifts = generateShiftSchedule(
|
|
115
|
+
* new Date('2024-01-15'),
|
|
116
|
+
* new Date('2024-01-17'),
|
|
117
|
+
* { pattern: '12hr', startTime: { hour: 7, minute: 0 } }
|
|
118
|
+
* );
|
|
119
|
+
* // Returns 4 shifts: day/night on 15th, day/night on 16th
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function generateShiftSchedule(start: DateInput, end: DateInput, config: ShiftConfig): DateRange[];
|
|
123
|
+
/**
|
|
124
|
+
* Get the shift containing a specific time
|
|
125
|
+
*
|
|
126
|
+
* @param date - The date/time to check
|
|
127
|
+
* @param config - Shift configuration
|
|
128
|
+
* @returns DateRange of the shift containing the time
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const shift = getShiftForTime(
|
|
133
|
+
* new Date('2024-01-15T14:00:00'),
|
|
134
|
+
* { pattern: '8hr', startTime: { hour: 7, minute: 0 } }
|
|
135
|
+
* );
|
|
136
|
+
* // Returns { start: 7:00 AM, end: 3:00 PM } (day shift)
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function getShiftForTime(date: DateInput, config: ShiftConfig): DateRange;
|
|
140
|
+
/**
|
|
141
|
+
* Check if a date/time is during a specific shift
|
|
142
|
+
*
|
|
143
|
+
* @param date - The date/time to check
|
|
144
|
+
* @param shiftStart - When the shift started
|
|
145
|
+
* @param config - Shift configuration
|
|
146
|
+
* @returns true if the time is during the shift
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* isOnShift(
|
|
151
|
+
* new Date('2024-01-15T10:00:00'),
|
|
152
|
+
* new Date('2024-01-15T07:00:00'),
|
|
153
|
+
* { pattern: '8hr', startTime: { hour: 7, minute: 0 } }
|
|
154
|
+
* ); // true (10 AM is during 7 AM - 3 PM shift)
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function isOnShift(date: DateInput, shiftStart: DateInput, config: ShiftConfig): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Create an on-call rotation schedule
|
|
160
|
+
*
|
|
161
|
+
* @param start - Start of rotation period
|
|
162
|
+
* @param end - End of rotation period
|
|
163
|
+
* @param staff - Array of staff names to rotate through
|
|
164
|
+
* @param hoursPerShift - Hours per on-call shift (default 24)
|
|
165
|
+
* @returns Array of OnCallSlot assignments
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const rotation = createOnCallRotation(
|
|
170
|
+
* new Date('2024-01-15'),
|
|
171
|
+
* new Date('2024-01-18'),
|
|
172
|
+
* ['Dr. Smith', 'Dr. Jones', 'Dr. Brown'],
|
|
173
|
+
* 24
|
|
174
|
+
* );
|
|
175
|
+
* // Returns 3 slots, one per doctor per day
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function createOnCallRotation(start: DateInput, end: DateInput, staff: string[], hoursPerShift?: number): OnCallSlot[];
|
|
179
|
+
/**
|
|
180
|
+
* Get the staff member on call at a specific time
|
|
181
|
+
*
|
|
182
|
+
* @param date - The date/time to check
|
|
183
|
+
* @param rotation - The on-call rotation schedule
|
|
184
|
+
* @returns Staff name or null if no one is on call
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const onCall = getOnCallStaff(new Date('2024-01-16T03:00:00'), rotation);
|
|
189
|
+
* // Returns 'Dr. Jones' (whoever is on call at 3 AM on the 16th)
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function getOnCallStaff(date: DateInput, rotation: OnCallSlot[]): string | null;
|
|
193
|
+
/**
|
|
194
|
+
* Check if an event occurred within its compliance window
|
|
195
|
+
*
|
|
196
|
+
* @param event - When the event occurred
|
|
197
|
+
* @param deadline - The compliance deadline
|
|
198
|
+
* @returns true if event is before or at deadline
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* isWithinComplianceWindow(
|
|
203
|
+
* new Date('2024-01-15T10:00:00'),
|
|
204
|
+
* new Date('2024-01-15T12:00:00')
|
|
205
|
+
* ); // true (event occurred before deadline)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function isWithinComplianceWindow(event: DateInput, deadline: DateInput): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Calculate the compliance deadline from an event
|
|
211
|
+
*
|
|
212
|
+
* @param event - The triggering event
|
|
213
|
+
* @param windowHours - Hours until deadline
|
|
214
|
+
* @returns Deadline Date
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* const deadline = getComplianceDeadline(
|
|
219
|
+
* new Date('2024-01-15T08:00:00'),
|
|
220
|
+
* 72
|
|
221
|
+
* );
|
|
222
|
+
* // Returns 2024-01-18T08:00:00 (72 hours later)
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export declare function getComplianceDeadline(event: DateInput, windowHours: number): Date;
|
|
226
|
+
/**
|
|
227
|
+
* Calculate time remaining until a compliance deadline
|
|
228
|
+
*
|
|
229
|
+
* @param event - Current time or event time
|
|
230
|
+
* @param deadline - The compliance deadline
|
|
231
|
+
* @returns Duration until deadline, or null if already past
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const remaining = timeUntilDeadline(
|
|
236
|
+
* new Date('2024-01-15T10:00:00'),
|
|
237
|
+
* new Date('2024-01-16T10:00:00')
|
|
238
|
+
* );
|
|
239
|
+
* // Returns Duration of 24 hours
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare function timeUntilDeadline(event: DateInput, deadline: DateInput): Duration | null;
|
|
243
|
+
/**
|
|
244
|
+
* Calculate rest hours between two shifts
|
|
245
|
+
*
|
|
246
|
+
* @param shift1End - End of first shift
|
|
247
|
+
* @param shift2Start - Start of second shift
|
|
248
|
+
* @returns Hours of rest between shifts
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const rest = calculateRestBetweenShifts(
|
|
253
|
+
* new Date('2024-01-15T19:00:00'),
|
|
254
|
+
* new Date('2024-01-16T07:00:00')
|
|
255
|
+
* );
|
|
256
|
+
* // Returns 12 (hours of rest)
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export declare function calculateRestBetweenShifts(shift1End: DateInput, shift2Start: DateInput): number;
|
|
260
|
+
//# sourceMappingURL=healthcare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthcare.d.ts","sourceRoot":"","sources":["../../src/healthcare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,IAAI,GACJ,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnD;;GAEG;AACH,MAA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