payemnt of paitientss - table added

This commit is contained in:
2025-08-15 17:52:50 +05:30
parent db36150d25
commit 7ff65246c1
6 changed files with 150 additions and 93 deletions

View File

@@ -183,14 +183,16 @@ export interface IStorage {
): Promise<Payment>;
deletePayment(id: number, userId: number): Promise<void>;
getPaymentById(id: number, userId: number): Promise<PaymentWithExtras | null>;
getRecentPaymentsByPatientId(
patientId: number,
limit: number,
offset: number
): Promise<PaymentWithExtras[] | null>;
getTotalPaymentCountByPatient(patientId: number): Promise<number>;
getPaymentsByClaimId(
claimId: number,
userId: number
): Promise<PaymentWithExtras | null>;
getPaymentsByPatientId(
patientId: number,
userId: number
): Promise<PaymentWithExtras[]>;
getRecentPaymentsByUser(
userId: number,
limit: number,
@@ -762,6 +764,45 @@ export const storage: IStorage = {
await db.payment.delete({ where: { id } });
},
async getRecentPaymentsByPatientId(
patientId: number,
limit: number,
offset: number
): Promise<PaymentWithExtras[]> {
const payments = await db.payment.findMany({
where: { claim: { patientId } },
orderBy: { createdAt: "desc" },
skip: offset,
take: limit,
include: {
claim: {
include: {
serviceLines: true,
},
},
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
updatedBy: true,
},
});
return payments.map((payment) => ({
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}));
},
async getTotalPaymentCountByPatient(patientId: number): Promise<number> {
return db.payment.count({
where: { claim: { patientId } },
});
},
async getPaymentById(
id: number,
userId: number
@@ -824,35 +865,6 @@ export const storage: IStorage = {
};
},
async getPaymentsByPatientId(
patientId: number,
userId: number
): Promise<PaymentWithExtras[]> {
const payments = await db.payment.findMany({
where: { patientId, userId },
include: {
claim: {
include: {
serviceLines: true,
},
},
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
updatedBy: true,
},
});
return payments.map((payment) => ({
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}));
},
async getRecentPaymentsByUser(
userId: number,
limit: number,