feat: cloud storage updates, claims storage, appointment and insurance routes
This commit is contained in:
@@ -186,31 +186,29 @@ router.post(
|
||||
return res.status(404).json({ message: "Patient not found" });
|
||||
}
|
||||
|
||||
// 2. Attempt to find the next available slot
|
||||
// 2. One patient per column per day: find existing appointment for this patient in the same staff column today
|
||||
const existingPatientAppointment = await storage.getPatientAppointmentByDateAndStaff(
|
||||
appointmentData.patientId,
|
||||
appointmentData.date,
|
||||
appointmentData.staffId
|
||||
);
|
||||
|
||||
// 3. Attempt to find the next available slot
|
||||
let [hour, minute] = originalStartTime.split(":").map(Number);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
|
||||
// Step by 15 minutes to support quarter-hour starts, but keep appointment duration 30 mins
|
||||
const STEP_MINUTES = 15;
|
||||
const APPT_DURATION_MINUTES = 30;
|
||||
|
||||
while (`${pad(hour)}:${pad(minute)}` <= MAX_END_TIME) {
|
||||
const currentStartTime = `${pad(hour)}:${pad(minute)}`;
|
||||
|
||||
// Check patient appointment at this time
|
||||
const sameDayAppointment =
|
||||
await storage.getPatientAppointmentByDateTime(
|
||||
appointmentData.patientId,
|
||||
appointmentData.date,
|
||||
currentStartTime
|
||||
);
|
||||
|
||||
// Check staff conflict at this time
|
||||
// Check staff conflict at this time (exclude the patient's existing appointment so it can move)
|
||||
const staffConflict = await storage.getStaffAppointmentByDateTime(
|
||||
appointmentData.staffId,
|
||||
appointmentData.date,
|
||||
currentStartTime,
|
||||
sameDayAppointment?.id // Ignore self if updating
|
||||
existingPatientAppointment?.id
|
||||
);
|
||||
|
||||
if (!staffConflict) {
|
||||
@@ -226,14 +224,13 @@ router.post(
|
||||
endTime: currentEndTime,
|
||||
};
|
||||
|
||||
let responseData;
|
||||
|
||||
if (sameDayAppointment?.id !== undefined) {
|
||||
if (existingPatientAppointment?.id !== undefined) {
|
||||
// Replace the existing appointment in-place (preserves linked claims/procedures)
|
||||
const updated = await storage.updateAppointment(
|
||||
sameDayAppointment.id,
|
||||
existingPatientAppointment.id,
|
||||
payload
|
||||
);
|
||||
responseData = {
|
||||
return res.status(200).json({
|
||||
...updated,
|
||||
originalRequestedTime: originalStartTime,
|
||||
finalScheduledTime: currentStartTime,
|
||||
@@ -241,12 +238,11 @@ router.post(
|
||||
originalStartTime !== currentStartTime
|
||||
? `Your requested time (${originalStartTime}) was unavailable. Appointment was updated to ${currentStartTime}.`
|
||||
: `Appointment successfully updated at ${currentStartTime}.`,
|
||||
};
|
||||
return res.status(200).json(responseData);
|
||||
});
|
||||
}
|
||||
|
||||
const created = await storage.createAppointment(payload);
|
||||
responseData = {
|
||||
return res.status(201).json({
|
||||
...created,
|
||||
originalRequestedTime: originalStartTime,
|
||||
finalScheduledTime: currentStartTime,
|
||||
@@ -254,8 +250,7 @@ router.post(
|
||||
originalStartTime !== currentStartTime
|
||||
? `Your requested time (${originalStartTime}) was unavailable. Appointment was scheduled at ${currentStartTime}.`
|
||||
: `Appointment successfully scheduled at ${currentStartTime}.`,
|
||||
};
|
||||
return res.status(201).json(responseData);
|
||||
});
|
||||
}
|
||||
|
||||
// Move to next STEP_MINUTES slot
|
||||
|
||||
Reference in New Issue
Block a user