388 lines
14 KiB
TypeScript
388 lines
14 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { BillingService } from './billing.service';
|
|
import {
|
|
BillingSheetKindQueryDto,
|
|
ListBillingSheetsQueryDto,
|
|
ResolvedLinesQueryDto,
|
|
} from './dto/billing-sheet-query.dto';
|
|
import {
|
|
AcknowledgePaymentDto,
|
|
AllocationSearchQueryDto,
|
|
CreatePaymentDto,
|
|
ListPaymentsQueryDto,
|
|
PartyReportQueryDto,
|
|
PartySearchQueryDto,
|
|
StaffIncomeQueryDto,
|
|
SaveStaffSalarySheetDto,
|
|
UpdateObligationAmountDto,
|
|
UpdatePaymentDto,
|
|
} from './dto/billing-payment.dto';
|
|
import { UpsertBillingSheetDto } from './dto/upsert-billing-sheet.dto';
|
|
import { LabPriceQuoteDto, OutsourceQuoteDto } from './dto/billing-quote.dto';
|
|
|
|
@ApiTags('billing')
|
|
@ApiBearerAuth('JWT-auth')
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('billing')
|
|
export class BillingController {
|
|
constructor(private readonly billingService: BillingService) {}
|
|
|
|
@Get('sheets')
|
|
@ApiOperation({ summary: 'List price and commission sheets (TAB_BILLING_READ)' })
|
|
listSheets(
|
|
@Query() query: ListBillingSheetsQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listSheets(req.user.id, organizationId, query.kind);
|
|
}
|
|
|
|
@Get('sheet-catalog')
|
|
@ApiOperation({ summary: 'Catalog rows for a sheet editor (TAB_BILLING_READ)' })
|
|
listCatalog(
|
|
@Query() query: BillingSheetKindQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string; language?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listCatalog(
|
|
req.user.id,
|
|
organizationId,
|
|
query.kind,
|
|
req.user.language,
|
|
);
|
|
}
|
|
|
|
@Get('sheet-targets')
|
|
@ApiOperation({ summary: 'People or clinics that can be attached to a sheet' })
|
|
listTargets(
|
|
@Query() query: BillingSheetKindQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listTargets(req.user.id, organizationId, query.kind);
|
|
}
|
|
|
|
@Get('sheets/:id')
|
|
@ApiOperation({ summary: 'Get one billing sheet' })
|
|
getSheet(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.getSheet(req.user.id, organizationId, id);
|
|
}
|
|
|
|
@Post('sheets')
|
|
@ApiOperation({ summary: 'Create a billing sheet (TAB_BILLING_EDIT)' })
|
|
createSheet(
|
|
@Body() dto: UpsertBillingSheetDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.createSheet(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Put('sheets/:id')
|
|
@ApiOperation({ summary: 'Replace a billing sheet (TAB_BILLING_EDIT)' })
|
|
updateSheet(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: UpsertBillingSheetDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.updateSheet(req.user.id, organizationId, id, dto);
|
|
}
|
|
|
|
@Delete('sheets/:id')
|
|
@ApiOperation({ summary: 'Delete a billing sheet (TAB_BILLING_EDIT)' })
|
|
deleteSheet(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.deleteSheet(req.user.id, organizationId, id);
|
|
}
|
|
|
|
@Get('partners')
|
|
@ApiOperation({ summary: 'Linked clinic or lab counterparts for partner payments' })
|
|
listPartners(@Req() req: { user: { id: string; organizationId?: string } }) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listPartners(req.user.id, organizationId);
|
|
}
|
|
|
|
@Get('settings')
|
|
@ApiOperation({ summary: 'Org billing currency settings' })
|
|
getSettings(@Req() req: { user: { id: string; organizationId?: string } }) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.getSettings(req.user.id, organizationId);
|
|
}
|
|
|
|
@Get('party-search')
|
|
@ApiOperation({ summary: 'Grouped party search for cash transactions' })
|
|
searchParties(
|
|
@Query() query: PartySearchQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.searchParties(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Get('transactions')
|
|
@ApiOperation({ summary: 'Merged cash ledger (patient, partner, staff) with optional net' })
|
|
listTransactions(
|
|
@Query() query: ListPaymentsQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listTransactions(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Get('staff-income')
|
|
@ApiOperation({ summary: 'Commission jobs and earning lines for one staff month' })
|
|
staffIncome(
|
|
@Query() query: StaffIncomeQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string; language?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.staffIncome(
|
|
req.user.id,
|
|
organizationId,
|
|
query,
|
|
req.user.language,
|
|
);
|
|
}
|
|
|
|
@Get('party-report')
|
|
@ApiOperation({ summary: 'Unified debit/credit report for one patient, staff member, or org' })
|
|
partyReport(
|
|
@Query() query: PartyReportQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.partyReport(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Put('cases/:labCaseId/amount')
|
|
@ApiOperation({ summary: 'Set the destination lab fee for a case' })
|
|
setCaseBilledAmount(
|
|
@Param('labCaseId', ParseUUIDPipe) labCaseId: string,
|
|
@Body() dto: UpdateObligationAmountDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.setCaseBilledAmount(
|
|
req.user.id,
|
|
organizationId,
|
|
labCaseId,
|
|
dto.amount,
|
|
);
|
|
}
|
|
|
|
@Put('obligations/:entryId/amount')
|
|
@ApiOperation({ summary: 'Set a destination lab case obligation amount' })
|
|
updateObligationAmount(
|
|
@Param('entryId', ParseUUIDPipe) entryId: string,
|
|
@Body() dto: UpdateObligationAmountDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.updateCaseObligationAmount(
|
|
req.user.id,
|
|
organizationId,
|
|
entryId,
|
|
dto.amount,
|
|
);
|
|
}
|
|
|
|
@Get('staff-salaries')
|
|
@ApiOperation({ summary: 'Read the single staff salary sheet' })
|
|
getStaffSalarySheet(@Req() req: { user: { id: string; organizationId?: string } }) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.getStaffSalarySheet(req.user.id, organizationId);
|
|
}
|
|
|
|
@Put('staff-salaries')
|
|
@ApiOperation({ summary: 'Save the single staff salary sheet (TAB_BILLING_EDIT)' })
|
|
saveStaffSalarySheet(
|
|
@Body() dto: SaveStaffSalarySheetDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.saveStaffSalarySheet(req.user.id, organizationId, dto.lines);
|
|
}
|
|
|
|
@Get('staff-payments')
|
|
@ApiOperation({ summary: 'List staff payments' })
|
|
listStaffPayments(
|
|
@Query() query: ListPaymentsQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listStaffPayments(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Post('staff-payments')
|
|
@ApiOperation({ summary: 'Record a staff payment (TAB_BILLING_EDIT)' })
|
|
createStaffPayment(
|
|
@Body() dto: CreatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.createStaffPayment(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Put('staff-payments/:id')
|
|
@ApiOperation({ summary: 'Edit a recorded staff cash payment (TAB_BILLING_EDIT)' })
|
|
updateStaffPayment(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: UpdatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.updateStaffPayment(req.user.id, organizationId, id, dto);
|
|
}
|
|
|
|
@Get('resolved-lines')
|
|
@ApiOperation({ summary: 'Resolved fee-schedule lines for a date (billing or treatment read)' })
|
|
getResolvedLines(
|
|
@Query() query: ResolvedLinesQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.getResolvedLines(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Get('allocation-treatments')
|
|
@ApiOperation({ summary: 'Search treatments to allocate a patient payment' })
|
|
searchTreatments(
|
|
@Query() query: AllocationSearchQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.searchTreatmentsForAllocation(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Get('allocation-cases')
|
|
@ApiOperation({ summary: 'Search cases to allocate a partner payment' })
|
|
searchCases(
|
|
@Query() query: AllocationSearchQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.searchCasesForAllocation(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Get('patient-payments')
|
|
@ApiOperation({ summary: 'List patient payments (clinic)' })
|
|
listPatientPayments(
|
|
@Query() query: ListPaymentsQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listPatientPayments(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Post('patient-payments')
|
|
@ApiOperation({ summary: 'Record a patient payment (clinic, TAB_BILLING_EDIT)' })
|
|
createPatientPayment(
|
|
@Body() dto: CreatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.createPatientPayment(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Put('patient-payments/:id')
|
|
@ApiOperation({ summary: 'Edit a recorded patient cash receipt (TAB_BILLING_EDIT)' })
|
|
updatePatientPayment(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: UpdatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.updatePatientPayment(req.user.id, organizationId, id, dto);
|
|
}
|
|
|
|
@Get('partner-payments')
|
|
@ApiOperation({ summary: 'List clinic-lab partner payments' })
|
|
listPartnerPayments(
|
|
@Query() query: ListPaymentsQueryDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.listPartnerPayments(req.user.id, organizationId, query);
|
|
}
|
|
|
|
@Post('lab-price-quote')
|
|
@ApiOperation({ summary: 'Preview a linked lab fee for the current prosthesis plan' })
|
|
quoteLabPrice(
|
|
@Body() dto: LabPriceQuoteDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.quoteLabPrice(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Post('outsource-price-quote')
|
|
@ApiOperation({ summary: 'Preview the destination lab fee for an outsource' })
|
|
quoteOutsource(
|
|
@Body() dto: OutsourceQuoteDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.quoteOutsource(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Post('partner-payments')
|
|
@ApiOperation({ summary: 'Record a clinic-lab payment (TAB_BILLING_EDIT)' })
|
|
createPartnerPayment(
|
|
@Body() dto: CreatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.createPartnerPayment(req.user.id, organizationId, dto);
|
|
}
|
|
|
|
@Put('partner-payments/:id')
|
|
@ApiOperation({ summary: 'Edit a recorder-owned partner cash payment (TAB_BILLING_EDIT)' })
|
|
updatePartnerPayment(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: UpdatePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.updatePartnerPayment(req.user.id, organizationId, id, dto);
|
|
}
|
|
|
|
@Post('partner-payments/:id/acknowledge')
|
|
@ApiOperation({ summary: 'Accept or decline a partner payment as the other organization' })
|
|
acknowledgePartnerPayment(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: AcknowledgePaymentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.billingService.getOrganizationIdFromUser(req.user);
|
|
return this.billingService.acknowledgePartnerPayment(
|
|
req.user.id,
|
|
organizationId,
|
|
id,
|
|
dto.decision,
|
|
dto.expectedUpdatedAt,
|
|
);
|
|
}
|
|
}
|