76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
/**
|
|
* QueueManager: Handles the hybrid slot logic for CuraFlow
|
|
* - 30-min slots
|
|
* - Max 3 online bookings (Hard Cap)
|
|
* - 5 Walk-in slots
|
|
*/
|
|
|
|
const configManager = require('./configManager');
|
|
|
|
class QueueManager {
|
|
constructor() {
|
|
this.slots = {}; // Key: "YYYY-MM-DD:HH:mm"
|
|
}
|
|
|
|
getSlotKey(date, time) {
|
|
// Round time to nearest slot duration
|
|
const duration = configManager.get('slotDuration');
|
|
const [hours, minutes] = time.split(':');
|
|
const roundedMins = parseInt(minutes) < duration ? '00' : duration;
|
|
return `${date}:${hours}:${roundedMins}`;
|
|
}
|
|
|
|
getSlotStatus(date, time) {
|
|
const key = this.getSlotKey(date, time);
|
|
if (!this.slots[key]) {
|
|
this.slots[key] = {
|
|
online: 0,
|
|
walkin: 0,
|
|
maxOnline: configManager.get('onlineSlotLimit'),
|
|
maxWalkin: configManager.get('walkinSlotLimit')
|
|
};
|
|
}
|
|
return this.slots[key];
|
|
}
|
|
|
|
bookOnline(date, time) {
|
|
const status = this.getSlotStatus(date, time);
|
|
if (status.online < status.maxOnline) {
|
|
status.online++;
|
|
return {
|
|
success: true,
|
|
token: `ON-${status.online}`,
|
|
slot: this.getSlotKey(date, time),
|
|
status: 'PENDING_PAYMENT',
|
|
fee: configManager.get('consultationFee')
|
|
};
|
|
}
|
|
return { success: false, message: "Slot full for online booking. Try next slot." };
|
|
}
|
|
|
|
bookWalkin(date, time) {
|
|
const status = this.getSlotStatus(date, time);
|
|
if (status.walkin < status.maxWalkin) {
|
|
status.walkin++;
|
|
return {
|
|
success: true,
|
|
token: `WK-${status.walkin}`,
|
|
status: 'PENDING_PAYMENT',
|
|
fee: configManager.get('consultationFee')
|
|
};
|
|
}
|
|
return { success: false, message: "Clinic is at full capacity for this slot." };
|
|
}
|
|
|
|
getDailyUpdates(patientId) {
|
|
// Mock data for daily updates
|
|
return [
|
|
"Good morning! Your appointment with Dr. Sharma is at 10:30 AM today.",
|
|
"Queue Update: The clinic is running 10 mins behind schedule. Please plan accordingly.",
|
|
"Reminder: Don't forget to bring your previous blood reports."
|
|
];
|
|
}
|
|
}
|
|
|
|
module.exports = new QueueManager();
|