feat: Claim Again button in Claim/Preauth Details reopens the claim form prefilled from that claim
Copies service date, procedure lines, remarks, missing teeth, staff, NPI provider, insurance type and attachments; submitting through an insurance button creates a new claim. MH/CCA routes read carried attachments from disk by ClaimFile id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import { forwardToSeleniumClaimPreAuthAgent } from "../services/seleniumInsuranc
|
||||
import { formatDobForAgent } from "../utils/dateUtils";
|
||||
import { ADA_PAYERS, adaPayerKeyForProvider, buildAdaClaimPdf } from "../services/adaClaimForm";
|
||||
import { backupScreenshots } from "../utils/screenshotBackup";
|
||||
import { appendAppointmentFiles, autoLinkAppointmentFiles } from "../utils/appointmentAttachments";
|
||||
import { appendAppointmentFiles, appendClaimFilesById, autoLinkAppointmentFiles } from "../utils/appointmentAttachments";
|
||||
import { buildPreAuthClaimDetails } from "../utils/preAuthClaim";
|
||||
|
||||
const router = Router();
|
||||
@@ -378,6 +378,7 @@ router.post(
|
||||
if (!claimData.skipAppointmentAttachmentMerge) {
|
||||
await appendAppointmentFiles(filesForQueue, claimData.appointmentId);
|
||||
}
|
||||
await appendClaimFilesById(filesForQueue, claimData.carriedClaimFileIds);
|
||||
|
||||
const job = await seleniumQueue.add("claim-submit", {
|
||||
jobType: "claim-submit",
|
||||
@@ -580,6 +581,7 @@ router.post(
|
||||
|
||||
// Include X-rays etc. already attached to the appointment
|
||||
await appendAppointmentFiles(filesForQueue, claimData.appointmentId);
|
||||
await appendClaimFilesById(filesForQueue, claimData.carriedClaimFileIds);
|
||||
|
||||
const job = await seleniumQueue.add("claim-pre-auth", {
|
||||
jobType: "claim-pre-auth",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Request, Response } from "express";
|
||||
import { storage } from "../storage";
|
||||
import { enqueueSeleniumJob } from "../queue/jobRunner";
|
||||
import multer from "multer";
|
||||
import { appendAppointmentFiles } from "../utils/appointmentAttachments";
|
||||
import { appendAppointmentFiles, appendClaimFilesById } from "../utils/appointmentAttachments";
|
||||
|
||||
const router = Router();
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
@@ -65,6 +65,7 @@ router.post(
|
||||
if (!claimData.skipAppointmentAttachmentMerge) {
|
||||
await appendAppointmentFiles(filesForQueue, claimData.appointmentId);
|
||||
}
|
||||
await appendClaimFilesById(filesForQueue, claimData.carriedClaimFileIds);
|
||||
|
||||
const enrichedPayload = {
|
||||
claim: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Request, Response } from "express";
|
||||
import { storage } from "../storage";
|
||||
import { enqueueSeleniumJob } from "../queue/jobRunner";
|
||||
import multer from "multer";
|
||||
import { appendAppointmentFiles, autoLinkAppointmentFiles } from "../utils/appointmentAttachments";
|
||||
import { appendAppointmentFiles, appendClaimFilesById, autoLinkAppointmentFiles } from "../utils/appointmentAttachments";
|
||||
import { buildPreAuthClaimDetails } from "../utils/preAuthClaim";
|
||||
|
||||
const router = Router();
|
||||
@@ -59,6 +59,7 @@ router.post(
|
||||
}));
|
||||
// Include X-rays etc. already attached to the appointment
|
||||
await appendAppointmentFiles(filesForQueue, claimData.appointmentId);
|
||||
await appendClaimFilesById(filesForQueue, claimData.carriedClaimFileIds);
|
||||
|
||||
const enrichedPayload = {
|
||||
claim: {
|
||||
|
||||
@@ -26,6 +26,32 @@ export async function appendAppointmentFiles(
|
||||
}
|
||||
}
|
||||
|
||||
// "Claim Again": include attachments of an earlier claim, looked up by ClaimFile id
|
||||
// (the path comes from the database, never from the request) and read from disk.
|
||||
export async function appendClaimFilesById(
|
||||
filesForQueue: QueuedFile[],
|
||||
claimFileIds: unknown,
|
||||
): Promise<void> {
|
||||
if (!Array.isArray(claimFileIds)) return;
|
||||
const ids = claimFileIds.map(Number).filter((id) => Number.isInteger(id) && id > 0);
|
||||
if (!ids.length) return;
|
||||
const { prisma: db } = await import("@repo/db/client");
|
||||
const rows = await db.claimFile.findMany({ where: { id: { in: ids } } });
|
||||
const seenNames = new Set(filesForQueue.map((f) => f.originalname));
|
||||
const root = path.resolve(process.cwd());
|
||||
for (const f of rows) {
|
||||
if (!f.filePath || seenNames.has(f.filename)) continue;
|
||||
const absPath = path.resolve(root, `.${path.sep}${f.filePath.replace(/^[\\/]+/, "")}`);
|
||||
if (!absPath.startsWith(root + path.sep) || !fs.existsSync(absPath)) continue;
|
||||
filesForQueue.push({
|
||||
originalname: f.filename,
|
||||
bufferBase64: fs.readFileSync(absPath).toString("base64"),
|
||||
mimetype: f.mimeType || "application/octet-stream",
|
||||
});
|
||||
seenNames.add(f.filename);
|
||||
}
|
||||
}
|
||||
|
||||
// Links AppointmentFile records to a claim as ClaimFile records (dedup by filename).
|
||||
// Called after claim create or update so files saved in the procedures form always appear.
|
||||
export async function autoLinkAppointmentFiles(claimId: number, appointmentId: number | null | undefined) {
|
||||
|
||||
Reference in New Issue
Block a user