diff --git a/apps/Backend/src/routes/insuranceStatusCCAClaim.ts b/apps/Backend/src/routes/insuranceStatusCCAClaim.ts index 21fca66e..52441163 100644 --- a/apps/Backend/src/routes/insuranceStatusCCAClaim.ts +++ b/apps/Backend/src/routes/insuranceStatusCCAClaim.ts @@ -2,6 +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"; const router = Router(); const upload = multer({ storage: multer.memoryStorage() }); @@ -59,6 +60,11 @@ router.post( bufferBase64: f.buffer.toString("base64"), mimetype: f.mimetype, })); + // Include attachments already saved on the appointment (X-rays etc.). Skipped for + // chatbot-driven submissions, which already send every intended file. + if (!claimData.skipAppointmentAttachmentMerge) { + await appendAppointmentFiles(filesForQueue, claimData.appointmentId); + } const enrichedPayload = { claim: { diff --git a/apps/Frontend/src/components/claims/claim-form.tsx b/apps/Frontend/src/components/claims/claim-form.tsx index 012485cc..999b3516 100755 --- a/apps/Frontend/src/components/claims/claim-form.tsx +++ b/apps/Frontend/src/components/claims/claim-form.tsx @@ -1183,11 +1183,9 @@ export function ClaimForm({ const appointmentIdToUse = appointmentId ?? null; const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f; + // Save uploaded files to disk (uploads/patients//) and record their paths const claimFilesMeta: ClaimFileMeta[] = mergeWithExistingAttachments( - (uploadedFiles || []).map((file) => ({ - filename: file.name, - mimeType: file.type, - })), + uploadedFiles?.length ? await uploadAttachmentsToLocalFolder(uploadedFiles) : [], ); const selectedNpiProviderId = npiProvider?.npiNumber @@ -1216,6 +1214,7 @@ export function ClaimForm({ appointmentId: appointmentIdToUse, insuranceSiteKey: "CCA", claimId: createdClaim.id, + skipAppointmentAttachmentMerge: !!autoSubmit && !!uploadedFiles?.length, }); onClose();