feat(eligibility-check) - appointment page redirecting to eligibility page
This commit is contained in:
@@ -131,6 +131,40 @@ router.get(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* GET /api/appointments/:id/patient
|
||||
*/
|
||||
router.get(
|
||||
"/:id/patient",
|
||||
async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
const rawId = req.params.id;
|
||||
if (!rawId) {
|
||||
return res.status(400).json({ message: "Appointment ID is required" });
|
||||
}
|
||||
|
||||
const apptId = parseInt(rawId, 10);
|
||||
if (Number.isNaN(apptId) || apptId <= 0) {
|
||||
return res.status(400).json({ message: "Invalid appointment ID" });
|
||||
}
|
||||
|
||||
const patient = await storage.getPatientFromAppointmentId(apptId);
|
||||
|
||||
if (!patient) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Patient not found for the given appointment" });
|
||||
}
|
||||
|
||||
return res.json(patient);
|
||||
} catch (err) {
|
||||
return res
|
||||
.status(500)
|
||||
.json({ message: "Failed to retrieve patient for appointment" });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Create a new appointment
|
||||
router.post(
|
||||
"/upsert",
|
||||
|
||||
@@ -70,6 +70,9 @@ export interface IStorage {
|
||||
getAllAppointments(): Promise<Appointment[]>;
|
||||
getAppointmentsByUserId(userId: number): Promise<Appointment[]>;
|
||||
getAppointmentsByPatientId(patientId: number): Promise<Appointment[]>;
|
||||
getPatientFromAppointmentId(
|
||||
appointmentId: number
|
||||
): Promise<Patient | undefined>;
|
||||
getRecentAppointments(limit: number, offset: number): Promise<Appointment[]>;
|
||||
getAppointmentsOnRange(start: Date, end: Date): Promise<Appointment[]>;
|
||||
createAppointment(appointment: InsertAppointment): Promise<Appointment>;
|
||||
@@ -393,6 +396,16 @@ export const storage: IStorage = {
|
||||
return await db.appointment.findMany({ where: { patientId } });
|
||||
},
|
||||
|
||||
async getPatientFromAppointmentId(
|
||||
appointmentId: number
|
||||
): Promise<Patient | undefined> {
|
||||
const appointment = await db.appointment.findUnique({
|
||||
where: { id: appointmentId },
|
||||
include: { patient: true },
|
||||
});
|
||||
return appointment?.patient ?? undefined;
|
||||
},
|
||||
|
||||
async getAppointmentsOnRange(start: Date, end: Date): Promise<Appointment[]> {
|
||||
return db.appointment.findMany({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user