Healthcare
Try in Playground →Medication schedules, shift patterns, on-call rotations, and compliance
Import
import { ... } from 'ts-time-utils/healthcare'; Examples
Medication Timing
Calculate medication administration times
import { getMedicationTimes, getNextMedicationTime, parseMedicationFrequency } from 'ts-time-utils/healthcare';
const today = new Date('2025-01-15');
// QD = once daily
const qdTimes = getMedicationTimes(today, 'QD');
console.log('QD (once daily):', qdTimes);
// BID = twice daily
const bidTimes = getMedicationTimes(today, 'BID');
console.log('BID (twice daily):', bidTimes);
// TID = three times daily
const tidTimes = getMedicationTimes(today, 'TID');
console.log('TID (three times daily):', tidTimes);
// q8h = every 8 hours
const q8hTimes = getMedicationTimes(today, 'q8h');
console.log('q8h (every 8 hours):', q8hTimes);
// Get next medication time after 10am
const next = getNextMedicationTime(new Date('2025-01-15T10:00:00'), 'BID');
console.log('Next BID dose after 10am:', next);
// Parse frequency string
console.log('Parse "bid":', parseMedicationFrequency('bid')); Shift Scheduling
Generate shift schedules and check assignments
import { generateShiftSchedule, getShiftForTime, isOnShift, calculateRestBetweenShifts } from 'ts-time-utils/healthcare';
const config = { pattern: '12hr', startTime: { hour: 7, minute: 0 } };
// Generate 3-day shift schedule
const shifts = generateShiftSchedule(
new Date('2025-01-15'),
new Date('2025-01-17'),
config
);
shifts.forEach((shift, i) => {
console.log(`Shift ${i + 1}: ${shift.start.toLocaleString()} - ${shift.end.toLocaleString()}`);
});
// Get shift for a specific time
const currentShift = getShiftForTime(new Date('2025-01-15T14:00:00'), config);
console.log('Current shift:', currentShift);
// Check if on shift
console.log('On shift at 2pm?', isOnShift(
new Date('2025-01-15T14:00:00'),
new Date('2025-01-15T07:00:00'),
config
));
// Calculate rest between shifts
const rest = calculateRestBetweenShifts(
new Date('2025-01-15T19:00:00'),
new Date('2025-01-16T07:00:00')
);
console.log('Rest hours:', rest); On-Call Rotation
Create and query on-call schedules
import { createOnCallRotation, getOnCallStaff, getComplianceDeadline, isWithinComplianceWindow, timeUntilDeadline } from 'ts-time-utils/healthcare';
// Create 1-week on-call rotation
const staff = ['Dr. Smith', 'Dr. Jones', 'Dr. Brown', 'Dr. Wilson'];
const rotation = createOnCallRotation(
new Date('2025-01-15'),
new Date('2025-01-22'),
staff,
24 // 24-hour shifts
);
rotation.forEach(slot => {
console.log(`${slot.staff}: ${slot.start.toDateString()}`);
});
// Who's on call at 3am on Jan 16?
const onCall = getOnCallStaff(new Date('2025-01-16T03:00:00'), rotation);
console.log('On call at 3am:', onCall);
// Compliance window (e.g., 72-hour documentation deadline)
const event = new Date('2025-01-15T08:00:00');
const deadline = getComplianceDeadline(event, 72);
console.log('Documentation deadline:', deadline);
// Check if compliant
const documented = new Date('2025-01-17T10:00:00');
console.log('Within window?', isWithinComplianceWindow(documented, deadline));
// Time remaining
const remaining = timeUntilDeadline(new Date(), deadline);
console.log('Time until deadline:', remaining?.toString());