feat(procedureCodes-dialog) - v2 done
This commit is contained in:
@@ -28,6 +28,32 @@ router.get("/:appointmentId", async (req: Request, res: Response) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get(
|
||||
"/prefill-from-appointment/:appointmentId",
|
||||
async (req: Request, res: Response) => {
|
||||
try {
|
||||
const appointmentId = Number(req.params.appointmentId);
|
||||
|
||||
if (!appointmentId || isNaN(appointmentId)) {
|
||||
return res.status(400).json({ error: "Invalid appointmentId" });
|
||||
}
|
||||
|
||||
const data = await storage.getPrefillDataByAppointmentId(appointmentId);
|
||||
|
||||
if (!data) {
|
||||
return res.status(404).json({ error: "Appointment not found" });
|
||||
}
|
||||
|
||||
return res.json(data);
|
||||
} catch (err: any) {
|
||||
console.error("prefill-from-appointment error", err);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: err.message ?? "Failed to prefill claim data" });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* POST /api/appointment-procedures
|
||||
* Add single manual procedure
|
||||
|
||||
@@ -336,6 +336,15 @@ router.post("/", async (req: Request, res: Response): Promise<any> => {
|
||||
}
|
||||
|
||||
// --- TRANSFORM serviceLines
|
||||
if (
|
||||
!Array.isArray(req.body.serviceLines) ||
|
||||
req.body.serviceLines.length === 0
|
||||
) {
|
||||
return res.status(400).json({
|
||||
message: "At least one service line is required to create a claim",
|
||||
});
|
||||
}
|
||||
|
||||
if (Array.isArray(req.body.serviceLines)) {
|
||||
req.body.serviceLines = req.body.serviceLines.map(
|
||||
(line: InputServiceLine) => ({
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import {
|
||||
Appointment,
|
||||
AppointmentProcedure,
|
||||
InsertAppointmentProcedure,
|
||||
Patient,
|
||||
UpdateAppointmentProcedure,
|
||||
} from "@repo/db/types";
|
||||
import { prisma as db } from "@repo/db/client";
|
||||
|
||||
export interface IAppointmentProceduresStorage {
|
||||
getByAppointmentId(appointmentId: number): Promise<AppointmentProcedure[]>;
|
||||
getPrefillDataByAppointmentId(appointmentId: number): Promise<{
|
||||
appointment: Appointment;
|
||||
patient: Patient;
|
||||
procedures: AppointmentProcedure[];
|
||||
} | null>;
|
||||
|
||||
createProcedure(
|
||||
data: InsertAppointmentProcedure
|
||||
): Promise<AppointmentProcedure>;
|
||||
@@ -29,6 +37,28 @@ export const appointmentProceduresStorage: IAppointmentProceduresStorage = {
|
||||
});
|
||||
},
|
||||
|
||||
async getPrefillDataByAppointmentId(appointmentId: number) {
|
||||
const appointment = await db.appointment.findUnique({
|
||||
where: { id: appointmentId },
|
||||
include: {
|
||||
patient: true,
|
||||
procedures: {
|
||||
orderBy: { createdAt: "asc" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!appointment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
appointment,
|
||||
patient: appointment.patient,
|
||||
procedures: appointment.procedures,
|
||||
};
|
||||
},
|
||||
|
||||
async createProcedure(
|
||||
data: InsertAppointmentProcedure
|
||||
): Promise<AppointmentProcedure> {
|
||||
|
||||
Reference in New Issue
Block a user