feat(procedure-combos) - v1
This commit is contained in:
139
apps/Backend/src/routes/appointments-procedures.ts
Normal file
139
apps/Backend/src/routes/appointments-procedures.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { storage } from "../storage";
|
||||
import { prisma } from "@repo/db/client";
|
||||
import {
|
||||
insertAppointmentProcedureSchema,
|
||||
updateAppointmentProcedureSchema,
|
||||
} from "@repo/db/types";
|
||||
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* GET /api/appointment-procedures/:appointmentId
|
||||
* Get all procedures for an appointment
|
||||
*/
|
||||
router.get("/:appointmentId", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const appointmentId = Number(req.params.appointmentId);
|
||||
if (isNaN(appointmentId)) {
|
||||
return res.status(400).json({ message: "Invalid appointmentId" });
|
||||
}
|
||||
|
||||
const rows = await storage.getByAppointmentId(appointmentId);
|
||||
|
||||
return res.json(rows);
|
||||
} catch (err: any) {
|
||||
console.error("GET appointment procedures error", err);
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/appointment-procedures
|
||||
* Add single manual procedure
|
||||
*/
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const parsed = insertAppointmentProcedureSchema.parse(req.body);
|
||||
|
||||
const created = await storage.createProcedure(parsed);
|
||||
|
||||
return res.json(created);
|
||||
} catch (err: any) {
|
||||
console.error("POST appointment procedure error", err);
|
||||
if (err.name === "ZodError") {
|
||||
return res.status(400).json({ message: err.errors });
|
||||
}
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/appointment-procedures/bulk
|
||||
* Add multiple procedures (combos)
|
||||
*/
|
||||
router.post("/bulk", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const rows = req.body;
|
||||
|
||||
if (!Array.isArray(rows) || rows.length === 0) {
|
||||
return res.status(400).json({ message: "Invalid payload" });
|
||||
}
|
||||
|
||||
const count = await storage.createProceduresBulk(rows);
|
||||
|
||||
return res.json({ success: true, count });
|
||||
} catch (err: any) {
|
||||
console.error("POST bulk appointment procedures error", err);
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT /api/appointment-procedures/:id
|
||||
* Update a procedure
|
||||
*/
|
||||
router.put("/:id", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const id = Number(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
return res.status(400).json({ message: "Invalid id" });
|
||||
}
|
||||
|
||||
const parsed = updateAppointmentProcedureSchema.parse(req.body);
|
||||
|
||||
const updated = await storage.updateProcedure(id, parsed);
|
||||
|
||||
return res.json(updated);
|
||||
} catch (err: any) {
|
||||
console.error("PUT appointment procedure error", err);
|
||||
|
||||
if (err.name === "ZodError") {
|
||||
return res.status(400).json({ message: err.errors });
|
||||
}
|
||||
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* DELETE /api/appointment-procedures/:id
|
||||
* Delete single procedure
|
||||
*/
|
||||
router.delete("/:id", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const id = Number(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
return res.status(400).json({ message: "Invalid id" });
|
||||
}
|
||||
|
||||
await storage.deleteProcedure(id);
|
||||
|
||||
return res.json({ success: true });
|
||||
} catch (err: any) {
|
||||
console.error("DELETE appointment procedure error", err);
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* DELETE /api/appointment-procedures/clear/:appointmentId
|
||||
* Clear all procedures for appointment
|
||||
*/
|
||||
router.delete("/clear/:appointmentId", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const appointmentId = Number(req.params.appointmentId);
|
||||
if (isNaN(appointmentId)) {
|
||||
return res.status(400).json({ message: "Invalid appointmentId" });
|
||||
}
|
||||
|
||||
await storage.clearByAppointmentId(appointmentId);
|
||||
|
||||
return res.json({ success: true });
|
||||
} catch (err: any) {
|
||||
console.error("CLEAR appointment procedures error", err);
|
||||
return res.status(500).json({ message: err.message ?? "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Router } from "express";
|
||||
import patientsRoutes from "./patients";
|
||||
import appointmentsRoutes from "./appointments";
|
||||
import appointmentProceduresRoutes from "./appointments-procedures";
|
||||
import usersRoutes from "./users";
|
||||
import staffsRoutes from "./staffs";
|
||||
import claimsRoutes from "./claims";
|
||||
@@ -21,6 +22,7 @@ const router = Router();
|
||||
|
||||
router.use("/patients", patientsRoutes);
|
||||
router.use("/appointments", appointmentsRoutes);
|
||||
router.use("/appointment-procedures", appointmentProceduresRoutes);
|
||||
router.use("/users", usersRoutes);
|
||||
router.use("/staffs", staffsRoutes);
|
||||
router.use("/patientDataExtraction", patientDataExtractionRoutes);
|
||||
|
||||
70
apps/Backend/src/storage/appointment-procedures-storage.ts
Normal file
70
apps/Backend/src/storage/appointment-procedures-storage.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
AppointmentProcedure,
|
||||
InsertAppointmentProcedure,
|
||||
UpdateAppointmentProcedure,
|
||||
} from "@repo/db/types";
|
||||
import { prisma as db } from "@repo/db/client";
|
||||
|
||||
export interface IAppointmentProceduresStorage {
|
||||
getByAppointmentId(appointmentId: number): Promise<AppointmentProcedure[]>;
|
||||
createProcedure(
|
||||
data: InsertAppointmentProcedure
|
||||
): Promise<AppointmentProcedure>;
|
||||
createProceduresBulk(data: InsertAppointmentProcedure[]): Promise<number>;
|
||||
updateProcedure(
|
||||
id: number,
|
||||
data: UpdateAppointmentProcedure
|
||||
): Promise<AppointmentProcedure>;
|
||||
deleteProcedure(id: number): Promise<void>;
|
||||
clearByAppointmentId(appointmentId: number): Promise<void>;
|
||||
}
|
||||
|
||||
export const appointmentProceduresStorage: IAppointmentProceduresStorage = {
|
||||
async getByAppointmentId(
|
||||
appointmentId: number
|
||||
): Promise<AppointmentProcedure[]> {
|
||||
return db.appointmentProcedure.findMany({
|
||||
where: { appointmentId },
|
||||
orderBy: { createdAt: "asc" },
|
||||
});
|
||||
},
|
||||
|
||||
async createProcedure(
|
||||
data: InsertAppointmentProcedure
|
||||
): Promise<AppointmentProcedure> {
|
||||
return db.appointmentProcedure.create({
|
||||
data: data as AppointmentProcedure,
|
||||
});
|
||||
},
|
||||
|
||||
async createProceduresBulk(
|
||||
data: InsertAppointmentProcedure[]
|
||||
): Promise<number> {
|
||||
const result = await db.appointmentProcedure.createMany({
|
||||
data: data as any[],
|
||||
});
|
||||
return result.count;
|
||||
},
|
||||
|
||||
async updateProcedure(
|
||||
id: number,
|
||||
data: UpdateAppointmentProcedure
|
||||
): Promise<AppointmentProcedure> {
|
||||
return db.appointmentProcedure.update({
|
||||
where: { id },
|
||||
data: data as any,
|
||||
});
|
||||
},
|
||||
|
||||
async deleteProcedure(id: number): Promise<void> {
|
||||
await db.appointmentProcedure.delete({
|
||||
where: { id },
|
||||
});
|
||||
},
|
||||
|
||||
async clearByAppointmentId(appointmentId: number): Promise<void> {
|
||||
await db.appointmentProcedure.deleteMany({
|
||||
where: { appointmentId },
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { usersStorage } from './users-storage';
|
||||
import { patientsStorage } from './patients-storage';
|
||||
import { appointmentsStorage } from './appointements-storage';
|
||||
import { appointmentsStorage } from './appointments-storage';
|
||||
import { appointmentProceduresStorage } from './appointment-procedures-storage';
|
||||
import { staffStorage } from './staff-storage';
|
||||
import { claimsStorage } from './claims-storage';
|
||||
import { insuranceCredsStorage } from './insurance-creds-storage';
|
||||
@@ -19,6 +20,7 @@ export const storage = {
|
||||
...usersStorage,
|
||||
...patientsStorage,
|
||||
...appointmentsStorage,
|
||||
...appointmentProceduresStorage,
|
||||
...staffStorage,
|
||||
...claimsStorage,
|
||||
...insuranceCredsStorage,
|
||||
|
||||
Reference in New Issue
Block a user