recent claim table, checkpoint
This commit is contained in:
@@ -90,9 +90,10 @@ router.post(
|
||||
claimData.insuranceSiteKey
|
||||
);
|
||||
if (!credentials) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ error: "No insurance credentials found for this provider. Kindly Update this at Settings Page." });
|
||||
return res.status(404).json({
|
||||
error:
|
||||
"No insurance credentials found for this provider. Kindly Update this at Settings Page.",
|
||||
});
|
||||
}
|
||||
|
||||
const enrichedData = {
|
||||
@@ -183,35 +184,20 @@ router.post(
|
||||
}
|
||||
);
|
||||
|
||||
// GET /api/claims?page=1&limit=5
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
const userId = req.user!.id;
|
||||
const offset = parseInt(req.query.offset as string) || 0;
|
||||
const limit = parseInt(req.query.limit as string) || 5;
|
||||
|
||||
try {
|
||||
const [claims, total] = await Promise.all([
|
||||
storage.getClaimsPaginated(userId, offset, limit),
|
||||
storage.countClaimsByUserId(userId),
|
||||
]);
|
||||
|
||||
res.json({
|
||||
data: claims,
|
||||
page: Math.floor(offset / limit) + 1,
|
||||
limit,
|
||||
total,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to retrieve paginated claims" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/claims/recent
|
||||
router.get("/recent", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const claims = await storage.getClaimsMetadataByUser(req.user!.id);
|
||||
res.json(claims); // Just ID and createdAt
|
||||
const limit = parseInt(req.query.limit as string) || 10;
|
||||
const offset = parseInt(req.query.offset as string) || 0;
|
||||
|
||||
const [claims, totalCount] = await Promise.all([
|
||||
storage.getRecentClaimsByUser(req.user!.id, limit, offset),
|
||||
storage.getTotalClaimCountByUser(req.user!.id),
|
||||
]);
|
||||
|
||||
res.json({ claims, totalCount });
|
||||
} catch (error) {
|
||||
console.error("Failed to retrieve recent claims:", error);
|
||||
res.status(500).json({ message: "Failed to retrieve recent claims" });
|
||||
}
|
||||
});
|
||||
@@ -219,7 +205,7 @@ router.get("/recent", async (req: Request, res: Response) => {
|
||||
// Get all claims for the logged-in user
|
||||
router.get("/all", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const claims = await storage.getClaimsByUserId(req.user!.id);
|
||||
const claims = await storage.getTotalClaimCountByUser(req.user!.id);
|
||||
res.json(claims);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to retrieve claims" });
|
||||
|
||||
@@ -218,18 +218,14 @@ export interface IStorage {
|
||||
|
||||
// Claim methods
|
||||
getClaim(id: number): Promise<Claim | undefined>;
|
||||
getClaimsByUserId(userId: number): Promise<Claim[]>;
|
||||
getClaimsByPatientId(patientId: number): Promise<Claim[]>;
|
||||
getClaimsByAppointmentId(appointmentId: number): Promise<Claim[]>;
|
||||
getClaimsPaginated(
|
||||
getRecentClaimsByUser(
|
||||
userId: number,
|
||||
offset: number,
|
||||
limit: number
|
||||
limit: number,
|
||||
offset: number
|
||||
): Promise<Claim[]>;
|
||||
countClaimsByUserId(userId: number): Promise<number>;
|
||||
getClaimsMetadataByUser(
|
||||
userId: number
|
||||
): Promise<{ id: number; createdAt: Date; status: string }[]>;
|
||||
getTotalClaimCountByUser(userId: number): Promise<number>;
|
||||
createClaim(claim: InsertClaim): Promise<Claim>;
|
||||
updateClaim(id: number, updates: UpdateClaim): Promise<Claim>;
|
||||
deleteClaim(id: number): Promise<void>;
|
||||
@@ -524,10 +520,6 @@ export const storage: IStorage = {
|
||||
return claim ?? undefined;
|
||||
},
|
||||
|
||||
async getClaimsByUserId(userId: number): Promise<Claim[]> {
|
||||
return await db.claim.findMany({ where: { userId } });
|
||||
},
|
||||
|
||||
async getClaimsByPatientId(patientId: number): Promise<Claim[]> {
|
||||
return await db.claim.findMany({ where: { patientId } });
|
||||
},
|
||||
@@ -536,6 +528,24 @@ export const storage: IStorage = {
|
||||
return await db.claim.findMany({ where: { appointmentId } });
|
||||
},
|
||||
|
||||
async getRecentClaimsByUser(
|
||||
userId: number,
|
||||
limit: number,
|
||||
offset: number
|
||||
): Promise<ClaimWithServiceLines[]> {
|
||||
return db.claim.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
skip: offset,
|
||||
take: limit,
|
||||
include: { serviceLines: true },
|
||||
});
|
||||
},
|
||||
|
||||
async getTotalClaimCountByUser(userId: number): Promise<number> {
|
||||
return db.claim.count({ where: { userId } });
|
||||
},
|
||||
|
||||
async createClaim(claim: InsertClaim): Promise<Claim> {
|
||||
return await db.claim.create({ data: claim as Claim });
|
||||
},
|
||||
@@ -559,38 +569,6 @@ export const storage: IStorage = {
|
||||
}
|
||||
},
|
||||
|
||||
async getClaimsPaginated(
|
||||
userId: number,
|
||||
offset: number,
|
||||
limit: number
|
||||
): Promise<ClaimWithServiceLines[]> {
|
||||
return db.claim.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
skip: offset,
|
||||
take: limit,
|
||||
include: { serviceLines: true },
|
||||
});
|
||||
},
|
||||
|
||||
async countClaimsByUserId(userId: number): Promise<number> {
|
||||
return db.claim.count({ where: { userId } });
|
||||
},
|
||||
|
||||
async getClaimsMetadataByUser(
|
||||
userId: number
|
||||
): Promise<{ id: number; createdAt: Date; status: string }[]> {
|
||||
return db.claim.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
status: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// Insurance Creds
|
||||
async getInsuranceCredentialsByUser(userId: number) {
|
||||
return await db.insuranceCredential.findMany({ where: { userId } });
|
||||
|
||||
Reference in New Issue
Block a user