claim page table logic done, ui to be fixed

This commit is contained in:
2025-07-25 19:17:20 +05:30
parent 0f54bc6121
commit a5844ab088
7 changed files with 158 additions and 219 deletions

View File

@@ -202,6 +202,39 @@ router.get("/recent", async (req: Request, res: Response) => {
}
});
// GET /api/claims/patient/:patientId
router.get(
"/patient/:patientId",
async (req: Request, res: Response): Promise<any> => {
try {
const patientIdParam = req.params.patientId;
if (!patientIdParam) {
return res.status(400).json({ message: "Missing patientId" });
}
const patientId = parseInt(patientIdParam);
if (isNaN(patientId)) {
return res.status(400).json({ message: "Invalid patientId" });
}
const limit = parseInt(req.query.limit as string) || 10;
const offset = parseInt(req.query.offset as string) || 0;
if (isNaN(patientId)) {
return res.status(400).json({ message: "Invalid patient ID" });
}
const [claims, totalCount] = await Promise.all([
storage.getRecentClaimsByPatientId(patientId, limit, offset),
storage.getTotalClaimCountByPatient(patientId),
]);
res.json({ claims, totalCount });
} catch (error) {
console.error("Failed to retrieve claims for patient:", error);
res.status(500).json({ message: "Failed to retrieve patient claims" });
}
}
);
// Get all claims for the logged-in user
router.get("/all", async (req: Request, res: Response) => {
try {

View File

@@ -219,7 +219,13 @@ export interface IStorage {
// Claim methods
getClaim(id: number): Promise<Claim | undefined>;
getClaimsByPatientId(patientId: number): Promise<Claim[]>;
getRecentClaimsByPatientId(
patientId: number,
limit: number,
offset: number
): Promise<ClaimWithServiceLines[]>;
getTotalClaimCountByPatient(patientId: number): Promise<number>;
getClaimsByAppointmentId(appointmentId: number): Promise<Claim[]>;
getRecentClaimsByUser(
userId: number,
@@ -521,8 +527,27 @@ export const storage: IStorage = {
return claim ?? undefined;
},
async getClaimsByPatientId(patientId: number): Promise<Claim[]> {
return await db.claim.findMany({ where: { patientId } });
async getRecentClaimsByPatientId(
patientId: number,
limit: number,
offset: number
): Promise<ClaimWithServiceLines[]> {
return db.claim.findMany({
where: { patientId },
orderBy: { createdAt: "desc" },
skip: offset,
take: limit,
include: {
serviceLines: true,
staff: true,
},
});
},
async getTotalClaimCountByPatient(patientId: number): Promise<number> {
return db.claim.count({
where: { patientId },
});
},
async getClaimsByAppointmentId(appointmentId: number): Promise<Claim[]> {